Skip to content

Commit 0da2807

Browse files
committed
Fix Explainer.md/Binary.md definition of outer aliases
1 parent a0a9398 commit 0da2807

2 files changed

Lines changed: 37 additions & 16 deletions

File tree

design/mvp/Binary.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ Notes:
126126
* For `export` aliases, `i` is validated to refer to an instance in the
127127
instance index space that exports `n` with the specified `sort`.
128128
* For `outer` aliases, `ct` is validated to be *less or equal than* the number
129-
of enclosing components and `i` is validated to be a valid
130-
index in the `sort` index space of the `i`th enclosing component (counting
131-
outward, starting with `0` referring to the current component).
132-
* For `outer` aliases, validation restricts the `sort` to one
133-
of `type`, `module` or `component` and additionally requires that the
134-
outer-aliased type is not a `resource` type (which is generative).
129+
of enclosing `component`s and `type`s and `i` is validated to be a valid index
130+
in the `sort` index space of the targeted `component`/`type` (counting
131+
outward, starting with `0` referring to the current `component`/`type`).
132+
* For `outer` aliases, validation restricts the `sort` to one of `type`,
133+
`module` or `component`.
134+
* For `outer` aliases that reach across a `component` boundary (as opposed to
135+
a `type` boundary), validation additionally requires that any outer-aliased
136+
`type` is not a `resource` type.
135137

136138

137139
## Type Definitions

design/mvp/Explainer.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,38 @@ In the case of `export` aliases, validation ensures `name` is an export in the
345345
target instance and has a matching sort.
346346

347347
In the case of `outer` aliases, the `u32` pair serves as a [de Bruijn
348-
index], with first `u32` being the number of enclosing components/modules to
349-
skip and the second `u32` being an index into the target's sort's index space.
350-
In particular, the first `u32` can be `0`, in which case the outer alias refers
351-
to the current component. To maintain the acyclicity of module instantiation,
352-
outer aliases are only allowed to refer to *preceding* outer definitions.
348+
index], with first `u32` being the number of enclosing `component`s or `type`s
349+
to skip and the second `u32` being an index into the target's sort's index
350+
space. In particular, the first `u32` can be `0`, in which case the outer alias
351+
refers to the current `component`/`type`. To maintain the acyclicity of module
352+
instantiation, outer aliases are only allowed to refer to *preceding* outer
353+
definitions.
353354

354355
Components containing outer aliases effectively produce a [closure] at
355356
instantiation time, including a copy of the outer-aliased definitions. Because
356-
of the prevalent assumption that components are immutable values, outer aliases
357-
are restricted to only refer to immutable definitions: non-resource types,
358-
modules and components. (In the future, outer aliases to all sorts of
359-
definitions could be allowed by recording the statefulness of the resulting
360-
component in its type via some kind of "`stateful`" type attribute.)
357+
components, like modules, are pure values, outer aliases that reach across
358+
`component` boundaries are restricted to only refer to pure definitions:
359+
non-resource types, modules and components. (As described in the next section,
360+
resource types are *generative* and thus not pure.) For example, in the
361+
following component, `$alias{1,2,3,4}` are allowed (b/c they only reach across a
362+
`type` boundary) while `$alias5` is disallowed (b/c it reaches across a
363+
`component` boundary to reach a `resource` type).
364+
```wat
365+
(component $C
366+
(component $D)
367+
(type $T (record (field "x" u32) (field "y" u32)))
368+
(type $R (resource (rep i32)))
369+
(type (component
370+
(alias outer $C $T (type $alias1))
371+
(alias outer $C $R (type $alias2))
372+
))
373+
(component
374+
(alias outer $C $D (component $alias3))
375+
(alias outer $C $T (type $alias4))
376+
;; (alias outer $C $R (type $alias5) ❌
377+
)
378+
)
379+
```
361380

362381
Both kinds of aliases come with syntactic sugar for implicitly declaring them
363382
inline:

0 commit comments

Comments
 (0)