diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/module-utils.h | 10 | ||||
-rw-r--r-- | src/ir/struct-utils.h | 9 | ||||
-rw-r--r-- | src/ir/subtypes.h | 13 | ||||
-rw-r--r-- | src/ir/type-updating.cpp | 5 | ||||
-rw-r--r-- | src/passes/Print.cpp | 5 | ||||
-rw-r--r-- | src/wasm-type.h | 7 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 7 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 9 |
8 files changed, 30 insertions, 35 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 13fa76fff..69c454410 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -597,15 +597,15 @@ inline void collectHeapTypes(Module& wasm, counts.note(child); } } - HeapType super; - if (ht.getSuperType(super)) { - if (!counts.count(super)) { - newTypes.insert(super); + + if (auto super = ht.getSuperType()) { + if (!counts.count(*super)) { + newTypes.insert(*super); // We should unconditionally count supertypes, but while the type system // is in flux, skip counting them to keep the type orderings in nominal // test outputs more similar to the orderings in the equirecursive // outputs. FIXME - counts.note(super); + counts.note(*super); } } } diff --git a/src/ir/struct-utils.h b/src/ir/struct-utils.h index b052a15f7..442d990fb 100644 --- a/src/ir/struct-utils.h +++ b/src/ir/struct-utils.h @@ -222,13 +222,12 @@ private: auto& infos = combinedInfos[type]; // Propagate shared fields to the supertype. - HeapType superType; - if (type.getSuperType(superType)) { - auto& superInfos = combinedInfos[superType]; - auto& superFields = superType.getStruct().fields; + if (auto superType = type.getSuperType()) { + auto& superInfos = combinedInfos[*superType]; + auto& superFields = superType->getStruct().fields; for (Index i = 0; i < superFields.size(); i++) { if (superInfos[i].combine(infos[i])) { - work.push(superType); + work.push(*superType); } } } diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h index 661eaf119..64697e2a3 100644 --- a/src/ir/subtypes.h +++ b/src/ir/subtypes.h @@ -57,12 +57,12 @@ struct SubTypes { std::vector<HeapType> getAllSuperTypes(HeapType type) { std::vector<HeapType> ret; while (1) { - HeapType super; - if (!type.getSuperType(super)) { + auto super = type.getSuperType(); + if (!super) { return ret; } - ret.push_back(super); - type = super; + ret.push_back(*super); + type = *super; } } @@ -71,9 +71,8 @@ struct SubTypes { private: // Add a type to the graph. void note(HeapType type) { - HeapType super; - if (type.getSuperType(super)) { - typeSubTypes[super].push_back(type); + if (auto super = type.getSuperType()) { + typeSubTypes[*super].push_back(type); } } diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp index c69cbe1be..d3ecf7ad6 100644 --- a/src/ir/type-updating.cpp +++ b/src/ir/type-updating.cpp @@ -65,9 +65,8 @@ void GlobalTypeRewriter::update() { } // Apply a super, if there is one - HeapType super; - if (type.getSuperType(super)) { - typeBuilder.setSubType(i, typeIndices[super]); + if (auto super = type.getSuperType()) { + typeBuilder.setSubType(i, typeIndices[*super]); } } diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 96a1abe73..34fe92ff6 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2515,9 +2515,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } // Module-level visitors void printSupertypeOr(HeapType curr, std::string noSuper) { - HeapType super; - if (curr.getSuperType(super)) { - TypeNamePrinter(o, currModule).print(super); + if (auto super = curr.getSuperType()) { + TypeNamePrinter(o, currModule).print(*super); } else { o << noSuper; } diff --git a/src/wasm-type.h b/src/wasm-type.h index a673b936f..4c401be6b 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -19,6 +19,7 @@ #include "support/name.h" #include "wasm-features.h" +#include <optional> #include <ostream> #include <vector> @@ -382,12 +383,12 @@ public: const Struct& getStruct() const; Array getArray() const; - // Return whether there is a nontrivial (i.e. non-basic) nominal supertype and - // store it in `out` if there is. Nominal types (in the sense of isNominal, + // If there is a nontrivial (i.e. non-basic) nominal supertype, return it, + // else an empty optional. Nominal types (in the sense of isNominal, // i.e. Milestone 4 nominal types) may always have supertypes and other types // may have supertypes in `TypeSystem::Nominal` mode but not in // `TypeSystem::Equirecursive` mode. - bool getSuperType(HeapType& out) const; + std::optional<HeapType> getSuperType() const; // Whether this is a nominal type in the sense of being a GC Milestone 4 // nominal type. Although all non-basic HeapTypes are nominal in diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 9c8b83325..6ce2c7979 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -251,12 +251,11 @@ void WasmBinaryWriter::writeTypes() { WASM_UNREACHABLE("TODO GC type writing"); } if (nominal) { - HeapType super; - bool hasSuper = type.getSuperType(super); - if (!hasSuper) { + auto super = type.getSuperType(); + if (!super) { super = type.isFunction() ? HeapType::func : HeapType::data; } - writeHeapType(super); + writeHeapType(*super); } } finishSection(start); diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 284a7e23b..94c6e96c6 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1206,16 +1206,15 @@ Array HeapType::getArray() const { return getHeapTypeInfo(*this)->array; } -bool HeapType::getSuperType(HeapType& out) const { +std::optional<HeapType> HeapType::getSuperType() const { if (isBasic()) { - return false; + return {}; } HeapTypeInfo* super = getHeapTypeInfo(*this)->supertype; if (super != nullptr) { - out = HeapType(uintptr_t(super)); - return true; + return HeapType(uintptr_t(super)); } - return false; + return {}; } bool HeapType::isNominal() const { |