@@ -53,7 +53,6 @@ At the top-level, a `component` is a sequence of definitions of various kinds:
53
53
component ::= (component <id>? <definition>*)
54
54
definition ::= core-prefix(<core:module>)
55
55
| core-prefix(<core:instance>)
56
- | core-prefix(<core:alias>)
57
56
| core-prefix(<core:type>)
58
57
| <component>
59
58
| <instance>
@@ -221,23 +220,17 @@ and export component functions.
221
220
222
221
Alias definitions project definitions out of other components' index spaces and
223
222
into the current component's index spaces. As represented in the AST below,
224
- there are two kinds of "targets" for an alias: the ` export ` of an instance and
225
- a definition in an index space of an ` outer ` component (containing the current
226
- component):
223
+ there are three kinds of "targets" for an alias: the ` export ` of a component
224
+ instance, the ` core export ` of a core module instance and a definition of an
225
+ ` outer ` component (containing the current component):
227
226
```
228
- core:alias ::= (alias <core:aliastarget> (<core:sort> <id>?))
229
- core:aliastarget ::= export <core:instanceidx> <name>
230
- | outer <u32> <u32>
231
-
232
227
alias ::= (alias <aliastarget> (<sort> <id>?))
233
228
aliastarget ::= export <instanceidx> <name>
229
+ | core export <core:instanceidx> <name>
234
230
| outer <u32> <u32>
235
231
```
236
- The ` core:sort ` /` sort ` immediate of the alias specifies which index space in
237
- the target component is being read from and which index space of the containing
238
- component is being added to. If present, the ` id ` of the alias is bound to the
239
- new index added by the alias and can be used anywhere a normal ` id ` can be
240
- used.
232
+ If present, the ` id ` of the alias is bound to the new index added by the alias
233
+ and can be used anywhere a normal ` id ` can be used.
241
234
242
235
In the case of ` export ` aliases, validation ensures ` name ` is an export in the
243
236
target instance and has a matching sort.
@@ -249,14 +242,6 @@ In particular, the first `u32` can be `0`, in which case the outer alias refers
249
242
to the current component. To maintain the acyclicity of module instantiation,
250
243
outer aliases are only allowed to refer to * preceding* outer definitions.
251
244
252
- As with other core definitions, core aliases are only supposed to "see" other
253
- core definitions (as-if they were defined by Core WebAssembly extended with
254
- [ module-linking] ). Thus, core ` outer ` aliases must have a skip-count of ` 0 `
255
- when defined within a component, only allowing them to duplicate core
256
- definitions in core index spaces. (Core ` outer ` aliases have a second use
257
- described in the next section, which is why they are included in the grammar
258
- at all.)
259
-
260
245
Components containing outer aliases effectively produce a [ closure] at
261
246
instantiation time, including a copy of the outer-aliased definitions. Because
262
247
of the prevalent assumption that components are immutable values, outer aliases
@@ -268,10 +253,18 @@ via some kind of "`stateful`" type attribute.)
268
253
Both kinds of aliases come with syntactic sugar for implicitly declaring them
269
254
inline:
270
255
271
- For ` export ` aliases, the inline sugar has the form ` (<sort> <instanceidx> <name>+) `
272
- and can be used in place of a ` sortidx ` or any sort-specific index (such as a
273
- ` typeidx ` or ` funcidx ` ). For example, the following snippet uses two inline
274
- function aliases:
256
+ For ` export ` aliases, the inline sugar extends the definition of ` sortidx `
257
+ and the various sort-specific indices:
258
+ ```
259
+ sortidx ::= (<sort> <u32>) ;; as above
260
+ | <inlinealias>
261
+ Xidx ::= <u32> ;; as above
262
+ | <inlinealias>
263
+ inlinealias ::= (<sort> <u32> <name>+)
264
+ ```
265
+ If ` <sort> ` refers to a ` <core:sort> ` , then the ` <u32> ` of ` inlinealias ` is a
266
+ ` <core:instanceidx> ` ; otherwise it's an ` <instanceidx> ` . For example, the
267
+ following snippet uses two inline function aliases:
275
268
``` wasm
276
269
(instance $j (instantiate $J (with "f" (func $i "f"))))
277
270
(export "x" (func $j "g" "h"))
@@ -310,9 +303,10 @@ is desugared into:
310
303
Lastly, for symmetry with [ imports] [ func-import-abbrev ] , aliases can be written
311
304
in an inverted form that puts the sort first:
312
305
``` wasm
313
- (func $f (import "i" "f") ...type...) ≡ (import "i" "f" (func $f ...type...)) (WebAssembly 1.0)
314
- (func $g (alias export $i "g1")) ≡ (alias export $i "g1" (func $g))
315
- (core func $g (alias export $i "g1")) ≡ (core alias export $i "g1" (func $g))
306
+ (func $f (import "i" "f") ...type...) ≡ (import "i" "f" (func $f ...type...)) (WebAssembly 1.0)
307
+ (func $f (alias export $i "f")) ≡ (alias export $i "f" (func $f))
308
+ (core module $m (alias export $i "m")) ≡ (alias export $i "m" (core module $m))
309
+ (core func $f (alias core export $i "f")) ≡ (alias core export $i "f" (core func $f))
316
310
```
317
311
318
312
With what's defined so far, we're able to link modules with arbitrary renamings:
@@ -328,17 +322,17 @@ With what's defined so far, we're able to link modules with arbitrary renamings:
328
322
)
329
323
(core instance $a (instantiate $A))
330
324
(core instance $b1 (instantiate $B
331
- (with "a" (instance $a)) ;; no renaming
325
+ (with "a" (instance $a)) ;; no renaming
332
326
))
333
- (core func $a_two (alias export $a "two")) ;; ≡ (core alias export $a "two" (func $a_two))
327
+ (core func $a_two (alias core export $a "two") ;; ≡ (alias core export $a "two" (core func $a_two))
334
328
(core instance $b2 (instantiate $B
335
329
(with "a" (instance
336
- (export "one" (func $a_two)) ;; renaming, using out-of-line alias
330
+ (export "one" (func $a_two)) ;; renaming, using out-of-line alias
337
331
))
338
332
))
339
333
(core instance $b3 (instantiate $B
340
334
(with "a" (instance
341
- (export "one" (func $a "three")) ;; renaming, using inline alias sugar
335
+ (export "one" (func $a "three")) ;; renaming, using <inlinealias>
342
336
))
343
337
))
344
338
)
@@ -352,19 +346,21 @@ type and function definitions which are introduced in the next two sections.
352
346
The syntax for defining core types extends the existing core type definition
353
347
syntax, adding a ` module ` type constructor:
354
348
```
355
- core:type ::= (type <id>? <core:deftype>) (GC proposal)
356
- core:deftype ::= <core:functype> (WebAssembly 1.0)
357
- | <core:structtype> (GC proposal)
358
- | <core:arraytype> (GC proposal)
359
- | <core:moduletype>
360
- core:moduletype ::= (module <core:moduledecl>*)
361
- core:moduledecl ::= <core:importdecl>
362
- | <core:type>
363
- | <core:alias>
364
- | <core:exportdecl>
365
- core:importdecl ::= (import <name> <name> <core:importdesc>)
366
- core:exportdecl ::= (export <name> <core:exportdesc>)
367
- core:exportdesc ::= strip-id(<core:importdesc>)
349
+ core:type ::= (type <id>? <core:deftype>) (GC proposal)
350
+ core:deftype ::= <core:functype> (WebAssembly 1.0)
351
+ | <core:structtype> (GC proposal)
352
+ | <core:arraytype> (GC proposal)
353
+ | <core:moduletype>
354
+ core:moduletype ::= (module <core:moduledecl>*)
355
+ core:moduledecl ::= <core:importdecl>
356
+ | <core:type>
357
+ | <core:alias>
358
+ | <core:exportdecl>
359
+ core:alias ::= (alias <core:aliastarget> (<core:sort> <id>?))
360
+ core:aliastarget ::= outer <u32> <u32>
361
+ core:importdecl ::= (import <name> <name> <core:importdesc>)
362
+ core:exportdecl ::= (export <name> <core:exportdesc>)
363
+ core:exportdesc ::= strip-id(<core:importdesc>)
368
364
369
365
where strip-id(X) parses '(' sort Y ')' when X parses '(' sort <id>? Y ')'
370
366
```
0 commit comments