@@ -953,15 +953,16 @@ final class WasmBeginBlock: WasmOperation {
953
953
init ( with signature: Signature ) {
954
954
self . signature = signature
955
955
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
956
- super. init ( inputTypes: parameterTypes, outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
956
+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
957
+ super. init ( inputTypes: parameterTypes, outputType: . nothing, innerOutputTypes: [ . label( labelTypes) ] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
957
958
}
958
959
}
959
960
960
961
final class WasmEndBlock : WasmOperation {
961
962
override var opcode : Opcode { . wasmEndBlock( self ) }
962
963
963
- init ( ) {
964
- super. init ( attributes: [ . isBlockEnd, . resumesSurroundingContext] , requiredContext: [ . wasmFunction, . wasmBlock] )
964
+ init ( outputType : ILType ) {
965
+ super. init ( inputTypes : outputType != . nothing ? [ outputType ] : [ ] , outputType : outputType , attributes: [ . isBlockEnd, . resumesSurroundingContext] , requiredContext: [ . wasmFunction, . wasmBlock] )
965
966
}
966
967
}
967
968
@@ -972,12 +973,13 @@ final class WasmBeginIf: WasmOperation {
972
973
init ( with signature: Signature = [ ] => . nothing) {
973
974
self . signature = signature
974
975
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
976
+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
975
977
// TODO(mliedtke): Why does this set .isNotInputMutable? Try to remove it and see if the WasmLifter failure rate is affected.
976
978
977
979
// Note that the condition is the last input! This is due to how lifting works for the wasm
978
980
// value stack and that the condition is the first value to be removed from the stack, so
979
981
// it needs to be the last one pushed to it.
980
- super. init ( inputTypes: parameterTypes + [ . wasmi32] , outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext, . isNotInputMutable] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
982
+ super. init ( inputTypes: parameterTypes + [ . wasmi32] , outputType: signature. outputType, innerOutputTypes: [ . label( labelTypes ) ] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext, . isNotInputMutable] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
981
983
}
982
984
}
983
985
@@ -988,7 +990,8 @@ final class WasmBeginElse: WasmOperation {
988
990
init ( with signature: Signature = [ ] => . nothing) {
989
991
self . signature = signature
990
992
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
991
- super. init ( outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . isBlockEnd, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
993
+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
994
+ super. init ( outputType: signature. outputType, innerOutputTypes: [ . label( labelTypes) ] + parameterTypes, attributes: [ . isBlockStart, . isBlockEnd, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmBlock] )
992
995
}
993
996
}
994
997
@@ -1008,7 +1011,10 @@ final class WasmBeginLoop: WasmOperation {
1008
1011
init ( with signature: Signature ) {
1009
1012
self . signature = signature
1010
1013
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
1011
- super. init ( outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] )
1014
+ // Note that different to all other blocks the loop's label parameters are the input types
1015
+ // of the block, not the result types (because a branch to a loop label jumps to the
1016
+ // beginning of the loop block instead of the end.)
1017
+ super. init ( outputType: . nothing, innerOutputTypes: [ . label( parameterTypes) ] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] )
1012
1018
}
1013
1019
}
1014
1020
@@ -1028,7 +1034,8 @@ final class WasmBeginTry: WasmOperation {
1028
1034
init ( with signature: Signature ) {
1029
1035
self . signature = signature
1030
1036
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
1031
- super. init ( inputTypes: parameterTypes, outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmTry] )
1037
+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
1038
+ super. init ( inputTypes: parameterTypes, outputType: signature. outputType, innerOutputTypes: [ . label( labelTypes) ] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ . wasmTry] )
1032
1039
}
1033
1040
}
1034
1041
@@ -1101,7 +1108,8 @@ final class WasmBeginTryDelegate: WasmOperation {
1101
1108
init ( with signature: Signature ) {
1102
1109
self . signature = signature
1103
1110
let parameterTypes = signature. parameters. convertPlainToILTypes ( )
1104
- super. init ( inputTypes: parameterTypes, outputType: signature. outputType, innerOutputTypes: [ . label] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ ] )
1111
+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
1112
+ super. init ( inputTypes: parameterTypes, outputType: signature. outputType, innerOutputTypes: [ . label( labelTypes) ] + parameterTypes, attributes: [ . isBlockStart, . propagatesSurroundingContext] , requiredContext: [ . wasmFunction] , contextOpened: [ ] )
1105
1113
}
1106
1114
}
1107
1115
@@ -1111,7 +1119,8 @@ final class WasmEndTryDelegate: WasmOperation {
1111
1119
override var opcode : Opcode { . wasmEndTryDelegate( self ) }
1112
1120
1113
1121
init ( ) {
1114
- super. init ( inputTypes: [ . label] , attributes: [ . isBlockEnd, . resumesSurroundingContext] , requiredContext: [ . wasmFunction] )
1122
+ // Note that the actual block signature doesn't matter as the try-delegate "rethrows" the exception at that block level.
1123
+ super. init ( inputTypes: [ . anyLabel] , attributes: [ . isBlockEnd, . resumesSurroundingContext] , requiredContext: [ . wasmFunction] )
1115
1124
}
1116
1125
}
1117
1126
@@ -1136,20 +1145,23 @@ final class WasmRethrow: WasmOperation {
1136
1145
1137
1146
final class WasmBranch : WasmOperation {
1138
1147
override var opcode : Opcode { . wasmBranch( self ) }
1148
+ let labelTypes : [ ILType ]
1139
1149
1140
- init ( ) {
1141
- super. init ( inputTypes: [ . label] , requiredContext: [ . wasmFunction] )
1150
+ init ( labelTypes: [ ILType ] ) {
1151
+ self . labelTypes = labelTypes
1152
+ super. init ( inputTypes: [ . label( self . labelTypes) ] + labelTypes, requiredContext: [ . wasmFunction] )
1142
1153
1143
1154
}
1144
1155
}
1145
1156
1146
1157
final class WasmBranchIf : WasmOperation {
1147
1158
override var opcode : Opcode { . wasmBranchIf( self ) }
1159
+ let labelTypes : [ ILType ]
1148
1160
1149
- init ( ) {
1150
- super. init ( inputTypes: [ . label, . wasmi32] , requiredContext: [ . wasmFunction] )
1161
+ init ( labelTypes: [ ILType ] ) {
1162
+ self . labelTypes = labelTypes
1163
+ super. init ( inputTypes: [ . label( self . labelTypes) ] + labelTypes + [ . wasmi32] , requiredContext: [ . wasmFunction] )
1151
1164
}
1152
-
1153
1165
}
1154
1166
1155
1167
// TODO: make this comprehensive, currently only works for locals, or assumes every thing it reassigns to is a local.
0 commit comments