Skip to content

Commit 00b5d7a

Browse files
committed
Remove component-level core aliases
Resolves #89
1 parent 6d5d8c0 commit 00b5d7a

File tree

2 files changed

+72
-80
lines changed

2 files changed

+72
-80
lines changed

design/mvp/Binary.md

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ layer ::= 0x01 0x00
2525
section ::= section_0(<core:custom>) => ϵ
2626
| m*:section_1(<core:module>) => [core-prefix(m)]
2727
| i*:section_2(vec(<core:instance>)) => core-prefix(i)*
28-
| a*:section_3(vec(<core:alias>)) => core-prefix(a)*
29-
| t*:section_4(vec(<core:type>)) => core-prefix(t)*
30-
| c: section_5(<component>) => [c]
31-
| i*:section_6(vec(<instance>)) => i*
32-
| a*:section_7(vec(<alias>)) => a*
33-
| t*:section_8(vec(<type>)) => t*
34-
| c*:section_9(vec(<canon>)) => c*
35-
| s: section_10(<start>) => [s]
36-
| i*:section_11(vec(<import>)) => i*
37-
| e*:section_12(vec(<export>)) => e*
28+
| t*:section_3(vec(<core:type>)) => core-prefix(t)*
29+
| c: section_4(<component>) => [c]
30+
| i*:section_5(vec(<instance>)) => i*
31+
| a*:section_6(vec(<alias>)) => a*
32+
| t*:section_7(vec(<type>)) => t*
33+
| c*:section_8(vec(<canon>)) => c*
34+
| s: section_9(<start>) => [s]
35+
| i*:section_10(vec(<import>)) => i*
36+
| e*:section_11(vec(<export>)) => e*
3837
```
3938
Notes:
4039
* Reused Core binary rules: [`core:section`], [`core:custom`], [`core:module`]
@@ -100,13 +99,10 @@ Notes:
10099

101100
(See [Alias Definitions](Explainer.md#alias-definitions) in the explainer.)
102101
```
103-
core:alias ::= sort:<core:sort> target:<core:aliastarget> => (core alias target (sort))
104-
core:aliastarget ::= 0x00 i:<core:instanceidx> n:<name> => export i n
105-
| 0x01 ct:<u32> idx:<u32> => outer ct idx
106-
107-
alias ::= sort:<sort> target:<aliastarget> => (alias target (sort))
108-
aliastarget ::= 0x00 i:<instanceidx> n:<name> => export i n
109-
| 0x01 ct:<u32> idx:<u32> => outer ct idx
102+
alias ::= s:<sort> t:<aliastarget> => (alias t (s))
103+
aliastarget ::= 0x00 i:<instanceidx> n:<name> => export i n
104+
| 0x01 i:<core:instanceidx> n:<name> => core export i n
105+
| 0x02 ct:<u32> idx:<u32> => outer ct idx
110106
```
111107
Notes:
112108
* Reused Core binary rules: (variable-length encoded) [`core:u32`]
@@ -116,38 +112,38 @@ Notes:
116112
of enclosing components and `i` is validated to be a valid
117113
index in the `sort` index space of the `i`th enclosing component (counting
118114
outward, starting with `0` referring to the current component).
119-
* For `outer` aliases of `core:aliastarget`, validation restricts the `sort` to
120-
`type` and `ct` must be `0` (for a component-level definition; see also the
121-
`core:alias` case of `core:moduledecl` below).
122-
* For `outer` aliases of `aliastarget`, validation restricts the `sort` to one
115+
* For `outer` aliases, validation restricts the `sort` to one
123116
of `type`, `module` or `component`.
124117

125118

126119
## Type Definitions
127120

128121
(See [Type Definitions](Explainer.md#type-definitions) in the explainer.)
129122
```
130-
core:type ::= dt:<core:deftype> => (type dt) (GC proposal)
131-
core:deftype ::= ft:<core:functype> => ft (WebAssembly 1.0)
132-
| st:<core:structtype> => st (GC proposal)
133-
| at:<core:arraytype> => at (GC proposal)
134-
| mt:<core:moduletype> => mt
135-
core:moduletype ::= 0x50 md*:vec(<core:moduledecl>) => (module md*)
136-
core:moduledecl ::= 0x00 i:<core:import> => i
137-
| 0x01 t:<core:type> => t
138-
| 0x02 a:<core:alias> => a
139-
| 0x03 e:<core:exportdecl> => e
140-
core:importdecl ::= i:<core:import> => i
141-
core:exportdecl ::= n:<name> d:<core:importdesc> => (export n d)
123+
core:type ::= dt:<core:deftype> => (type dt) (GC proposal)
124+
core:deftype ::= ft:<core:functype> => ft (WebAssembly 1.0)
125+
| st:<core:structtype> => st (GC proposal)
126+
| at:<core:arraytype> => at (GC proposal)
127+
| mt:<core:moduletype> => mt
128+
core:moduletype ::= 0x50 md*:vec(<core:moduledecl>) => (module md*)
129+
core:moduledecl ::= 0x00 i:<core:import> => i
130+
| 0x01 t:<core:type> => t
131+
| 0x02 a:<core:alias> => a
132+
| 0x03 e:<core:exportdecl> => e
133+
core:alias ::= s:<core:sort> t:<core:aliastarget> => (alias t (s))
134+
core:aliastarget ::= 0x01 ct:<u32> idx:<u32> => outer ct idx
135+
core:importdecl ::= i:<core:import> => i
136+
core:exportdecl ::= n:<name> d:<core:importdesc> => (export n d)
142137
```
143138
Notes:
144139
* Reused Core binary rules: [`core:import`], [`core:importdesc`], [`core:functype`]
145140
* Validation of `core:moduledecl` (currently) rejects `core:moduletype` definitions
146141
inside `type` declarators (i.e., nested core module types).
147142
* As described in the explainer, each module type is validated with an
148143
initially-empty type index space.
149-
* Validation of `alias` declarators only allows `outer` `type` aliases.
150-
Validation of these aliases cannot see beyond the enclosing core type index
144+
* `alias` declarators currently only allow `outer` `type` aliases but
145+
would add `export` aliases when core wasm adds type exports.
146+
* Validation of `outer` aliases cannot see beyond the enclosing core type index
151147
space. Since core modules and core module types cannot nest in the MVP, this
152148
means that the maximum `ct` in an MVP `alias` declarator is `1`.
153149

design/mvp/Explainer.md

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ At the top-level, a `component` is a sequence of definitions of various kinds:
5353
component ::= (component <id>? <definition>*)
5454
definition ::= core-prefix(<core:module>)
5555
| core-prefix(<core:instance>)
56-
| core-prefix(<core:alias>)
5756
| core-prefix(<core:type>)
5857
| <component>
5958
| <instance>
@@ -221,23 +220,17 @@ and export component functions.
221220

222221
Alias definitions project definitions out of other components' index spaces and
223222
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):
227226
```
228-
core:alias ::= (alias <core:aliastarget> (<core:sort> <id>?))
229-
core:aliastarget ::= export <core:instanceidx> <name>
230-
| outer <u32> <u32>
231-
232227
alias ::= (alias <aliastarget> (<sort> <id>?))
233228
aliastarget ::= export <instanceidx> <name>
229+
| core export <core:instanceidx> <name>
234230
| outer <u32> <u32>
235231
```
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.
241234

242235
In the case of `export` aliases, validation ensures `name` is an export in the
243236
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
249242
to the current component. To maintain the acyclicity of module instantiation,
250243
outer aliases are only allowed to refer to *preceding* outer definitions.
251244

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-
260245
Components containing outer aliases effectively produce a [closure] at
261246
instantiation time, including a copy of the outer-aliased definitions. Because
262247
of the prevalent assumption that components are immutable values, outer aliases
@@ -268,10 +253,18 @@ via some kind of "`stateful`" type attribute.)
268253
Both kinds of aliases come with syntactic sugar for implicitly declaring them
269254
inline:
270255

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:
275268
```wasm
276269
(instance $j (instantiate $J (with "f" (func $i "f"))))
277270
(export "x" (func $j "g" "h"))
@@ -310,9 +303,10 @@ is desugared into:
310303
Lastly, for symmetry with [imports][func-import-abbrev], aliases can be written
311304
in an inverted form that puts the sort first:
312305
```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))
316310
```
317311

318312
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:
328322
)
329323
(core instance $a (instantiate $A))
330324
(core instance $b1 (instantiate $B
331-
(with "a" (instance $a)) ;; no renaming
325+
(with "a" (instance $a)) ;; no renaming
332326
))
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))
334328
(core instance $b2 (instantiate $B
335329
(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
337331
))
338332
))
339333
(core instance $b3 (instantiate $B
340334
(with "a" (instance
341-
(export "one" (func $a "three")) ;; renaming, using inline alias sugar
335+
(export "one" (func $a "three")) ;; renaming, using <inlinealias>
342336
))
343337
))
344338
)
@@ -352,19 +346,21 @@ type and function definitions which are introduced in the next two sections.
352346
The syntax for defining core types extends the existing core type definition
353347
syntax, adding a `module` type constructor:
354348
```
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>)
368364
369365
where strip-id(X) parses '(' sort Y ')' when X parses '(' sort <id>? Y ')'
370366
```

0 commit comments

Comments
 (0)