From a6d26d74bfef0bc73f8aad3d9809e4683458520f Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sun, 13 Aug 2023 10:02:23 +0800 Subject: [PATCH 1/2] Remove extra brace for stringified nullable reference types The extra } at the end is clearly a mistake from writing that template literal. --- src/types.ts | 2 +- tests/compiler/bindings/esm.debug.js | 2 +- tests/compiler/bindings/esm.release.js | 2 +- tests/compiler/bindings/raw.debug.js | 2 +- tests/compiler/bindings/raw.release.js | 2 +- tests/compiler/features/reference-types.debug.wat | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/types.ts b/src/types.ts index 4aef00a5b2..17bf8cbdbb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -638,7 +638,7 @@ export class Type { : signatureReference.toString(validWat); } else { return this.isNullableReference - ? `${this.kindToString()}${nullablePostfix}}` + ? `${this.kindToString()}${nullablePostfix}` : this.kindToString(); } } diff --git a/tests/compiler/bindings/esm.debug.js b/tests/compiler/bindings/esm.debug.js index 15804abe90..d2d89456b8 100644 --- a/tests/compiler/bindings/esm.debug.js +++ b/tests/compiler/bindings/esm.debug.js @@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) { return Math.log(x); }, "globalThis.globalThis": ( - // bindings/esm/immutableGlobalNested: ref_extern | null} + // bindings/esm/immutableGlobalNested: ref_extern | null globalThis.globalThis ), "Date.getTimezoneOffset"() { diff --git a/tests/compiler/bindings/esm.release.js b/tests/compiler/bindings/esm.release.js index 6df7b0c319..30c529402d 100644 --- a/tests/compiler/bindings/esm.release.js +++ b/tests/compiler/bindings/esm.release.js @@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) { return Math.log(x); }, "globalThis.globalThis": ( - // bindings/esm/immutableGlobalNested: ref_extern | null} + // bindings/esm/immutableGlobalNested: ref_extern | null globalThis.globalThis ), "Date.getTimezoneOffset"() { diff --git a/tests/compiler/bindings/raw.debug.js b/tests/compiler/bindings/raw.debug.js index 80551c4d39..cc59b6a796 100644 --- a/tests/compiler/bindings/raw.debug.js +++ b/tests/compiler/bindings/raw.debug.js @@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) { return Math.log(x); }, "globalThis.globalThis": ( - // bindings/esm/immutableGlobalNested: ref_extern | null} + // bindings/esm/immutableGlobalNested: ref_extern | null globalThis.globalThis ), "Date.getTimezoneOffset"() { diff --git a/tests/compiler/bindings/raw.release.js b/tests/compiler/bindings/raw.release.js index 80551c4d39..cc59b6a796 100644 --- a/tests/compiler/bindings/raw.release.js +++ b/tests/compiler/bindings/raw.release.js @@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) { return Math.log(x); }, "globalThis.globalThis": ( - // bindings/esm/immutableGlobalNested: ref_extern | null} + // bindings/esm/immutableGlobalNested: ref_extern | null globalThis.globalThis ), "Date.getTimezoneOffset"() { diff --git a/tests/compiler/features/reference-types.debug.wat b/tests/compiler/features/reference-types.debug.wat index d7dfc388c9..2e036c937e 100644 --- a/tests/compiler/features/reference-types.debug.wat +++ b/tests/compiler/features/reference-types.debug.wat @@ -35,7 +35,7 @@ (export "nonNullReal" (global $features/reference-types/nonNullReal)) (export "memory" (memory $0)) (start $~start) - (func $features/reference-types/testLocal + (func $features/reference-types/testLocal (local $local funcref) ref.null nofunc local.set $local @@ -68,7 +68,7 @@ unreachable end ) - (func $features/reference-types/testLocal + (func $features/reference-types/testLocal (local $local externref) ref.null noextern local.set $local @@ -256,8 +256,8 @@ call $~lib/builtins/abort unreachable end - call $features/reference-types/testLocal - 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 From 11e3c321abf255b09fe1492d32dc1cd1accda7d6 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sun, 13 Aug 2023 10:06:28 +0800 Subject: [PATCH 2/2] Error instead of crashing on reference typed fields Since reference types can't be written to linear memory, they don't have proper byte sizes, which triggers an assert. Instead, the compiler should signal its lack of support for this feature. Fixes #2726. --- src/resolver.ts | 8 ++++++++ tests/compiler/field-reference-types.json | 7 +++++++ tests/compiler/field-reference-types.ts | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/compiler/field-reference-types.json create mode 100644 tests/compiler/field-reference-types.ts diff --git a/src/resolver.ts b/src/resolver.ts index 16bd967847..e3e389d331 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -3407,6 +3407,14 @@ export class Resolver extends DiagnosticEmitter { if (boundInstance) { let fieldType = boundInstance.type; if (fieldType == Type.void) break; // failed to resolve earlier + if (fieldType.isExternalReference) { + this.error( + DiagnosticCode.Not_implemented_0, + assert(boundPrototype.typeNode).range, + "Reference typed fields" + ); + break; + } let needsLayout = true; if (base) { let existingMember = base.getMember(boundPrototype.name); diff --git a/tests/compiler/field-reference-types.json b/tests/compiler/field-reference-types.json new file mode 100644 index 0000000000..328a6864a7 --- /dev/null +++ b/tests/compiler/field-reference-types.json @@ -0,0 +1,7 @@ +{ + "stderr": [ + "Not implemented: Reference typed fields", + "Not implemented: Reference typed fields", + "EOF" + ] +} diff --git a/tests/compiler/field-reference-types.ts b/tests/compiler/field-reference-types.ts new file mode 100644 index 0000000000..181e62a0ef --- /dev/null +++ b/tests/compiler/field-reference-types.ts @@ -0,0 +1,12 @@ +class Foo { + bar: externref = null; +} + +class Baz { + qux: T; +} + +new Foo(); +new Baz(); + +ERROR("EOF");