Skip to content

Commit 7e5724c

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Simplify Table.get/set
The TableType will need to be adapted for tracking wasm-gc signatures. I just couldn't find a good reason why we'd need to store the TableType on Table.get and Table.set? Bug: 445356784 Change-Id: Ia115d287b27cc18f52a48ddce25b897f1a19b293 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9123736 Reviewed-by: Manos Koukoutos <manoskouk@google.com> Commit-Queue: Matthias Liedtke <mliedtke@google.com>
1 parent 794dda8 commit 7e5724c

6 files changed

Lines changed: 22 additions & 168 deletions

File tree

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,14 +3747,14 @@ public class ProgramBuilder {
37473747
public func wasmTableGet(tableRef: Variable, idx: Variable) -> Variable {
37483748
let tableType = b.type(of: tableRef)
37493749
let offsetType = tableType.wasmTableType!.isTable64 ? ILType.wasmi64 : ILType.wasmi32
3750-
return b.emit(WasmTableGet(tableType: tableType), withInputs: [tableRef, idx], types: [tableType, offsetType]).output
3750+
return b.emit(WasmTableGet(), withInputs: [tableRef, idx], types: [tableType, offsetType]).output
37513751
}
37523752

37533753
public func wasmTableSet(tableRef: Variable, idx: Variable, to value: Variable) {
37543754
let tableType = b.type(of: tableRef)
37553755
let elementType = tableType.wasmTableType!.elementType
37563756
let offsetType = tableType.wasmTableType!.isTable64 ? ILType.wasmi64 : ILType.wasmi32
3757-
b.emit(WasmTableSet(tableType: tableType), withInputs: [tableRef, idx, value], types: [tableType, offsetType, elementType])
3757+
b.emit(WasmTableSet(), withInputs: [tableRef, idx, value], types: [tableType, offsetType, elementType])
37583758
}
37593759

37603760
@discardableResult

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,24 +1258,10 @@ extension Instruction: ProtobufConvertible {
12581258
$0.wasmStoreGlobal = Fuzzilli_Protobuf_WasmStoreGlobal.with {
12591259
$0.globalType = ILTypeToWasmTypeEnum(op.globalType)
12601260
}
1261-
case .wasmTableGet(let op):
1262-
$0.wasmTableGet = Fuzzilli_Protobuf_WasmTableGet.with {
1263-
$0.elementType = ILTypeToWasmTypeEnum(op.tableType.elementType)
1264-
$0.minSize = Int64(op.tableType.limits.min)
1265-
if let max = op.tableType.limits.max {
1266-
$0.maxSize = Int64(max)
1267-
}
1268-
$0.isTable64 = op.tableType.isTable64
1269-
}
1270-
case .wasmTableSet(let op):
1271-
$0.wasmTableSet = Fuzzilli_Protobuf_WasmTableSet.with {
1272-
$0.elementType = ILTypeToWasmTypeEnum(op.tableType.elementType)
1273-
$0.minSize = Int64(op.tableType.limits.min)
1274-
if let max = op.tableType.limits.max {
1275-
$0.maxSize = Int64(max)
1276-
}
1277-
$0.isTable64 = op.tableType.isTable64
1278-
}
1261+
case .wasmTableGet(_):
1262+
$0.wasmTableGet = Fuzzilli_Protobuf_WasmTableGet()
1263+
case .wasmTableSet(_):
1264+
$0.wasmTableSet = Fuzzilli_Protobuf_WasmTableSet()
12791265
case .wasmCallIndirect(let op):
12801266
$0.wasmCallIndirect = Fuzzilli_Protobuf_WasmCallIndirect.with {
12811267
$0.parameterTypes = op.signature.parameterTypes.map(ILTypeToWasmTypeEnum)
@@ -2340,14 +2326,10 @@ extension Instruction: ProtobufConvertible {
23402326
op = WasmLoadGlobal(globalType: WasmTypeEnumToILType(p.globalType))
23412327
case .wasmStoreGlobal(let p):
23422328
op = WasmStoreGlobal(globalType: WasmTypeEnumToILType(p.globalType))
2343-
case .wasmTableGet(let p):
2344-
op = WasmTableGet(tableType: .wasmTable(wasmTableType:
2345-
WasmTableType(elementType: WasmTypeEnumToILType(p.elementType),
2346-
limits: Limits(min: Int(p.minSize), max: p.hasMaxSize ? Int(p.maxSize) : nil), isTable64: p.isTable64, knownEntries: [])))
2347-
case .wasmTableSet(let p):
2348-
op = WasmTableSet(tableType: .wasmTable(wasmTableType:
2349-
WasmTableType(elementType: WasmTypeEnumToILType(p.elementType),
2350-
limits: Limits(min: Int(p.minSize), max: p.hasMaxSize ? Int(p.maxSize) : nil), isTable64: p.isTable64, knownEntries: [])))
2329+
case .wasmTableGet(_):
2330+
op = WasmTableGet()
2331+
case .wasmTableSet(_):
2332+
op = WasmTableSet()
23512333
case .wasmCallIndirect(let p):
23522334
let parameters = p.parameterTypes.map(WasmTypeEnumToILType)
23532335
let outputs = p.outputTypes.map(WasmTypeEnumToILType)

Sources/Fuzzilli/FuzzIL/JSTyper.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,11 @@ public struct JSTyper: Analyzer {
768768
case .wasmStoreGlobal(_):
769769
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
770770
dynamicObjectGroupManager.addWasmGlobal(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
771-
case .wasmTableGet(let op):
771+
case .wasmTableGet(_):
772772
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
773-
dynamicObjectGroupManager.addWasmTable(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
774-
setType(of: instr.output, to: op.tableType.elementType)
773+
let tableType = type(of: instr.input(0))
774+
dynamicObjectGroupManager.addWasmTable(withType: tableType, forDefinition: definingInstruction, forVariable: instr.input(0))
775+
setType(of: instr.output, to: tableType.wasmTableType!.elementType)
775776
case .wasmTableSet(_):
776777
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
777778
dynamicObjectGroupManager.addWasmTable(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -912,24 +912,15 @@ final class WasmStoreGlobal: WasmOperation {
912912
final class WasmTableGet: WasmOperation {
913913
override var opcode: Opcode { .wasmTableGet(self) }
914914

915-
let tableType: WasmTableType
916-
917-
init(tableType: ILType) {
918-
assert(tableType.isWasmTableType)
919-
self.tableType = tableType.wasmTableType!
920-
915+
init() {
921916
super.init(numInputs: 2, numOutputs: 1, requiredContext: [.wasmFunction])
922917
}
923918
}
924919

925920
final class WasmTableSet: WasmOperation {
926921
override var opcode: Opcode { .wasmTableSet(self) }
927922

928-
let tableType: WasmTableType
929-
930-
init(tableType: ILType) {
931-
assert(tableType.isWasmTableType)
932-
self.tableType = tableType.wasmTableType!
923+
init() {
933924
super.init(numInputs: 3, requiredContext: [.wasmFunction])
934925
}
935926
}

Sources/Fuzzilli/Protobuf/operations.pb.swift

Lines changed: 6 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,75 +4754,24 @@ public struct Fuzzilli_Protobuf_WasmStoreGlobal: Sendable {
47544754
fileprivate var _globalType: Fuzzilli_Protobuf_WasmILType? = nil
47554755
}
47564756

4757-
/// WasmTableGet and WasmTableSet need a WasmTableType as input.
47584757
public struct Fuzzilli_Protobuf_WasmTableGet: Sendable {
47594758
// SwiftProtobuf.Message conformance is added in an extension below. See the
47604759
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
47614760
// methods supported on all messages.
47624761

4763-
public var elementType: Fuzzilli_Protobuf_WasmILType {
4764-
get {_elementType ?? Fuzzilli_Protobuf_WasmILType()}
4765-
set {_elementType = newValue}
4766-
}
4767-
/// Returns true if `elementType` has been explicitly set.
4768-
public var hasElementType: Bool {self._elementType != nil}
4769-
/// Clears the value of `elementType`. Subsequent reads from it will return its default value.
4770-
public mutating func clearElementType() {self._elementType = nil}
4771-
4772-
public var minSize: Int64 = 0
4773-
4774-
public var maxSize: Int64 {
4775-
get {_maxSize ?? 0}
4776-
set {_maxSize = newValue}
4777-
}
4778-
/// Returns true if `maxSize` has been explicitly set.
4779-
public var hasMaxSize: Bool {self._maxSize != nil}
4780-
/// Clears the value of `maxSize`. Subsequent reads from it will return its default value.
4781-
public mutating func clearMaxSize() {self._maxSize = nil}
4782-
4783-
public var isTable64: Bool = false
4784-
47854762
public var unknownFields = SwiftProtobuf.UnknownStorage()
47864763

47874764
public init() {}
4788-
4789-
fileprivate var _elementType: Fuzzilli_Protobuf_WasmILType? = nil
4790-
fileprivate var _maxSize: Int64? = nil
47914765
}
47924766

47934767
public struct Fuzzilli_Protobuf_WasmTableSet: Sendable {
47944768
// SwiftProtobuf.Message conformance is added in an extension below. See the
47954769
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
47964770
// methods supported on all messages.
47974771

4798-
public var elementType: Fuzzilli_Protobuf_WasmILType {
4799-
get {_elementType ?? Fuzzilli_Protobuf_WasmILType()}
4800-
set {_elementType = newValue}
4801-
}
4802-
/// Returns true if `elementType` has been explicitly set.
4803-
public var hasElementType: Bool {self._elementType != nil}
4804-
/// Clears the value of `elementType`. Subsequent reads from it will return its default value.
4805-
public mutating func clearElementType() {self._elementType = nil}
4806-
4807-
public var minSize: Int64 = 0
4808-
4809-
public var maxSize: Int64 {
4810-
get {_maxSize ?? 0}
4811-
set {_maxSize = newValue}
4812-
}
4813-
/// Returns true if `maxSize` has been explicitly set.
4814-
public var hasMaxSize: Bool {self._maxSize != nil}
4815-
/// Clears the value of `maxSize`. Subsequent reads from it will return its default value.
4816-
public mutating func clearMaxSize() {self._maxSize = nil}
4817-
4818-
public var isTable64: Bool = false
4819-
48204772
public var unknownFields = SwiftProtobuf.UnknownStorage()
48214773

48224774
public init() {}
4823-
4824-
fileprivate var _elementType: Fuzzilli_Protobuf_WasmILType? = nil
4825-
fileprivate var _maxSize: Int64? = nil
48264775
}
48274776

48284777
public struct Fuzzilli_Protobuf_WasmTableSize: Sendable {
@@ -12732,97 +12681,37 @@ extension Fuzzilli_Protobuf_WasmStoreGlobal: SwiftProtobuf.Message, SwiftProtobu
1273212681

1273312682
extension Fuzzilli_Protobuf_WasmTableGet: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1273412683
public static let protoMessageName: String = _protobuf_package + ".WasmTableGet"
12735-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}elementType\0\u{1}minSize\0\u{1}maxSize\0\u{1}isTable64\0")
12684+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
1273612685

1273712686
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
12738-
while let fieldNumber = try decoder.nextFieldNumber() {
12739-
// The use of inline closures is to circumvent an issue where the compiler
12740-
// allocates stack space for every case branch when no optimizations are
12741-
// enabled. https://github.com/apple/swift-protobuf/issues/1034
12742-
switch fieldNumber {
12743-
case 1: try { try decoder.decodeSingularMessageField(value: &self._elementType) }()
12744-
case 2: try { try decoder.decodeSingularInt64Field(value: &self.minSize) }()
12745-
case 3: try { try decoder.decodeSingularInt64Field(value: &self._maxSize) }()
12746-
case 4: try { try decoder.decodeSingularBoolField(value: &self.isTable64) }()
12747-
default: break
12748-
}
12749-
}
12687+
// Load everything into unknown fields
12688+
while try decoder.nextFieldNumber() != nil {}
1275012689
}
1275112690

1275212691
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
12753-
// The use of inline closures is to circumvent an issue where the compiler
12754-
// allocates stack space for every if/case branch local when no optimizations
12755-
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
12756-
// https://github.com/apple/swift-protobuf/issues/1182
12757-
try { if let v = self._elementType {
12758-
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
12759-
} }()
12760-
if self.minSize != 0 {
12761-
try visitor.visitSingularInt64Field(value: self.minSize, fieldNumber: 2)
12762-
}
12763-
try { if let v = self._maxSize {
12764-
try visitor.visitSingularInt64Field(value: v, fieldNumber: 3)
12765-
} }()
12766-
if self.isTable64 != false {
12767-
try visitor.visitSingularBoolField(value: self.isTable64, fieldNumber: 4)
12768-
}
1276912692
try unknownFields.traverse(visitor: &visitor)
1277012693
}
1277112694

1277212695
public static func ==(lhs: Fuzzilli_Protobuf_WasmTableGet, rhs: Fuzzilli_Protobuf_WasmTableGet) -> Bool {
12773-
if lhs._elementType != rhs._elementType {return false}
12774-
if lhs.minSize != rhs.minSize {return false}
12775-
if lhs._maxSize != rhs._maxSize {return false}
12776-
if lhs.isTable64 != rhs.isTable64 {return false}
1277712696
if lhs.unknownFields != rhs.unknownFields {return false}
1277812697
return true
1277912698
}
1278012699
}
1278112700

1278212701
extension Fuzzilli_Protobuf_WasmTableSet: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1278312702
public static let protoMessageName: String = _protobuf_package + ".WasmTableSet"
12784-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}elementType\0\u{1}minSize\0\u{1}maxSize\0\u{1}isTable64\0")
12703+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
1278512704

1278612705
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
12787-
while let fieldNumber = try decoder.nextFieldNumber() {
12788-
// The use of inline closures is to circumvent an issue where the compiler
12789-
// allocates stack space for every case branch when no optimizations are
12790-
// enabled. https://github.com/apple/swift-protobuf/issues/1034
12791-
switch fieldNumber {
12792-
case 1: try { try decoder.decodeSingularMessageField(value: &self._elementType) }()
12793-
case 2: try { try decoder.decodeSingularInt64Field(value: &self.minSize) }()
12794-
case 3: try { try decoder.decodeSingularInt64Field(value: &self._maxSize) }()
12795-
case 4: try { try decoder.decodeSingularBoolField(value: &self.isTable64) }()
12796-
default: break
12797-
}
12798-
}
12706+
// Load everything into unknown fields
12707+
while try decoder.nextFieldNumber() != nil {}
1279912708
}
1280012709

1280112710
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
12802-
// The use of inline closures is to circumvent an issue where the compiler
12803-
// allocates stack space for every if/case branch local when no optimizations
12804-
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
12805-
// https://github.com/apple/swift-protobuf/issues/1182
12806-
try { if let v = self._elementType {
12807-
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
12808-
} }()
12809-
if self.minSize != 0 {
12810-
try visitor.visitSingularInt64Field(value: self.minSize, fieldNumber: 2)
12811-
}
12812-
try { if let v = self._maxSize {
12813-
try visitor.visitSingularInt64Field(value: v, fieldNumber: 3)
12814-
} }()
12815-
if self.isTable64 != false {
12816-
try visitor.visitSingularBoolField(value: self.isTable64, fieldNumber: 4)
12817-
}
1281812711
try unknownFields.traverse(visitor: &visitor)
1281912712
}
1282012713

1282112714
public static func ==(lhs: Fuzzilli_Protobuf_WasmTableSet, rhs: Fuzzilli_Protobuf_WasmTableSet) -> Bool {
12822-
if lhs._elementType != rhs._elementType {return false}
12823-
if lhs.minSize != rhs.minSize {return false}
12824-
if lhs._maxSize != rhs._maxSize {return false}
12825-
if lhs.isTable64 != rhs.isTable64 {return false}
1282612715
if lhs.unknownFields != rhs.unknownFields {return false}
1282712716
return true
1282812717
}

Sources/Fuzzilli/Protobuf/operations.proto

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,19 +1097,10 @@ message WasmStoreGlobal {
10971097
WasmILType globalType = 2;
10981098
}
10991099

1100-
// WasmTableGet and WasmTableSet need a WasmTableType as input.
11011100
message WasmTableGet {
1102-
WasmILType elementType = 1;
1103-
int64 minSize = 2;
1104-
optional int64 maxSize = 3;
1105-
bool isTable64 = 4;
11061101
}
11071102

11081103
message WasmTableSet {
1109-
WasmILType elementType = 1;
1110-
int64 minSize = 2;
1111-
optional int64 maxSize = 3;
1112-
bool isTable64 = 4;
11131104
}
11141105

11151106
message WasmTableSize {

0 commit comments

Comments
 (0)