diff options
-rw-r--r-- | src/literal.h | 6 | ||||
-rw-r--r-- | src/passes/Precompute.cpp | 2 | ||||
-rw-r--r-- | src/tools/execution-results.h | 6 | ||||
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 3 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 3 | ||||
-rw-r--r-- | src/wasm-builder.h | 40 | ||||
-rw-r--r-- | src/wasm-type.h | 2 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 2 |
9 files changed, 31 insertions, 35 deletions
diff --git a/src/literal.h b/src/literal.h index 1c1128163..190fe0eec 100644 --- a/src/literal.h +++ b/src/literal.h @@ -96,9 +96,7 @@ 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.isRef() && type.getHeapType().isMaybeShared(HeapType::string); - } + bool isString() const { return type.isString(); } bool isNull() const { return type.isNull(); } @@ -776,7 +774,7 @@ template<> struct hash<wasm::Literal> { wasm::rehash(digest, a.geti31(true)); return digest; } - if (a.type.getHeapType().isMaybeShared(wasm::HeapType::string)) { + if (a.type.isString()) { auto& values = a.getGCData()->values; wasm::rehash(digest, values.size()); for (auto c : values) { diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index 48977dd78..ba04a68aa 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -829,7 +829,7 @@ private: return true; } // We can emit a StringConst for a string constant. - if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::string)) { + if (type.isString()) { return true; } // All other reference types cannot be precomputed. Even an immutable GC diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h index 31c572e65..920bb200a 100644 --- a/src/tools/execution-results.h +++ b/src/tools/execution-results.h @@ -148,8 +148,7 @@ struct ExecutionResults { // simple and stable internal structures that optimizations will not alter. auto type = value.type; if (type.isRef()) { - if (type.getHeapType().isMaybeShared(HeapType::string) || - type.getHeapType().isMaybeShared(HeapType::i31)) { + if (type.isString() || type.getHeapType().isMaybeShared(HeapType::i31)) { std::cout << value << '\n'; } else if (value.isNull()) { std::cout << "null\n"; @@ -190,8 +189,7 @@ struct ExecutionResults { // TODO: Once we support optimizing under some form of open-world // assumption, we should be able to check that the types and/or structure of // GC data passed out of the module does not change. - if (a.type.isRef() && - !a.type.getHeapType().isMaybeShared(HeapType::string) && + if (a.type.isRef() && !a.type.isString() && !a.type.getHeapType().isMaybeShared(HeapType::i31)) { return true; } diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 138831860..2aff7146e 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -2536,8 +2536,7 @@ Expression* TranslateToFuzzReader::makeConst(Type type) { if (type.isNullable() && oneIn(8)) { return builder.makeRefNull(type.getHeapType()); } - if (type.getHeapType().isMaybeShared(HeapType::string)) { - assert(!type.getHeapType().isShared() && "TODO: shared strings"); + if (type.getHeapType().isString()) { return makeStringConst(); } if (type.getHeapType().isBasic()) { diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 11fee72fb..22e666a52 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -841,8 +841,7 @@ public: // externalized i31s) can be handled by the general makeConstantExpression // logic (which knows how to handle externalization, for i31s; and it also // can handle string constants). - if (!value.isData() || - value.type.getHeapType().isMaybeShared(HeapType::string)) { + if (!value.isData() || value.isString()) { return builder.makeConstantExpression(original); } diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 0f9ec7b03..a4f1c5cf9 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -1217,28 +1217,26 @@ public: if (type.isFunction()) { return makeRefFunc(value.getFunc(), type.getHeapType()); } - if (type.isRef()) { - if (type.getHeapType().isMaybeShared(HeapType::i31)) { - return makeRefI31(makeConst(value.geti31()), - type.getHeapType().getShared()); - } - if (type.getHeapType().isMaybeShared(HeapType::string)) { - // The string is already WTF-16, but we need to convert from `Literals` - // to actual string. - std::stringstream wtf16; - for (auto c : value.getGCData()->values) { - auto u = c.getInteger(); - assert(u < 0x10000); - wtf16 << uint8_t(u & 0xFF); - wtf16 << uint8_t(u >> 8); - } - // TODO: Use wtf16.view() once we have C++20. - return makeStringConst(wtf16.str()); - } - if (type.getHeapType().isMaybeShared(HeapType::ext)) { - return makeRefAs(ExternConvertAny, - makeConstantExpression(value.internalize())); + if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31)) { + return makeRefI31(makeConst(value.geti31()), + type.getHeapType().getShared()); + } + if (type.isString()) { + // The string is already WTF-16, but we need to convert from `Literals` to + // actual string. + std::stringstream wtf16; + for (auto c : value.getGCData()->values) { + auto u = c.getInteger(); + assert(u < 0x10000); + wtf16 << uint8_t(u & 0xFF); + wtf16 << uint8_t(u >> 8); } + // TODO: Use wtf16.view() once we have C++20. + return makeStringConst(wtf16.str()); + } + if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::ext)) { + return makeRefAs(ExternConvertAny, + makeConstantExpression(value.internalize())); } TODO_SINGLE_COMPOUND(type); WASM_UNREACHABLE("unsupported constant expression"); diff --git a/src/wasm-type.h b/src/wasm-type.h index 58655edc7..88590cc17 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -170,6 +170,7 @@ public: bool isSignature() const; bool isStruct() const; bool isArray() const; + bool isString() const; bool isDefaultable() const; Nullability getNullability() const; @@ -387,6 +388,7 @@ public: bool isContinuation() const { return getKind() == HeapTypeKind::Cont; } bool isStruct() const { return getKind() == HeapTypeKind::Struct; } bool isArray() const { return getKind() == HeapTypeKind::Array; } + bool isString() const { return isMaybeShared(HeapType::string); } bool isBottom() const; bool isOpen() const; bool isShared() const { return getShared() == Shared; } diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 3dcf9e350..f2100ea71 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -439,7 +439,7 @@ bool Literal::operator==(const Literal& other) const { assert(func.is() && other.func.is()); return func == other.func; } - if (type.getHeapType().isMaybeShared(HeapType::string)) { + if (type.isString()) { return gcData->values == other.gcData->values; } if (type.isData()) { diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index aa3847a8b..173e4b8c3 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -814,6 +814,8 @@ bool Type::isStruct() const { return isRef() && getHeapType().isStruct(); } bool Type::isArray() const { return isRef() && getHeapType().isArray(); } +bool Type::isString() const { return isRef() && getHeapType().isString(); } + bool Type::isDefaultable() const { // A variable can get a default value if its type is concrete (unreachable // and none have no values, hence no default), and if it's a reference, it |