Skip to content

Commit 53d1197

Browse files
rherouart-collabv8-internal-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[js] Refactor Loops to mutualize common code.
Bug: 515363087 Change-Id: I41e4b487ee08dbf7da22959c6c1d08e4099a6ad4 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9317282 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Raphaël Hérouart <rherouart@google.com> Auto-Submit: Raphaël Hérouart <rherouart@google.com>
1 parent fd0e618 commit 53d1197

25 files changed

Lines changed: 1157 additions & 1899 deletions

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 8 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,97 +4120,19 @@ public class ProgramBuilder {
41204120
emit(EndForLoop())
41214121
}
41224122

4123-
public func buildForInLoop(_ obj: Variable, _ body: (Variable, Variable) -> Void) {
4124-
let instr = emit(BeginForInLoop(), withInputs: [obj])
4125-
body(instr.innerOutput(0), instr.innerOutput(1))
4126-
emit(EndForInLoop())
4127-
}
4128-
4129-
public func buildForInLoop(_ obj: Variable, _ body: (Variable) -> Void) {
4130-
buildForInLoop(obj) { i, _ in body(i) }
4131-
}
4132-
4133-
public func buildForOfLoop(_ obj: Variable, _ body: (Variable, Variable) -> Void) {
4134-
let instr = emit(BeginForOfLoop(), withInputs: [obj])
4135-
body(instr.innerOutput(0), instr.innerOutput(1))
4136-
emit(EndForOfLoop())
4137-
}
4138-
4139-
public func buildForAwaitOfLoop(_ obj: Variable, _ body: (Variable, Variable) -> Void) {
4140-
let instr = emit(BeginForAwaitOfLoop(), withInputs: [obj])
4141-
body(instr.innerOutput(0), instr.innerOutput(1))
4142-
emit(EndForOfLoop())
4143-
}
4144-
4145-
public func buildForOfLoop(_ obj: Variable, _ body: (Variable) -> Void) {
4146-
buildForOfLoop(obj) { i, _ in body(i) }
4147-
}
4148-
4149-
public func buildForAwaitOfLoop(_ obj: Variable, _ body: (Variable) -> Void) {
4150-
buildForAwaitOfLoop(obj) { i, _ in body(i) }
4151-
}
4152-
4153-
public func buildForOfLoop(
4154-
_ obj: Variable, selecting indices: [Int64], hasRestElement: Bool = false,
4155-
_ body: ([Variable], Variable) -> Void
4156-
) {
4157-
let instr = emit(
4158-
BeginForOfLoopWithDestruct(indices: indices, hasRestElement: hasRestElement),
4159-
withInputs: [obj])
4160-
let label = instr.innerOutputs.last!
4161-
let vars = instr.innerOutputs.dropLast()
4162-
body(Array(vars), label)
4163-
emit(EndForOfLoop())
4164-
}
4165-
4166-
public func buildForOfLoop(
4167-
_ obj: Variable, selecting indices: [Int64], hasRestElement: Bool = false,
4168-
_ body: ([Variable]) -> Void
4169-
) {
4170-
buildForOfLoop(obj, selecting: indices, hasRestElement: hasRestElement) { vars, _ in
4171-
body(vars)
4172-
}
4173-
}
4174-
4175-
public func buildForAwaitOfLoop(
4176-
_ obj: Variable, selecting indices: [Int64], hasRestElement: Bool = false,
4123+
public func buildForInOfLoop(
4124+
_ obj: Variable,
4125+
type: ForInOfLoopType,
4126+
isAsync: Bool,
4127+
header: LoopHeader,
41774128
_ body: ([Variable], Variable) -> Void
41784129
) {
4179-
let instr = emit(
4180-
BeginForAwaitOfLoopWithDestruct(indices: indices, hasRestElement: hasRestElement),
4181-
withInputs: [obj])
4130+
let beginOp = ForLoop(type: type, isAsync: isAsync, header: header)
4131+
let instr = emit(beginOp, withInputs: [obj])
41824132
let label = instr.innerOutputs.last!
41834133
let vars = instr.innerOutputs.dropLast()
41844134
body(Array(vars), label)
4185-
emit(EndForOfLoop())
4186-
}
4187-
4188-
public func buildForOfLoop(
4189-
_ obj: Variable, selectingProperties properties: [String], hasRestElement: Bool = false,
4190-
_ body: ([Variable], Variable) -> Void
4191-
) {
4192-
let instr = emit(
4193-
BeginForOfLoopWithObjectDestruct(
4194-
properties: properties, hasRestElement: hasRestElement),
4195-
withInputs: [obj])
4196-
let label = instr.innerOutputs.last!
4197-
let vars = instr.innerOutputs.dropLast()
4198-
body(Array(vars), label)
4199-
emit(EndForOfLoop())
4200-
}
4201-
4202-
public func buildForAwaitOfLoop(
4203-
_ obj: Variable, selectingProperties properties: [String], hasRestElement: Bool = false,
4204-
_ body: ([Variable], Variable) -> Void
4205-
) {
4206-
let instr = emit(
4207-
BeginForAwaitOfLoopWithObjectDestruct(
4208-
properties: properties, hasRestElement: hasRestElement),
4209-
withInputs: [obj])
4210-
let label = instr.innerOutputs.last!
4211-
let vars = instr.innerOutputs.dropLast()
4212-
body(Array(vars), label)
4213-
emit(EndForOfLoop())
4135+
emit(EndForLoop())
42144136
}
42154137

42164138
public func buildRepeatLoop(n numIterations: Int, _ body: (Variable, Variable) -> Void) {

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public let codeGeneratorWeights = [
186186
"ForInLoopGenerator": 10,
187187
"ForOfLoopGenerator": 10,
188188
"ForAwaitOfLoopGenerator": 10,
189-
"ForOfWithDestructLoopGenerator": 3,
190-
"ForAwaitOfWithDestructLoopGenerator": 3,
189+
"ForOfWithArrayDestructLoopGenerator": 3,
190+
"ForAwaitOfWithArrayDestructLoopGenerator": 3,
191191
"ForOfWithObjectDestructLoopGenerator": 3,
192192
"ForAwaitOfWithObjectDestructLoopGenerator": 3,
193193
"RepeatLoopGenerator": 10,

0 commit comments

Comments
 (0)