From c287dce7289ea066acb097df2269be16be7a9d82 Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 7 Nov 2022 04:56:45 +0100 Subject: [PATCH] Prepare for dataref becoming structref --- src/builtins.ts | 4 ++-- src/common.ts | 4 ++-- src/compiler.ts | 23 ++++++++++++----------- src/module.ts | 16 ++++++++-------- src/program.ts | 4 ++-- src/types.ts | 26 +++++++++++++------------- std/assembly/index.d.ts | 8 ++++---- std/assembly/reference.ts | 2 +- tests/compiler/features/gc.debug.wat | 8 ++++---- tests/compiler/features/gc.release.wat | 8 ++++---- tests/compiler/features/gc.ts | 4 ++-- 11 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 802724b7c4..837949d675 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -3466,7 +3466,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Externref: case TypeKind.Anyref: case TypeKind.Eqref: - case TypeKind.Dataref: + case TypeKind.Structref: case TypeKind.Arrayref: case TypeKind.I31ref: case TypeKind.Stringref: @@ -3547,7 +3547,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Externref: case TypeKind.Anyref: case TypeKind.Eqref: - case TypeKind.Dataref: + case TypeKind.Structref: case TypeKind.Arrayref: case TypeKind.I31ref: case TypeKind.Stringref: diff --git a/src/common.ts b/src/common.ts index 6206dad9f0..54e8fff7a0 100644 --- a/src/common.ts +++ b/src/common.ts @@ -131,7 +131,7 @@ export namespace CommonNames { export const anyref = "anyref"; export const eqref = "eqref"; export const i31ref = "i31ref"; - export const dataref = "dataref"; + export const structref = "structref"; export const arrayref = "arrayref"; export const stringref = "stringref"; export const stringview_wtf8 = "stringview_wtf8"; @@ -212,7 +212,7 @@ export namespace CommonNames { export const Anyref = "Anyref"; export const Eqref = "Eqref"; export const I31ref = "I31ref"; - export const Dataref = "Dataref"; + export const Structref = "Structref"; export const Arrayref = "Arrayref"; export const String = "String"; export const RegExp = "RegExp"; diff --git a/src/compiler.ts b/src/compiler.ts index f0980d05cc..5ba2271365 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -4831,9 +4831,9 @@ export class Compiler extends DiagnosticEmitter { ); } case TypeKind.Eqref: - case TypeKind.I31ref: - case TypeKind.Dataref: - case TypeKind.Arrayref: return module.ref_eq(leftExpr, rightExpr); + case TypeKind.Structref: + case TypeKind.Arrayref: + case TypeKind.I31ref: return module.ref_eq(leftExpr, rightExpr); case TypeKind.Stringref: return module.string_eq(leftExpr, rightExpr); case TypeKind.StringviewWTF8: case TypeKind.StringviewWTF16: @@ -4881,9 +4881,9 @@ export class Compiler extends DiagnosticEmitter { ); } case TypeKind.Eqref: - case TypeKind.I31ref: - case TypeKind.Dataref: - case TypeKind.Arrayref: { + case TypeKind.Structref: + case TypeKind.Arrayref: + case TypeKind.I31ref: { return module.unary(UnaryOp.EqzI32, module.ref_eq(leftExpr, rightExpr) ); @@ -9784,9 +9784,9 @@ export class Compiler extends DiagnosticEmitter { return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode); case TypeKind.Anyref: case TypeKind.Eqref: - case TypeKind.I31ref: - case TypeKind.Dataref: - case TypeKind.Arrayref: { + case TypeKind.Structref: + case TypeKind.Arrayref: + case TypeKind.I31ref: { return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode) && this.checkFeatureEnabled(Feature.GC, reportNode); } @@ -9902,7 +9902,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Externref: case TypeKind.Anyref: case TypeKind.Eqref: - case TypeKind.Dataref: + case TypeKind.Structref: case TypeKind.Arrayref: case TypeKind.Stringref: case TypeKind.StringviewWTF8: @@ -10061,8 +10061,9 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Externref: case TypeKind.Anyref: case TypeKind.Eqref: + case TypeKind.Structref: + case TypeKind.Arrayref: case TypeKind.I31ref: - case TypeKind.Dataref: case TypeKind.Stringref: case TypeKind.StringviewWTF8: case TypeKind.StringviewWTF16: diff --git a/src/module.ts b/src/module.ts index f74fcf9c59..d6c9c4e473 100644 --- a/src/module.ts +++ b/src/module.ts @@ -75,15 +75,15 @@ export namespace TypeRef { export const Anyref = binaryen._BinaryenTypeAnyref(); export const Eqref = binaryen._BinaryenTypeEqref(); export const I31ref = binaryen._BinaryenTypeI31ref(); - export const Dataref = binaryen._BinaryenTypeDataref(); + export const Structref = binaryen._BinaryenTypeDataref(); // TODO: about to become struct export const Arrayref = binaryen._BinaryenTypeArrayref(); export const Stringref = binaryen._BinaryenTypeStringref(); export const StringviewWTF8 = binaryen._BinaryenTypeStringviewWTF8(); export const StringviewWTF16 = binaryen._BinaryenTypeStringviewWTF16(); export const StringviewIter = binaryen._BinaryenTypeStringviewIter(); - export const Noneref = binaryen._BinaryenTypeNullref(); - export const Nofuncref = binaryen._BinaryenTypeNullFuncref(); - export const Noexternref = binaryen._BinaryenTypeNullExternref(); + export const Nullref = binaryen._BinaryenTypeNullref(); + export const Nullfuncref = binaryen._BinaryenTypeNullFuncref(); + export const Nullexternref = binaryen._BinaryenTypeNullExternref(); } /** Reference to a Binaryen heap type. */ @@ -3742,15 +3742,15 @@ function tryEnsureBasicType(type: Type): TypeRef { case TypeKind.Eqref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Eq, type.is(TypeFlags.Nullable)); } - case TypeKind.I31ref: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, type.is(TypeFlags.Nullable)); - } - case TypeKind.Dataref: { + case TypeKind.Structref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, type.is(TypeFlags.Nullable)); } case TypeKind.Arrayref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Array, type.is(TypeFlags.Nullable)); } + case TypeKind.I31ref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, type.is(TypeFlags.Nullable)); + } case TypeKind.Stringref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.String, type.is(TypeFlags.Nullable)); } diff --git a/src/program.ts b/src/program.ts index 09032d0477..ded6f0a71b 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1032,7 +1032,7 @@ export class Program extends DiagnosticEmitter { this.registerNativeType(CommonNames.anyref, Type.anyref); this.registerNativeType(CommonNames.eqref, Type.eqref); this.registerNativeType(CommonNames.i31ref, Type.i31ref); - this.registerNativeType(CommonNames.dataref, Type.dataref); + this.registerNativeType(CommonNames.structref, Type.structref); this.registerNativeType(CommonNames.arrayref, Type.arrayref); this.registerNativeType(CommonNames.stringref, Type.stringref); this.registerNativeType(CommonNames.stringview_wtf8, Type.stringview_wtf8); @@ -1306,7 +1306,7 @@ export class Program extends DiagnosticEmitter { this.registerWrapperClass(Type.anyref, CommonNames.Anyref); this.registerWrapperClass(Type.eqref, CommonNames.Eqref); this.registerWrapperClass(Type.i31ref, CommonNames.I31ref); - this.registerWrapperClass(Type.dataref, CommonNames.Dataref); + this.registerWrapperClass(Type.structref, CommonNames.Structref); this.registerWrapperClass(Type.arrayref, CommonNames.Arrayref); } } diff --git a/src/types.ts b/src/types.ts index 521a0dbd38..df5f7c98c8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -75,12 +75,12 @@ export const enum TypeKind { Anyref, /** Equatable reference. */ Eqref, - /** 31-bit integer reference. */ - I31ref, - /** Data reference. */ - Dataref, + /** Struct reference. */ + Structref, /** Array reference. */ Arrayref, + /** 31-bit integer reference. */ + I31ref, /** String reference. */ Stringref, /** WTF8 string view. */ @@ -579,9 +579,9 @@ export class Type { case TypeKind.Externref: return CommonNames.externref; case TypeKind.Anyref: return CommonNames.anyref; case TypeKind.Eqref: return CommonNames.eqref; - case TypeKind.I31ref: return CommonNames.i31ref; - case TypeKind.Dataref: return CommonNames.dataref; + case TypeKind.Structref: return CommonNames.structref; case TypeKind.Arrayref: return CommonNames.arrayref; + case TypeKind.I31ref: return CommonNames.i31ref; case TypeKind.Stringref: return CommonNames.stringref; case TypeKind.StringviewWTF8: return CommonNames.stringview_wtf8; case TypeKind.StringviewWTF16: return CommonNames.stringview_wtf16; @@ -625,7 +625,7 @@ export class Type { case TypeKind.I31ref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, this.is(TypeFlags.Nullable)); } - case TypeKind.Dataref: { + case TypeKind.Structref: { return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, this.is(TypeFlags.Nullable)); } case TypeKind.Arrayref: { @@ -805,22 +805,22 @@ export class Type { TypeFlags.Reference, 0 ); - /** 31-bit integer reference. */ - static readonly i31ref: Type = new Type(TypeKind.I31ref, + /** Struct reference. */ + static readonly structref: Type = new Type(TypeKind.Structref, TypeFlags.External | TypeFlags.Nullable | TypeFlags.Reference, 0 ); - /** Data reference. */ - static readonly dataref: Type = new Type(TypeKind.Dataref, + /** Array reference. */ + static readonly arrayref: Type = new Type(TypeKind.Arrayref, TypeFlags.External | TypeFlags.Nullable | TypeFlags.Reference, 0 ); - /** Array reference. */ - static readonly arrayref: Type = new Type(TypeKind.Arrayref, + /** 31-bit integer reference. */ + static readonly i31ref: Type = new Type(TypeKind.I31ref, TypeFlags.External | TypeFlags.Nullable | TypeFlags.Reference, 0 diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 65306fdfa9..d7e7d839ad 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -43,12 +43,12 @@ declare type externref = object | null; declare type anyref = object | null; /** Equatable reference. */ declare type eqref = object | null; -/** 31-bit integer reference. */ -declare type i31ref = object | null; -/** Data reference. */ -declare type dataref = object | null; +/** Struct reference. */ +declare type structref = object | null; /** Array reference. */ declare type arrayref = object | null; +/** 31-bit integer reference. */ +declare type i31ref = object | null; /** String reference. */ declare type stringref = object | null; /** WTF-8 string view. */ diff --git a/std/assembly/reference.ts b/std/assembly/reference.ts index 65e7291147..1c7b85cb13 100644 --- a/std/assembly/reference.ts +++ b/std/assembly/reference.ts @@ -23,7 +23,7 @@ export abstract class I31ref extends Ref { } @final @unmanaged -export abstract class Dataref extends Ref { +export abstract class Structref extends Ref { } @final @unmanaged diff --git a/tests/compiler/features/gc.debug.wat b/tests/compiler/features/gc.debug.wat index 2f3d12527d..e05cddf199 100644 --- a/tests/compiler/features/gc.debug.wat +++ b/tests/compiler/features/gc.debug.wat @@ -6,9 +6,9 @@ (global $features/gc/globalExtern externref (ref.null noextern)) (global $features/gc/globalAny anyref (ref.null none)) (global $features/gc/globalEq eqref (ref.null none)) - (global $features/gc/globalI31 i31ref (ref.null none)) - (global $features/gc/globalData dataref (ref.null none)) + (global $features/gc/globalStruct dataref (ref.null none)) (global $features/gc/globalArray arrayref (ref.null none)) + (global $features/gc/globalI31 i31ref (ref.null none)) (global $~lib/memory/__data_end i32 (i32.const 60)) (global $~lib/memory/__stack_pointer (mut i32) (i32.const 32828)) (global $~lib/memory/__heap_base i32 (i32.const 32828)) @@ -21,9 +21,9 @@ (export "globalExtern" (global $features/gc/globalExtern)) (export "globalAny" (global $features/gc/globalAny)) (export "globalEq" (global $features/gc/globalEq)) - (export "globalI31" (global $features/gc/globalI31)) - (export "globalData" (global $features/gc/globalData)) + (export "globalStruct" (global $features/gc/globalStruct)) (export "globalArray" (global $features/gc/globalArray)) + (export "globalI31" (global $features/gc/globalI31)) (export "memory" (memory $0)) (export "_start" (func $~start)) (func $features/gc/test_i31 (type $none_=>_none) diff --git a/tests/compiler/features/gc.release.wat b/tests/compiler/features/gc.release.wat index 210ed85abe..804d53501a 100644 --- a/tests/compiler/features/gc.release.wat +++ b/tests/compiler/features/gc.release.wat @@ -4,9 +4,9 @@ (global $features/gc/globalExtern externref (ref.null noextern)) (global $features/gc/globalAny anyref (ref.null none)) (global $features/gc/globalEq eqref (ref.null none)) - (global $features/gc/globalI31 i31ref (ref.null none)) - (global $features/gc/globalData dataref (ref.null none)) + (global $features/gc/globalStruct dataref (ref.null none)) (global $features/gc/globalArray arrayref (ref.null none)) + (global $features/gc/globalI31 i31ref (ref.null none)) (memory $0 1) (data (i32.const 1036) ",") (data (i32.const 1048) "\01\00\00\00\1c\00\00\00f\00e\00a\00t\00u\00r\00e\00s\00/\00g\00c\00.\00t\00s") @@ -14,9 +14,9 @@ (export "globalExtern" (global $features/gc/globalExtern)) (export "globalAny" (global $features/gc/globalAny)) (export "globalEq" (global $features/gc/globalEq)) - (export "globalI31" (global $features/gc/globalI31)) - (export "globalData" (global $features/gc/globalData)) + (export "globalStruct" (global $features/gc/globalStruct)) (export "globalArray" (global $features/gc/globalArray)) + (export "globalI31" (global $features/gc/globalI31)) (export "memory" (memory $0)) (export "_start" (func $~start)) (func $~start (type $none_=>_none) diff --git a/tests/compiler/features/gc.ts b/tests/compiler/features/gc.ts index 56501d37f8..fdc6163838 100644 --- a/tests/compiler/features/gc.ts +++ b/tests/compiler/features/gc.ts @@ -13,6 +13,6 @@ export const globalFunc: funcref = null; export const globalExtern: externref = null; export const globalAny: anyref = null; export const globalEq: eqref = null; -export const globalI31: i31ref = null; -export const globalData: dataref = null; +export const globalStruct: structref = null; export const globalArray: arrayref = null; +export const globalI31: i31ref = null;