summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-08-15 10:27:37 -0700
committerGitHub <noreply@github.com>2024-08-15 10:27:37 -0700
commitd5675780f45f4e2994787fd7dbc5283a6c0162f0 (patch)
treebf30f2c53dadc35731a07251d1876625a7b60605 /src
parentad0802226a180d9797d17bb7fee391c0d62f9913 (diff)
downloadbinaryen-d5675780f45f4e2994787fd7dbc5283a6c0162f0.tar.gz
binaryen-d5675780f45f4e2994787fd7dbc5283a6c0162f0.tar.bz2
binaryen-d5675780f45f4e2994787fd7dbc5283a6c0162f0.zip
[NFC] Clean up Literal copy constructor (#6841)
Diff without whitespace is smaller. * HeapType::ext was handled in two places. The second place was wrong, but not reached. * Near the end all we have left are refs, so no need to check isRef etc. * Simplify the code to get the heap type once.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/literal.cpp57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index b0dcf5177..40a1f9519 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -117,7 +117,11 @@ 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;
}
@@ -125,35 +129,28 @@ Literal::Literal(const Literal& other) : type(other.type) {
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");
}
}