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/gc/MVP.md
+38-14Lines changed: 38 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ Based on [reference types proposal](https://github.com/WebAssembly/reference-typ
28
28
*`i31ref` is a new reference type
29
29
-`reftype ::= ... | i31ref`
30
30
31
-
*`rtt <typeuse>` is a new reference type that is a runtime representation of type `<typeuse>` (see [overview](Overview.md#casting-and-runtime-types))
31
+
*`rtt <typeuse>` is a new reference type that is a runtime representation of type `<typeuse>` (see [Runtime types](#runtime-types))
32
32
-`reftype ::= ... | rtt <typeuse>`
33
33
-`rtt t ok` iff `t ok`
34
34
@@ -159,12 +159,35 @@ In addition to the rules for basic reference types:
159
159
* Table definitions with non-zero minimum size must have an element type that is defaultable. (Imports are not affected.)
160
160
161
161
162
-
### Values
162
+
### Runtime
163
163
164
-
* Each reference value has an associated *runtime type*, which is a runtime description of its type:
165
-
- For structures or arrays, it is determined by an [RTT](#runtime-types) value provided upon creation, or `anyref` if none.
166
-
- For `i31ref` references it is `i31ref`.
167
-
- For `null` it is `nullref`.
164
+
#### Runtime Types
165
+
166
+
* Runtime types (RTTs) are explicit values representing types at runtime; a value of type `rtt <t>` is a dynamic representative of static type `<t>`.
167
+
168
+
* All RTTs are explicitly created and all operations involving dynamic type information (like casts) operate on explicit RTT operands.
169
+
170
+
* There is a runtime subtyping hierarchy on RTTs; creating an RTT requires providing a *parent type* in the form of an existing RTT; the RTT for `anyref` is the root of this hierarchy.
171
+
172
+
* An RTT t1 is a *sub-RTT* of another RTT t2 iff either of the following holds:
173
+
- t1 and t2 represent the same static type, or
174
+
- t1 has a parent that is a sub-RTT of t2.
175
+
176
+
* Validation requires that each parent type is a representative of a static supertype of its child; runtime subtyping hence is a sub-relation of static subtyping (a graph with fewer nodes and edges).
177
+
178
+
* At the same time, runtime subtyping forms a linear hierarchy such that the relation can be checked efficiently using standard implementation techniques (it is a tree-shaped graph).
179
+
180
+
181
+
#### Values
182
+
183
+
* Creating a structure or array optionally allows supplying a suitable RTT to represent its runtime type; it defaults to `anyref` if none is given.
184
+
185
+
* Each reference value has an associated runtime type:
186
+
- For structures or arrays, it is the RTT provided upon creation, or `anyref` if none.
187
+
- For `i31ref` references it is the RTT for `i31ref`.
188
+
- For `null` it is the RTT for `nullref`.
189
+
190
+
* The so-defined runtime type is the only type information that can be discovered about a reference value at runtime; a structure or array with RTT `anyref` thereby is fully opaque to runtime type checks (and an implementation may choose to optimize away its RTT).
168
191
169
192
170
193
### Instructions
@@ -265,7 +288,7 @@ Perhaps also the following short-hands:
265
288
- traps on `null`
266
289
267
290
268
-
#### Integer references
291
+
#### Integer References
269
292
270
293
Tentatively, support a type of guaranteed unboxed scalars.
271
294
@@ -290,7 +313,7 @@ Perhaps also the following short-hands:
290
313
- equivalent to `(rtt.i31ref) (ref.cast anyref i31ref)`
291
314
292
315
293
-
#### Optional references
316
+
#### Optional References
294
317
295
318
*`ref.as_nonnull` converts an optional reference to a non-optional one
296
319
-`ref.as_nonnull : [(optref $t)] -> [(ref $t)]`
@@ -307,33 +330,34 @@ Perhaps also the following short-hands:
307
330
308
331
#### Runtime Types
309
332
310
-
*`rtt.anyref` returns the RTT of type `anyref` as a subtype of only itself
333
+
*`rtt.anyref` returns the RTT of type `anyref` as a sub-RTT of only itself
311
334
-`rtt.anyref : [] -> [(rtt anyref)]`
312
335
313
-
*`rtt.new <typeuse> <typeuse>` returns the RTT of the specified type as a subtype of a given RTT operand
336
+
*`rtt.new <typeuse> <typeuse>` returns the RTT of the specified type as a sub-RTT of a given parent RTT operand
314
337
-`rtt.new t t' : [(rtt t')] -> [(rtt t)]`
315
338
- iff `t <: t'`
316
-
- multiple invocations of this instruction with the same operand yield the same RTTs
339
+
- multiple invocations of this instruction with the same operand yield the same observable RTTs
317
340
318
341
* All RTT instructions are considered *constant expressions*.
319
342
320
343
321
344
#### Casts
322
345
323
-
*`ref.test <typeuse> <typeuse>` tests whether a reference value's [runtime type](#values)matches a type given by a RTT representation
346
+
*`ref.test <typeuse> <typeuse>` tests whether a reference value's [runtime type](#values)is a [runtime subtype](#runtime) of a given RTT
324
347
-`ref.test t t' : [t (rtt t')] -> [i32]`
325
348
- iff `t' <: t <: anyref`
326
-
- returns 1 if the operand's runtime type is defined to be a (transitive) subtype of `t`, 0 otherwise
349
+
- returns 1 if the first operand's runtime type is a sub-RTT of the RTT operand, 0 otherwise
327
350
328
351
*`ref.cast <typeuse> <typeuse>` casts a reference value down to a type given by a RTT representation
329
352
-`ref.cast t t' : [t (rtt t')] -> [t']`
330
353
- iff `t' <: t <: anyref`
331
-
- traps if the operand's runtime type is not defined to be a (transitive) subtype of `t`
354
+
- traps if the first operand's runtime type is not a sub-RTT of the RTT operand
332
355
333
356
*`br_on_cast <labelidx> <typeuse> <typeuse>` branches if a value can be cast down to a given reference type
334
357
-`br_on_cast $l t t' : [t (rtt t')] -> [t]`
335
358
- iff `t' <: t <: anyref`
336
359
- and `$l : [t']`
360
+
- branches iff the first operand's runtime type is a sub-RTT of the RTT operand
0 commit comments