Skip to content
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

Rename anyref to externref to match proposal change #1319

Merged
merged 13 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-mirror: https://nodejs.org/download/v8-canary/
# FIXME: newer node-v8 builds are currently broken
node-version: "14.0.0-v8-canary201911242015a12d82"
node-version: "15.0.0-v8-canary202007077c53168ead"
- name: Install dependencies
run: npm ci --no-audit
- name: Clean distribution files
Expand Down
6 changes: 3 additions & 3 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 @@ -21,7 +21,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "93.0.0-nightly.20200609",
"binaryen": "93.0.0-nightly.20200611",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"ts-node": "^6.2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ function builtin_nameof(ctx: BuiltinContext): ExpressionRef {
if (signatureReference) {
value = "Function";
} else {
value = "Anyref";
value = "Externref";
}
}
} else {
Expand All @@ -990,7 +990,7 @@ function builtin_nameof(ctx: BuiltinContext): ExpressionRef {
case TypeKind.ISIZE: { value = "isize"; break; }
case TypeKind.USIZE: { value = "usize"; break; }
case TypeKind.V128: { value = "v128"; break; }
case TypeKind.ANYREF: { value = "anyref"; break; }
case TypeKind.EXTERNREF: { value = "externref"; break; }
default: assert(false);
case TypeKind.VOID: { value = "void"; break; }
}
Expand Down
4 changes: 2 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace CommonNames {
export const f32 = "f32";
export const f64 = "f64";
export const v128 = "v128";
export const anyref = "anyref";
export const externref = "externref";
export const i8x16 = "i8x16";
export const u8x16 = "u8x16";
export const i16x8 = "i16x8";
Expand Down Expand Up @@ -185,7 +185,7 @@ export namespace CommonNames {
export const F32 = "F32";
export const F64 = "F64";
export const V128 = "V128";
export const Anyref = "Anyref";
export const Externref = "Externref";
export const String = "String";
export const Array = "Array";
export const StaticArray = "StaticArray";
Expand Down
27 changes: 18 additions & 9 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4375,7 +4375,7 @@ export class Compiler extends DiagnosticEmitter {
);
break;
}
case TypeKind.ANYREF: {
case TypeKind.EXTERNREF: {
// TODO: ref.eq
this.error(
DiagnosticCode.Not_implemented_0,
Expand Down Expand Up @@ -4476,7 +4476,7 @@ export class Compiler extends DiagnosticEmitter {
);
break;
}
case TypeKind.ANYREF: {
case TypeKind.EXTERNREF: {
// TODO: !ref.eq
this.error(
DiagnosticCode.Not_implemented_0,
Expand Down Expand Up @@ -8271,7 +8271,12 @@ export class Compiler extends DiagnosticEmitter {
this.currentType = signatureReference.type.asNullable();
return module.i32(0);
}
return module.ref_null();
// TODO: return null ref for externref or funcref
this.error(
DiagnosticCode.Not_implemented_0,
expression.range,
"null references"
);
jayphelps marked this conversation as resolved.
Show resolved Hide resolved
}
this.currentType = options.usizeType;
this.warning(
Expand Down Expand Up @@ -8464,7 +8469,7 @@ export class Compiler extends DiagnosticEmitter {
);
if (!functionInstance || !this.compileFunction(functionInstance)) return module.unreachable();
if (contextualType.is(TypeFlags.HOST | TypeFlags.REFERENCE)) {
this.currentType = Type.anyref;
this.currentType = Type.externref;
return module.ref_func(functionInstance.internalName);
}
let index = this.ensureFunctionTableEntry(functionInstance);
Expand Down Expand Up @@ -10469,7 +10474,7 @@ export class Compiler extends DiagnosticEmitter {
typeString = "object";
}
} else {
typeString = "anyref"; // TODO?
typeString = "externref"; // TODO?
}
}
} else if (type == Type.bool) {
Expand Down Expand Up @@ -10580,7 +10585,7 @@ export class Compiler extends DiagnosticEmitter {
checkTypeSupported(type: Type, reportNode: Node): bool {
switch (type.kind) {
case TypeKind.V128: return this.checkFeatureEnabled(Feature.SIMD, reportNode);
case TypeKind.ANYREF: return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode);
case TypeKind.EXTERNREF: return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode);
}
if (type.is(TypeFlags.REFERENCE)) {
let classReference = type.classReference;
Expand Down Expand Up @@ -10653,7 +10658,10 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.F32: return module.f32(0);
case TypeKind.F64: return module.f64(0);
case TypeKind.V128: return module.v128(v128_zero);
case TypeKind.ANYREF: return module.ref_null();
case TypeKind.EXTERNREF:
// TODO: return null ref for both externref as well as funcref
assert(false, 'null for externref is not yet supported');
return module.unreachable();
}
}

Expand Down Expand Up @@ -10752,10 +10760,11 @@ export class Compiler extends DiagnosticEmitter {
flow.freeTempLocal(temp);
return ret;
}
case TypeKind.ANYREF: {
case TypeKind.EXTERNREF: {
// TODO: non-null object might still be considered falseish
// i.e. a ref to Boolean(false), Number(0), String("") etc.
return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr));
// TODO: return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr));
assert(false, 'Truthy checks for externref are not yet supported');
dcodeIO marked this conversation as resolved.
Show resolved Hide resolved
}
default: {
assert(false);
Expand Down
10 changes: 5 additions & 5 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class Flow {
case <u32>NativeType.F32: { temps = parentFunction.tempF32s; break; }
case <u32>NativeType.F64: { temps = parentFunction.tempF64s; break; }
case <u32>NativeType.V128: { temps = parentFunction.tempV128s; break; }
case <u32>NativeType.Anyref: { temps = parentFunction.tempAnyrefs; break; }
case <u32>NativeType.Externref: { temps = parentFunction.tempExternrefs; break; }
case <u32>NativeType.Exnref: { temps = parentFunction.tempExnrefs; break; }
default: throw new Error("concrete type expected");
}
Expand Down Expand Up @@ -395,10 +395,10 @@ export class Flow {
else parentFunction.tempV128s = temps = [];
break;
}
case <u32>NativeType.Anyref: {
let tempAnyrefs = parentFunction.tempAnyrefs;
if (tempAnyrefs) temps = tempAnyrefs;
else parentFunction.tempAnyrefs = temps = [];
case <u32>NativeType.Externref: {
let tempExternrefs = parentFunction.tempExternrefs;
if (tempExternrefs) temps = tempExternrefs;
else parentFunction.tempExternrefs = temps = [];
break;
}
case <u32>NativeType.Exnref: {
Expand Down
4 changes: 2 additions & 2 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @fileoverview Portable definitions for Binaryen's C-API.
*
*
* tsc uses the .js file next to it, while asc makes it a Wasm import.
*
* See: https://github.com/WebAssembly/binaryen/blob/master/src/binaryen-c.h
Expand Down Expand Up @@ -34,7 +34,7 @@ export declare function _BinaryenTypeFloat32(): BinaryenType;
export declare function _BinaryenTypeFloat64(): BinaryenType;
export declare function _BinaryenTypeVec128(): BinaryenType;
export declare function _BinaryenTypeFuncref(): BinaryenType;
export declare function _BinaryenTypeAnyref(): BinaryenType;
export declare function _BinaryenTypeExternref(): BinaryenType;
export declare function _BinaryenTypeNullref(): BinaryenType;
export declare function _BinaryenTypeExnref(): BinaryenType;
export declare function _BinaryenTypeUnreachable(): BinaryenType;
Expand Down
6 changes: 3 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export namespace NativeType {
export const F64: NativeType = 5 /* _BinaryenTypeFloat64 */;
export const V128: NativeType = 6 /* _BinaryenTypeVec128 */;
export const Funcref: NativeType = 7 /* _BinaryenTypeFuncref */;
export const Anyref: NativeType = 8 /* _BinaryenTypeAnyref */;
export const Externref: NativeType = 8 /* _BinaryenTypeExternref */;
export const Nullref: NativeType = 9 /* _BinaryenTypeNullref */;
export const Exnref: NativeType = 10 /* _BinaryenTypeExnref */;
export const Auto: NativeType = -1 /* _BinaryenTypeAuto */;
Expand Down Expand Up @@ -1759,8 +1759,8 @@ export class Module {
// TODO
return 0;
}
// Not possible to clone an anyref as it is opaque
case <u32>NativeType.Anyref: {
// Not possible to clone an externref as it is opaque
case <u32>NativeType.Externref: {
return 0;
}
default: {
Expand Down
6 changes: 3 additions & 3 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ export class Program extends DiagnosticEmitter {
// compiler needs to check this condition whenever such a value is created
// respectively stored or loaded.
this.registerNativeType(CommonNames.v128, Type.v128);
this.registerNativeType(CommonNames.anyref, Type.anyref);
this.registerNativeType(CommonNames.externref, Type.externref);

// register compiler hints
this.registerConstantInteger(CommonNames.ASC_TARGET, Type.i32,
Expand Down Expand Up @@ -1136,7 +1136,7 @@ export class Program extends DiagnosticEmitter {
this.registerWrapperClass(Type.f32, CommonNames.F32);
this.registerWrapperClass(Type.f64, CommonNames.F64);
if (options.hasFeature(Feature.SIMD)) this.registerWrapperClass(Type.v128, CommonNames.V128);
if (options.hasFeature(Feature.REFERENCE_TYPES)) this.registerWrapperClass(Type.anyref, CommonNames.Anyref);
if (options.hasFeature(Feature.REFERENCE_TYPES)) this.registerWrapperClass(Type.externref, CommonNames.Externref);

// resolve prototypes of extended classes or interfaces
var resolver = this.resolver;
Expand Down Expand Up @@ -3565,7 +3565,7 @@ export class Function extends TypedElement {
tempF32s: Local[] | null = null;
tempF64s: Local[] | null = null;
tempV128s: Local[] | null = null;
tempAnyrefs: Local[] | null = null;
tempExternrefs: Local[] | null = null;
tempExnrefs: Local[] | null = null;

// used by flows to keep track of break labels
Expand Down
4 changes: 2 additions & 2 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ export class Resolver extends DiagnosticEmitter {
let classReference = ctxType.classReference;
return ctxType.is(TypeFlags.REFERENCE) && classReference !== null
? classReference.type.asNullable()
: this.program.options.usizeType; // TODO: anyref context?
: this.program.options.usizeType; // TODO: externref context?
}
}
var element = this.lookupIdentifierExpression(node, ctxFlow, ctxElement, reportMode);
Expand Down Expand Up @@ -2301,7 +2301,7 @@ export class Resolver extends DiagnosticEmitter {
if (
numNullLiterals > 0 &&
elementType.is(TypeFlags.REFERENCE) &&
!elementType.is(TypeFlags.HOST) // TODO: anyref isn't nullable as-is
!elementType.is(TypeFlags.HOST) // TODO: externref isn't nullable as-is
) {
elementType = elementType.asNullable();
}
Expand Down
14 changes: 7 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const enum TypeKind {
// references

/** Any host reference. */
ANYREF,
EXTERNREF,

// other

Expand Down Expand Up @@ -267,7 +267,7 @@ export class Type {
if (targetFunction = target.signatureReference) {
return currentFunction.isAssignableTo(targetFunction);
}
} else if (this.kind == TypeKind.ANYREF && target.kind == TypeKind.ANYREF) {
} else if (this.kind == TypeKind.EXTERNREF && target.kind == TypeKind.EXTERNREF) {
return true;
}
}
Expand Down Expand Up @@ -344,8 +344,8 @@ export class Type {
: signatureReference.toString();
}
// TODO: Reflect.apply(value, "toString", []) ?
assert(this.kind == TypeKind.ANYREF);
return "anyref";
assert(this.kind == TypeKind.EXTERNREF);
return "externref";
}
switch (this.kind) {
case TypeKind.I8: return "i8";
Expand All @@ -362,7 +362,7 @@ export class Type {
case TypeKind.F32: return "f32";
case TypeKind.F64: return "f64";
case TypeKind.V128: return "v128";
case TypeKind.ANYREF: return "anyref";
case TypeKind.EXTERNREF: return "externref";
default: assert(false);
case TypeKind.VOID: return "void";
}
Expand All @@ -388,7 +388,7 @@ export class Type {
case TypeKind.F32: return NativeType.F32;
case TypeKind.F64: return NativeType.F64;
case TypeKind.V128: return NativeType.V128;
case TypeKind.ANYREF: return NativeType.Anyref;
case TypeKind.EXTERNREF: return NativeType.Externref;
case TypeKind.VOID: return NativeType.None;
}
}
Expand Down Expand Up @@ -521,7 +521,7 @@ export class Type {
);

/** Any host reference. */
static readonly anyref: Type = new Type(TypeKind.ANYREF,
static readonly externref: Type = new Type(TypeKind.EXTERNREF,
TypeFlags.HOST |
TypeFlags.REFERENCE, 0
);
Expand Down
8 changes: 4 additions & 4 deletions std/assembly/bindings/Reflect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare function get(target: anyref, propertyKey: anyref/* , receiver: anyref */): anyref;
export declare function has(target: anyref, propertyKey: anyref): bool;
export declare function set(target: anyref, propertyKey: anyref, value: anyref/* , receiver: anyref */): anyref;
export declare function apply(target: anyref, thisArgument: anyref, argumentsList: anyref): anyref;
export declare function get(target: externref, propertyKey: externref/* , receiver: externref */): externref;
export declare function has(target: externref, propertyKey: externref): bool;
export declare function set(target: externref, propertyKey: externref, value: externref/* , receiver: externref */): externref;
export declare function apply(target: externref, thisArgument: externref, argumentsList: externref): externref;
16 changes: 8 additions & 8 deletions std/assembly/bindings/console.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export declare function assert(value: anyref): void;
export declare function assert(value: externref): void;
export declare function clear(): void;
export declare function error(value: anyref): void;
export declare function info(value: anyref): void;
export declare function log(value: anyref): void;
export declare function time(label: anyref): anyref;
export declare function timeEnd(label: anyref): void;
export declare function timeLog(label: anyref): void;
export declare function error(value: externref): void;
export declare function info(value: externref): void;
export declare function log(value: externref): void;
export declare function time(label: externref): externref;
export declare function timeEnd(label: externref): void;
export declare function timeLog(label: externref): void;
export declare function trace(): void;
export declare function warn(value: anyref): void;
export declare function warn(value: externref): void;
2 changes: 1 addition & 1 deletion std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare type f64 = number;
/** A 128-bit vector. */
declare type v128 = object;
/** A host reference. */
declare type anyref = object;
declare type externref = object;

// Compiler hints

Expand Down
2 changes: 1 addition & 1 deletion std/assembly/reference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Host reference abstraction. */
@final @unmanaged
export abstract class Anyref {
export abstract class Externref {
}
Loading