Skip to content

Commit b7c4bcf

Browse files
authored
[BoS] Fix description of subtyping (#54)
Stack types are contravariant in all their parameters, including the return stack reference.
1 parent f749c3f commit b7c4bcf

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

proposals/bag-o-stacks/Explainer.md

+10-22
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,24 @@ In order for a switch between coroutines to be valid, the type of the target sta
114114

115115
Given this, we can statically verify that WebAssembly programs that switch between coroutines are guaranteed to observe type safety during the switch.
116116

117-
#### Subtype relations between `stack` types
117+
#### Subtyping
118118

119-
Like function types, two stack types
119+
Like function types, stack types are contravariant in their parameters.
120120

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
129124
```
130125

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`.
132128

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.
134130

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
143133
```
144134

145-
Like other bottom types, the nostack type is uninhabited.
146-
147135
### Life-cycle of a coroutine
148136

149137
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

Comments
 (0)