Skip to content

Commit

Permalink
Fix non-iteratrable input of yieldEach (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi2255 authored Nov 15, 2024
1 parent d6f77d7 commit 0f52182
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public let codeGeneratorWeights = [
"AsyncGeneratorFunctionGenerator": 1,
"ConstructorGenerator": 5,
"SubroutineReturnGenerator": 3,
"YieldGenerator": 2,
"YieldGenerator": 5,
"YieldEachGenerator": 5,
"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

0 comments on commit 0f52182

Please sign in to comment.