Skip to content

Commit

Permalink
Small ProgramBuilder cleanups
Browse files Browse the repository at this point in the history
Mostly removing parameter names where they are obvious or renaming them.
  • Loading branch information
Samuel Groß committed Oct 17, 2022
1 parent fba3900 commit 489b3a9
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 87 deletions.
42 changes: 21 additions & 21 deletions Sources/Fuzzilli/Core/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,55 +127,55 @@ public let CodeGenerators: [CodeGenerator] = [
CodeGenerator("PlainFunctionGenerator") { b in
b.buildPlainFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.doReturn(value: b.randVar())
b.doReturn(b.randVar())
}
},

CodeGenerator("ArrowFunctionGenerator") { b in
b.buildArrowFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.doReturn(value: b.randVar())
b.doReturn(b.randVar())
}
},

CodeGenerator("GeneratorFunctionGenerator") { b in
b.buildGeneratorFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
if probability(0.5) {
b.yield(value: b.randVar())
b.yield(b.randVar())
} else {
b.yieldEach(value: b.randVar())
b.yieldEach(b.randVar())
}
b.doReturn(value: b.randVar())
b.doReturn(b.randVar())
}
},

CodeGenerator("AsyncFunctionGenerator") { b in
b.buildAsyncFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.await(value: b.randVar())
b.doReturn(value: b.randVar())
b.await(b.randVar())
b.doReturn(b.randVar())
}
},

CodeGenerator("AsyncArrowFunctionGenerator") { b in
b.buildAsyncArrowFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.await(value: b.randVar())
b.doReturn(value: b.randVar())
b.await(b.randVar())
b.doReturn(b.randVar())
}
},

CodeGenerator("AsyncGeneratorFunctionGenerator") { b in
b.buildAsyncGeneratorFunction(with: b.generateFunctionParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.await(value: b.randVar())
b.await(b.randVar())
if probability(0.5) {
b.yield(value: b.randVar())
b.yield(b.randVar())
} else {
b.yieldEach(value: b.randVar())
b.yieldEach(b.randVar())
}
b.doReturn(value: b.randVar())
b.doReturn(b.randVar())
}
},

Expand Down Expand Up @@ -260,7 +260,7 @@ public let CodeGenerators: [CodeGenerator] = [
let type = b.typeof(val)
// Also generate a comparison here, since that's probably the only interesting thing you can do with the result.
let rhs = b.loadString(chooseUniform(from: JavaScriptEnvironment.jsTypeNames))
b.compare(type, rhs, with: .strictEqual)
b.compare(type, with: rhs, using: .strictEqual)
},

CodeGenerator("InstanceOfGenerator", inputs: (.anything, .function() | .constructor())) { b, val, cls in
Expand Down Expand Up @@ -348,21 +348,21 @@ public let CodeGenerators: [CodeGenerator] = [

CodeGenerator("SubroutineReturnGenerator", inContext: .subroutine, input: .anything) { b, val in
assert(b.context.contains(.subroutine))
b.doReturn(value: val)
b.doReturn(val)
},

CodeGenerator("YieldGenerator", inContext: .generatorFunction, input: .anything) { b, val in
assert(b.context.contains(.generatorFunction))
if probability(0.5) {
b.yield(value: val)
b.yield(val)
} else {
b.yieldEach(value: val)
b.yieldEach(val)
}
},

CodeGenerator("AwaitGenerator", inContext: .asyncFunction, input: .anything) { b, val in
assert(b.context.contains(.asyncFunction))
b.await(value: val)
b.await(val)
},

CodeGenerator("UnaryOperationGenerator", input: .anything) { b, val in
Expand Down Expand Up @@ -451,11 +451,11 @@ public let CodeGenerators: [CodeGenerator] = [
},

CodeGenerator("ComparisonGenerator", inputs: (.anything, .anything)) { b, lhs, rhs in
b.compare(lhs, rhs, with: chooseUniform(from: allComparators))
b.compare(lhs, with: rhs, using: chooseUniform(from: allComparators))
},

CodeGenerator("ConditionalOperationGenerator", inputs: (.anything, .anything)) { b, lhs, rhs in
let condition = b.compare(lhs, rhs, with: chooseUniform(from: allComparators))
let condition = b.compare(lhs, with: rhs, using: chooseUniform(from: allComparators))
b.conditional(condition, lhs, rhs)
},

Expand Down Expand Up @@ -554,7 +554,7 @@ public let CodeGenerators: [CodeGenerator] = [
},

CodeGenerator("CompareWithIfElseGenerator", inputs: (.anything, .anything)) { b, lhs, rhs in
let cond = b.compare(lhs, rhs, with: chooseUniform(from: allComparators))
let cond = b.compare(lhs, with: rhs, using: chooseUniform(from: allComparators))
b.buildIfElse(cond, ifBody: {
b.buildRecursive()
}, elseBody: {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Fuzzilli/Core/ProgramBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public class ProgramBuilder {
let signature = type.signature ?? Signature(withParameterCount: Int.random(in: 2...5), hasRestParam: probability(0.1))
return buildPlainFunction(with: .signature(signature), isStrict: probability(0.1)) { _ in
buildRecursive()
doReturn(value: randVar())
doReturn(randVar())
}
}
if type.Is(.regexp) || type.Is(fuzzer.environment.regExpType) {
Expand Down Expand Up @@ -1299,21 +1299,21 @@ public class ProgramBuilder {
return instr.output
}

public func doReturn(value: Variable) {
public func doReturn(_ value: Variable) {
emit(Return(), withInputs: [value])
}

@discardableResult
public func yield(value: Variable) -> Variable {
public func yield(_ value: Variable) -> Variable {
return emit(Yield(), withInputs: [value]).output
}

public func yieldEach(value: Variable) {
public func yieldEach(_ value: Variable) {
emit(YieldEach(), withInputs: [value])
}

@discardableResult
public func await(value: Variable) -> Variable {
public func await(_ value: Variable) -> Variable {
return emit(Await(), withInputs: [value]).output
}

Expand Down Expand Up @@ -1405,7 +1405,7 @@ public class ProgramBuilder {
}

@discardableResult
public func compare(_ lhs: Variable, _ rhs: Variable, with comparator: Comparator) -> Variable {
public func compare(_ lhs: Variable, with rhs: Variable, using comparator: Comparator) -> Variable {
return emit(Compare(comparator), withInputs: [lhs, rhs]).output
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Core/ProgramTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public let ProgramTemplates = [

let index = b.genIndex()
b.loadElement(index, of: array)
b.doReturn(value: b.randVar())
b.doReturn(b.randVar())
}

// TODO: check if these are actually different, or if
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/FuzzIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public struct Instruction {
return op.attributes.contains(.isJump)
}

/// Whether this instruction propagates contexts.
/// Whether this block start instruction propagates the outer context into the newly started block.
/// See Operation.Attributes.propagatesSurroundingContext.
public var propagatesSurroundingContext: Bool {
assert(isBlockStart)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/FuzzIL/JsOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ class SwitchBreak: JsOperation {
/// Internal operations.
///
/// These can be used for internal fuzzer operations but will not appear in the corpus.
class InternalOperation: Operation {
class InternalOperation: JsOperation {
init(numInputs: Int) {
super.init(numInputs: numInputs, numOutputs: 0, attributes: [.isInternal])
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Fuzzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public class Fuzzer {
let y = b.loadProperty("y", of: params[0])
let s = b.binary(x, y, with: .Add)
let p = b.binary(s, params[1], with: .Mul)
b.doReturn(value: p)
b.doReturn(p)
}

b.buildForLoop(b.loadInt(0), .lessThan, b.loadInt(1000), .Add, b.loadInt(1)) { i in
Expand Down
16 changes: 8 additions & 8 deletions Sources/Fuzzilli/Mutators/ExplorationMutator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ public class ExplorationMutator: Mutator {
"SIGNED_RIGHT_SHIFT": Handler(expectedInputs: 1) { b, v, inputs in b.binary(v, inputs[0], with: .RShift) },
"UNSIGNED_RIGHT_SHIFT": Handler(expectedInputs: 1) { b, v, inputs in b.binary(v, inputs[0], with: .UnRShift) },
"BITWISE_NOT": Handler(expectedInputs: 0) { b, v, inputs in b.unary(.BitwiseNot, v) },
"COMPARE_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .equal) },
"COMPARE_STRICT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .strictEqual) },
"COMPARE_NOT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .notEqual) },
"COMPARE_STRICT_NOT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .strictNotEqual) },
"COMPARE_GREATER_THAN": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .greaterThan) },
"COMPARE_LESS_THAN": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .greaterThanOrEqual) },
"COMPARE_GREATER_THAN_OR_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .lessThan) },
"COMPARE_LESS_THAN_OR_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, inputs[0], with: .lessThanOrEqual) },
"COMPARE_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .equal) },
"COMPARE_STRICT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .strictEqual) },
"COMPARE_NOT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .notEqual) },
"COMPARE_STRICT_NOT_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .strictNotEqual) },
"COMPARE_GREATER_THAN": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .greaterThan) },
"COMPARE_LESS_THAN": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .greaterThanOrEqual) },
"COMPARE_GREATER_THAN_OR_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .lessThan) },
"COMPARE_LESS_THAN_OR_EQUAL": Handler(expectedInputs: 1) { b, v, inputs in b.compare(v, with: inputs[0], using: .lessThanOrEqual) },
"TEST_IS_NAN": Handler(expectedInputs: 0) { b, v, inputs in
let Number = b.reuseOrLoadBuiltin("Number")
b.callMethod("isNaN", on: v, withArgs: [])
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Util/VariableSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public struct VariableSet: Hashable, Codable {
return result
}

/// Returns true if this set and provided set have no variables in common.
/// Returns true if this set and the provided set have no variables in common.
public func isDisjoint(with other: VariableSet) -> Bool {
for (i, w) in other.words.enumerated() {
if i < words.count && words[i] & w != 0 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/FuzzilliCli/Profiles/V8Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fileprivate let MapTransitionsTemplate = ProgramTemplate("MapTransitionsTemplate
// Now create a bunch of objects to operate on and one function that constructs a new object.
b.buildPlainFunction(with: .parameters(n: 0)) { args in
let o = b.createObject(with: ["a": intVal])
b.doReturn(value: o)
b.doReturn(o)
}
for _ in 0..<3 {
objects.append(b.createObject(with: ["a": intVal]))
Expand All @@ -130,7 +130,7 @@ fileprivate let MapTransitionsTemplate = ProgramTemplate("MapTransitionsTemplate
b.buildPlainFunction(with: .signature(sig)) { params in
objects += params
b.buildRecursive()
b.doReturn(value: b.randVar(ofType: objType)!)
b.doReturn(b.randVar(ofType: objType)!)
}
objects.removeLast(objects.count - prevSize)
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/FuzzilliTests/AnalyzerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AnalyzerTests: XCTestCase {
XCTAssertEqual(b.context, [.javascript, .subroutine])
}
XCTAssertEqual(b.context, [.javascript, .subroutine, .asyncFunction])
b.await(value: v3)
b.await(v3)
b.buildAsyncGeneratorFunction(with: .parameters(n: 2)) { _ in
XCTAssertEqual(b.context, [.javascript, .subroutine, .asyncFunction, .generatorFunction])
}
Expand Down Expand Up @@ -180,26 +180,26 @@ class AnalyzerTests: XCTestCase {
b.buildIfElse(args[0], ifBody: {
XCTAssertEqual(b.context, [.javascript, .subroutine, .loop])
let v = b.binary(args[0], args[1], with: .Mul)
b.doReturn(value: v)
b.doReturn(v)
}, elseBody: {
XCTAssertEqual(b.context, [.javascript, .subroutine, .loop])
b.doReturn(value: args[2])
b.doReturn(args[2])
})
}
b.blockStatement {
XCTAssertEqual(b.context, [.javascript, .subroutine])
b.buildTryCatchFinally(tryBody: {
XCTAssertEqual(b.context, [.javascript, .subroutine])
let v = b.binary(args[0], args[1], with: .Mul)
b.doReturn(value: v)
b.doReturn(v)
}, catchBody: { _ in
XCTAssertEqual(b.context, [.javascript, .subroutine])
let v4 = b.createObject(with: ["a" : b.loadInt(1337)])
b.reassign(args[0], to: v4)
}, finallyBody: {
XCTAssertEqual(b.context, [.javascript, .subroutine])
let v = b.binary(args[0], args[1], with: .Add)
b.doReturn(value: v)
b.doReturn(v)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/FuzzilliTests/JSTyperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class JSTyperTests: XCTestCase {

XCTAssertEqual(b.type(of: params[1]), .float)

b.doReturn(value: b.loadString("foobar"))
b.doReturn(b.loadString("foobar"))
}
}
XCTAssertEqual(b.type(of: superclass), .constructor([.integer] => superType))
Expand Down
Loading

0 comments on commit 489b3a9

Please sign in to comment.