@@ -357,6 +357,7 @@ core:deftype ::= <core:functype> (WebAssembly 1.0)
357
357
core:moduletype ::= (module <core:moduledecl>*)
358
358
core:moduledecl ::= <core:importdecl>
359
359
| <core:type>
360
+ | <core:alias>
360
361
| <core:exportdecl>
361
362
core:importdecl ::= (import <name> <name> <core:importdesc>)
362
363
core:exportdecl ::= (export <name> <core:exportdesc>)
@@ -387,7 +388,7 @@ type imports local to the module type itself. For example, in the future, the
387
388
following module type would be expressible:
388
389
```
389
390
(component $C
390
- (type $M (module
391
+ (core type $M (module
391
392
(import "" "T" (type $T))
392
393
(type $PairT (struct (field (ref $T)) (field (ref $T))))
393
394
(export "make_pair" (func (param (ref $T)) (result (ref $PairT))))
@@ -398,6 +399,36 @@ In this example, `$M` has a distinct type index space from `$C`, where element
398
399
0 is the imported type, element 1 is the ` struct ` type, and element 2 is an
399
400
implicitly-created ` func ` type referring to both.
400
401
402
+ Lastly, the ` core:alias ` module declarator allows a module type definition to
403
+ reuse (rather than redefine) type definitions in the enclosing component's core
404
+ type index space via ` outer ` ` type ` alias. In the MVP, validation restricts
405
+ ` core:alias ` module declarators to * only* allow ` outer ` ` type ` aliases but,
406
+ in the future, more kinds of aliases would be meaningful and allowed.
407
+
408
+ As an example, the following component defines two semantically-equivalent
409
+ module types, where the former defines the function type via ` type ` declarator
410
+ and the latter refers via ` alias ` declarator. Note that, since core type
411
+ definitions are validated in a Core WebAssembly context that doesn't "know"
412
+ anything about components, the module type ` $C2 ` can't name ` $C ` directly in
413
+ the text format but must instead use the appropriate [ de Bruijn] index (` 1 ` ).
414
+ In both cases, the defined/aliased function type is given index ` 0 ` since
415
+ module types always start with an empty type index space.
416
+ ``` wasm
417
+ (component $C
418
+ (core type $C1 (module
419
+ (type (func (param i32) (result i32)))
420
+ (import "a" (func (type 0)))
421
+ (export "b" (func (type 0)))
422
+ ))
423
+ (core type $F (func (param i32) (result i32)))
424
+ (core type $C2 (module
425
+ (alias outer 1 $F (type))
426
+ (import "a" (func (type 0)))
427
+ (export "b" (func (type 0)))
428
+ ))
429
+ )
430
+ ```
431
+
401
432
Component-level type definitions are symmetric to core-level type definitions,
402
433
but use a completely different set of value types. Unlike [ ` core:valtype ` ]
403
434
which is low-level and assumes a shared linear memory for communicating
@@ -542,28 +573,6 @@ When [resource and handle types] are added to the explainer, `typebound` will
542
573
be extended with a ` sub ` option (symmetric to the [ type-imports] proposal) that
543
574
allows importing and exporting * abstract* types.
544
575
545
- Lastly, component and instance types also include an ` alias ` declarator for
546
- projecting the exports out of imported instances and sharing types with outer
547
- components. As an example, the following component defines two equivalent
548
- component types, where the former defines the function type via ` type `
549
- declarator and the latter via ` alias ` declarator. In both cases, the type is
550
- given index ` 0 ` since component types start with an empty type index space.
551
- ``` wasm
552
- (component $C
553
- (type $C1 (component
554
- (type (func (param string) (result string)))
555
- (import "a" (func (type 0)))
556
- (export "b" (func (type 0)))
557
- ))
558
- (type $F (func (param string) (result string)))
559
- (type $C2 (component
560
- (alias outer $C $F (type))
561
- (import "a" (func (type 0)))
562
- (export "b" (func (type 0)))
563
- ))
564
- )
565
- ```
566
-
567
576
With what's defined so far, we can define component types using a mix of inline
568
577
and out-of-line type definitions:
569
578
``` wasm
0 commit comments