diff options
author | Alon Zakai <azakai@google.com> | 2021-07-12 17:15:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-12 17:15:50 -0700 |
commit | 58ce30422a24f44dcac6f5d1b6950d900582f0f2 (patch) | |
tree | b3f75d30ada94bed39a2f73d80665df4502551cb /src | |
parent | e8137784824bb2578b8ecbe2f76e09e20a1e5442 (diff) | |
download | binaryen-58ce30422a24f44dcac6f5d1b6950d900582f0f2.tar.gz binaryen-58ce30422a24f44dcac6f5d1b6950d900582f0f2.tar.bz2 binaryen-58ce30422a24f44dcac6f5d1b6950d900582f0f2.zip |
Improve NameTypes to keep reasonable names (#3977)
We only set a name now if there was no name, or the existing name
was really really long.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/NameTypes.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/passes/NameTypes.cpp b/src/passes/NameTypes.cpp index 2939f9ad5..a2c5016bc 100644 --- a/src/passes/NameTypes.cpp +++ b/src/passes/NameTypes.cpp @@ -21,14 +21,14 @@ // // Ensures each type has a name. This can be useful for debugging. // -// TODO: keep existing useful (short-enough) names, and just replace ones that -// are bothersome -// using namespace std; namespace wasm { +// An arbitrary limit, above which we rename types. +static const size_t NameLenLimit = 20; + struct NameTypes : public Pass { void run(PassRunner* runner, Module* module) override { // Find all the types. @@ -36,10 +36,14 @@ struct NameTypes : public Pass { std::unordered_map<HeapType, Index> typeIndices; ModuleUtils::collectHeapTypes(*module, types, typeIndices); - // Ensure simple names. + // Ensure simple names. If a name already exists, and is short enough, keep + // it. size_t i = 0; for (auto& type : types) { - module->typeNames[type].name = "type$" + std::to_string(i++); + if (module->typeNames.count(type) == 0 || + module->typeNames[type].name.size() >= NameLenLimit) { + module->typeNames[type].name = "type$" + std::to_string(i++); + } } } }; |