-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix non-iteratrable input of yieldEach #455
Open
Yi2255
wants to merge
1
commit into
googleprojectzero:main
Choose a base branch
from
Yi2255:fix-yieldEachInput
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -769,13 +769,13 @@ public let CodeGenerators: [CodeGenerator] = [ | |
// These are "typically" used as arguments, so we don't directly generate a call operation here. | ||
}, | ||
|
||
RecursiveCodeGenerator("GeneratorFunctionGenerator") { b in | ||
RecursiveCodeGenerator("GeneratorFunctionGenerator", inputs: .preferred(.iterable)) { b, it in | ||
let f = b.buildGeneratorFunction(with: b.randomParameters(), isStrict: probability(0.1)) { _ in | ||
b.buildRecursive() | ||
if probability(0.5) { | ||
b.yield(b.randomVariable()) | ||
} else { | ||
b.yieldEach(b.randomVariable()) | ||
b.yieldEach(b.buildIteratorVariable(b, it)) | ||
} | ||
b.doReturn(b.randomVariable()) | ||
} | ||
|
@@ -800,14 +800,14 @@ public let CodeGenerators: [CodeGenerator] = [ | |
// These are "typically" used as arguments, so we don't directly generate a call operation here. | ||
}, | ||
|
||
RecursiveCodeGenerator("AsyncGeneratorFunctionGenerator") { b in | ||
RecursiveCodeGenerator("AsyncGeneratorFunctionGenerator", inputs: .preferred(.iterable)) { b, it in | ||
let f = b.buildAsyncGeneratorFunction(with: b.randomParameters(), isStrict: probability(0.1)) { _ in | ||
b.buildRecursive() | ||
b.await(b.randomVariable()) | ||
if probability(0.5) { | ||
b.yield(b.randomVariable()) | ||
} else { | ||
b.yieldEach(b.randomVariable()) | ||
b.yieldEach(b.buildIteratorVariable(b, it)) | ||
} | ||
b.doReturn(b.randomVariable()) | ||
} | ||
|
@@ -1085,7 +1085,7 @@ public let CodeGenerators: [CodeGenerator] = [ | |
} | ||
} else { | ||
// TODO only do this when the value is iterable? | ||
b.yieldEach(val) | ||
b.yieldEach(b.buildIteratorVariable(b, val)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here it would make sense to split this into two generators:
That way it's easy to guarantee that we get a .iterable. |
||
} | ||
}, | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in the AsyncGeneratorFunctionGenerator, I would recommend doing this differently. For one, I think we would usually prefer to yield something that we create in this function (i.e. in the
buildRecursive()
call), but that's not possible if theit
comes from the outside. I would probably recommend just doing something like this:This will then cause us to always yield a plain array, but we have the other CodeGenerator below for yielding other stuff. Also the InputMutator will quickly shuffle this around to yield from other things.