Skip to content

Add initial support for anyref as an opaque type #2294

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 1 commit into from
Aug 20, 2019
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export_function "_BinaryenTypeInt64"
export_function "_BinaryenTypeFloat32"
export_function "_BinaryenTypeFloat64"
export_function "_BinaryenTypeVec128"
export_function "_BinaryenTypeAnyref"
export_function "_BinaryenTypeExnref"
export_function "_BinaryenTypeUnreachable"
export_function "_BinaryenTypeAuto"
Expand Down
4 changes: 2 additions & 2 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
self.stderr = stderr


def run_process(cmd, check=True, input=None, capture_output=False, *args, **kw):
def run_process(cmd, check=True, input=None, capture_output=False, decode_output=True, *args, **kw):
if input and type(input) == str:
input = bytes(input, 'utf-8')
if capture_output:
kw['stdout'] = subprocess.PIPE
kw['stderr'] = subprocess.PIPE
ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
if ret.stdout is not None:
if decode_output and ret.stdout is not None:
ret.stdout = ret.stdout.decode('utf-8')
if ret.stderr is not None:
ret.stderr = ret.stderr.decode('utf-8')
Expand Down
8 changes: 7 additions & 1 deletion src/asmjs/asm_v_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ AsmType wasmToAsmType(Type type) {
return ASM_INT64;
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref is not supported by asm2wasm");
case exnref:
assert(false && "exnref is not in asm2wasm");
assert(false && "exnref is not supported by asm2wasm");
case none:
return ASM_NONE;
case unreachable:
Expand All @@ -75,6 +77,8 @@ char getSig(Type type) {
return 'd';
case v128:
return 'V';
case anyref:
return 'a';
case exnref:
return 'e';
case none:
Expand Down Expand Up @@ -105,6 +109,8 @@ Type sigToType(char sig) {
return f64;
case 'V':
return v128;
case 'a':
return anyref;
case 'e':
return exnref;
case 'v':
Expand Down
4 changes: 4 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
break;
}

case Type::anyref: // there's no anyref literals
case Type::exnref: // there's no exnref literals
case Type::none:
case Type::unreachable:
Expand All @@ -90,6 +91,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
return Literal(x.i64).castToF64();
case Type::v128:
return Literal(x.v128);
case Type::anyref: // there's no anyref literals
case Type::exnref: // there's no exnref literals
case Type::none:
case Type::unreachable:
Expand Down Expand Up @@ -210,6 +212,7 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) {
out << "BinaryenLiteralVec128(" << array << ")";
break;
}
case Type::anyref: // there's no anyref literals
case Type::exnref: // there's no exnref literals
case Type::none:
case Type::unreachable:
Expand Down Expand Up @@ -265,6 +268,7 @@ BinaryenType BinaryenTypeInt64(void) { return i64; }
BinaryenType BinaryenTypeFloat32(void) { return f32; }
BinaryenType BinaryenTypeFloat64(void) { return f64; }
BinaryenType BinaryenTypeVec128(void) { return v128; }
BinaryenType BinaryenTypeAnyref(void) { return anyref; }
BinaryenType BinaryenTypeExnref(void) { return exnref; }
BinaryenType BinaryenTypeUnreachable(void) { return unreachable; }
BinaryenType BinaryenTypeAuto(void) { return uint32_t(-1); }
Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ BinaryenType BinaryenTypeInt64(void);
BinaryenType BinaryenTypeFloat32(void);
BinaryenType BinaryenTypeFloat64(void);
BinaryenType BinaryenTypeVec128(void);
BinaryenType BinaryenTypeAnyref(void);
BinaryenType BinaryenTypeExnref(void);
BinaryenType BinaryenTypeUnreachable(void);
// Not a real type. Used as the last parameter to BinaryenBlock to let
Expand Down
2 changes: 2 additions & 0 deletions src/ir/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ inline UnaryOp getUnary(Type type, Op op) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case anyref: // there's no unary instructions for anyref
case exnref: // there's no unary instructions for exnref
case none:
case unreachable: {
Expand Down Expand Up @@ -212,6 +213,7 @@ inline BinaryOp getBinary(Type type, Op op) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case anyref: // there's no binary instructions for anyref
case exnref: // there's no binary instructions for exnref
case none:
case unreachable: {
Expand Down
1 change: 1 addition & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Module['i64'] = Module['_BinaryenTypeInt64']();
Module['f32'] = Module['_BinaryenTypeFloat32']();
Module['f64'] = Module['_BinaryenTypeFloat64']();
Module['v128'] = Module['_BinaryenTypeVec128']();
Module['anyref'] = Module['_BinaryenTypeAnyref']();
Module['exnref'] = Module['_BinaryenTypeExnref']();
Module['unreachable'] = Module['_BinaryenTypeUnreachable']();
Module['auto'] = /* deprecated */ Module['undefined'] = Module['_BinaryenTypeAuto']();
Expand Down
2 changes: 2 additions & 0 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Literal {
Literal(int32_t(0)),
Literal(int32_t(0)),
Literal(int32_t(0))}});
case Type::anyref: // there's no anyref literals
case Type::exnref: // there's no exnref literals
case none:
case unreachable:
Expand Down Expand Up @@ -430,6 +431,7 @@ template<> struct less<wasm::Literal> {
return a.reinterpreti64() < b.reinterpreti64();
case wasm::Type::v128:
return memcmp(a.getv128Ptr(), b.getv128Ptr(), 16) < 0;
case wasm::Type::anyref: // anyref is an opaque value
case wasm::Type::exnref: // exnref is an opaque value
case wasm::Type::none:
case wasm::Type::unreachable:
Expand Down
1 change: 1 addition & 0 deletions src/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
break;
}
case v128:
case anyref: // there's no anyref.const
case exnref: // there's no exnref.const
WASM_UNREACHABLE();
case none:
Expand Down
9 changes: 3 additions & 6 deletions src/passes/ConstHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ struct ConstHoisting : public WalkerPass<PostWalker<ConstHoisting>> {
size = getTypeSize(value.type);
break;
}
case v128: {
// v128 not implemented yet
return false;
}
case exnref: {
// exnref cannot have literals
case v128: // v128 not implemented yet
case anyref: // anyref cannot have literals
case exnref: { // exnref cannot have literals
return false;
}
case none:
Expand Down
8 changes: 8 additions & 0 deletions src/passes/FuncCastEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ static Expression* toABI(Expression* value, Module* module) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case anyref: {
assert(false && "anyref cannot be converted to i64");
WASM_UNREACHABLE();
}
case exnref: {
assert(false && "exnref cannot be converted to i64");
WASM_UNREACHABLE();
Expand Down Expand Up @@ -108,6 +112,10 @@ static Expression* fromABI(Expression* value, Type type, Module* module) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case anyref: {
assert(false && "anyref cannot be converted from i64");
WASM_UNREACHABLE();
}
case exnref: {
assert(false && "exnref cannot be converted from i64");
WASM_UNREACHABLE();
Expand Down
6 changes: 5 additions & 1 deletion src/passes/InstrumentLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
break;
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref not implemented yet");
case exnref:
assert(false && "not implemented yet");
assert(false && "exnref not implemented yet");
case none:
WASM_UNREACHABLE();
case unreachable:
Expand Down Expand Up @@ -113,6 +115,8 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
break;
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref not implemented yet");
case exnref:
assert(false && "exnref not implemented yet");
case unreachable:
Expand Down
2 changes: 2 additions & 0 deletions src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
break;
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref not implemented yet");
case exnref:
assert(false && "exnref not implemented yet");
case none:
Expand Down
34 changes: 27 additions & 7 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ class TranslateToFuzzReader {
case f32:
case f64:
case v128:
case anyref:
case exnref:
ret = _makeConcrete(type);
break;
Expand Down Expand Up @@ -1370,6 +1371,7 @@ class TranslateToFuzzReader {
return builder.makeLoad(
16, false, offset, pick(1, 2, 4, 8, 16), ptr, type);
}
case anyref: // anyref cannot be loaded from memory
case exnref: // exnref cannot be loaded from memory
case none:
case unreachable:
Expand Down Expand Up @@ -1471,6 +1473,7 @@ class TranslateToFuzzReader {
return builder.makeStore(
16, offset, pick(1, 2, 4, 8, 16), ptr, value, type);
}
case anyref: // anyref cannot be stored in memory
case exnref: // exnref cannot be stored in memory
case none:
case unreachable:
Expand All @@ -1481,7 +1484,7 @@ class TranslateToFuzzReader {

Expression* makeStore(Type type) {
// exnref type cannot be stored in memory
if (!allowMemory || type == exnref) {
if (!allowMemory || isReferenceType(type)) {
return makeTrivial(type);
}
auto* ret = makeNonAtomicStore(type);
Expand Down Expand Up @@ -1566,6 +1569,7 @@ class TranslateToFuzzReader {
case f64:
return Literal(getDouble());
case v128:
case anyref: // anyref cannot have literals
case exnref: // exnref cannot have literals
case none:
case unreachable:
Expand Down Expand Up @@ -1608,6 +1612,7 @@ class TranslateToFuzzReader {
case f64:
return Literal(double(small));
case v128:
case anyref: // anyref cannot have literals
case exnref: // exnref cannot have literals
case none:
case unreachable:
Expand Down Expand Up @@ -1673,6 +1678,7 @@ class TranslateToFuzzReader {
std::numeric_limits<uint64_t>::max()));
break;
case v128:
case anyref: // anyref cannot have literals
case exnref: // exnref cannot have literals
case none:
case unreachable:
Expand Down Expand Up @@ -1704,6 +1710,7 @@ class TranslateToFuzzReader {
value = Literal(double(int64_t(1) << upTo(64)));
break;
case v128:
case anyref: // anyref cannot have literals
case exnref: // exnref cannot have literals
case none:
case unreachable:
Expand All @@ -1728,12 +1735,21 @@ class TranslateToFuzzReader {
}

Expression* makeConst(Type type) {
if (type == exnref) {
// There's no exnref.const.
// TODO We should return a nullref once we implement instructions for
// reference types proposal.
assert(false && "exnref const is not implemented yet");
switch (type) {
case anyref:
// There's no anyref.const.
// TODO We should return a nullref once we implement instructions for
// reference types proposal.
assert(false && "anyref const is not implemented yet");
case exnref:
// There's no exnref.const.
// TODO We should return a nullref once we implement instructions for
// reference types proposal.
assert(false && "exnref const is not implemented yet");
default:
break;
}

auto* ret = wasm.allocator.alloc<Const>();
ret->value = makeLiteral(type);
ret->type = type;
Expand Down Expand Up @@ -1802,6 +1818,7 @@ class TranslateToFuzzReader {
AllTrueVecI64x2),
make(v128)});
}
case anyref: // there's no unary ops for anyref
case exnref: // there's no unary ops for exnref
case none:
case unreachable:
Expand Down Expand Up @@ -1933,6 +1950,7 @@ class TranslateToFuzzReader {
}
WASM_UNREACHABLE();
}
case anyref: // there's no unary ops for anyref
case exnref: // there's no unary ops for exnref
case none:
case unreachable:
Expand All @@ -1955,7 +1973,7 @@ class TranslateToFuzzReader {
return makeTrivial(type);
}
// There's no binary ops for exnref
if (type == exnref) {
if (isReferenceType(type)) {
makeTrivial(type);
}

Expand Down Expand Up @@ -2146,6 +2164,7 @@ class TranslateToFuzzReader {
make(v128),
make(v128)});
}
case anyref: // there's no binary ops for anyref
case exnref: // there's no binary ops for exnref
case none:
case unreachable:
Expand Down Expand Up @@ -2340,6 +2359,7 @@ class TranslateToFuzzReader {
op = ExtractLaneVecF64x2;
break;
case v128:
case anyref:
case exnref:
case none:
case unreachable:
Expand Down
1 change: 1 addition & 0 deletions src/tools/spec-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static std::string generateSpecWrapper(Module& wasm) {
case v128:
ret += "(v128.const i32x4 0 0 0 0)";
break;
case anyref: // there's no anyref.const
case exnref: // there's no exnref.const
case none:
case unreachable:
Expand Down
1 change: 1 addition & 0 deletions src/tools/tool-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::ExceptionHandling,
"exception handling operations")
.addFeature(FeatureSet::TailCall, "tail call operations")
.addFeature(FeatureSet::ReferenceTypes, "reference types")
.add("--no-validation",
"-n",
"Disables validation, assumes inputs are correct",
Expand Down
5 changes: 5 additions & 0 deletions src/tools/wasm-reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ struct Reducer
fixed = builder->makeUnary(TruncSFloat64ToInt32, child);
break;
case v128:
case anyref:
case exnref:
continue; // not implemented yet
case none:
Expand All @@ -614,6 +615,7 @@ struct Reducer
fixed = builder->makeUnary(TruncSFloat64ToInt64, child);
break;
case v128:
case anyref:
case exnref:
continue; // not implemented yet
case none:
Expand All @@ -636,6 +638,7 @@ struct Reducer
fixed = builder->makeUnary(DemoteFloat64, child);
break;
case v128:
case anyref:
case exnref:
continue; // not implemented yet
case none:
Expand All @@ -658,6 +661,7 @@ struct Reducer
case f64:
WASM_UNREACHABLE();
case v128:
case anyref:
case exnref:
continue; // not implemented yet
case none:
Expand All @@ -667,6 +671,7 @@ struct Reducer
break;
}
case v128:
case anyref:
case exnref:
continue; // not implemented yet
case none:
Expand Down
Loading