@@ -345,19 +345,38 @@ In the case of `export` aliases, validation ensures `name` is an export in the
345345target instance and has a matching sort.
346346
347347In 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
354355Components containing outer aliases effectively produce a [ closure] at
355356instantiation 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
362381Both kinds of aliases come with syntactic sugar for implicitly declaring them
363382inline:
0 commit comments