Skip to content

BREAKING CHANGE: Prepare for dataref becoming structref #2551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
23 changes: 12 additions & 11 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion std/assembly/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/features/gc.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/features/gc.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
(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")
(export "globalFunc" (global $features/gc/globalFunc))
(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)
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/features/gc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;