Skip to content

Commit 17f779f

Browse files
Try adding subtyping, not working
1 parent 225564f commit 17f779f

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/passes/GlobalEffects.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "ir/effects.h"
2525
#include "ir/module-utils.h"
26+
#include "ir/subtypes.h"
2627
#include "pass.h"
2728
#include "support/unique_deferring_queue.h"
2829
#include "wasm.h"
@@ -117,8 +118,15 @@ std::unordered_map<HeapType, std::unordered_set<Name>>
117118
typeToFunctionNames(const Module& module) {
118119
std::unordered_map<HeapType, std::unordered_set<Name>> ret;
119120

121+
// TODO
122+
SubTypes s(*const_cast<Module*>(&module));
123+
120124
for (const auto& func : module.functions) {
121-
ret[func->type.getHeapType()].insert(func->name);
125+
s.iterSubTypes(func->type.getHeapType(), [&ret, &func](HeapType type, int _) {
126+
std::cout<<"subtype "<< func->type.getHeapType() << " " << type<< "\n";
127+
ret[type].insert(func->name);
128+
});
129+
// ret[func->type.getHeapType()].insert(func->name);
122130
}
123131

124132
return ret;
@@ -166,13 +174,6 @@ transitiveClosure(const Module& module,
166174
// caller => called => called by called
167175
//
168176
auto it = funcInfos.find(module.getFunction(called));
169-
170-
// TODO: this should never be missing?
171-
if (it == funcInfos.end()) {
172-
std::cout << "missing key " << called << "\n";
173-
throw(1);
174-
// assert(false && ("missing key " + called));
175-
}
176177
auto& calledInfo = it->second;
177178
// auto& calledInfo = funcInfos.at(module.getFunction(called));
178179
for (auto calledByCalled : calledInfo.calledFunctions) {
@@ -225,11 +226,6 @@ struct GenerateGlobalEffects : public Pass {
225226
for (auto& [func, info] : funcInfos) {
226227
indirectCallersNonTransitive[func->name];
227228
for (auto& calledType : info.indirectCalledTypes) {
228-
// auto asdf = functionsWithType.at(calledType);
229-
// auto foo = indirectCallersNonTransitive[func->name];
230-
// asdf.merge(foo);
231-
// foo.merge(asdf);
232-
233229
if (auto it = functionsWithType.find(calledType);
234230
it != functionsWithType.end()) {
235231
indirectCallersNonTransitive[func->name].insert(it->second.begin(),

test/lit/passes/global-effects-closed-world.wast

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
;; CHECK: (type $sub (sub $super (struct)))
1414
(type $sub (sub $super (struct)))
1515

16-
;; CHECK: (type $func-with-sub-param (func (param (ref $sub))))
16+
;; CHECK: (type $func-with-sub-param (sub (func (param (ref $sub)))))
1717

1818
;; CHECK: (type $uninhabited (func (param f32)))
1919
(type $uninhabited (func (param f32)))
2020

2121
;; Subtype
22-
;; CHECK: (type $func-with-super-param (func (param (ref $super))))
23-
(type $func-with-super-param (func (param (ref $super))))
24-
;; Supertype
25-
(type $func-with-sub-param (func (param (ref $sub))))
22+
(type $func-with-sub-param (sub (func (param (ref $sub)))))
23+
24+
;; Subtype
25+
;; CHECK: (type $func-with-super-param (sub $func-with-sub-param (func (param (ref $super)))))
26+
(type $func-with-super-param (sub $func-with-sub-param (func (param (ref $super)))))
2627

2728
;; CHECK: (global $g (mut i32) (i32.const 0))
2829
(global $g (mut i32) (i32.const 0))

0 commit comments

Comments
 (0)