From 58ce30422a24f44dcac6f5d1b6950d900582f0f2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 12 Jul 2021 17:15:50 -0700 Subject: 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. --- src/passes/NameTypes.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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 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++); + } } } }; -- cgit v1.2.3