Skip to content

Commit c0543a1

Browse files
Add more tests + split up
1 parent 01198f8 commit c0543a1

File tree

3 files changed

+121
-111
lines changed

3 files changed

+121
-111
lines changed

src/ir/subtypes.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ struct SubTypes {
173173
// true if we did not stop early, and false if we did.
174174
template<typename F>
175175
bool iterSubTypes(HeapType type, Index depth, F func) const
176-
requires requires(F func, HeapType subtype, Index depth) { { func(subtype, depth) } -> std::same_as<bool>; } {
176+
requires requires(F func, HeapType subtype, Index depth) {
177+
{ func(subtype, depth) } -> std::same_as<bool>;
178+
}
179+
{
177180
// Start by traversing the type itself.
178181
if (!func(type, 0)) {
179182
return false;
@@ -222,7 +225,10 @@ struct SubTypes {
222225
// As above, but iterate to the maximum depth.
223226
template<typename F>
224227
bool iterSubTypes(HeapType type, F func) const
225-
requires requires(F func, HeapType subtype, Index depth) { { func(subtype, depth) } -> std::same_as<bool>; } {
228+
requires requires(F func, HeapType subtype, Index depth) {
229+
{ func(subtype, depth) } -> std::same_as<bool>;
230+
}
231+
{
226232
return iterSubTypes(type, std::numeric_limits<Index>::max(), func);
227233
}
228234

src/passes/GlobalEffects.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
// Function::effects; see more details there.
2020
//
2121

22-
#include "ir/table-utils.h"
23-
#include "ir/subtypes.h"
2422
#include "ir/effects.h"
23+
#include "ir/element-utils.h"
2524
#include "ir/module-utils.h"
25+
#include "ir/subtypes.h"
26+
#include "ir/table-utils.h"
2627
#include "pass.h"
27-
#include "ir/element-utils.h"
2828
#include "support/unique_deferring_queue.h"
2929
#include "wasm.h"
3030

@@ -125,7 +125,8 @@ using CallGraphNode = std::variant<Name, HeapType>;
125125
// Then B inherits effects from C and A inherits effects from both B and C.
126126
void propagateEffects(
127127
const Module& module,
128-
const std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>>& reverseCallGraph,
128+
const std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>>&
129+
reverseCallGraph,
129130
std::map<Function*, FuncInfo>& funcInfos) {
130131

131132
using CallGraphEdge = std::pair<CallGraphNode, CallGraphNode>;
@@ -164,8 +165,10 @@ void propagateEffects(
164165
while (!work.empty()) {
165166
auto [callee, caller] = work.pop();
166167

167-
if (std::get_if<Name>(&callee) == std::get_if<Name>(&caller) && std::holds_alternative<Name>(callee)) {
168-
auto& callerEffects = funcInfos.at(module.getFunction(std::get<Name>(caller))).effects;
168+
if (std::get_if<Name>(&callee) == std::get_if<Name>(&caller) &&
169+
std::holds_alternative<Name>(callee)) {
170+
auto& callerEffects =
171+
funcInfos.at(module.getFunction(std::get<Name>(caller))).effects;
169172
if (callerEffects) {
170173
callerEffects->trap = true;
171174
}
@@ -193,15 +196,18 @@ struct GenerateGlobalEffects : public Pass {
193196
analyzeFuncs(*module, getPassOptions());
194197

195198
// callee : caller
196-
std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>> callers;
199+
std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>>
200+
callers;
197201

198202
std::unordered_set<HeapType> allIndirectCalledTypes;
199203

200204
std::unordered_set<Name> funcsWithAddress;
201205

202206
auto refFuncs = TableUtils::getFunctionsNeedingElemDeclare(*module);
203207
funcsWithAddress.insert(refFuncs.begin(), refFuncs.end());
204-
ElementUtils::iterAllElementFunctionNames(module, [&funcsWithAddress](Name name) { funcsWithAddress.insert(name); });
208+
ElementUtils::iterAllElementFunctionNames(
209+
module,
210+
[&funcsWithAddress](Name name) { funcsWithAddress.insert(name); });
205211
for (const auto& export_ : module->exports) {
206212
if (export_->kind == ExternalKind::Function) {
207213
// This exported function might flow back to us even in a closed world,
@@ -233,10 +239,10 @@ struct GenerateGlobalEffects : public Pass {
233239
for (auto type : allIndirectCalledTypes) {
234240
subtypes.iterSubTypes(type, [&callers, type](HeapType sub, int _) {
235241
// HeapType -> HeapType
236-
// A subtype is a 'callee' of its supertype. Supertypes need to inherit effects from their subtypes
237-
// See the example in (TODO)
242+
// A subtype is a 'callee' of its supertype.
243+
// Supertypes need to inherit effects from their subtypes since they may
244+
// be called via a ref to the subtype.
238245
callers[sub].insert(type);
239-
// callers[type].insert(sub);
240246
return true;
241247
});
242248
}
@@ -247,7 +253,7 @@ struct GenerateGlobalEffects : public Pass {
247253
// known.
248254
for (auto& [func, info] : funcInfos) {
249255
func->effects.reset();
250-
if (!info.effects) {
256+
if (info.effects == UnknownEffects) {
251257
continue;
252258
}
253259

0 commit comments

Comments
 (0)