Skip to content
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
2 changes: 1 addition & 1 deletion src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Literal {
return i32;
}
int32_t geti31(bool signed_ = true) const {
assert(type.getHeapType().getBasic(Unshared) == HeapType::i31);
assert(type.getHeapType().isMaybeShared(HeapType::i31));
// Cast to unsigned for the left shift to avoid undefined behavior.
return signed_ ? int32_t((uint32_t(i32) << 1)) >> 1 : (i32 & 0x7fffffff);
}
Expand Down
3 changes: 1 addition & 2 deletions src/tools/fuzzing/heap-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ void Inhabitator::markExternRefsNullable() {
auto children = type.getTypeChildren();
for (size_t i = 0; i < children.size(); ++i) {
auto child = children[i];
if (child.isRef() && child.getHeapType().isBasic() &&
child.getHeapType().getBasic(Unshared) == HeapType::ext &&
if (child.isRef() && child.getHeapType().isMaybeShared(HeapType::ext) &&
child.isNonNullable()) {
markNullable({type, i});
}
Expand Down
3 changes: 1 addition & 2 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,7 @@ class Builder {
if (type.isFunction()) {
return makeRefFunc(value.getFunc(), type.getHeapType());
}
if (type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31) {
if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31)) {
return makeRefI31(makeConst(value.geti31()),
type.getHeapType().getShared());
}
Expand Down
6 changes: 6 additions & 0 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ class HeapType {

Shareability getShared() const;

// Check if the type is a given basic heap type, while ignoring whether it is
// shared or not.
bool isMaybeShared(BasicHeapType type) {
return isBasic() && getBasic(Unshared) == type;
}

Signature getSignature() const;
Continuation getContinuation() const;

Expand Down
3 changes: 1 addition & 2 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Literal::Literal(Type type) : type(type) {
return;
}

if (type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31) {
if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31)) {
assert(type.isNonNullable());
i32 = 0;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ void WasmBinaryWriter::writeType(Type type) {
// those more refined types.
if (!wasm->features.hasGC()) {
auto ht = type.getHeapType();
if (ht.isBasic() && ht.getBasic(Unshared) == HeapType::string) {
if (ht.isMaybeShared(HeapType::string)) {
// Do not overgeneralize stringref to anyref. We have tests that when a
// stringref is expected, we actually get a stringref. If we see a
// string, the stringref feature must be enabled.
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,7 @@ void FunctionValidator::visitStructSet(StructSet* curr) {
return;
}
auto type = curr->ref->type.getHeapType();
if (type.isBasic() && type.getBasic(Unshared) == HeapType::none) {
if (type.isMaybeShared(HeapType::none)) {
return;
}
if (!shouldBeTrue(
Expand Down
3 changes: 1 addition & 2 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,7 @@ void RefI31::finalize() {
if (value->type == Type::unreachable) {
type = Type::unreachable;
} else {
assert(type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31);
assert(type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31));
}
}

Expand Down