From 9d5aec380a98bdad27092ddb86bbe9211f61938b Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 17:12:06 +0300 Subject: [PATCH 1/9] init --- src/compiler.ts | 29 +++++--- src/module.ts | 12 ++++ src/passes/pass.ts | 3 +- .../features/reference-types.debug.wat | 66 ++++++++++++++----- tests/compiler/features/reference-types.json | 3 +- .../features/reference-types.release.wat | 22 +++++++ tests/compiler/features/reference-types.ts | 28 ++++---- 7 files changed, 122 insertions(+), 41 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 74518ef05d..0d526e4879 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -25,7 +25,6 @@ import { ExpressionRef, UnaryOp, BinaryOp, - RefIsOp, TypeRef, FunctionRef, ExpressionId, @@ -10331,11 +10330,11 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.EXTERNREF: case TypeKind.ANYREF: case TypeKind.EQREF: - case TypeKind.DATAREF: - case TypeKind.I31REF: { + case TypeKind.I31REF: + case TypeKind.DATAREF: { // Needs to be true (i.e. not zero) when the ref is _not_ null, // which means `ref.is_null` returns false (i.e. zero). - return module.unary(UnaryOp.EqzI32, module.ref_is(RefIsOp.RefIsNull, expr)); + return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr)); } default: { @@ -10585,11 +10584,23 @@ export class Compiler extends DiagnosticEmitter { var temp = flow.getTempLocal(type); if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); flow.setLocalFlag(temp.index, LocalFlags.NONNULL); - expr = module.if( - module.local_tee(temp.index, expr, type.isManaged), - module.local_get(temp.index, type.toRef()), - this.makeStaticAbort(this.ensureStaticString("unexpected null"), reportNode) // TODO: throw - ); + if (type.kind >= TypeKind.FUNCREF && type.kind <= TypeKind.DATAREF) { + let nonNullExpr = module.local_get(temp.index, type.toRef()); + if (this.options.hasFeature(Feature.GC)) { + nonNullExpr = module.ref_as_nonnull(nonNullExpr); + } + expr = module.if( + module.ref_is_null(module.local_tee(temp.index, expr, false)), + this.makeStaticAbort(this.ensureStaticString("unexpected null"), reportNode), // TODO: throw + nonNullExpr + ); + } else { + expr = module.if( + module.local_tee(temp.index, expr, type.isManaged), + module.local_get(temp.index, type.toRef()), + this.makeStaticAbort(this.ensureStaticString("unexpected null"), reportNode) // TODO: throw + ); + } flow.freeTempLocal(temp); this.currentType = type.nonNullableType; return expr; diff --git a/src/module.ts b/src/module.ts index 4e31ff6a1d..e461220557 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1774,6 +1774,12 @@ export class Module { return binaryen._BinaryenRefIs(this.ref, op, expr); } + ref_is_null( + expr: ExpressionRef + ): ExpressionRef { + return binaryen._BinaryenRefIs(this.ref, RefIsOp.RefIsNull, expr); + } + ref_as( op: RefAsOp, expr: ExpressionRef @@ -1781,6 +1787,12 @@ export class Module { return binaryen._BinaryenRefAs(this.ref, op, expr); } + ref_as_nonnull( + expr: ExpressionRef + ): ExpressionRef { + return binaryen._BinaryenRefAs(this.ref, RefAsOp.RefAsNonNull, expr); + } + ref_func( name: string, type: TypeRef diff --git a/src/passes/pass.ts b/src/passes/pass.ts index 5106c307df..6af6307be3 100644 --- a/src/passes/pass.ts +++ b/src/passes/pass.ts @@ -81,6 +81,7 @@ import { _BinaryenMemoryFillGetValue, _BinaryenMemoryFillGetSize, _BinaryenRefIsGetValue, + _BinaryenRefAsGetValue, _BinaryenTryGetBody, _BinaryenTryGetNumCatchBodies, _BinaryenTryGetCatchBodyAt, @@ -989,7 +990,7 @@ export abstract class Visitor { } case ExpressionId.RefAs: { this.stack.push(expr); - assert(false); // TODO + this.visit(_BinaryenRefAsGetValue(expr)); assert(this.stack.pop() == expr); this.visitRefAs(expr); break; diff --git a/tests/compiler/features/reference-types.debug.wat b/tests/compiler/features/reference-types.debug.wat index 36a0e0c6b0..2d90f1ad8d 100644 --- a/tests/compiler/features/reference-types.debug.wat +++ b/tests/compiler/features/reference-types.debug.wat @@ -14,11 +14,14 @@ (global $features/reference-types/otherFuncGlobal (mut funcref) (ref.func $features/reference-types/someFunc)) (global $features/reference-types/a anyref (ref.null any)) (global $features/reference-types/b funcref (ref.null func)) - (global $~lib/memory/__data_end i32 (i32.const 92)) - (global $~lib/memory/__stack_pointer (mut i32) (i32.const 16476)) - (global $~lib/memory/__heap_base i32 (i32.const 16476)) + (global $features/reference-types/nonNullFunc (mut funcref) (ref.null func)) + (global $features/reference-types/nonNullReal (mut anyref) (ref.null any)) + (global $~lib/memory/__data_end i32 (i32.const 156)) + (global $~lib/memory/__stack_pointer (mut i32) (i32.const 16540)) + (global $~lib/memory/__heap_base i32 (i32.const 16540)) (memory $0 1) (data (i32.const 12) "L\00\00\00\00\00\00\00\00\00\00\00\01\00\00\006\00\00\00f\00e\00a\00t\00u\00r\00e\00s\00/\00r\00e\00f\00e\00r\00e\00n\00c\00e\00-\00t\00y\00p\00e\00s\00.\00t\00s\00\00\00\00\00\00\00") + (data (i32.const 92) "<\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\1e\00\00\00u\00n\00e\00x\00p\00e\00c\00t\00e\00d\00 \00n\00u\00l\00l\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (table $0 1 1 funcref) (elem $0 (i32.const 1)) (elem declare func $features/reference-types/someFunc) @@ -28,6 +31,8 @@ (export "internal" (func $features/reference-types/internal)) (export "a" (global $features/reference-types/a)) (export "b" (global $features/reference-types/b)) + (export "nonNullFunc" (global $features/reference-types/nonNullFunc)) + (export "nonNullReal" (global $features/reference-types/nonNullReal)) (export "memory" (memory $0)) (start $~start) (func $features/reference-types/testLocal @@ -77,7 +82,7 @@ unreachable end ) - (func $features/reference-types/testLocal + (func $features/reference-types/testLocal (local $0 anyref) (local $1 anyref) local.get $0 @@ -129,6 +134,7 @@ ) (func $start:features/reference-types (local $0 funcref) + (local $1 anyref) call $features/reference-types/somethingReal ref.is_null i32.eqz @@ -278,7 +284,7 @@ unreachable end call $features/reference-types/testLocal - call $features/reference-types/testLocal + call $features/reference-types/testLocal ref.func $features/reference-types/someFunc global.set $features/reference-types/funcGlobal global.get $features/reference-types/funcGlobal @@ -301,20 +307,46 @@ call $~lib/builtins/abort unreachable end - block - ref.func $features/reference-types/someFunc - local.set $0 + ref.func $features/reference-types/someFunc + local.set $0 + local.get $0 + ref.is_null + if + i32.const 0 + i32.const 32 + i32.const 88 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + global.get $features/reference-types/otherFuncGlobal + local.tee $0 + ref.is_null + if (result funcref) + i32.const 112 + i32.const 32 + i32.const 97 + i32.const 28 + call $~lib/builtins/abort + unreachable + else local.get $0 - ref.is_null - if - i32.const 0 - i32.const 32 - i32.const 88 - i32.const 3 - call $~lib/builtins/abort - unreachable - end end + global.set $features/reference-types/nonNullFunc + call $features/reference-types/somethingReal + local.tee $1 + ref.is_null + if (result anyref) + i32.const 112 + i32.const 32 + i32.const 98 + i32.const 28 + call $~lib/builtins/abort + unreachable + else + local.get $1 + end + global.set $features/reference-types/nonNullReal ) (func $features/reference-types/internal (param $0 anyref) (result anyref) (local $1 anyref) diff --git a/tests/compiler/features/reference-types.json b/tests/compiler/features/reference-types.json index 44dbffd87b..a12f0f88e3 100644 --- a/tests/compiler/features/reference-types.json +++ b/tests/compiler/features/reference-types.json @@ -1,7 +1,6 @@ { "features": [ - "reference-types", - "gc" + "reference-types" ], "asc_flags": [ ] diff --git a/tests/compiler/features/reference-types.release.wat b/tests/compiler/features/reference-types.release.wat index 21a1358272..88e754780d 100644 --- a/tests/compiler/features/reference-types.release.wat +++ b/tests/compiler/features/reference-types.release.wat @@ -10,9 +10,13 @@ (global $features/reference-types/funcGlobal (mut funcref) (ref.null func)) (global $features/reference-types/a anyref (ref.null any)) (global $features/reference-types/b funcref (ref.null func)) + (global $features/reference-types/nonNullFunc (mut funcref) (ref.null func)) + (global $features/reference-types/nonNullReal (mut anyref) (ref.null any)) (memory $0 1) (data (i32.const 1036) "L") (data (i32.const 1048) "\01\00\00\006\00\00\00f\00e\00a\00t\00u\00r\00e\00s\00/\00r\00e\00f\00e\00r\00e\00n\00c\00e\00-\00t\00y\00p\00e\00s\00.\00t\00s") + (data (i32.const 1116) "<") + (data (i32.const 1128) "\01\00\00\00\1e\00\00\00u\00n\00e\00x\00p\00e\00c\00t\00e\00d\00 \00n\00u\00l\00l") (elem declare func $features/reference-types/someFunc) (export "external" (func $features/reference-types/external)) (export "somethingReal" (func $features/reference-types/somethingReal)) @@ -20,6 +24,8 @@ (export "internal" (func $features/reference-types/internal)) (export "a" (global $features/reference-types/a)) (export "b" (global $features/reference-types/b)) + (export "nonNullFunc" (global $features/reference-types/nonNullFunc)) + (export "nonNullReal" (global $features/reference-types/nonNullReal)) (export "memory" (memory $0)) (start $~start) (func $features/reference-types/someFunc @@ -32,6 +38,7 @@ call $features/reference-types/external ) (func $~start + (local $0 anyref) call $features/reference-types/somethingReal ref.is_null if @@ -89,5 +96,20 @@ global.set $features/reference-types/funcGlobal ref.func $features/reference-types/someFunc global.set $features/reference-types/funcGlobal + ref.func $features/reference-types/someFunc + global.set $features/reference-types/nonNullFunc + call $features/reference-types/somethingReal + local.tee $0 + ref.is_null + if + i32.const 1136 + i32.const 1056 + i32.const 98 + i32.const 28 + call $~lib/builtins/abort + unreachable + end + local.get $0 + global.set $features/reference-types/nonNullReal ) ) diff --git a/tests/compiler/features/reference-types.ts b/tests/compiler/features/reference-types.ts index bd97272d30..0588399629 100644 --- a/tests/compiler/features/reference-types.ts +++ b/tests/compiler/features/reference-types.ts @@ -1,10 +1,10 @@ // can use anyref as a parameter or return type -export declare function external(a: anyref): anyref; -export declare function somethingReal(): anyref; -export declare function somethingNull(): anyref; +export declare function external(a: externref): externref; +export declare function somethingReal(): externref; +export declare function somethingNull(): externref; -export function internal(a: anyref): anyref { +export function internal(a: externref): externref { const b = external(a); let c = external(b); var d = external(c); @@ -12,20 +12,20 @@ export function internal(a: anyref): anyref { } // Truthiness conversion -if(!somethingReal()) { +if (!somethingReal()) { assert(false); } -if(!somethingNull()) { +if (!somethingNull()) { // nop } else { assert(false); } -if(somethingReal()) { +if (somethingReal()) { // nop } else { assert(false); } -if(somethingNull()) { +if (somethingNull()) { assert(false); } @@ -58,11 +58,11 @@ assert(!funcGlobal); var funcGlobalInit: funcref = null; assert(!funcGlobalInit); -var anyGlobal: anyref; +var anyGlobal: externref; assert(!anyGlobal); anyGlobal = null; assert(!anyGlobal); -var anyGlobalInit: anyref = null; +var anyGlobalInit: externref = null; assert(!anyGlobalInit); function testLocal(): void { @@ -74,7 +74,7 @@ function testLocal(): void { assert(!localInit); } testLocal(); -testLocal(); +testLocal(); // funcref can represent function references @@ -90,5 +90,9 @@ assert(otherFuncGlobal); // constant globals -export const a: anyref = null; +export const a: externref = null; export const b: funcref = null; + +// non-null assertions +export const nonNullFunc = otherFuncGlobal!; +export const nonNullReal = somethingReal()!; From 0db6b9c56da7fe401d9f92f4ce329330e3f37091 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 17:22:29 +0300 Subject: [PATCH 2/9] refactor --- src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 0d526e4879..a47b1ae7a5 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10584,7 +10584,7 @@ export class Compiler extends DiagnosticEmitter { var temp = flow.getTempLocal(type); if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); flow.setLocalFlag(temp.index, LocalFlags.NONNULL); - if (type.kind >= TypeKind.FUNCREF && type.kind <= TypeKind.DATAREF) { + if (type.isExternalReference) { let nonNullExpr = module.local_get(temp.index, type.toRef()); if (this.options.hasFeature(Feature.GC)) { nonNullExpr = module.ref_as_nonnull(nonNullExpr); From dee4dc6f8642b843dff63114b0b34b8f9c2973ed Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 17:26:02 +0300 Subject: [PATCH 3/9] add nullable bitset for i32ref type --- src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types.ts b/src/types.ts index d0d48fdb2e..dc3aa2976a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -697,6 +697,7 @@ export class Type { /** 31-bit integer reference. */ static readonly i31ref: Type = new Type(TypeKind.I31REF, TypeFlags.EXTERNAL | + TypeFlags.NULLABLE | TypeFlags.REFERENCE, 0 ); From 6d5c4d11631138bcc28c67134161a0bf37916801 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 17:37:10 +0300 Subject: [PATCH 4/9] refactor --- src/compiler.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index a47b1ae7a5..60c1dc41ce 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10584,6 +10584,12 @@ export class Compiler extends DiagnosticEmitter { var temp = flow.getTempLocal(type); if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); flow.setLocalFlag(temp.index, LocalFlags.NONNULL); + + var staticAbortCallExpr = this.makeStaticAbort( + this.ensureStaticString("unexpected null"), + reportNode + ); // TODO: throw + if (type.isExternalReference) { let nonNullExpr = module.local_get(temp.index, type.toRef()); if (this.options.hasFeature(Feature.GC)) { @@ -10591,14 +10597,14 @@ export class Compiler extends DiagnosticEmitter { } expr = module.if( module.ref_is_null(module.local_tee(temp.index, expr, false)), - this.makeStaticAbort(this.ensureStaticString("unexpected null"), reportNode), // TODO: throw + staticAbortCallExpr, nonNullExpr ); } else { expr = module.if( module.local_tee(temp.index, expr, type.isManaged), module.local_get(temp.index, type.toRef()), - this.makeStaticAbort(this.ensureStaticString("unexpected null"), reportNode) // TODO: throw + staticAbortCallExpr ); } flow.freeTempLocal(temp); From 6dac3b1a680932d68ed29f7ce6f43007f089c8f5 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 17:38:36 +0300 Subject: [PATCH 5/9] more (for better readability) --- src/compiler.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 60c1dc41ce..8f4ab5deb3 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10596,7 +10596,9 @@ export class Compiler extends DiagnosticEmitter { nonNullExpr = module.ref_as_nonnull(nonNullExpr); } expr = module.if( - module.ref_is_null(module.local_tee(temp.index, expr, false)), + module.ref_is_null( + module.local_tee(temp.index, expr, false) + ), staticAbortCallExpr, nonNullExpr ); From 1f4add1f8c0528091abf83f1b8cc27b47e72743d Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 20:24:56 +0300 Subject: [PATCH 6/9] minor refactoring for makeRuntimeUpcastCheck --- src/compiler.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 8f4ab5deb3..2661cb899e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10631,6 +10631,12 @@ export class Compiler extends DiagnosticEmitter { var temp = flow.getTempLocal(type); var instanceofInstance = this.program.instanceofInstance; assert(this.compileFunction(instanceofInstance)); + + var staticAbortCallExpr = this.makeStaticAbort( + this.ensureStaticString("unexpected upcast"), + reportNode + ); // TODO: throw + if (!toType.isNullableReference || flow.isNonnull(expr, type)) { // Simplify if the value cannot be `null`. If toType is non-nullable, a // null-check would have been emitted separately so is not necessary here. @@ -10640,7 +10646,7 @@ export class Compiler extends DiagnosticEmitter { module.i32(toType.classReference!.id) ], TypeRef.I32), module.local_get(temp.index, type.toRef()), - this.makeStaticAbort(this.ensureStaticString("unexpected upcast"), reportNode) // TODO: throw + staticAbortCallExpr ); } else { expr = module.if( @@ -10651,7 +10657,7 @@ export class Compiler extends DiagnosticEmitter { module.i32(toType.classReference!.id) ], TypeRef.I32), module.local_get(temp.index, type.toRef()), - this.makeStaticAbort(this.ensureStaticString("unexpected upcast"), reportNode) // TODO: throw + staticAbortCallExpr ), module.usize(0) ); From e46b0b0213d945b754103daa7badb2fa8e190ef8 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 20:46:06 +0300 Subject: [PATCH 7/9] add I31REF case for makeNegOne --- src/compiler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler.ts b/src/compiler.ts index 2661cb899e..6736ab842f 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10260,6 +10260,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U64: return module.i64(-1, -1); case TypeKind.F32: return module.f32(-1); case TypeKind.F64: return module.f64(-1); + case TypeKind.I31REF: return module.i31_new(module.i32(-1)); } } From 3803ae8f141811b7c776356fc0d8e424115ddf0d Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 20:55:46 +0300 Subject: [PATCH 8/9] remove reportNode in makeZero --- src/builtins.ts | 2 +- src/compiler.ts | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 6e8cd28d4e..394e965b5f 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -3119,7 +3119,7 @@ function builtin_memory_data(ctx: BuiltinContext): ExpressionRef { } exprs[i] = expr; } else { - exprs[i] = compiler.makeZero(elementType, elementExpression); + exprs[i] = compiler.makeZero(elementType); } } if (!isStatic) { diff --git a/src/compiler.ts b/src/compiler.ts index 6736ab842f..2b7e1194b4 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1242,7 +1242,7 @@ export class Compiler extends DiagnosticEmitter { if (global.is(CommonFlags.INLINED)) { initExpr = this.compileInlineConstant(global, global.type, Constraints.PREFER_STATIC); } else { - initExpr = this.makeZero(type, global.declaration); + initExpr = this.makeZero(type); } } @@ -1255,7 +1255,7 @@ export class Compiler extends DiagnosticEmitter { findDecorator(DecoratorKind.INLINE, global.decoratorNodes)!.range, "inline" ); } - module.addGlobal(internalName, typeRef, true, this.makeZero(type, global.declaration)); + module.addGlobal(internalName, typeRef, true, this.makeZero(type)); this.currentBody.push( module.global_set(internalName, initExpr) ); @@ -7038,7 +7038,7 @@ export class Compiler extends DiagnosticEmitter { let needsVarargsStub = false; for (let n = numParameters; n < overloadNumParameters; ++n) { // TODO: inline constant initializers and skip varargs stub - paramExprs[1 + n] = this.makeZero(overloadParameterTypes[n], overloadInstance.declaration); + paramExprs[1 + n] = this.makeZero(overloadParameterTypes[n]); needsVarargsStub = true; } let calledName = needsVarargsStub @@ -7238,7 +7238,7 @@ export class Compiler extends DiagnosticEmitter { } } } - operands.push(this.makeZero(parameterTypes[i], instance.declaration)); + operands.push(this.makeZero(parameterTypes[i])); allOptionalsAreConstant = false; } if (!allOptionalsAreConstant && !instance.is(CommonFlags.MODULE_IMPORT)) { @@ -7348,7 +7348,7 @@ export class Compiler extends DiagnosticEmitter { } let parameterTypes = signature.parameterTypes; for (let i = numArguments; i < maxArguments; ++i) { - operands.push(this.makeZero(parameterTypes[i], reportNode)); + operands.push(this.makeZero(parameterTypes[i])); } } @@ -7642,7 +7642,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = signatureReference.type.asNullable(); return options.isWasm64 ? module.i64(0) : module.i32(0); } - return this.makeZero(contextualType, expression); + return this.makeZero(contextualType); } this.currentType = options.usizeType; this.warning( @@ -7934,7 +7934,7 @@ export class Compiler extends DiagnosticEmitter { ? BinaryOp.NeI64 : BinaryOp.NeI32, expr, - this.makeZero(actualType, expression.expression) + this.makeZero(actualType) ); } @@ -8041,7 +8041,7 @@ export class Compiler extends DiagnosticEmitter { ? BinaryOp.NeI64 : BinaryOp.NeI32, expr, - this.makeZero(actualType, expression.expression) + this.makeZero(actualType) ); // is just `true` @@ -8392,7 +8392,7 @@ export class Compiler extends DiagnosticEmitter { } values[i] = expr; } else { - values[i] = this.makeZero(elementType, elementExpression); + values[i] = this.makeZero(elementType); } } @@ -8544,7 +8544,7 @@ export class Compiler extends DiagnosticEmitter { } values[i] = expr; } else { - values[i] = this.makeZero(elementType, elementExpression); + values[i] = this.makeZero(elementType); } } @@ -8781,7 +8781,7 @@ export class Compiler extends DiagnosticEmitter { exprs.push( module.call(fieldInstance.internalSetterName, [ module.local_get(tempLocal.index, classTypeRef), - this.makeZero(fieldType, expression) + this.makeZero(fieldType) ], TypeRef.None) ); this.compileFieldSetter(fieldInstance); @@ -9077,7 +9077,7 @@ export class Compiler extends DiagnosticEmitter { ctorInstance, argumentExpressions, reportNode, - this.makeZero(this.options.usizeType, reportNode), + this.makeZero(this.options.usizeType), constraints ); if (getExpressionType(expr) != TypeRef.None) { // possibly WILL_DROP @@ -9644,7 +9644,7 @@ export class Compiler extends DiagnosticEmitter { this.options.isWasm64 ? BinaryOp.SubI64 : BinaryOp.SubI32, - this.makeZero(this.currentType, expression.operand), + this.makeZero(this.currentType), expr ); break; @@ -10194,7 +10194,7 @@ export class Compiler extends DiagnosticEmitter { // === Specialized code generation ============================================================== /** Makes a constant zero of the specified type. */ - makeZero(type: Type, reportNode: Node): ExpressionRef { + makeZero(type: Type): ExpressionRef { var module = this.module; switch (type.kind) { default: assert(false); @@ -10536,7 +10536,7 @@ export class Compiler extends DiagnosticEmitter { if (message) { messageArg = this.compileExpression(message, stringInstance.type, Constraints.CONV_IMPLICIT); } else { - messageArg = this.makeZero(stringInstance.type, codeLocation); + messageArg = this.makeZero(stringInstance.type); } return this.makeStaticAbort(messageArg, codeLocation); From cb7f43c30b0019cf45366d2e8355a7586903a8d4 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jun 2022 20:58:18 +0300 Subject: [PATCH 9/9] fix --- src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 2b7e1194b4..ddbd06a23d 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10510,7 +10510,7 @@ export class Compiler extends DiagnosticEmitter { module.local_get(thisLocalIndex, sizeTypeRef), initializerNode // use initializer if present, otherwise initialize with zero ? this.compileExpression(initializerNode, fieldType, Constraints.CONV_IMPLICIT) - : this.makeZero(fieldType, fieldPrototype.declaration) + : this.makeZero(fieldType) ], TypeRef.None) ); }