diff options
author | Thomas Lively <tlively@google.com> | 2023-09-13 10:13:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-13 15:13:33 +0000 |
commit | 3ca8c21b89c207ce5d872e9cb2d410a869522d38 (patch) | |
tree | 10757c566326c6894512508a71719ed3b4c594fd | |
parent | bd497d3def1e2c702e29521f097be26024a8253e (diff) | |
download | binaryen-3ca8c21b89c207ce5d872e9cb2d410a869522d38.tar.gz binaryen-3ca8c21b89c207ce5d872e9cb2d410a869522d38.tar.bz2 binaryen-3ca8c21b89c207ce5d872e9cb2d410a869522d38.zip |
Replace I31New with RefI31 everywhere (#5930)
Globally replace the source string "I31New" with "RefI31" in preparation for
renaming the instruction from "i31.new" to "ref.i31", as implemented in the spec
in https://github.com/WebAssembly/gc/pull/422. This would be NFC, except that it
also changes the string in the external-facing C APIs.
A follow-up PR will make the corresponding behavioral change.
36 files changed, 98 insertions, 96 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f76642fa0..7ad9af6b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ full changeset diff at the end of each section. Current Trunk ------------- + - "I31New" changed to "RefI31" everywhere it appears in the C API. + v115 ---- diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py index 715a23d82..e4cd642ca 100755 --- a/scripts/gen-s-parser.py +++ b/scripts/gen-s-parser.py @@ -564,7 +564,7 @@ instructions = [ ("call_ref", "makeCallRef(s, /*isReturn=*/false)"), ("return_call_ref", "makeCallRef(s, /*isReturn=*/true)"), # GC - ("i31.new", "makeI31New(s)"), + ("i31.new", "makeRefI31(s)"), ("i31.get_s", "makeI31Get(s, true)"), ("i31.get_u", "makeI31Get(s, false)"), ("ref.test", "makeRefTest(s)"), diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index fd00c25c0..598156782 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -1732,10 +1732,10 @@ BinaryenExpressionRef BinaryenRethrow(BinaryenModuleRef module, Builder(*(Module*)module).makeRethrow(target)); } -BinaryenExpressionRef BinaryenI31New(BinaryenModuleRef module, +BinaryenExpressionRef BinaryenRefI31(BinaryenModuleRef module, BinaryenExpressionRef value) { return static_cast<Expression*>( - Builder(*(Module*)module).makeI31New((Expression*)value)); + Builder(*(Module*)module).makeRefI31((Expression*)value)); } BinaryenExpressionRef BinaryenI31Get(BinaryenModuleRef module, @@ -3952,18 +3952,18 @@ void BinaryenTupleExtractSetIndex(BinaryenExpressionRef expr, assert(expression->is<TupleExtract>()); static_cast<TupleExtract*>(expression)->index = index; } -// I31New -BinaryenExpressionRef BinaryenI31NewGetValue(BinaryenExpressionRef expr) { +// RefI31 +BinaryenExpressionRef BinaryenRefI31GetValue(BinaryenExpressionRef expr) { auto* expression = (Expression*)expr; - assert(expression->is<I31New>()); - return static_cast<I31New*>(expression)->value; + assert(expression->is<RefI31>()); + return static_cast<RefI31*>(expression)->value; } -void BinaryenI31NewSetValue(BinaryenExpressionRef expr, +void BinaryenRefI31SetValue(BinaryenExpressionRef expr, BinaryenExpressionRef valueExpr) { auto* expression = (Expression*)expr; - assert(expression->is<I31New>()); + assert(expression->is<RefI31>()); assert(valueExpr); - static_cast<I31New*>(expression)->value = (Expression*)valueExpr; + static_cast<RefI31*>(expression)->value = (Expression*)valueExpr; } // I31Get BinaryenExpressionRef BinaryenI31GetGetI31(BinaryenExpressionRef expr) { diff --git a/src/binaryen-c.h b/src/binaryen-c.h index f4f4f2d74..4321ec452 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -1028,7 +1028,7 @@ BINARYEN_API BinaryenExpressionRef BinaryenTupleExtract( BinaryenModuleRef module, BinaryenExpressionRef tuple, BinaryenIndex index); BINARYEN_API BinaryenExpressionRef BinaryenPop(BinaryenModuleRef module, BinaryenType type); -BINARYEN_API BinaryenExpressionRef BinaryenI31New(BinaryenModuleRef module, +BINARYEN_API BinaryenExpressionRef BinaryenRefI31(BinaryenModuleRef module, BinaryenExpressionRef value); BINARYEN_API BinaryenExpressionRef BinaryenI31Get(BinaryenModuleRef module, BinaryenExpressionRef i31, @@ -2306,13 +2306,13 @@ BinaryenTupleExtractGetIndex(BinaryenExpressionRef expr); BINARYEN_API void BinaryenTupleExtractSetIndex(BinaryenExpressionRef expr, BinaryenIndex index); -// I31New +// RefI31 // Gets the value expression of an `i31.new` expression. BINARYEN_API BinaryenExpressionRef -BinaryenI31NewGetValue(BinaryenExpressionRef expr); +BinaryenRefI31GetValue(BinaryenExpressionRef expr); // Sets the value expression of an `i31.new` expression. -BINARYEN_API void BinaryenI31NewSetValue(BinaryenExpressionRef expr, +BINARYEN_API void BinaryenRefI31SetValue(BinaryenExpressionRef expr, BinaryenExpressionRef valueExpr); // I31Get diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc index 57fd2ffed..5b812c6d1 100644 --- a/src/gen-s-parser.inc +++ b/src/gen-s-parser.inc @@ -1203,7 +1203,7 @@ switch (buf[0]) { } } case 'n': - if (op == "i31.new"sv) { return makeI31New(s); } + if (op == "i31.new"sv) { return makeRefI31(s); } goto parse_error; default: goto parse_error; } @@ -5593,7 +5593,7 @@ switch (buf[0]) { } case 'n': if (op == "i31.new"sv) { - auto ret = makeI31New(ctx, pos); + auto ret = makeRefI31(ctx, pos); CHECK_ERR(ret); return *ret; } diff --git a/src/ir/ReFinalize.cpp b/src/ir/ReFinalize.cpp index bcbac85cc..b0dea7627 100644 --- a/src/ir/ReFinalize.cpp +++ b/src/ir/ReFinalize.cpp @@ -132,7 +132,7 @@ void ReFinalize::visitUnreachable(Unreachable* curr) { curr->finalize(); } void ReFinalize::visitPop(Pop* curr) { curr->finalize(); } void ReFinalize::visitTupleMake(TupleMake* curr) { curr->finalize(); } void ReFinalize::visitTupleExtract(TupleExtract* curr) { curr->finalize(); } -void ReFinalize::visitI31New(I31New* curr) { curr->finalize(); } +void ReFinalize::visitRefI31(RefI31* curr) { curr->finalize(); } void ReFinalize::visitI31Get(I31Get* curr) { curr->finalize(); } void ReFinalize::visitCallRef(CallRef* curr) { curr->finalize(); } void ReFinalize::visitRefTest(RefTest* curr) { curr->finalize(); } diff --git a/src/ir/cost.h b/src/ir/cost.h index c34ca1fb6..e7287de77 100644 --- a/src/ir/cost.h +++ b/src/ir/cost.h @@ -598,7 +598,7 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> { CostType visitNop(Nop* curr) { return 0; } CostType visitUnreachable(Unreachable* curr) { return 0; } CostType visitDataDrop(DataDrop* curr) { return 5; } - CostType visitI31New(I31New* curr) { return 3 + visit(curr->value); } + CostType visitRefI31(RefI31* curr) { return 3 + visit(curr->value); } CostType visitI31Get(I31Get* curr) { return 2 + visit(curr->i31); } CostType visitRefTest(RefTest* curr) { // Casts have a very high cost because in the VM they end up implemented as diff --git a/src/ir/effects.h b/src/ir/effects.h index 5670e3ef6..171a17803 100644 --- a/src/ir/effects.h +++ b/src/ir/effects.h @@ -718,7 +718,7 @@ private: } void visitTupleMake(TupleMake* curr) {} void visitTupleExtract(TupleExtract* curr) {} - void visitI31New(I31New* curr) {} + void visitRefI31(RefI31* curr) {} void visitI31Get(I31Get* curr) { // traps when the ref is null if (curr->i31->type.isNullable()) { diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index b44046b39..b23d8220a 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -678,7 +678,7 @@ struct InfoCollector totalPops++; #endif } - void visitI31New(I31New* curr) { + void visitRefI31(RefI31* curr) { // TODO: optimize like struct references addRoot(curr); } diff --git a/src/ir/properties.cpp b/src/ir/properties.cpp index b564b3bf1..63b7cedd1 100644 --- a/src/ir/properties.cpp +++ b/src/ir/properties.cpp @@ -40,7 +40,7 @@ bool isGenerative(Expression* curr, FeatureSet features) { // to whether it is valid in a wasm constant expression. static bool isValidInConstantExpression(Module& wasm, Expression* expr) { if (isSingleConstantExpression(expr) || expr->is<StructNew>() || - expr->is<ArrayNew>() || expr->is<ArrayNewFixed>() || expr->is<I31New>() || + expr->is<ArrayNew>() || expr->is<ArrayNewFixed>() || expr->is<RefI31>() || expr->is<StringConst>()) { return true; } diff --git a/src/ir/properties.h b/src/ir/properties.h index 7f247f72f..e8a17b106 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -117,7 +117,7 @@ inline Literal getLiteral(const Expression* curr) { return Literal(n->type); } else if (auto* r = curr->dynCast<RefFunc>()) { return Literal(r->func, r->type.getHeapType()); - } else if (auto* i = curr->dynCast<I31New>()) { + } else if (auto* i = curr->dynCast<RefI31>()) { if (auto* c = i->value->dynCast<Const>()) { return Literal::makeI31(c->value.geti32()); } diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index d57d5955e..b6ea4d490 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -105,7 +105,7 @@ function initializeConstants() { 'TupleMake', 'TupleExtract', 'Pop', - 'I31New', + 'RefI31', 'I31Get', 'CallRef', 'RefTest', @@ -2419,7 +2419,7 @@ function wrapModule(module, self = {}) { self['i31'] = { 'new'(value) { - return Module['_BinaryenI31New'](module, value); + return Module['_BinaryenRefI31'](module, value); }, 'get_s'(i31) { return Module['_BinaryenI31Get'](module, i31, 1); @@ -3271,11 +3271,11 @@ Module['getExpressionInfo'] = function(expr) { 'tuple': Module['_BinaryenTupleExtractGetTuple'](expr), 'index': Module['_BinaryenTupleExtractGetIndex'](expr) }; - case Module['I31NewId']: + case Module['RefI31Id']: return { 'id': id, 'type': type, - 'value': Module['_BinaryenI31NewGetValue'](expr) + 'value': Module['_BinaryenRefI31GetValue'](expr) }; case Module['I31GetId']: return { @@ -4837,12 +4837,12 @@ Module['TupleExtract'] = makeExpressionWrapper({ } }); -Module['I31New'] = makeExpressionWrapper({ +Module['RefI31'] = makeExpressionWrapper({ 'getValue'(expr) { - return Module['_BinaryenI31NewGetValue'](expr); + return Module['_BinaryenRefI31GetValue'](expr); }, 'setValue'(expr, valueExpr) { - Module['_BinaryenI31NewSetValue'](expr, valueExpr); + Module['_BinaryenRefI31SetValue'](expr, valueExpr); } }); diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 87e30c882..203d922d0 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -1959,7 +1959,7 @@ struct PrintExpressionContents printMedium(o, "tuple.extract "); o << curr->index; } - void visitI31New(I31New* curr) { printMedium(o, "i31.new"); } + void visitRefI31(RefI31* curr) { printMedium(o, "i31.new"); } void visitI31Get(I31Get* curr) { printMedium(o, curr->signed_ ? "i31.get_s" : "i31.get_u"); } diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 2317e7d49..1aa52e70d 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -2341,7 +2341,7 @@ Expression* TranslateToFuzzReader::makeBasicRef(Type type) { if (type.isNullable() && oneIn(4)) { return builder.makeRefNull(HeapType::none); } - return builder.makeI31New(makeConst(Type::i32)); + return builder.makeRefI31(makeConst(Type::i32)); } case HeapType::struct_: { assert(wasm.features.hasGC()); diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 9a857ca14..8c8ae70e6 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1188,7 +1188,7 @@ enum ASTNodes { BrOnCastFail = 0x19, ExternInternalize = 0x1a, ExternExternalize = 0x1b, - I31New = 0x1c, + RefI31 = 0x1c, I31GetS = 0x1d, I31GetU = 0x1e, #else @@ -1209,7 +1209,7 @@ enum ASTNodes { ArrayNew = 0x1b, ArrayNewDefault = 0x1c, ArrayNewData = 0x1d, - I31New = 0x20, + RefI31 = 0x20, I31GetS = 0x21, I31GetU = 0x22, RefTest = 0x40, @@ -1838,7 +1838,7 @@ public: bool maybeVisitMemoryFill(Expression*& out, uint32_t code); bool maybeVisitTableSize(Expression*& out, uint32_t code); bool maybeVisitTableGrow(Expression*& out, uint32_t code); - bool maybeVisitI31New(Expression*& out, uint32_t code); + bool maybeVisitRefI31(Expression*& out, uint32_t code); bool maybeVisitI31Get(Expression*& out, uint32_t code); bool maybeVisitRefTest(Expression*& out, uint32_t code); bool maybeVisitRefCast(Expression*& out, uint32_t code); diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 2093b9419..b9db66983 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -856,8 +856,8 @@ public: ret->finalize(); return ret; } - I31New* makeI31New(Expression* value) { - auto* ret = wasm.allocator.alloc<I31New>(); + RefI31* makeRefI31(Expression* value) { + auto* ret = wasm.allocator.alloc<RefI31>(); ret->value = value; ret->finalize(); return ret; @@ -1209,7 +1209,7 @@ public: return makeRefFunc(value.getFunc(), type.getHeapType()); } if (type.isRef() && type.getHeapType() == HeapType::i31) { - return makeI31New(makeConst(value.geti31())); + return makeRefI31(makeConst(value.geti31())); } if (type.isString()) { // TODO: more than ascii support @@ -1359,7 +1359,7 @@ public: return ExpressionManipulator::refNull(curr, curr->type); } if (curr->type.isRef() && curr->type.getHeapType() == HeapType::i31) { - Expression* ret = makeI31New(makeConst(0)); + Expression* ret = makeRefI31(makeConst(0)); if (curr->type.isNullable()) { // To keep the type identical, wrap it in a block that adds nullability. ret = makeBlock({ret}, curr->type); diff --git a/src/wasm-delegations-fields.def b/src/wasm-delegations-fields.def index cd8976f82..43cb28325 100644 --- a/src/wasm-delegations-fields.def +++ b/src/wasm-delegations-fields.def @@ -618,10 +618,10 @@ switch (DELEGATE_ID) { DELEGATE_END(TupleExtract); break; } - case Expression::Id::I31NewId: { - DELEGATE_START(I31New); - DELEGATE_FIELD_CHILD(I31New, value); - DELEGATE_END(I31New); + case Expression::Id::RefI31Id: { + DELEGATE_START(RefI31); + DELEGATE_FIELD_CHILD(RefI31, value); + DELEGATE_END(RefI31); break; } case Expression::Id::I31GetId: { diff --git a/src/wasm-delegations.def b/src/wasm-delegations.def index eecd981cd..e6aa865ec 100644 --- a/src/wasm-delegations.def +++ b/src/wasm-delegations.def @@ -67,7 +67,7 @@ DELEGATE(Throw); DELEGATE(Rethrow); DELEGATE(TupleMake); DELEGATE(TupleExtract); -DELEGATE(I31New); +DELEGATE(RefI31); DELEGATE(I31Get); DELEGATE(CallRef); DELEGATE(RefTest); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 2a522c732..1d8c60883 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1409,8 +1409,8 @@ public: WASM_UNREACHABLE("throw"); } Flow visitRethrow(Rethrow* curr) { WASM_UNREACHABLE("unimp"); } - Flow visitI31New(I31New* curr) { - NOTE_ENTER("I31New"); + Flow visitRefI31(RefI31* curr) { + NOTE_ENTER("RefI31"); Flow flow = visit(curr->value); if (flow.breaking()) { return flow; diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 3805a3e38..6c85a2f37 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -130,7 +130,7 @@ public: // [[nodiscard]] Result<> makeRethrow(); // [[nodiscard]] Result<> makeTupleMake(); // [[nodiscard]] Result<> makeTupleExtract(); - [[nodiscard]] Result<> makeI31New(); + [[nodiscard]] Result<> makeRefI31(); [[nodiscard]] Result<> makeI31Get(bool signed_); // [[nodiscard]] Result<> makeCallRef(); // [[nodiscard]] Result<> makeRefTest(); diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 84299f04b..ad2d83e64 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -285,7 +285,7 @@ private: Expression* makeTupleMake(Element& s); Expression* makeTupleExtract(Element& s); Expression* makeCallRef(Element& s, bool isReturn); - Expression* makeI31New(Element& s); + Expression* makeRefI31(Element& s); Expression* makeI31Get(Element& s, bool signed_); Expression* makeRefTest(Element& s); Expression* makeRefCast(Element& s); diff --git a/src/wasm.h b/src/wasm.h index c2c2db79e..ab40d5330 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -703,7 +703,7 @@ public: RethrowId, TupleMakeId, TupleExtractId, - I31NewId, + RefI31Id, I31GetId, CallRefId, RefTestId, @@ -1478,10 +1478,10 @@ public: void finalize(); }; -class I31New : public SpecificExpression<Expression::I31NewId> { +class RefI31 : public SpecificExpression<Expression::RefI31Id> { public: - I31New() = default; - I31New(MixedArena& allocator) {} + RefI31() = default; + RefI31(MixedArena& allocator) {} Expression* value; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index d43640e26..969c15aaa 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -4055,7 +4055,7 @@ BinaryConsts::ASTNodes WasmBinaryReader::readExpression(Expression*& curr) { } case BinaryConsts::GCPrefix: { auto opcode = getU32LEB(); - if (maybeVisitI31New(curr, opcode)) { + if (maybeVisitRefI31(curr, opcode)) { break; } if (maybeVisitI31Get(curr, opcode)) { @@ -6959,11 +6959,11 @@ void WasmBinaryReader::visitCallRef(CallRef* curr) { curr->finalize(); } -bool WasmBinaryReader::maybeVisitI31New(Expression*& out, uint32_t code) { - if (code != BinaryConsts::I31New) { +bool WasmBinaryReader::maybeVisitRefI31(Expression*& out, uint32_t code) { + if (code != BinaryConsts::RefI31) { return false; } - auto* curr = allocator.alloc<I31New>(); + auto* curr = allocator.alloc<RefI31>(); curr->value = popNonVoidExpression(); curr->finalize(); out = curr; diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 7e163fe4e..6445cc3c9 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -661,10 +661,10 @@ Result<> IRBuilder::makeRefEq() { // Result<> IRBuilder::makeTupleExtract() {} -Result<> IRBuilder::makeI31New() { - I31New curr; - CHECK_ERR(visitI31New(&curr)); - push(builder.makeI31New(curr.value)); +Result<> IRBuilder::makeRefI31() { + RefI31 curr; + CHECK_ERR(visitRefI31(&curr)); + push(builder.makeRefI31(curr.value)); return Ok{}; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index d4dd99c2c..40bd6288d 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2838,8 +2838,8 @@ Expression* SExpressionWasmBuilder::makeCallRef(Element& s, bool isReturn) { target, operands, sigType.getSignature().results, isReturn); } -Expression* SExpressionWasmBuilder::makeI31New(Element& s) { - auto ret = allocator.alloc<I31New>(); +Expression* SExpressionWasmBuilder::makeRefI31(Element& s) { + auto ret = allocator.alloc<RefI31>(); ret->value = parseExpression(s[1]); ret->finalize(); return ret; diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 115013307..1ddf69d41 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -1989,8 +1989,8 @@ void BinaryInstWriter::visitTupleExtract(TupleExtract* curr) { o << int8_t(BinaryConsts::LocalGet) << U32LEB(scratch); } -void BinaryInstWriter::visitI31New(I31New* curr) { - o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::I31New); +void BinaryInstWriter::visitRefI31(RefI31* curr) { + o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefI31); } void BinaryInstWriter::visitI31Get(I31Get* curr) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index d6575f7d4..0d45a4773 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -448,7 +448,7 @@ public: void visitTupleMake(TupleMake* curr); void visitTupleExtract(TupleExtract* curr); void visitCallRef(CallRef* curr); - void visitI31New(I31New* curr); + void visitRefI31(RefI31* curr); void visitI31Get(I31Get* curr); void visitRefTest(RefTest* curr); void visitRefCast(RefCast* curr); @@ -2502,7 +2502,7 @@ void FunctionValidator::visitCallRef(CallRef* curr) { } } -void FunctionValidator::visitI31New(I31New* curr) { +void FunctionValidator::visitRefI31(RefI31* curr) { shouldBeTrue( getModule()->features.hasGC(), curr, "i31.new requires gc [--enable-gc]"); shouldBeSubType(curr->value->type, diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index d7bc106e4..ca7e265f8 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -903,7 +903,7 @@ void TupleExtract::finalize() { } } -void I31New::finalize() { +void RefI31::finalize() { if (value->type == Type::unreachable) { type = Type::unreachable; } else { diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp index bdd1af0d8..6a18b2f87 100644 --- a/src/wasm/wat-parser.cpp +++ b/src/wasm/wat-parser.cpp @@ -760,7 +760,7 @@ struct NullInstrParserCtx { InstrT makeRefEq(Index) { return Ok{}; } - InstrT makeI31New(Index) { return Ok{}; } + InstrT makeRefI31(Index) { return Ok{}; } InstrT makeI31Get(Index, bool) { return Ok{}; } template<typename HeapTypeT> InstrT makeStructNew(Index, HeapTypeT) { @@ -1762,8 +1762,8 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { Result<> makeRefEq(Index pos) { return withLoc(pos, irBuilder.makeRefEq()); } - Result<> makeI31New(Index pos) { - return withLoc(pos, irBuilder.makeI31New()); + Result<> makeRefI31(Index pos) { + return withLoc(pos, irBuilder.makeRefI31()); } Result<> makeI31Get(Index pos, bool signed_) { @@ -1947,7 +1947,7 @@ template<typename Ctx> Result<typename Ctx::InstrT> makeTupleExtract(Ctx&, Index); template<typename Ctx> Result<typename Ctx::InstrT> makeCallRef(Ctx&, Index, bool isReturn); -template<typename Ctx> Result<typename Ctx::InstrT> makeI31New(Ctx&, Index); +template<typename Ctx> Result<typename Ctx::InstrT> makeRefI31(Ctx&, Index); template<typename Ctx> Result<typename Ctx::InstrT> makeI31Get(Ctx&, Index, bool signed_); template<typename Ctx> Result<typename Ctx::InstrT> makeRefTest(Ctx&, Index); @@ -3042,8 +3042,8 @@ Result<typename Ctx::InstrT> makeCallRef(Ctx& ctx, Index pos, bool isReturn) { } template<typename Ctx> -Result<typename Ctx::InstrT> makeI31New(Ctx& ctx, Index pos) { - return ctx.makeI31New(pos); +Result<typename Ctx::InstrT> makeRefI31(Ctx& ctx, Index pos) { + return ctx.makeRefI31(pos); } template<typename Ctx> diff --git a/src/wasm2js.h b/src/wasm2js.h index e12749836..2fbde5b65 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -2275,7 +2275,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, unimplemented(curr); WASM_UNREACHABLE("unimp"); } - Ref visitI31New(I31New* curr) { + Ref visitRefI31(RefI31* curr) { unimplemented(curr); WASM_UNREACHABLE("unimp"); } diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 13295a33d..83e005f0d 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1771,26 +1771,26 @@ console.log("# TupleExtract"); module.dispose(); })(); -console.log("# I31New"); -(function testI31New() { +console.log("# RefI31"); +(function testRefI31() { const module = new binaryen.Module(); var value = module.local.get(1, binaryen.i32); - const theI31New = binaryen.I31New(module.i31.new(value)); - assert(theI31New instanceof binaryen.I31New); - assert(theI31New instanceof binaryen.Expression); - assert(theI31New.value === value); - // assert(theI31New.type === binaryen.?); // TODO: (ref i31) - - theI31New.value = value = module.local.get(2, binaryen.i32); - assert(theI31New.value === value); - theI31New.type = binaryen.f64; - theI31New.finalize(); - // assert(theI31New.type === binaryen.?); // TODO: (ref i31) - - console.log(theI31New.toText()); + const theRefI31 = binaryen.RefI31(module.i31.new(value)); + assert(theRefI31 instanceof binaryen.RefI31); + assert(theRefI31 instanceof binaryen.Expression); + assert(theRefI31.value === value); + // assert(theRefI31.type === binaryen.?); // TODO: (ref i31) + + theRefI31.value = value = module.local.get(2, binaryen.i32); + assert(theRefI31.value === value); + theRefI31.type = binaryen.f64; + theRefI31.finalize(); + // assert(theRefI31.type === binaryen.?); // TODO: (ref i31) + + console.log(theRefI31.toText()); assert( - theI31New.toText() + theRefI31.toText() == "(i31.new\n (local.get $2)\n)\n" ); diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt index f548c4037..01ef40f70 100644 --- a/test/binaryen.js/expressions.js.txt +++ b/test/binaryen.js/expressions.js.txt @@ -330,7 +330,7 @@ ) ) -# I31New +# RefI31 (i31.new (local.get $2) ) diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index a9e3a4eae..ecc20448f 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -157,7 +157,7 @@ function test_ids() { console.log("RethrowId: " + binaryen.RethrowId); console.log("TupleMakeId: " + binaryen.TupleMakeId); console.log("TupleExtractId: " + binaryen.TupleExtractId); - console.log("I31NewId: " + binaryen.I31NewId); + console.log("RefI31Id: " + binaryen.RefI31Id); console.log("I31GetId: " + binaryen.I31GetId); console.log("CallRefId: " + binaryen.CallRefId); console.log("RefTestId: " + binaryen.RefTestId); diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index d8bb8d4ed..ce0150f81 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -87,7 +87,7 @@ ThrowId: 50 RethrowId: 51 TupleMakeId: 52 TupleExtractId: 53 -I31NewId: 54 +RefI31Id: 54 I31GetId: 55 CallRefId: 56 RefTestId: 57 diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index c2c5d6e31..d3368a6b1 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -471,7 +471,7 @@ void test_core() { funcrefExpr = BinaryenRefFunc(module, "kitchen()sinker", BinaryenTypeFuncref()); BinaryenExpressionRef i31refExpr = - BinaryenI31New(module, makeInt32(module, 1)); + BinaryenRefI31(module, makeInt32(module, 1)); // Tags BinaryenAddTag(module, "a-tag", BinaryenTypeInt32(), BinaryenTypeNone()); @@ -1101,9 +1101,9 @@ void test_core() { BinaryenMemorySize(module, "0", false), BinaryenMemoryGrow(module, makeInt32(module, 0), "0", false), // GC - BinaryenI31New(module, makeInt32(module, 0)), + BinaryenRefI31(module, makeInt32(module, 0)), BinaryenI31Get(module, i31refExpr, 1), - BinaryenI31Get(module, BinaryenI31New(module, makeInt32(module, 2)), 0), + BinaryenI31Get(module, BinaryenRefI31(module, makeInt32(module, 2)), 0), BinaryenRefTest( module, BinaryenGlobalGet(module, "i8Array-global", i8Array), i8Array), BinaryenRefCast( diff --git a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt index 0cb110a88..2c4396485 100644 --- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt +++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt @@ -24,7 +24,6 @@ total GlobalGet : 28 GlobalSet : 28 I31Get : 1 - I31New : 3 If : 24 Load : 20 LocalGet : 33 @@ -33,6 +32,7 @@ total MemoryFill : 2 Nop : 7 RefFunc : 6 + RefI31 : 3 RefIsNull : 1 RefNull : 7 RefTest : 1 |