Skip to content

Commit ffb73c5

Browse files
Fix test
1 parent 68971e4 commit ffb73c5

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

src/support/graph_traversal.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121

2222
namespace wasm {
2323

24-
template<typename T, typename SuccessorFunction>
25-
requires std::
26-
invocable<SuccessorFunction, std::function<void(const T&)>&, const T&>
27-
class Graph {
24+
// SuccessorFunction should be an invocable that takes a 'push' function (which
25+
// is an invocable that takes a `const T&`), and a `const T&`. i.e.
26+
// SuccessorFunction should call `push` for each neighbor of the T that it's
27+
// called with.
28+
// TODO: We don't have a good way to write this with concepts today.
29+
// Something like this should do it, but we hit an ICE on dwarf symbols in debug
30+
// builds: requires requires(const SuccessorFunction& successors, const T& t) {
31+
// successors([](const T&) { }, t); }
32+
template<typename T, typename SuccessorFunction> class Graph {
2833
public:
2934
template<std::input_iterator It, std::sentinel_for<It> Sen>
3035
requires std::convertible_to<std::iter_reference_t<It>, T>
31-
Graph(It rootsBegin, Sen rootsEnd, auto&& successors)
32-
: roots(rootsBegin, rootsEnd),
33-
successors(std::forward<decltype(successors)>(successors)) {}
36+
Graph(It rootsBegin, Sen rootsEnd, SuccessorFunction successors)
37+
: roots(rootsBegin, rootsEnd), successors(std::move(successors)) {}
3438

3539
// Traverse the graph depth-first, calling `successors` exactly once for each
3640
// node (unless the node appears multiple times in `roots`). Return the set of
@@ -40,12 +44,10 @@ template<typename T, typename SuccessorFunction>
4044
std::unordered_set<T> visited(roots.begin(), roots.end());
4145

4246
auto maybePush = [&](const T& t) {
43-
if (visited.contains(t)) {
44-
return;
47+
auto [_, inserted] = visited.insert(t);
48+
if (inserted) {
49+
stack.push_back(t);
4550
}
46-
47-
visited.insert(t);
48-
stack.push_back(t);
4951
};
5052

5153
while (!stack.empty()) {

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2-
;; RUN: foreach %s %t wasm-opt -all --closed-world --generate-global-effects --simplify-locals -S -o - | filecheck %s
2+
;; RUN: foreach %s %t wasm-opt --enable-gc --enable-reference-types --closed-world --generate-global-effects --simplify-locals -S -o - | filecheck %s
33

44
;; Tests for aggregating effects from indirect calls in GlobalEffects when
55
;; --closed-world is true. Continued from global-effects-closed-world.wast.
66

77
(module
8-
;; CHECK: (type $indirect-type (sub (func (param i32))))
9-
(type $indirect-type (sub (func (param i32))))
10-
;; CHECK: (type $1 (func (param (ref $indirect-type))))
8+
;; CHECK: (type $indirect-type-super (sub (func (param i32))))
9+
(type $indirect-type-super (sub (func (param i32))))
1110

12-
;; CHECK: (type $indirect-type-sub (sub $indirect-type (func (param i32))))
13-
(type $indirect-type-sub (sub $indirect-type (func (param i32))))
11+
;; CHECK: (type $1 (func (param (ref $indirect-type-super))))
12+
13+
;; CHECK: (type $indirect-type-sub (sub $indirect-type-super (func (param i32))))
14+
(type $indirect-type-sub (sub $indirect-type-super (func (param i32))))
1415

1516
;; CHECK: (global $g1 (mut i32) (i32.const 0))
1617
(global $g1 (mut i32) (i32.const 0))
@@ -23,12 +24,12 @@
2324

2425
;; CHECK: (export "impl2" (func $impl2))
2526

26-
;; CHECK: (func $impl1 (type $indirect-type) (param $i32 i32)
27+
;; CHECK: (func $impl1 (type $indirect-type-super) (param $i32 i32)
2728
;; CHECK-NEXT: (global.set $g1
2829
;; CHECK-NEXT: (local.get $i32)
2930
;; CHECK-NEXT: )
3031
;; CHECK-NEXT: )
31-
(func $impl1 (export "impl1") (type $indirect-type) (param $i32 i32)
32+
(func $impl1 (export "impl1") (type $indirect-type-super) (param $i32 i32)
3233
(global.set $g1 (local.get $i32))
3334
)
3435

@@ -41,18 +42,18 @@
4142
(global.set $g2 (local.get $i32))
4243
)
4344

44-
;; CHECK: (func $caller (type $1) (param $ref (ref $indirect-type))
45-
;; CHECK-NEXT: (call_ref $indirect-type
45+
;; CHECK: (func $caller (type $1) (param $ref (ref $indirect-type-super))
46+
;; CHECK-NEXT: (call_ref $indirect-type-super
4647
;; CHECK-NEXT: (i32.const 1)
4748
;; CHECK-NEXT: (local.get $ref)
4849
;; CHECK-NEXT: )
4950
;; CHECK-NEXT: )
50-
(func $caller (param $ref (ref $indirect-type))
51+
(func $caller (param $ref (ref $indirect-type-super))
5152
;; This inherits effects from $impl1 and $impl2, so may mutate $g1 and $g2.
52-
(call_ref $indirect-type (i32.const 1) (local.get $ref))
53+
(call_ref $indirect-type-super (i32.const 1) (local.get $ref))
5354
)
5455

55-
;; CHECK: (func $merges-multiple-effects (type $1) (param $ref (ref $indirect-type))
56+
;; CHECK: (func $test-merge (type $1) (param $ref (ref $indirect-type-super))
5657
;; CHECK-NEXT: (local $x i32)
5758
;; CHECK-NEXT: (local $y i32)
5859
;; CHECK-NEXT: (local $z i32)
@@ -62,9 +63,7 @@
6263
;; CHECK-NEXT: (local.set $y
6364
;; CHECK-NEXT: (global.get $g2)
6465
;; CHECK-NEXT: )
65-
;; CHECK-NEXT: (local.set $z
66-
;; CHECK-NEXT: (global.get $g3)
67-
;; CHECK-NEXT: )
66+
;; CHECK-NEXT: (nop)
6867
;; CHECK-NEXT: (call $caller
6968
;; CHECK-NEXT: (local.get $ref)
7069
;; CHECK-NEXT: )
@@ -75,10 +74,10 @@
7574
;; CHECK-NEXT: (local.get $y)
7675
;; CHECK-NEXT: )
7776
;; CHECK-NEXT: (drop
78-
;; CHECK-NEXT: (local.get $z)
77+
;; CHECK-NEXT: (global.get $g3)
7978
;; CHECK-NEXT: )
8079
;; CHECK-NEXT: )
81-
(func $merges-multiple-effects (param $ref (ref $indirect-type))
80+
(func $merges-multiple-effects (param $ref (ref $indirect-type-super))
8281
(local $x i32)
8382
(local $y i32)
8483
(local $z i32)

0 commit comments

Comments
 (0)