Skip to content
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 #463

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public let codeGeneratorWeights = [
"AsyncArrowFunctionGenerator": 1,
"AsyncGeneratorFunctionGenerator": 1,
"ConstructorGenerator": 5,
"SubroutineReturnGenerator": 3,
"YieldGenerator": 2,
"SubroutineReturnGenerator": 5,
saelo marked this conversation as resolved.
Show resolved Hide resolved
"YieldGenerator": 5,
"YieldEachGenerator": 2,
"AwaitGenerator": 2,
"PropertyRetrievalGenerator": 20,
"PropertyAssignmentGenerator": 20,
Expand Down
24 changes: 14 additions & 10 deletions Sources/Fuzzilli/CodeGen/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ public let CodeGenerators: [CodeGenerator] = [
if probability(0.5) {
b.yield(b.randomVariable())
} else {
b.yieldEach(b.randomVariable())
let randomVariables = b.randomVariables(n: Int.random(in: 1...5))
let array = b.createArray(with: randomVariables)
b.yieldEach(array)
}
b.doReturn(b.randomVariable())
}
Expand Down Expand Up @@ -807,7 +809,9 @@ public let CodeGenerators: [CodeGenerator] = [
if probability(0.5) {
b.yield(b.randomVariable())
} else {
b.yieldEach(b.randomVariable())
let randomVariables = b.randomVariables(n: Int.random(in: 1...5))
let array = b.createArray(with: randomVariables)
b.yieldEach(array)
}
b.doReturn(b.randomVariable())
}
Expand Down Expand Up @@ -1077,18 +1081,18 @@ public let CodeGenerators: [CodeGenerator] = [

CodeGenerator("YieldGenerator", inContext: .generatorFunction, inputs: .one) { b, val in
assert(b.context.contains(.generatorFunction))
if probability(0.5) {
if probability(0.9) {
b.yield(val)
} else {
b.yield()
}
if probability(0.9) {
b.yield(val)
} else {
// TODO only do this when the value is iterable?
b.yieldEach(val)
b.yield()
}
},

CodeGenerator("YieldEachGenerator", inContext: .generatorFunction, inputs: .required(.iterable)) { b, val in
assert(b.context.contains(.generatorFunction))
b.yieldEach(val)
},

CodeGenerator("AwaitGenerator", inContext: .asyncFunction, inputs: .one) { b, val in
assert(b.context.contains(.asyncFunction))
b.await(val)
Expand Down