Skip to content

Commit 38cad33

Browse files
authored
Updated validation rules for struct.new (#17)
Explicitly spell out the types of `struct.new` and `struct.new_default` when there is a custom descriptor involved. Make the custom descriptor the last operand for consistency with all GC accessor instructions (and e.g. `call_indirect`), where the operand determined by (or determining) the type immediate always comes last.
1 parent a7c2481 commit 38cad33

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

proposals/custom-descriptors/Overview.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,27 @@ As a general rule, non-nullable exact references to abstract heap types are unin
305305

306306
When allocating types with custom descriptors,
307307
`struct.new` and `struct.new_default` take exact references to the descriptors
308-
as their first operands.
308+
as their last operands.
309309
This makes the unsound program above invalid.
310310

311-
> TODO: Provide new validation rules for `struct.new` and `struct.new_default`.
311+
```
312+
struct.new x
313+
C |- struct.new x : t* (ref null exact y) -> (ref exact x)
314+
-- C.types[x] ~ descriptor y (struct (field t)*)
315+
```
316+
317+
```
318+
struct.new_default x
319+
C |- struct.new_default x : (ref null exact y) -> (ref exact x)
320+
-- C.types[x] ~ descriptor y (struct (field t)*)
321+
-- defaultable(t)*
322+
```
323+
324+
> Note: The descriptors could alternatively be the first operands.
325+
> They are chosen to be the last operands here because in a hypothetical future
326+
> where we have variants of these instructions that do not take type immediates,
327+
> the descriptors would have to be on top of the stack to determine the type of
328+
> the allocation. This is consistent with GC accessor instructions.
312329
313330
## New Instructions
314331

0 commit comments

Comments
 (0)