@@ -953,15 +953,16 @@ final class WasmBeginBlock: WasmOperation {
953953 init ( with signature: Signature ) {
954954 self . signature = signature
955955 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] )
957958 }
958959}
959960
960961final class WasmEndBlock : WasmOperation {
961962 override var opcode : Opcode { . wasmEndBlock( self ) }
962963
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] )
965966 }
966967}
967968
@@ -972,12 +973,13 @@ final class WasmBeginIf: WasmOperation {
972973 init ( with signature: Signature = [ ] => . nothing) {
973974 self . signature = signature
974975 let parameterTypes = signature. parameters. convertPlainToILTypes ( )
976+ let labelTypes = signature. outputType != . nothing ? [ signature. outputType] : [ ]
975977 // TODO(mliedtke): Why does this set .isNotInputMutable? Try to remove it and see if the WasmLifter failure rate is affected.
976978
977979 // Note that the condition is the last input! This is due to how lifting works for the wasm
978980 // value stack and that the condition is the first value to be removed from the stack, so
979981 // 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] )
981983 }
982984}
983985
@@ -988,7 +990,8 @@ final class WasmBeginElse: WasmOperation {
988990 init ( with signature: Signature = [ ] => . nothing) {
989991 self . signature = signature
990992 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] )
992995 }
993996}
994997
@@ -1008,7 +1011,10 @@ final class WasmBeginLoop: WasmOperation {
10081011 init ( with signature: Signature ) {
10091012 self . signature = signature
10101013 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] )
10121018 }
10131019}
10141020
@@ -1028,7 +1034,8 @@ final class WasmBeginTry: WasmOperation {
10281034 init ( with signature: Signature ) {
10291035 self . signature = signature
10301036 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] )
10321039 }
10331040}
10341041
@@ -1101,7 +1108,8 @@ final class WasmBeginTryDelegate: WasmOperation {
11011108 init ( with signature: Signature ) {
11021109 self . signature = signature
11031110 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: [ ] )
11051113 }
11061114}
11071115
@@ -1111,7 +1119,8 @@ final class WasmEndTryDelegate: WasmOperation {
11111119 override var opcode : Opcode { . wasmEndTryDelegate( self ) }
11121120
11131121 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] )
11151124 }
11161125}
11171126
@@ -1136,20 +1145,23 @@ final class WasmRethrow: WasmOperation {
11361145
11371146final class WasmBranch : WasmOperation {
11381147 override var opcode : Opcode { . wasmBranch( self ) }
1148+ let labelTypes : [ ILType ]
11391149
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] )
11421153
11431154 }
11441155}
11451156
11461157final class WasmBranchIf : WasmOperation {
11471158 override var opcode : Opcode { . wasmBranchIf( self ) }
1159+ let labelTypes : [ ILType ]
11481160
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] )
11511164 }
1152-
11531165}
11541166
11551167// TODO: make this comprehensive, currently only works for locals, or assumes every thing it reassigns to is a local.
0 commit comments