diff options
author | Thomas Lively <tlively@google.com> | 2023-07-06 15:08:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 19:08:12 +0000 |
commit | 195e18d0602108b18f305711f8ea1c902b729cb0 (patch) | |
tree | 578f1b0c26603c89f28fe99aa908d82c07863543 | |
parent | 20a543b73d302cf773961fef5d1c281844127140 (diff) | |
download | binaryen-195e18d0602108b18f305711f8ea1c902b729cb0.tar.gz binaryen-195e18d0602108b18f305711f8ea1c902b729cb0.tar.bz2 binaryen-195e18d0602108b18f305711f8ea1c902b729cb0.zip |
[NFC] Fix the use of "strict" in subtypes.h (#5804)
Previously we incorrectly used "strict" to mean the immediate subtypes of a
type, when in fact a strict subtype of a type is any subtype excluding the type
itself. Rename the incorrect `getStrictSubTypes` to `getImmediateSubTypes`,
rename the redundant `getAllStrictSubTypes` to `getStrictSubTypes`, and rename
the redundant `getAllSubTypes` to `getSubTypes`. Fixing the capitalization of
"SubType" to "Subtype" is left as future work.
-rw-r--r-- | src/ir/struct-utils.h | 2 | ||||
-rw-r--r-- | src/ir/subtypes.h | 29 | ||||
-rw-r--r-- | src/passes/AbstractTypeRefining.cpp | 4 | ||||
-rw-r--r-- | src/passes/RemoveUnusedModuleElements.cpp | 2 | ||||
-rw-r--r-- | src/passes/SignaturePruning.cpp | 2 | ||||
-rw-r--r-- | src/passes/SignatureRefining.cpp | 2 | ||||
-rw-r--r-- | src/passes/TypeRefining.cpp | 2 | ||||
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 3 | ||||
-rw-r--r-- | test/gtest/type-builder.cpp | 6 |
10 files changed, 27 insertions, 27 deletions
diff --git a/src/ir/struct-utils.h b/src/ir/struct-utils.h index dc87ed574..eb5ee5d2d 100644 --- a/src/ir/struct-utils.h +++ b/src/ir/struct-utils.h @@ -275,7 +275,7 @@ private: if (toSubTypes) { // Propagate shared fields to the subtypes. auto numFields = type.getStruct().fields.size(); - for (auto subType : subTypes.getStrictSubTypes(type)) { + for (auto subType : subTypes.getImmediateSubTypes(type)) { auto& subInfos = combinedInfos[subType]; for (Index i = 0; i < numFields; i++) { if (subInfos[i].combine(infos[i])) { diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h index 2a629a05d..ebf21e0ae 100644 --- a/src/ir/subtypes.h +++ b/src/ir/subtypes.h @@ -36,7 +36,7 @@ struct SubTypes { SubTypes(Module& wasm) : SubTypes(ModuleUtils::collectHeapTypes(wasm)) {} - const std::vector<HeapType>& getStrictSubTypes(HeapType type) const { + const std::vector<HeapType>& getImmediateSubTypes(HeapType type) const { // When we return an empty result, use a canonical constant empty vec to // avoid allocation. static const std::vector<HeapType> empty; @@ -55,14 +55,15 @@ struct SubTypes { return empty; } - // Get all subtypes of a type, and their subtypes and so forth, recursively. - std::vector<HeapType> getAllStrictSubTypes(HeapType type) { + // Get all subtypes of a type, and their subtypes and so forth, recursively, + // excluding the type itself. + std::vector<HeapType> getStrictSubTypes(HeapType type) { std::vector<HeapType> ret, work; work.push_back(type); while (!work.empty()) { auto curr = work.back(); work.pop_back(); - for (auto sub : getStrictSubTypes(curr)) { + for (auto sub : getImmediateSubTypes(curr)) { ret.push_back(sub); work.push_back(sub); } @@ -70,9 +71,9 @@ struct SubTypes { return ret; } - // Like getAllStrictSubTypes, but also includes the type itself. - std::vector<HeapType> getAllSubTypes(HeapType type) { - auto ret = getAllStrictSubTypes(type); + // Like getStrictSubTypes, but also includes the type itself. + std::vector<HeapType> getSubTypes(HeapType type) { + auto ret = getStrictSubTypes(type); ret.push_back(type); return ret; } @@ -94,7 +95,7 @@ struct SubTypes { void pushPredecessors(HeapType type) { // Things we need to process before each type are its subtypes. Once we // know their depth, we can easily compute our own. - for (auto pred : parent.getStrictSubTypes(type)) { + for (auto pred : parent.getImmediateSubTypes(type)) { push(pred); } } @@ -114,7 +115,7 @@ struct SubTypes { for (auto type : getSubTypesFirstSort()) { // Begin with depth 0, then take into account the subtype depths. Index depth = 0; - for (auto subType : getStrictSubTypes(type)) { + for (auto subType : getImmediateSubTypes(type)) { depth = std::max(depth, depths[subType] + 1); } depths[type] = depth; @@ -154,9 +155,9 @@ struct SubTypes { return; } - // getStrictSubTypes() returns vectors of subtypes, so for efficiency store - // pointers to those in our work queue to avoid allocations. See the note - // below on typeSubTypes for why this is safe. + // getImmediateSubTypes() returns vectors of subtypes, so for efficiency + // store pointers to those in our work queue to avoid allocations. See the + // note below on typeSubTypes for why this is safe. struct Item { const std::vector<HeapType>* vec; Index depth; @@ -167,7 +168,7 @@ struct SubTypes { SmallVector<Item, 10> work; // Start with the subtypes of the base type. Those have depth 1. - work.push_back({&getStrictSubTypes(type), 1}); + work.push_back({&getImmediateSubTypes(type), 1}); while (!work.empty()) { auto& item = work.back(); @@ -177,7 +178,7 @@ struct SubTypes { assert(currDepth <= depth); for (auto type : currVec) { func(type, currDepth); - auto* subVec = &getStrictSubTypes(type); + auto* subVec = &getImmediateSubTypes(type); if (currDepth + 1 <= depth && !subVec->empty()) { work.push_back({subVec, currDepth + 1}); } diff --git a/src/passes/AbstractTypeRefining.cpp b/src/passes/AbstractTypeRefining.cpp index 1d3ff3f74..8de0301a7 100644 --- a/src/passes/AbstractTypeRefining.cpp +++ b/src/passes/AbstractTypeRefining.cpp @@ -113,7 +113,7 @@ struct AbstractTypeRefining : public Pass { createdTypesOrSubTypes = createdTypes; for (auto type : subTypes.getSubTypesFirstSort()) { // If any of our subtypes are created, so are we. - for (auto subType : subTypes.getStrictSubTypes(type)) { + for (auto subType : subTypes.getImmediateSubTypes(type)) { if (createdTypesOrSubTypes.count(subType)) { createdTypesOrSubTypes.insert(type); break; @@ -159,7 +159,7 @@ struct AbstractTypeRefining : public Pass { } std::optional<HeapType> refinedType; - auto& typeSubTypes = subTypes.getStrictSubTypes(type); + auto& typeSubTypes = subTypes.getImmediateSubTypes(type); if (typeSubTypes.size() == 1) { // There is only a single possibility, so we can definitely use that /// one. diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index 25b5ea9e9..88e806768 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -350,7 +350,7 @@ struct Analyzer { // Call all the functions of that signature, and subtypes. We can then // forget about them, as those signatures will be marked as called. - for (auto subType : subTypes->getAllSubTypes(type)) { + for (auto subType : subTypes->getSubTypes(type)) { auto iter = uncalledRefFuncMap.find(subType); if (iter != uncalledRefFuncMap.end()) { // We must not have a type in both calledSignatures and diff --git a/src/passes/SignaturePruning.cpp b/src/passes/SignaturePruning.cpp index dd6d278d1..e25f9555f 100644 --- a/src/passes/SignaturePruning.cpp +++ b/src/passes/SignaturePruning.cpp @@ -181,7 +181,7 @@ struct SignaturePruning : public Pass { continue; } - if (!subTypes.getStrictSubTypes(type).empty()) { + if (!subTypes.getImmediateSubTypes(type).empty()) { continue; } if (auto super = type.getSuperType()) { diff --git a/src/passes/SignatureRefining.cpp b/src/passes/SignatureRefining.cpp index 281214e32..51aef429b 100644 --- a/src/passes/SignatureRefining.cpp +++ b/src/passes/SignatureRefining.cpp @@ -145,7 +145,7 @@ struct SignatureRefining : public Pass { // TypeRefining, and perhaps we can unify this pass with that. TODO SubTypes subTypes(*module); for (auto& [type, info] : allInfo) { - if (!subTypes.getStrictSubTypes(type).empty()) { + if (!subTypes.getImmediateSubTypes(type).empty()) { info.canModify = false; } else if (type.getSuperType()) { // Also avoid modifying types with supertypes, as we do not handle diff --git a/src/passes/TypeRefining.cpp b/src/passes/TypeRefining.cpp index 7fd039411..864cb81b3 100644 --- a/src/passes/TypeRefining.cpp +++ b/src/passes/TypeRefining.cpp @@ -216,7 +216,7 @@ struct TypeRefining : public Pass { } } - for (auto subType : subTypes.getStrictSubTypes(type)) { + for (auto subType : subTypes.getImmediateSubTypes(type)) { work.push(subType); } } diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 3fb8c1ea5..7bfd07854 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -279,7 +279,7 @@ void TranslateToFuzzReader::setupHeapTypes() { // now, rather than lazily later. SubTypes subTypes(interestingHeapTypes); for (auto type : interestingHeapTypes) { - for (auto subType : subTypes.getStrictSubTypes(type)) { + for (auto subType : subTypes.getImmediateSubTypes(type)) { interestingHeapSubTypes[type].push_back(subType); } // Basic types must be handled directly, since subTypes doesn't look at diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 4d51e0f43..d9b7e1a84 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -226,8 +226,7 @@ void WasmBinaryWriter::writeTypes() { return; } // Count the number of recursion groups, which is the number of elements in - // the type section. With nominal typing there is always one group and with - // equirecursive typing there is one group per type. + // the type section. size_t numGroups = 0; { std::optional<RecGroup> lastGroup; diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 84b9f33c8..0744e2b5e 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -853,13 +853,13 @@ TEST_F(TypeTest, TestSubTypes) { {Type(built[0], Nullable), Type(built[1], Nullable)}, wasmBuilder.makeNop())); SubTypes subTypes(wasm); - auto subTypes0 = subTypes.getStrictSubTypes(built[0]); + auto subTypes0 = subTypes.getImmediateSubTypes(built[0]); EXPECT_TRUE(subTypes0.size() == 1 && subTypes0[0] == built[1]); - auto subTypes0Inclusive = subTypes.getAllSubTypes(built[0]); + auto subTypes0Inclusive = subTypes.getSubTypes(built[0]); EXPECT_TRUE(subTypes0Inclusive.size() == 2 && subTypes0Inclusive[0] == built[1] && subTypes0Inclusive[1] == built[0]); - auto subTypes1 = subTypes.getStrictSubTypes(built[1]); + auto subTypes1 = subTypes.getImmediateSubTypes(built[1]); EXPECT_EQ(subTypes1.size(), 0u); } |