Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
store shareability in type only
  • Loading branch information
tlively committed Jul 12, 2024
commit c3d9b6eda51f17386cc0861369cb012453ce07fb
3 changes: 2 additions & 1 deletion src/ir/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ inline Literal getLiteral(const Expression* curr) {
return Literal(r->func, r->type.getHeapType());
} else if (auto* i = curr->dynCast<RefI31>()) {
if (auto* c = i->value->dynCast<Const>()) {
return Literal::makeI31(c->value.geti32(), i->share);
return Literal::makeI31(c->value.geti32(),
i->type.getHeapType().getShared());
}
} else if (auto* s = curr->dynCast<StringConst>()) {
return Literal(s->string.toString());
Expand Down
3 changes: 2 additions & 1 deletion src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,8 @@ struct PrintExpressionContents
o << curr->index;
}
void visitRefI31(RefI31* curr) {
printMedium(o, curr->share == Shared ? "ref.i31_shared" : "ref.i31");
printMedium(
o, curr->type.getHeapType().isShared() ? "ref.i31_shared" : "ref.i31");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may need to guard here against curr->type being unreachable (when the i32 child is unreachable), in which case getHeapType errors.

}
void visitI31Get(I31Get* curr) {
printMedium(o, curr->signed_ ? "i31.get_s" : "i31.get_u");
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ class Builder {
}
RefI31* makeRefI31(Expression* value, Shareability share = Unshared) {
auto* ret = wasm.allocator.alloc<RefI31>();
ret->share = share;
ret->value = value;
ret->type = Type(HeapTypes::i31.getBasic(share), NonNullable);
ret->finalize();
return ret;
}
Expand Down
1 change: 0 additions & 1 deletion src/wasm-delegations-fields.def
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ DELEGATE_FIELD_INT(TupleExtract, index)
DELEGATE_FIELD_CASE_END(TupleExtract)

DELEGATE_FIELD_CASE_START(RefI31)
DELEGATE_FIELD_INT(RefI31, share)
DELEGATE_FIELD_CHILD(RefI31, value)
DELEGATE_FIELD_CASE_END(RefI31)

Expand Down
3 changes: 2 additions & 1 deletion src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
const auto& value = flow.getSingleValue();
NOTE_EVAL1(value);
return Literal::makeI31(value.geti32(), curr->share);
return Literal::makeI31(value.geti32(),
curr->type.getHeapType().getShared());
}
Flow visitI31Get(I31Get* curr) {
NOTE_ENTER("I31Get");
Expand Down
1 change: 0 additions & 1 deletion src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,6 @@ class RefI31 : public SpecificExpression<Expression::RefI31Id> {
RefI31() = default;
RefI31(MixedArena& allocator) {}

Shareability share;
Expression* value;

void finalize();
Expand Down
7 changes: 2 additions & 5 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7255,11 +7255,8 @@ bool WasmBinaryReader::maybeVisitRefI31(Expression*& out, uint32_t code) {
default:
return false;
}
auto* curr = allocator.alloc<RefI31>();
curr->share = share;
curr->value = popNonVoidExpression();
curr->finalize();
out = curr;
auto* value = popNonVoidExpression();
out = Builder(wasm).makeRefI31(value, share);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2115,8 +2115,8 @@ void BinaryInstWriter::visitTupleExtract(TupleExtract* curr) {

void BinaryInstWriter::visitRefI31(RefI31* curr) {
o << int8_t(BinaryConsts::GCPrefix)
<< U32LEB(curr->share == Shared ? BinaryConsts::RefI31Shared
: BinaryConsts::RefI31);
<< U32LEB(curr->type.getHeapType().isShared() ? BinaryConsts::RefI31Shared
: BinaryConsts::RefI31);
}

void BinaryInstWriter::visitI31Get(I31Get* curr) {
Expand Down
3 changes: 2 additions & 1 deletion src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,8 @@ void RefI31::finalize() {
if (value->type == Type::unreachable) {
type = Type::unreachable;
} else {
type = Type(HeapTypes::i31.getBasic(share), NonNullable);
assert(type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31);
}
}

Expand Down