1;;! component_model_async = true
2
3;; backpressure.inc
4(component
5  (core module $m
6    (import "" "backpressure.inc" (func $backpressure-inc))
7  )
8  (core func $backpressure-inc (canon backpressure.inc))
9  (core instance $i (instantiate $m (with "" (instance (export "backpressure.inc" (func $backpressure-inc))))))
10)
11
12;; backpressure.dec
13(component
14  (core module $m
15    (import "" "backpressure.dec" (func $backpressure-dec))
16  )
17  (core func $backpressure-dec (canon backpressure.dec))
18  (core instance $i (instantiate $m (with "" (instance (export "backpressure.dec" (func $backpressure-dec))))))
19)
20
21;; task.return
22(component
23  (core module $m
24    (import "" "task.return" (func $task-return (param i32)))
25  )
26  (core func $task-return (canon task.return (result u32)))
27  (core instance $i (instantiate $m (with "" (instance (export "task.return" (func $task-return))))))
28)
29
30;; waitable-set.wait
31(component
32  (core module $libc (memory (export "memory") 1))
33  (core instance $libc (instantiate $libc))
34  (core module $m
35    (import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
36  )
37  (core func $waitable-set-wait (canon waitable-set.wait (memory $libc "memory")))
38  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
39)
40
41;; waitable-set.poll
42(component
43  (core module $libc (memory (export "memory") 1))
44  (core instance $libc (instantiate $libc))
45  (core module $m
46    (import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
47  )
48  (core func $waitable-set-poll (canon waitable-set.poll (memory $libc "memory")))
49  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
50)
51
52;; thread.yield
53(component
54  (core module $m
55    (import "" "thread.yield" (func $thread-yield (result i32)))
56  )
57  (core func $thread-yield (canon thread.yield))
58  (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread-yield))))))
59)
60
61;; subtask.drop
62(component
63  (core module $m
64    (import "" "subtask.drop" (func $subtask-drop (param i32)))
65  )
66  (core func $subtask-drop (canon subtask.drop))
67  (core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
68)
69
70;; subtask.cancel
71(component
72  (core module $m
73    (import "" "subtask.cancel" (func $subtask-drop (param i32) (result i32)))
74  )
75  (core func $subtask-cancel (canon subtask.cancel))
76  (core instance $i (instantiate $m (with "" (instance (export "subtask.cancel" (func $subtask-cancel))))))
77)
78
79;; Test that some intrinsics are exempt from may-leave checks
80(component
81  (core func $backpressure.inc (canon backpressure.inc))
82  (core func $backpressure.dec (canon backpressure.dec))
83  (core func $context.get (canon context.get i32 0))
84  (core func $context.set (canon context.set i32 0))
85
86  (core module $DM
87    (import "" "backpressure.inc" (func $backpressure.inc))
88    (import "" "backpressure.dec" (func $backpressure.dec))
89    (import "" "context.get" (func $context.get (result i32)))
90    (import "" "context.set" (func $context.set (param i32)))
91
92    (global $g (mut i32) (i32.const 0))
93
94    (func (export "run")
95      (call $context.set (i32.const 100))
96    )
97    (func (export "post-return")
98      call $backpressure.inc
99      call $backpressure.dec
100
101      ;; context.get should be what was set in `run`
102      call $context.get
103      i32.const 100
104      i32.ne
105      if unreachable end
106
107      i32.const 32
108      call $context.set
109    )
110  )
111  (core instance $dm (instantiate $DM (with "" (instance
112    (export "backpressure.inc" (func $backpressure.inc))
113    (export "backpressure.dec" (func $backpressure.dec))
114    (export "context.get" (func $context.get))
115    (export "context.set" (func $context.set))
116  ))))
117  (func (export "run")
118    (canon lift (core func $dm "run") (post-return (func $dm "post-return"))))
119)
120
121(assert_return (invoke "run"))
122