|
| 1 | +;; $D exports one function for each place in the spec where may_leave is |
| 2 | +;; guarded to be true and ensures that the call traps before any other guard. |
| 3 | +;; Since each trap tears down the instance, a fresh instance of $Tester is |
| 4 | +;; created for each export call. |
| 5 | +(component definition $Tester |
| 6 | + (component $C |
| 7 | + (core module $CM |
| 8 | + (func (export "import")) |
| 9 | + ) |
| 10 | + (core instance $cm (instantiate $CM)) |
| 11 | + (func (export "import") (canon lift (core func $cm "import"))) |
| 12 | + ) |
| 13 | + (component $D |
| 14 | + (import "import" (func $import)) |
| 15 | + |
| 16 | + (core module $Memory (memory (export "mem") 1)) |
| 17 | + (core instance $memory (instantiate $Memory)) |
| 18 | + (type $R (resource (rep i32))) |
| 19 | + (type $ST (stream u32)) |
| 20 | + (type $FT (future u32)) |
| 21 | + (canon resource.new $R (core func $resource.new)) |
| 22 | + (canon resource.drop $R (core func $resource.drop)) |
| 23 | + (canon task.return (core func $task.return)) |
| 24 | + (canon task.cancel (core func $task.cancel)) |
| 25 | + (canon yield (core func $yield)) |
| 26 | + (canon waitable-set.new (core func $waitable-set.new)) |
| 27 | + (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait)) |
| 28 | + (canon waitable-set.poll (memory $memory "mem") (core func $waitable-set.poll)) |
| 29 | + (canon waitable-set.drop (core func $waitable-set.drop)) |
| 30 | + (canon waitable.join (core func $waitable.join)) |
| 31 | + (canon subtask.cancel (core func $subtask.cancel)) |
| 32 | + (canon subtask.drop (core func $subtask.drop)) |
| 33 | + (canon stream.new $ST (core func $stream.new)) |
| 34 | + (canon stream.read $ST (memory $memory "mem") (core func $stream.read)) |
| 35 | + (canon stream.write $ST (memory $memory "mem") (core func $stream.write)) |
| 36 | + (canon stream.cancel-read $ST (core func $stream.cancel-read)) |
| 37 | + (canon stream.cancel-write $ST (core func $stream.cancel-write)) |
| 38 | + (canon stream.drop-readable $ST (core func $stream.drop-readable)) |
| 39 | + (canon stream.drop-writable $ST (core func $stream.drop-writable)) |
| 40 | + (canon future.new $FT (core func $future.new)) |
| 41 | + (canon future.read $FT (memory $memory "mem") (core func $future.read)) |
| 42 | + (canon future.write $FT (memory $memory "mem") (core func $future.write)) |
| 43 | + (canon future.cancel-read $FT (core func $future.cancel-read)) |
| 44 | + (canon future.cancel-write $FT (core func $future.cancel-write)) |
| 45 | + (canon future.drop-readable $FT (core func $future.drop-readable)) |
| 46 | + (canon future.drop-writable $FT (core func $future.drop-writable)) |
| 47 | + (core module $DM |
| 48 | + (import "" "mem" (memory 1)) |
| 49 | + (import "" "import" (func $import)) |
| 50 | + (import "" "resource.new" (func $resource.new (param i32) (result i32))) |
| 51 | + (import "" "resource.drop" (func $resource.drop (param i32))) |
| 52 | + (import "" "task.return" (func $task.return)) |
| 53 | + (import "" "task.cancel" (func $task.cancel)) |
| 54 | + (import "" "yield" (func $yield (result i32))) |
| 55 | + (import "" "waitable-set.new" (func $waitable-set.new (result i32))) |
| 56 | + (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32))) |
| 57 | + (import "" "waitable-set.poll" (func $waitable-set.poll (param i32 i32) (result i32))) |
| 58 | + (import "" "waitable-set.drop" (func $waitable-set.drop (param i32))) |
| 59 | + (import "" "waitable.join" (func $waitable.join (param i32 i32))) |
| 60 | + (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32))) |
| 61 | + (import "" "subtask.drop" (func $subtask.drop (param i32))) |
| 62 | + (import "" "stream.new" (func $stream.new (result i64))) |
| 63 | + (import "" "stream.read" (func $stream.read (param i32 i32 i32) (result i32))) |
| 64 | + (import "" "stream.write" (func $stream.write (param i32 i32 i32) (result i32))) |
| 65 | + (import "" "stream.cancel-read" (func $stream.cancel-read (param i32) (result i32))) |
| 66 | + (import "" "stream.cancel-write" (func $stream.cancel-write (param i32) (result i32))) |
| 67 | + (import "" "stream.drop-readable" (func $stream.drop-readable (param i32))) |
| 68 | + (import "" "stream.drop-writable" (func $stream.drop-writable (param i32))) |
| 69 | + (import "" "future.new" (func $future.new (result i64))) |
| 70 | + (import "" "future.read" (func $future.read (param i32 i32) (result i32))) |
| 71 | + (import "" "future.write" (func $future.write (param i32 i32) (result i32))) |
| 72 | + (import "" "future.cancel-read" (func $future.cancel-read (param i32) (result i32))) |
| 73 | + (import "" "future.cancel-write" (func $future.cancel-write (param i32) (result i32))) |
| 74 | + (import "" "future.drop-readable" (func $future.drop-readable (param i32))) |
| 75 | + (import "" "future.drop-writable" (func $future.drop-writable (param i32))) |
| 76 | + |
| 77 | + (func (export "noop")) |
| 78 | + (func (export "trap-calling-import") (call $import)) |
| 79 | + (func (export "trap-calling-resource-new") (drop (call $resource.new (i32.const 0)))) |
| 80 | + (func (export "trap-calling-resource-drop") (call $resource.drop (i32.const 0))) |
| 81 | + (func (export "trap-calling-task-return") (call $task.return)) |
| 82 | + (func (export "trap-calling-task-cancel") (call $task.cancel)) |
| 83 | + (func (export "trap-calling-yield") (drop (call $yield))) |
| 84 | + (func (export "trap-calling-waitable-set-new") (drop (call $waitable-set.new))) |
| 85 | + (func (export "trap-calling-waitable-set-wait") (drop (call $waitable-set.wait (i32.const 0) (i32.const 0)))) |
| 86 | + (func (export "trap-calling-waitable-set-poll") (drop (call $waitable-set.poll (i32.const 0) (i32.const 0)))) |
| 87 | + (func (export "trap-calling-waitable-set-drop") (call $waitable-set.drop (i32.const 0))) |
| 88 | + (func (export "trap-calling-waitable-join") (call $waitable.join (i32.const 0) (i32.const 0))) |
| 89 | + (func (export "trap-calling-subtask-cancel") (drop (call $subtask.cancel (i32.const 0)))) |
| 90 | + (func (export "trap-calling-subtask-drop") (call $subtask.drop (i32.const 0))) |
| 91 | + (func (export "trap-calling-stream-new") (drop (call $stream.new))) |
| 92 | + (func (export "trap-calling-stream-read") (drop (call $stream.read (i32.const 0) (i32.const 0) (i32.const 0)))) |
| 93 | + (func (export "trap-calling-stream-write") (drop (call $stream.write (i32.const 0) (i32.const 0) (i32.const 0)))) |
| 94 | + (func (export "trap-calling-stream-cancel-read") (drop (call $stream.cancel-read (i32.const 0)))) |
| 95 | + (func (export "trap-calling-stream-cancel-write") (drop (call $stream.cancel-write (i32.const 0)))) |
| 96 | + (func (export "trap-calling-stream-drop-readable") (call $stream.drop-readable (i32.const 0))) |
| 97 | + (func (export "trap-calling-stream-drop-writable") (call $stream.drop-writable (i32.const 0))) |
| 98 | + (func (export "trap-calling-future-new") (drop (call $future.new))) |
| 99 | + (func (export "trap-calling-future-read") (drop (call $future.read (i32.const 0) (i32.const 0)))) |
| 100 | + (func (export "trap-calling-future-write") (drop (call $future.write (i32.const 0) (i32.const 0)))) |
| 101 | + (func (export "trap-calling-future-cancel-read") (drop (call $future.cancel-read (i32.const 0)))) |
| 102 | + (func (export "trap-calling-future-cancel-write") (drop (call $future.cancel-write (i32.const 0)))) |
| 103 | + (func (export "trap-calling-future-drop-readable") (call $future.drop-readable (i32.const 0))) |
| 104 | + (func (export "trap-calling-future-drop-writable") (call $future.drop-writable (i32.const 0))) |
| 105 | + ) |
| 106 | + (canon lower (func $import) (core func $import')) |
| 107 | + (core instance $dm (instantiate $DM (with "" (instance |
| 108 | + (export "mem" (memory $memory "mem")) |
| 109 | + (export "import" (func $import')) |
| 110 | + (export "resource.new" (func $resource.new)) |
| 111 | + (export "resource.drop" (func $resource.drop)) |
| 112 | + (export "task.return" (func $task.return)) |
| 113 | + (export "task.cancel" (func $task.cancel)) |
| 114 | + (export "yield" (func $yield)) |
| 115 | + (export "waitable-set.new" (func $waitable-set.new)) |
| 116 | + (export "waitable-set.wait" (func $waitable-set.wait)) |
| 117 | + (export "waitable-set.poll" (func $waitable-set.poll)) |
| 118 | + (export "waitable-set.drop" (func $waitable-set.drop)) |
| 119 | + (export "waitable.join" (func $waitable.join)) |
| 120 | + (export "subtask.cancel" (func $subtask.cancel)) |
| 121 | + (export "subtask.drop" (func $subtask.drop)) |
| 122 | + (export "stream.new" (func $stream.new)) |
| 123 | + (export "stream.read" (func $stream.read)) |
| 124 | + (export "stream.write" (func $stream.write)) |
| 125 | + (export "stream.cancel-read" (func $stream.cancel-read)) |
| 126 | + (export "stream.cancel-write" (func $stream.cancel-write)) |
| 127 | + (export "stream.drop-readable" (func $stream.drop-readable)) |
| 128 | + (export "stream.drop-writable" (func $stream.drop-writable)) |
| 129 | + (export "future.new" (func $future.new)) |
| 130 | + (export "future.read" (func $future.read)) |
| 131 | + (export "future.write" (func $future.write)) |
| 132 | + (export "future.cancel-read" (func $future.cancel-read)) |
| 133 | + (export "future.cancel-write" (func $future.cancel-write)) |
| 134 | + (export "future.drop-readable" (func $future.drop-readable)) |
| 135 | + (export "future.drop-writable" (func $future.drop-writable)) |
| 136 | + )))) |
| 137 | + (func (export "trap-calling-import") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-import")))) |
| 138 | + (func (export "trap-calling-resource-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-resource-new")))) |
| 139 | + (func (export "trap-calling-resource-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-resource-drop")))) |
| 140 | + (func (export "trap-calling-task-return") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-task-return")))) |
| 141 | + (func (export "trap-calling-task-cancel") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-task-cancel")))) |
| 142 | + (func (export "trap-calling-yield") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-yield")))) |
| 143 | + (func (export "trap-calling-waitable-set-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-new")))) |
| 144 | + (func (export "trap-calling-waitable-set-wait") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-wait")))) |
| 145 | + (func (export "trap-calling-waitable-set-poll") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-poll")))) |
| 146 | + (func (export "trap-calling-waitable-set-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-drop")))) |
| 147 | + (func (export "trap-calling-waitable-join") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-join")))) |
| 148 | + (func (export "trap-calling-subtask-cancel") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-subtask-cancel")))) |
| 149 | + (func (export "trap-calling-subtask-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-subtask-drop")))) |
| 150 | + (func (export "trap-calling-stream-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-new")))) |
| 151 | + (func (export "trap-calling-stream-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-read")))) |
| 152 | + (func (export "trap-calling-stream-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-write")))) |
| 153 | + (func (export "trap-calling-stream-cancel-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-cancel-read")))) |
| 154 | + (func (export "trap-calling-stream-cancel-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-cancel-write")))) |
| 155 | + (func (export "trap-calling-stream-drop-readable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-drop-readable")))) |
| 156 | + (func (export "trap-calling-stream-drop-writable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-drop-writable")))) |
| 157 | + (func (export "trap-calling-future-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-new")))) |
| 158 | + (func (export "trap-calling-future-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-read")))) |
| 159 | + (func (export "trap-calling-future-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-write")))) |
| 160 | + (func (export "trap-calling-future-cancel-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-cancel-read")))) |
| 161 | + (func (export "trap-calling-future-cancel-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-cancel-write")))) |
| 162 | + (func (export "trap-calling-future-drop-readable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-drop-readable")))) |
| 163 | + (func (export "trap-calling-future-drop-writable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-drop-writable")))) |
| 164 | + ) |
| 165 | + (instance $c (instantiate $C)) |
| 166 | + (instance $d (instantiate $D (with "import" (func $c "import")))) |
| 167 | + (func (export "trap-calling-import") (alias export $d "trap-calling-import")) |
| 168 | + (func (export "trap-calling-resource-new") (alias export $d "trap-calling-resource-new")) |
| 169 | + (func (export "trap-calling-resource-drop") (alias export $d "trap-calling-resource-drop")) |
| 170 | + (func (export "trap-calling-task-return") (alias export $d "trap-calling-task-return")) |
| 171 | + (func (export "trap-calling-task-cancel") (alias export $d "trap-calling-task-cancel")) |
| 172 | + (func (export "trap-calling-yield") (alias export $d "trap-calling-yield")) |
| 173 | + (func (export "trap-calling-waitable-set-new") (alias export $d "trap-calling-waitable-set-new")) |
| 174 | + (func (export "trap-calling-waitable-set-wait") (alias export $d "trap-calling-waitable-set-wait")) |
| 175 | + (func (export "trap-calling-waitable-set-poll") (alias export $d "trap-calling-waitable-set-poll")) |
| 176 | + (func (export "trap-calling-waitable-set-drop") (alias export $d "trap-calling-waitable-set-drop")) |
| 177 | + (func (export "trap-calling-waitable-join") (alias export $d "trap-calling-waitable-join")) |
| 178 | + (func (export "trap-calling-subtask-cancel") (alias export $d "trap-calling-subtask-cancel")) |
| 179 | + (func (export "trap-calling-subtask-drop") (alias export $d "trap-calling-subtask-drop")) |
| 180 | + (func (export "trap-calling-stream-new") (alias export $d "trap-calling-stream-new")) |
| 181 | + (func (export "trap-calling-stream-read") (alias export $d "trap-calling-stream-read")) |
| 182 | + (func (export "trap-calling-stream-write") (alias export $d "trap-calling-stream-write")) |
| 183 | + (func (export "trap-calling-stream-cancel-read") (alias export $d "trap-calling-stream-cancel-read")) |
| 184 | + (func (export "trap-calling-stream-cancel-write") (alias export $d "trap-calling-stream-cancel-write")) |
| 185 | + (func (export "trap-calling-stream-drop-readable") (alias export $d "trap-calling-stream-drop-readable")) |
| 186 | + (func (export "trap-calling-stream-drop-writable") (alias export $d "trap-calling-stream-drop-writable")) |
| 187 | + (func (export "trap-calling-future-new") (alias export $d "trap-calling-future-new")) |
| 188 | + (func (export "trap-calling-future-read") (alias export $d "trap-calling-future-read")) |
| 189 | + (func (export "trap-calling-future-write") (alias export $d "trap-calling-future-write")) |
| 190 | + (func (export "trap-calling-future-cancel-read") (alias export $d "trap-calling-future-cancel-read")) |
| 191 | + (func (export "trap-calling-future-cancel-write") (alias export $d "trap-calling-future-cancel-write")) |
| 192 | + (func (export "trap-calling-future-drop-readable") (alias export $d "trap-calling-future-drop-readable")) |
| 193 | + (func (export "trap-calling-future-drop-writable") (alias export $d "trap-calling-future-drop-writable")) |
| 194 | +) |
| 195 | + |
| 196 | +(component instance $i1 $Tester) |
| 197 | +(assert_trap (invoke "trap-calling-import") "cannot leave component instance") |
| 198 | +(component instance $i2 $Tester) |
| 199 | +(assert_trap (invoke "trap-calling-resource-new") "cannot leave component instance") |
| 200 | +(component instance $i3 $Tester) |
| 201 | +(assert_trap (invoke "trap-calling-resource-drop") "cannot leave component instance") |
| 202 | +(component instance $i4 $Tester) |
| 203 | +(assert_trap (invoke "trap-calling-task-return") "cannot leave component instance") |
| 204 | +(component instance $i5 $Tester) |
| 205 | +(assert_trap (invoke "trap-calling-task-cancel") "cannot leave component instance") |
| 206 | +(component instance $i6 $Tester) |
| 207 | +(assert_trap (invoke "trap-calling-yield") "cannot leave component instance") |
| 208 | +(component instance $i7 $Tester) |
| 209 | +(assert_trap (invoke "trap-calling-waitable-set-new") "cannot leave component instance") |
| 210 | +(component instance $i8 $Tester) |
| 211 | +(assert_trap (invoke "trap-calling-waitable-set-wait") "cannot leave component instance") |
| 212 | +(component instance $i9 $Tester) |
| 213 | +(assert_trap (invoke "trap-calling-waitable-set-poll") "cannot leave component instance") |
| 214 | +(component instance $i10 $Tester) |
| 215 | +(assert_trap (invoke "trap-calling-waitable-set-drop") "cannot leave component instance") |
| 216 | +(component instance $i11 $Tester) |
| 217 | +(assert_trap (invoke "trap-calling-waitable-join") "cannot leave component instance") |
| 218 | +(component instance $i12 $Tester) |
| 219 | +(assert_trap (invoke "trap-calling-subtask-cancel") "cannot leave component instance") |
| 220 | +(component instance $i13 $Tester) |
| 221 | +(assert_trap (invoke "trap-calling-subtask-drop") "cannot leave component instance") |
| 222 | +(component instance $i14 $Tester) |
| 223 | +(assert_trap (invoke "trap-calling-stream-new") "cannot leave component instance") |
| 224 | +(component instance $i15 $Tester) |
| 225 | +(assert_trap (invoke "trap-calling-stream-read") "cannot leave component instance") |
| 226 | +(component instance $i16 $Tester) |
| 227 | +(assert_trap (invoke "trap-calling-stream-write") "cannot leave component instance") |
| 228 | +(component instance $i17 $Tester) |
| 229 | +(assert_trap (invoke "trap-calling-stream-cancel-read") "cannot leave component instance") |
| 230 | +(component instance $i18 $Tester) |
| 231 | +(assert_trap (invoke "trap-calling-stream-cancel-write") "cannot leave component instance") |
| 232 | +(component instance $i19 $Tester) |
| 233 | +(assert_trap (invoke "trap-calling-stream-drop-readable") "cannot leave component instance") |
| 234 | +(component instance $i20 $Tester) |
| 235 | +(assert_trap (invoke "trap-calling-stream-drop-writable") "cannot leave component instance") |
| 236 | +(component instance $i21 $Tester) |
| 237 | +(assert_trap (invoke "trap-calling-future-new") "cannot leave component instance") |
| 238 | +(component instance $i22 $Tester) |
| 239 | +(assert_trap (invoke "trap-calling-future-read") "cannot leave component instance") |
| 240 | +(component instance $i23 $Tester) |
| 241 | +(assert_trap (invoke "trap-calling-future-write") "cannot leave component instance") |
| 242 | +(component instance $i24 $Tester) |
| 243 | +(assert_trap (invoke "trap-calling-future-cancel-read") "cannot leave component instance") |
| 244 | +(component instance $i25 $Tester) |
| 245 | +(assert_trap (invoke "trap-calling-future-cancel-write") "cannot leave component instance") |
| 246 | +(component instance $i26 $Tester) |
| 247 | +(assert_trap (invoke "trap-calling-future-drop-readable") "cannot leave component instance") |
| 248 | +(component instance $i27 $Tester) |
| 249 | +(assert_trap (invoke "trap-calling-future-drop-writable") "cannot leave component instance") |
0 commit comments