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

[NFC] Clean up Literal copy constructor #6841

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
57 changes: 27 additions & 30 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,43 +117,40 @@ Literal::Literal(const Literal& other) : type(other.type) {
new (&gcData) std::shared_ptr<GCData>();
return;
}
if (other.isData() || other.type.getHeapType().isMaybeShared(HeapType::ext)) {
// After handling nulls, only non-nullable Literals remain.
assert(!type.isNullable());

auto heapType = type.getHeapType();
if (other.isData() || heapType.isMaybeShared(HeapType::ext)) {
new (&gcData) std::shared_ptr<GCData>(other.gcData);
return;
}
if (type.isFunction()) {
func = other.func;
return;
}
if (type.isRef()) {
assert(!type.isNullable());
auto heapType = type.getHeapType();
if (heapType.isBasic()) {
switch (heapType.getBasic(Unshared)) {
case HeapType::i31:
i32 = other.i32;
return;
case HeapType::ext:
gcData = other.gcData;
return;
case HeapType::none:
case HeapType::noext:
case HeapType::nofunc:
case HeapType::noexn:
case HeapType::nocont:
WASM_UNREACHABLE("null literals should already have been handled");
case HeapType::any:
case HeapType::eq:
case HeapType::func:
case HeapType::cont:
case HeapType::struct_:
case HeapType::array:
case HeapType::exn:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
WASM_UNREACHABLE("TODO: string literals");
}
}
switch (heapType.getBasic(Unshared)) {
case HeapType::i31:
i32 = other.i32;
return;
case HeapType::ext:
WASM_UNREACHABLE("handled above with isData()");
case HeapType::none:
case HeapType::noext:
case HeapType::nofunc:
case HeapType::noexn:
case HeapType::nocont:
WASM_UNREACHABLE("null literals should already have been handled");
case HeapType::any:
case HeapType::eq:
case HeapType::func:
case HeapType::cont:
case HeapType::struct_:
case HeapType::array:
case HeapType::exn:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
WASM_UNREACHABLE("TODO: string literals");
}
}

Expand Down
Loading