You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: proposals/bag-o-stacks/Explainer.md
+10-22
Original file line number
Diff line number
Diff line change
@@ -114,36 +114,24 @@ In order for a switch between coroutines to be valid, the type of the target sta
114
114
115
115
Given this, we can statically verify that WebAssembly programs that switch between coroutines are guaranteed to observe type safety during the switch.
116
116
117
-
#### Subtype relations between `stack` types
117
+
#### Subtyping
118
118
119
-
Like function types, two stack types
119
+
Like function types, stack types are contravariant in their parameters.
120
120
121
-
```wasm
122
-
(stack (param P1*) (ref $c1))
123
-
```
124
-
125
-
and
126
-
127
-
```wasm
128
-
(stack (param P2*) (ref $c2))
121
+
```pseudo
122
+
C |- stack t_1* rt_1 <: stack t_2* rt_2
123
+
-- C |- t_2* rt_2 <: t_1* rt_1
129
124
```
130
125
131
-
are in a subtype relationship if the `P1*` vector is a vector subtype of `P2*` and the type referenced in `$c2` is a subtype of $c1. I.e., covariant in the result types but contravariant in the parameter types. This is directly analogous to function subtyping.
126
+
`stack t_1 rt_1` is a subtype of `stack t_2* rt_2` iff:
127
+
-`t_2* rt_2` is a subtype of `t_1* rt_1`.
132
128
133
-
The top type for stack references is simply:
129
+
The top type for stack references is `stack` and the bottom type is `nostack`. Like other bottom types, the nostack type is uninhabited.
134
130
135
-
```wasm
136
-
stack
137
-
```
138
-
139
-
and the bottom type is `nostack` which results in a new extension to the heap type hierarchy:
140
-
141
-
```wasm
142
-
heaptype ::= ... | stack | nostack
131
+
```pseudo
132
+
absheaptype ::= ... | stack | nostack
143
133
```
144
134
145
-
Like other bottom types, the nostack type is uninhabited.
146
-
147
135
### Life-cycle of a coroutine
148
136
149
137
A coroutine is started using the `stack.new_switch` instruction. This performs the equivalent of a function call – on a new stack resource. In addition to the arguments normally expected in a function call, an additional argument is provided that is a stack reference to the caller code -- the caller is suspended as a result of the `stack.new_switch` instruction.
0 commit comments