Skip to content

Implement preliminary creation of Wasm GC types #2537

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

Merged
merged 11 commits into from
Oct 21, 2022
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"engineStrict": true,
"dependencies": {
"binaryen": "110.0.0-nightly.20221006",
"binaryen": "110.0.0-nightly.20221019",
"long": "^5.2.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3492,6 +3492,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef {
case TypeKind.ANYREF:
case TypeKind.EQREF:
case TypeKind.DATAREF:
case TypeKind.ARRAYREF:
case TypeKind.I31REF:
case TypeKind.STRINGREF:
case TypeKind.STRINGVIEW_WTF8:
Expand Down Expand Up @@ -3578,6 +3579,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef {
case TypeKind.ANYREF:
case TypeKind.EQREF:
case TypeKind.DATAREF:
case TypeKind.ARRAYREF:
case TypeKind.I31REF:
case TypeKind.STRINGREF:
case TypeKind.STRINGVIEW_WTF8:
Expand Down
2 changes: 2 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export namespace CommonNames {
export const eqref = "eqref";
export const i31ref = "i31ref";
export const dataref = "dataref";
export const arrayref = "arrayref";
export const stringref = "stringref";
export const stringview_wtf8 = "stringview_wtf8";
export const stringview_wtf16 = "stringview_wtf16";
Expand Down Expand Up @@ -212,6 +213,7 @@ export namespace CommonNames {
export const Eqref = "Eqref";
export const I31ref = "I31ref";
export const Dataref = "Dataref";
export const Arrayref = "Arrayref";
export const String = "String";
export const RegExp = "RegExp";
export const Object = "Object";
Expand Down
20 changes: 14 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
ExpressionRunnerFlags,
isConstZero,
isConstNegZero,
isConstExpressionNaN
isConstExpressionNaN,
ensureType
} from "./module";

import {
Expand Down Expand Up @@ -4869,7 +4870,8 @@ export class Compiler extends DiagnosticEmitter {
}
case TypeKind.EQREF:
case TypeKind.I31REF:
case TypeKind.DATAREF: return module.ref_eq(leftExpr, rightExpr);
case TypeKind.DATAREF:
case TypeKind.ARRAYREF: return module.ref_eq(leftExpr, rightExpr);
case TypeKind.STRINGREF: return module.string_eq(leftExpr, rightExpr);
case TypeKind.STRINGVIEW_WTF8:
case TypeKind.STRINGVIEW_WTF16:
Expand Down Expand Up @@ -4918,7 +4920,8 @@ export class Compiler extends DiagnosticEmitter {
}
case TypeKind.EQREF:
case TypeKind.I31REF:
case TypeKind.DATAREF: {
case TypeKind.DATAREF:
case TypeKind.ARRAYREF: {
return module.unary(UnaryOp.EqzI32,
module.ref_eq(leftExpr, rightExpr)
);
Expand Down Expand Up @@ -7612,8 +7615,11 @@ export class Compiler extends DiagnosticEmitter {
return module.unreachable();
}
if (contextualType.isExternalReference) {
// TODO: Concrete function types currently map to first class functions implemented in
// linear memory (on top of `usize`), leaving only generic `funcref` for use here. In the
// future, once functions become Wasm GC objects, the actual signature type can be used.
this.currentType = Type.funcref;
return module.ref_func(functionInstance.internalName, TypeRef.Funcref); // TODO
return module.ref_func(functionInstance.internalName, ensureType(functionInstance.type));
}
let offset = this.ensureRuntimeFunction(functionInstance);
this.currentType = functionInstance.signature.type;
Expand Down Expand Up @@ -9854,7 +9860,8 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.ANYREF:
case TypeKind.EQREF:
case TypeKind.I31REF:
case TypeKind.DATAREF: {
case TypeKind.DATAREF:
case TypeKind.ARRAYREF: {
return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode)
&& this.checkFeatureEnabled(Feature.GC, reportNode);
}
Expand Down Expand Up @@ -9970,7 +9977,8 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.EXTERNREF:
case TypeKind.ANYREF:
case TypeKind.EQREF:
case TypeKind.DATAREF:
case TypeKind.DATAREF:
case TypeKind.ARRAYREF:
case TypeKind.STRINGREF:
case TypeKind.STRINGVIEW_WTF8:
case TypeKind.STRINGVIEW_WTF16:
Expand Down
7 changes: 7 additions & 0 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class Flow {
case <u32>TypeRef.Eqref: { temps = parentFunction.tempEqrefs; break; }
case <u32>TypeRef.I31ref: { temps = parentFunction.tempI31refs; break; }
case <u32>TypeRef.Dataref: { temps = parentFunction.tempDatarefs; break; }
case <u32>TypeRef.Arrayref: { temps = parentFunction.tempArrayrefs; break; }
default: throw new Error("concrete type expected");
}
var local: Local;
Expand Down Expand Up @@ -446,6 +447,12 @@ export class Flow {
else parentFunction.tempDatarefs = temps = [];
break;
}
case <u32>TypeRef.Arrayref: {
let tempArrayrefs = parentFunction.tempArrayrefs;
if (tempArrayrefs) temps = tempArrayrefs;
else parentFunction.tempArrayrefs = temps = [];
break;
}
default: throw new Error("concrete type expected");
}
temps.push(local);
Expand Down
15 changes: 13 additions & 2 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,32 @@ export declare function _BinaryenTypeAnyref(): TypeRef;
export declare function _BinaryenTypeEqref(): TypeRef;
export declare function _BinaryenTypeI31ref(): TypeRef;
export declare function _BinaryenTypeDataref(): TypeRef;
export declare function _BinaryenTypeArrayref(): TypeRef;
export declare function _BinaryenTypeStringref(): TypeRef;
export declare function _BinaryenTypeStringviewWTF8(): TypeRef;
export declare function _BinaryenTypeStringviewWTF16(): TypeRef;
export declare function _BinaryenTypeStringviewIter(): TypeRef;
export declare function _BinaryenTypeNullref(): TypeRef;
export declare function _BinaryenTypeNullExternref(): TypeRef;
export declare function _BinaryenTypeNullFuncref(): TypeRef;

export declare function _BinaryenHeapTypeFunc(): HeapTypeRef;
export declare function _BinaryenHeapTypeExt(): HeapTypeRef;
export declare function _BinaryenHeapTypeAny(): HeapTypeRef;
export declare function _BinaryenHeapTypeEq(): HeapTypeRef;
export declare function _BinaryenHeapTypeI31(): HeapTypeRef;
export declare function _BinaryenHeapTypeData(): HeapTypeRef;
export declare function _BinaryenHeapTypeArray(): HeapTypeRef;
export declare function _BinaryenHeapTypeString(): HeapTypeRef;
export declare function _BinaryenHeapTypeStringviewWTF8(): HeapTypeRef;
export declare function _BinaryenHeapTypeStringviewWTF16(): HeapTypeRef;
export declare function _BinaryenHeapTypeStringviewIter(): HeapTypeRef;
export declare function _BinaryenHeapTypeNone(): HeapTypeRef;
export declare function _BinaryenHeapTypeNoext(): HeapTypeRef;
export declare function _BinaryenHeapTypeNofunc(): HeapTypeRef;

export declare function _BinaryenHeapTypeIsBottom(heapType: HeapTypeRef): bool;
export declare function _BinaryenHeapTypeGetBottom(heapType: HeapTypeRef): HeapTypeRef;

export declare function _BinaryenModuleCreate(): ModuleRef;
export declare function _BinaryenModuleDispose(module: ModuleRef): void;
Expand Down Expand Up @@ -594,7 +605,7 @@ export declare function _BinaryenStructSetSetValue(expr: ExpressionRef, valueExp
export declare function _BinaryenArrayNew(module: ModuleRef, type: HeapTypeRef, size: ExpressionRef, init: ExpressionRef): ExpressionRef;
export declare function _BinaryenArrayNewGetInit(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenArrayNewSetInit(expr: ExpressionRef, initExpr: ExpressionRef): void;
export declare function _BinaryenArrayNewGetSize(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenArrayNewGetSize(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenArrayNewSetSize(expr: ExpressionRef, sizeExpr: ExpressionRef): void;

export declare function _BinaryenArrayInit(module: ModuleRef, type: HeapTypeRef, values: ArrayRef<ExpressionRef>, numValues: Index): ExpressionRef;
Expand All @@ -605,7 +616,7 @@ export declare function _BinaryenArrayInitAppendValue(expr: ExpressionRef, value
export declare function _BinaryenArrayInitInsertValueAt(expr: ExpressionRef, index: Index, valueExpr: ExpressionRef): void;
export declare function _BinaryenArrayInitRemoveValueAt(expr: ExpressionRef, index: Index): ExpressionRef;

export declare function _BinaryenArrayGet(module: ModuleRef, ref: ExpressionRef, index: ExpressionRef, signed: bool): ExpressionRef;
export declare function _BinaryenArrayGet(module: ModuleRef, ref: ExpressionRef, index: ExpressionRef, type: TypeRef, signed: bool): ExpressionRef;
export declare function _BinaryenArrayGetGetRef(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenArrayGetSetRef(expr: ExpressionRef, refExpr: ExpressionRef): void;
export declare function _BinaryenArrayGetGetIndex(expr: ExpressionRef): ExpressionRef;
Expand Down
11 changes: 11 additions & 0 deletions src/glue/binaryen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,32 @@ export const {
_BinaryenTypeEqref,
_BinaryenTypeI31ref,
_BinaryenTypeDataref,
_BinaryenTypeArrayref,
_BinaryenTypeStringref,
_BinaryenTypeStringviewWTF8,
_BinaryenTypeStringviewWTF16,
_BinaryenTypeStringviewIter,
_BinaryenTypeNullref,
_BinaryenTypeNullExternref,
_BinaryenTypeNullFuncref,

_BinaryenHeapTypeFunc,
_BinaryenHeapTypeExt,
_BinaryenHeapTypeAny,
_BinaryenHeapTypeEq,
_BinaryenHeapTypeI31,
_BinaryenHeapTypeData,
_BinaryenHeapTypeArray,
_BinaryenHeapTypeString,
_BinaryenHeapTypeStringviewWTF8,
_BinaryenHeapTypeStringviewWTF16,
_BinaryenHeapTypeStringviewIter,
_BinaryenHeapTypeNone,
_BinaryenHeapTypeNoext,
_BinaryenHeapTypeNofunc,

_BinaryenHeapTypeIsBottom,
_BinaryenHeapTypeGetBottom,

_BinaryenModuleCreate,
_BinaryenModuleDispose,
Expand Down
Loading