diff options
author | Thomas Lively <tlively@google.com> | 2024-08-06 13:22:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 10:22:38 -0700 |
commit | bae0da03af8f4f240d659d016b6e4ee998551059 (patch) | |
tree | 02ea1286345871e9f4223bc817804e5515c625c7 /src/literal.h | |
parent | 6fe3d885604bb053979f4e5adad2840ea936fd17 (diff) | |
download | binaryen-bae0da03af8f4f240d659d016b6e4ee998551059.tar.gz binaryen-bae0da03af8f4f240d659d016b6e4ee998551059.tar.bz2 binaryen-bae0da03af8f4f240d659d016b6e4ee998551059.zip |
[NFC] Add HeapType::getKind returning a new HeapTypeKind enum (#6804)
The HeapType API has functions like `isBasic()`, `isStruct()`,
`isSignature()`, etc. to test the classification of a heap type. Many
users have to call these functions in sequence and handle all or most of
the possible classifications. When we add a new kind of heap type,
finding and updating all these sites is a manual and error-prone
process.
To make adding new heap type kinds easier, introduce a new API that
returns an enum classifying the heap type. The enum can be used in
switch statements and the compiler's exhaustiveness checker will flag
use sites that need to be updated when we add a new kind of heap type.
This commit uses the new enum internally in the type system, but
follow-on commits will add new uses and convert uses of the existing
APIs to use `getKind` instead.
Diffstat (limited to 'src/literal.h')
-rw-r--r-- | src/literal.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/literal.h b/src/literal.h index f7703d9e6..1c1128163 100644 --- a/src/literal.h +++ b/src/literal.h @@ -96,7 +96,9 @@ public: // Whether this is GC data, that is, something stored on the heap (aside from // a null or i31). This includes structs, arrays, and also strings. bool isData() const { return type.isData(); } - bool isString() const { return type.isString(); } + bool isString() const { + return type.isRef() && type.getHeapType().isMaybeShared(HeapType::string); + } bool isNull() const { return type.isNull(); } @@ -770,11 +772,11 @@ template<> struct hash<wasm::Literal> { wasm::rehash(digest, a.getFunc()); return digest; } - if (a.type.getHeapType() == wasm::HeapType::i31) { + if (a.type.getHeapType().isMaybeShared(wasm::HeapType::i31)) { wasm::rehash(digest, a.geti31(true)); return digest; } - if (a.type.isString()) { + if (a.type.getHeapType().isMaybeShared(wasm::HeapType::string)) { auto& values = a.getGCData()->values; wasm::rehash(digest, values.size()); for (auto c : values) { |