This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Improve handling of nested continuations #54
Merged
dhil
merged 19 commits into
effect-handlers:typed-continuations
from
frank-emrich:nested_testing
Aug 16, 2023
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
031e7dd
new test for nested use of continuations
frank-emrich 2f6bddc
simpler nesting test
frank-emrich bc578db
formatting
frank-emrich c004e94
renamed file
frank-emrich 05e94e3
cont_nested2
frank-emrich f137917
renamed cont_nested3
frank-emrich 842e1ca
new cont_nested3
frank-emrich d9de745
cont_nested4
frank-emrich dc72c5d
cont_nested9
frank-emrich 9e32694
cont_nested8
frank-emrich 25cea45
do not use readonly flag for loading continuation object
frank-emrich 7cc61ad
restore tsp pointer
frank-emrich fcc5488
debug printing
frank-emrich 7f48b6e
delete cont_nested8 and 9
frank-emrich c893615
regression test for TSP setting after return
frank-emrich 28398fb
revamp debug printing
frank-emrich 3149157
rename cont_nested10
frank-emrich 3ec6489
_tsp
frank-emrich 7c15275
formatting
frank-emrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/misc_testsuite/typed-continuations/cont_nested1.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
;; test using continuations from within a continuation | ||
|
||
(module | ||
|
||
(type $unit_to_unit (func)) | ||
(type $ct (cont $unit_to_unit)) | ||
|
||
(type $g2_res_type (func (result (ref $ct)))) | ||
(type $g2_res_type_ct (cont $g2_res_type)) | ||
|
||
(tag $e1) | ||
(tag $e2 (param (ref $ct))) | ||
|
||
(global $marker (mut i32) (i32.const 0)) | ||
|
||
(func $update_marker (param $x i32) | ||
(i32.add (global.get $marker) (i32.const 1)) | ||
(i32.mul (local.get $x)) | ||
(global.set $marker)) | ||
|
||
(func $g1 | ||
(call $update_marker (i32.const 2)) | ||
(suspend $e1) | ||
(call $update_marker (i32.const 3)) | ||
) | ||
(elem declare func $g1) | ||
|
||
(func $g2 | ||
(local $k1 (ref $ct)) | ||
(local $k2 (ref $ct)) | ||
(call $update_marker (i32.const 5)) | ||
|
||
(block $on_e1 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(local.set $k1) | ||
(call $update_marker (i32.const 7)) | ||
(block $on_e1_2 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1_2) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(local.set $k2) | ||
(call $update_marker (i32.const 11)) | ||
(resume $ct (local.get $k1))) | ||
(elem declare func $g2) | ||
|
||
|
||
|
||
(func $test (export "test") (result i32) | ||
(resume $ct (cont.new $ct (ref.func $g2))) | ||
(global.get $marker))) | ||
|
||
(assert_return (invoke "test") (i32.const 6_108)) |
64 changes: 64 additions & 0 deletions
64
tests/misc_testsuite/typed-continuations/cont_nested2.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
;; Similar to cont_nested1, but with payloads | ||
|
||
(module | ||
|
||
(type $int_to_int (func (param i32) (result i32))) | ||
(type $ct (cont $int_to_int)) | ||
|
||
(type $unit_to_int (func (result i32))) | ||
(type $ct_unit_to_int (cont $unit_to_int)) | ||
|
||
(tag $e1 (param i32) (result i32)) | ||
|
||
(global $marker (mut i32) (i32.const 0)) | ||
|
||
;; (func $update_marker (param $x i32) (result i32) | ||
;; (i32.add (global.get $marker) (i32.const 1)) | ||
;; (i32.mul (local.get $x)) | ||
;; (global.set $marker) | ||
;; (global.get $marker)) | ||
|
||
(func $scramble (param $x i32) (param $y i32) (result i32) | ||
(i32.add (local.get $y) (i32.const 1)) | ||
(i32.mul (local.get $x)) | ||
) | ||
|
||
(func $g1 (param $x i32) (result i32) | ||
(call $scramble (i32.const 3) (local.get $x)) | ||
(suspend $e1) | ||
(call $scramble (i32.const 5)) | ||
(i32.add (local.get $x)) | ||
(global.set $marker) | ||
(global.get $marker)) | ||
(elem declare func $g1) | ||
|
||
(func $g2 (result i32) | ||
(local $k1 (ref $ct)) | ||
(local $v i32) | ||
|
||
(block $on_e1 (result i32 (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1) (i32.const 7) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(local.set $k1) | ||
(call $scramble (i32.const 11)) ;; scramble the value received via $e1 from $g1 | ||
(local.set $v) | ||
|
||
(block $on_e1_2 (result i32 (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1_2) (local.get $v) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(drop) ;; drop continuation, we don't intend to resume the second invocation of g1 | ||
(call $scramble (i32.const 13)) | ||
|
||
(resume $ct (local.get $k1)) | ||
(i32.add (global.get $marker))) | ||
(elem declare func $g2) | ||
|
||
|
||
|
||
(func $test (export "test") (result i32) | ||
(resume $ct_unit_to_int (cont.new $ct_unit_to_int (ref.func $g2))) | ||
|
||
) | ||
) | ||
|
||
(assert_return (invoke "test") (i32.const 145_670)) |
40 changes: 40 additions & 0 deletions
40
tests/misc_testsuite/typed-continuations/cont_nested3.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
;; Minimal test for resuming continuation after its original parent is gone | ||
|
||
(module | ||
|
||
(type $unit_to_unit (func)) | ||
(type $ct (cont $unit_to_unit)) | ||
|
||
(type $g2 (func (result (ref $ct)))) | ||
(type $g2_ct (cont $g2)) | ||
|
||
(tag $e1) | ||
;;(tag $e2 (param (ref $ct))) | ||
|
||
(global $marker (mut i32) (i32.const 0)) | ||
|
||
;;(global $orphan (mut (ref $ct))) | ||
|
||
(func $g1 | ||
(suspend $e1) | ||
(global.set $marker (i32.const 100)) | ||
) | ||
(elem declare func $g1) | ||
|
||
(func $g2 (result (ref $ct)) | ||
(block $on_e1 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
;; continuation becomes return value | ||
) | ||
|
||
(elem declare func $g2) | ||
|
||
|
||
(func $test (export "test") (result i32) | ||
(resume $g2_ct (cont.new $g2_ct (ref.func $g2))) | ||
(resume $ct) ;; resume return value of $g2 | ||
(global.get $marker)) | ||
) | ||
|
||
(assert_return (invoke "test") (i32.const 100)) |
44 changes: 44 additions & 0 deletions
44
tests/misc_testsuite/typed-continuations/cont_nested4.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
;; Minimal test for resuming continuation after its original parent is suspended | ||
|
||
(module | ||
|
||
(type $unit_to_unit (func)) | ||
(type $ct (cont $unit_to_unit)) | ||
|
||
;;(type $g2 (func (result (ref $ct)))) | ||
;;(type $g2_ct (cont $g2)) | ||
|
||
(tag $e1) | ||
(tag $e2 (param (ref $ct))) | ||
|
||
(global $marker (mut i32) (i32.const 0)) | ||
|
||
;;(global $orphan (mut (ref $ct))) | ||
|
||
(func $g1 | ||
(suspend $e1) | ||
(global.set $marker (i32.const 100)) | ||
) | ||
(elem declare func $g1) | ||
|
||
(func $g2 | ||
(block $on_e1 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(suspend $e2) | ||
;; continuation becomes return value | ||
(unreachable)) | ||
|
||
(elem declare func $g2) | ||
|
||
|
||
(func $test (export "test") (result i32) | ||
(block $on_e2 (result (ref $ct) (ref $ct)) | ||
(resume $ct (tag $e2 $on_e2) (cont.new $ct (ref.func $g2))) | ||
(unreachable)) | ||
(drop) ;; drop the continuation (i.e., for resuming g2) | ||
(resume $ct) ;; resume continuation received as payload of $e2 (i.e., continuing execution of $g1) | ||
(global.get $marker)) | ||
) | ||
|
||
(assert_return (invoke "test") (i32.const 100)) |
68 changes: 68 additions & 0 deletions
68
tests/misc_testsuite/typed-continuations/cont_nested5.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
;; test using continuations from within a continuation | ||
|
||
|
||
(module | ||
|
||
(type $unit_to_unit (func)) | ||
(type $ct (cont $unit_to_unit)) | ||
|
||
(type $g2_res_type (func (result (ref $ct)))) | ||
(type $g2_res_type_ct (cont $g2_res_type)) | ||
|
||
(tag $e1) | ||
(tag $e2 (param (ref $ct))) | ||
|
||
(global $marker (mut i32) (i32.const 0)) | ||
|
||
(func $update_marker (param $x i32) | ||
(i32.add (global.get $marker) (i32.const 1)) | ||
(i32.mul (local.get $x)) | ||
(global.set $marker)) | ||
|
||
(func $g1 | ||
(call $update_marker (i32.const 2)) | ||
(suspend $e1) | ||
(call $update_marker (i32.const 3)) | ||
) | ||
(elem declare func $g1) | ||
|
||
(func $g2 (result (ref $ct)) | ||
(local $k1 (ref $ct)) | ||
(local $k2 (ref $ct)) | ||
(call $update_marker (i32.const 5)) | ||
|
||
(block $on_e1 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(local.set $k1) | ||
(call $update_marker (i32.const 7)) | ||
(block $on_e1_2 (result (ref $ct)) | ||
(resume $ct (tag $e1 $on_e1_2) (cont.new $ct (ref.func $g1))) | ||
(unreachable)) | ||
(local.set $k2) | ||
(call $update_marker (i32.const 11)) | ||
(resume $ct (local.get $k1)) | ||
(call $update_marker (i32.const 13)) | ||
(local.get $k2) | ||
) | ||
(elem declare func $g2) | ||
|
||
(func $g3 | ||
(call $update_marker (i32.const 17)) | ||
(resume $g2_res_type_ct (cont.new $g2_res_type_ct (ref.func $g2))) | ||
(call $update_marker (i32.const 19)) | ||
(suspend $e2)) | ||
(elem declare func $g3) | ||
|
||
|
||
(func $test (export "test") (result i32) | ||
(call $update_marker (i32.const 23)) | ||
(block $on_e2 (result (ref $ct) (ref $ct)) | ||
(resume $ct (tag $e2 $on_e2) (cont.new $ct (ref.func $g3))) | ||
(unreachable)) | ||
(drop) ;; we won't resume g3, but want the payload | ||
(call $update_marker (i32.const 31)) | ||
(resume $ct) | ||
(global.get $marker))) | ||
|
||
(assert_return (invoke "test") (i32.const 490_074_902)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this perform any side-effects? Can we remove it?