Skip to content

Commit

Permalink
Split linking_tags.wast into two files (#255)
Browse files Browse the repository at this point in the history
This PR splits `linking_tags.wast` into two files.

This is a preparation step needed to land fast effect forwarding due to
the following:
`linking_tags.wast` currently has two `assert_suspension` directives. In
the current implementation, we are always on the main stack when we
detect that a tag is unhandled and trap from there. However, in the
presence of fast effect forwarding, we detect the lack of an appropriate
handler at the `suspend` site and trap there (i.e., possibly while still
running on a continuation stack).

As a result, the `assert_suspension` directives in `linking_tags.wast`
trigger the problem described in #253 as soon as fast fowarding lands.
As a workaround, this PR splits the file into two, where the
`assert_suspension` is the very last step in each test (i.e., we avoid
further execution inside the `Store` where we trapped while inside a
continuation). The combined contents of both files is identical to the
original `linking_tags.wast`, but the module `bar` is moved to the end
of the second file.
  • Loading branch information
frank-emrich authored Nov 18, 2024
1 parent 6c25f94 commit d5c1957
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 73 deletions.
36 changes: 36 additions & 0 deletions tests/misc_testsuite/stack-switching/linking_tags1.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(module $alien
(tag $alien_tag (export "alien_tag"))
)
(register "alien")

(module $mine
(type $ft (func))
(type $ct (cont $ft))
(tag $alien_tag (import "alien" "alien_tag"))
(tag $my_tag)
(func $do_alien_tag
(suspend $alien_tag))

;; Don't handle the imported alien.
(func (export "main-1")
(block $on_my_tag (result (ref $ct))
(resume $ct (on $my_tag $on_my_tag) (cont.new $ct (ref.func $do_alien_tag)))
(unreachable)
)
(unreachable))

;; Handle the imported alien.
(func (export "main-2")
(block $on_alien_tag (result (ref $ct))
(resume $ct (on $alien_tag $on_alien_tag) (cont.new $ct (ref.func $do_alien_tag)))
(unreachable)
)
(drop))

(elem declare func $do_alien_tag)
)
(register "mine")
(assert_return (invoke "main-2"))
;; Due to issue #253, we need to make sure that nothing happens afterwards in
;; the test:
(assert_suspension (invoke "main-1") "unhandled")
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
(module $alien
(tag $alien_tag (export "alien_tag"))
)
(register "alien")

(module $mine
(type $ft (func))
(type $ct (cont $ft))
(tag $alien_tag (import "alien" "alien_tag"))
(tag $my_tag)
(func $do_alien_tag
(suspend $alien_tag))

;; Don't handle the imported alien.
(func (export "main-1")
(block $on_my_tag (result (ref $ct))
(resume $ct (on $my_tag $on_my_tag) (cont.new $ct (ref.func $do_alien_tag)))
(unreachable)
)
(unreachable))

;; Handle the imported alien.
(func (export "main-2")
(block $on_alien_tag (result (ref $ct))
(resume $ct (on $alien_tag $on_alien_tag) (cont.new $ct (ref.func $do_alien_tag)))
(unreachable)
)
(drop))

(elem declare func $do_alien_tag)
)
(register "mine")
(assert_suspension (invoke "main-1") "unhandled")
(assert_return (invoke "main-2"))

(module $foo
(type $ft (func (result i32)))
(type $ct (cont $ft))
Expand All @@ -58,43 +23,6 @@
(register "foo")
(assert_return (invoke "test_foo") (i32.const 1))

(module $bar
(type $ft (func (result i32)))
(type $ct (cont $ft))

(type $ft-2 (func (param i32) (result i32)))
(type $ct-2 (cont $ft-2))

(tag $foo (import "foo" "foo") (result i32))
(tag $bar (result i32))
(func $do_foo (result i32)
(suspend $foo))

;; Don't handle the imported foo.
(func (export "skip-imported-foo") (result i32)
(block $on_bar (result (ref $ct-2))
(resume $ct (on $bar $on_bar) (cont.new $ct (ref.func $do_foo)))
(unreachable)
)
(unreachable))

;; Handle the imported foo.
(func (export "handle-imported-foo") (result i32)
(block $on_foo (result (ref $ct-2))
(resume $ct (on $foo $on_foo) (cont.new $ct (ref.func $do_foo)))
(unreachable)
)
(drop)
(return (i32.const 2))
)

(elem declare func $do_foo)
)
(register "bar")
(assert_suspension (invoke "skip-imported-foo") "unhandled")
(assert_return (invoke "handle-imported-foo") (i32.const 2))


(module $baz
(type $ft (func (result i32)))
(type $ct (cont $ft))
Expand Down Expand Up @@ -166,4 +94,42 @@
)
(register "quux")
(assert_return (invoke "compose-handle-foo-my-foo") (i32.const 4))
(assert_return (invoke "compose-handle-my-foo-foo") (i32.const 1))
(assert_return (invoke "compose-handle-my-foo-foo") (i32.const 1))

(module $bar
(type $ft (func (result i32)))
(type $ct (cont $ft))

(type $ft-2 (func (param i32) (result i32)))
(type $ct-2 (cont $ft-2))

(tag $foo (import "foo" "foo") (result i32))
(tag $bar (result i32))
(func $do_foo (result i32)
(suspend $foo))

;; Don't handle the imported foo.
(func (export "skip-imported-foo") (result i32)
(block $on_bar (result (ref $ct-2))
(resume $ct (on $bar $on_bar) (cont.new $ct (ref.func $do_foo)))
(unreachable)
)
(unreachable))

;; Handle the imported foo.
(func (export "handle-imported-foo") (result i32)
(block $on_foo (result (ref $ct-2))
(resume $ct (on $foo $on_foo) (cont.new $ct (ref.func $do_foo)))
(unreachable)
)
(drop)
(return (i32.const 2))
)

(elem declare func $do_foo)
)
(register "bar")
(assert_return (invoke "handle-imported-foo") (i32.const 2))
;; Due to issue #253, we need to make sure that nothing happens afterwards in
;; the test:
(assert_suspension (invoke "skip-imported-foo") "unhandled")

2 comments on commit d5c1957

@dhil
Copy link
Member

@dhil dhil commented on d5c1957 Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, don't you have to rebless the snapshots and commit them?

@frank-emrich
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware that .wast tests have expected output files stored somewhere that would require (re-)blessing, only disas tests. Am I missing something?

Please sign in to comment.