Skip to content

Commit 1e98192

Browse files
committed
ModuleHeapType
1 parent fb093b2 commit 1e98192

3 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/passes/Print.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,4 +3903,12 @@ std::ostream& operator<<(std::ostream& o, wasm::ModuleType pair) {
39033903
return o;
39043904
}
39053905

3906+
std::ostream& operator<<(std::ostream& o, wasm::ModuleHeapType pair) {
3907+
if (auto it = pair.first.typeNames.find(pair.second);
3908+
it != pair.first.typeNames.end()) {
3909+
return o << it->second.name;
3910+
}
3911+
return o << "(unnamed)";
3912+
}
3913+
39063914
} // namespace std

src/passes/Unsubtyping.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ template<typename K, typename V> using Map = std::unordered_map<K, V>;
129129
template<typename T> using Set = std::unordered_set<T>;
130130
#endif
131131

132-
#if UNSUBTYPING_DEBUG
133-
Name getTypeName(Module& wasm, HeapType type) {
134-
if (auto it = wasm.typeNames.find(type); it != wasm.typeNames.end()) {
135-
return it->second.name;
136-
}
137-
return Name("(unnamed)");
138-
}
139-
#endif
140-
141132
// A tree (or rather a forest) of types with the ability to query and set
142133
// supertypes in constant time and efficiently iterate over supertypes and
143134
// subtypes.
@@ -291,13 +282,13 @@ struct TypeTree {
291282
#if UNSUBTYPING_DEBUG
292283
void dump(Module& wasm) {
293284
for (auto& node : nodes) {
294-
std::cerr << getTypeName(wasm, node.type);
285+
std::cerr << ModuleHeapType(wasm, node.type);
295286
if (auto super = getSupertype(node.type)) {
296-
std::cerr << " <: " << getTypeName(wasm, *super);
287+
std::cerr << " <: " << ModuleHeapType(wasm, *super);
297288
}
298289
std::cerr << ", children:";
299290
for (auto child : node.children) {
300-
std::cerr << " " << getTypeName(wasm, nodes[child].type);
291+
std::cerr << " " << ModuleHeapType(wasm, nodes[child].type);
301292
}
302293
std::cerr << '\n';
303294
}
@@ -360,8 +351,8 @@ struct Unsubtyping : Pass {
360351
if (sub == super || sub.isBottom()) {
361352
return;
362353
}
363-
DBG(std::cerr << "noting " << getTypeName(*wasm, sub)
364-
<< " <: " << getTypeName(*wasm, super) << '\n');
354+
DBG(std::cerr << "noting " << ModuleHeapType(*wasm, sub)
355+
<< " <: " << ModuleHeapType(*wasm, super) << '\n');
365356
work.push_back({sub, super});
366357
}
367358

@@ -520,8 +511,8 @@ struct Unsubtyping : Pass {
520511
}
521512

522513
void process(HeapType sub, HeapType super) {
523-
DBG(std::cerr << "processing " << getTypeName(*wasm, sub)
524-
<< " <: " << getTypeName(*wasm, super) << '\n');
514+
DBG(std::cerr << "processing " << ModuleHeapType(*wasm, sub)
515+
<< " <: " << ModuleHeapType(*wasm, super) << '\n');
525516
assert(HeapType::isSubType(sub, super));
526517
auto oldSuper = types.getSupertype(sub);
527518
if (oldSuper) {

src/wasm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2623,8 +2623,9 @@ class Module {
26232623
// Utility for printing an expression with named types.
26242624
using ModuleExpression = std::pair<Module&, Expression*>;
26252625

2626-
// Utility for printing an type with a name, if the module defines a name.
2626+
// Utilities for printing an type with a name, if the module defines a name.
26272627
using ModuleType = std::pair<Module&, Type>;
2628+
using ModuleHeapType = std::pair<Module&, HeapType>;
26282629

26292630
// Utility for printing only the top level of an expression. Named types will be
26302631
// used if `module` is non-null.
@@ -2648,6 +2649,7 @@ std::ostream& operator<<(std::ostream& o, wasm::Expression& expression);
26482649
std::ostream& operator<<(std::ostream& o, wasm::ModuleExpression pair);
26492650
std::ostream& operator<<(std::ostream& o, wasm::ShallowExpression expression);
26502651
std::ostream& operator<<(std::ostream& o, wasm::ModuleType pair);
2652+
std::ostream& operator<<(std::ostream& o, wasm::ModuleHeapType pair);
26512653

26522654
} // namespace std
26532655

0 commit comments

Comments
 (0)