Skip to content

Commit b8a2bf2

Browse files
authored
Merge pull request #109 from WebAssembly/kebab-case
split import/export names into kebab-case name + optional URL fields
2 parents aa563a1 + cc63724 commit b8a2bf2

File tree

4 files changed

+257
-87
lines changed

4 files changed

+257
-87
lines changed

design/mvp/Binary.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Notes:
5555
```
5656
core:instance ::= ie:<instance-expr> => (instance ie)
5757
core:instanceexpr ::= 0x00 m:<moduleidx> arg*:vec(<core:instantiatearg>) => (instantiate m arg*)
58-
| 0x01 e*:vec(<core:export>) => e*
59-
core:instantiatearg ::= n:<name> 0x12 i:<instanceidx> => (with n (instance i))
58+
| 0x01 e*:vec(<core:inlineexport>) => e*
59+
core:instantiatearg ::= n:<core:name> 0x12 i:<instanceidx> => (with n (instance i))
6060
core:sortidx ::= sort:<core:sort> idx:<u32> => (sort idx)
6161
core:sort ::= 0x00 => func
6262
| 0x01 => table
@@ -65,11 +65,11 @@ core:sort ::= 0x00 => fu
6565
| 0x10 => type
6666
| 0x11 => module
6767
| 0x12 => instance
68-
core:export ::= n:<name> si:<core:sortidx> => (export n si)
68+
core:inlineexport ::= n:<core:name> si:<core:sortidx> => (export n si)
6969
7070
instance ::= ie:<instance-expr> => (instance ie)
7171
instanceexpr ::= 0x00 c:<componentidx> arg*:vec(<instantiatearg>) => (instantiate c arg*)
72-
| 0x01 e*:vec(<export>) => e*
72+
| 0x01 e*:vec(<inlineexport>) => e*
7373
instantiatearg ::= n:<name> si:<sortidx> => (with n si)
7474
sortidx ::= sort:<sort> idx:<u32> => (sort idx)
7575
sort ::= 0x00 cs:<core:sort> => core cs
@@ -78,7 +78,12 @@ sort ::= 0x00 cs:<core:sort> => co
7878
| 0x03 => type
7979
| 0x04 => component
8080
| 0x05 => instance
81-
export ::= n:<name> si:<sortidx> => (export n si)
81+
inlineexport ::= n:<name> si:<sortidx> => (export n si)
82+
name ::= len:<u32> n:<name-chars> => n (if len = |n|)
83+
name-chars ::= w:<word> => w
84+
| n:<name> 0x2d w:<word> => n-w
85+
word ::= w:[0x61-0x7a] x*:[0x30-0x39,0x61-0x7a]* => char(w)char(x)*
86+
| W:[0x41-0x5a] X*:[0x30-0x39,0x41-0x5a]* => char(W)char(X)*
8287
```
8388
Notes:
8489
* Reused Core binary rules: [`core:name`], (variable-length encoded) [`core:u32`]
@@ -92,17 +97,19 @@ Notes:
9297
for aliases (below).
9398
* Validation of `core:instantiatearg` initially only allows the `instance`
9499
sort, but would be extended to accept other sorts as core wasm is extended.
100+
* Validation of `instantiate` requires that `name` is present in an
101+
`externname` of `c` (with a matching type).
95102
* The indices in `sortidx` are validated according to their `sort`'s index
96103
spaces, which are built incrementally as each definition is validated.
97104

98105
## Alias Definitions
99106

100107
(See [Alias Definitions](Explainer.md#alias-definitions) in the explainer.)
101108
```
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
109+
alias ::= s:<sort> t:<aliastarget> => (alias t (s))
110+
aliastarget ::= 0x00 i:<instanceidx> n:<name> => export i n
111+
| 0x01 i:<core:instanceidx> n:<core:name> => core export i n
112+
| 0x02 ct:<u32> idx:<u32> => outer ct idx
106113
```
107114
Notes:
108115
* Reused Core binary rules: (variable-length encoded) [`core:u32`]
@@ -133,7 +140,7 @@ core:moduledecl ::= 0x00 i:<core:import> => i
133140
core:alias ::= s:<core:sort> t:<core:aliastarget> => (alias t (s))
134141
core:aliastarget ::= 0x01 ct:<u32> idx:<u32> => outer ct idx
135142
core:importdecl ::= i:<core:import> => i
136-
core:exportdecl ::= n:<name> d:<core:importdesc> => (export n d)
143+
core:exportdecl ::= n:<core:name> d:<core:importdesc> => (export n d)
137144
```
138145
Notes:
139146
* Reused Core binary rules: [`core:import`], [`core:importdesc`], [`core:functype`]
@@ -175,12 +182,11 @@ defvaltype ::= pvt:<primvaltype> => pvt
175182
| 0x6d n*:vec(<name>) => (enum n*)
176183
| 0x6c t*:vec(<valtype>) => (union t*)
177184
| 0x6b t:<valtype> => (option t)
178-
| 0x6a t?:<casetype> u?:<casetype> => (result t? (error u)?)
185+
| 0x6a t?:<valtype>? u?:<valtype>? => (result t? (error u)?)
179186
namedvaltype ::= n:<name> t:<valtype> => n t
180-
case ::= n:<name> t?:<casetype> 0x0 => (case n t?)
181-
| n:<name> t?:<casetype> 0x1 i:<u32> => (case n t? (refines case-label[i]))
182-
casetype ::= 0x00 =>
183-
| 0x01 t:<valtype> => t
187+
case ::= n:<name> t?:<valtype>? r?:<u32>? => (case n t? (refines case-label[r])?)
188+
<T>? ::= 0x00 =>
189+
| 0x01 t:<T> => t
184190
valtype ::= i:<typeidx> => i
185191
| pvt:<primvaltype> => pvt
186192
functype ::= 0x40 ps:<paramlist> rs:<resultlist> => (func ps rs)
@@ -195,8 +201,8 @@ instancedecl ::= 0x00 t:<core:type> => t
195201
| 0x01 t:<type> => t
196202
| 0x02 a:<alias> => a
197203
| 0x04 ed:<exportdecl> => ed
198-
importdecl ::= n:<name> ed:<externdesc> => (import n ed)
199-
exportdecl ::= n:<name> ed:<externdesc> => (export n ed)
204+
importdecl ::= en:<externname> ed:<externdesc> => (import en ed)
205+
exportdecl ::= en:<externname> ed:<externdesc> => (export en ed)
200206
externdesc ::= 0x00 0x11 i:<core:typeidx> => (core module (type i))
201207
| 0x01 i:<typeidx> => (func (type i))
202208
| 0x02 t:<valtype> => (value t)
@@ -215,6 +221,8 @@ Notes:
215221
* As described in the explainer, each component and instance type is validated
216222
with an initially-empty type index space. Outer aliases can be used to pull
217223
in type definitions from containing components.
224+
* The uniqueness validation rules for `externname` described below are also
225+
applied at the instance- and component-type level.
218226
* Validation of `externdesc` requires the various `typeidx` type constructors
219227
to match the preceding `sort`.
220228
* Validation of function parameter and result names, record field names,
@@ -286,13 +294,21 @@ flags are set.
286294
(See [Import and Export Definitions](Explainer.md#import-and-export-definitions)
287295
in the explainer.)
288296
```
289-
import ::= n:<name> ed:<externdesc> => (import n ed)
290-
export ::= n:<name> si:<sortidx> => (export n si)
297+
import ::= en:<externname> ed:<externdesc> => (import en ed)
298+
export ::= en:<externname> si:<sortidx> => (export en si)
299+
externname ::= n:<name> u?:<URL>? => n u?
300+
URL ::= b*:vec(byte) => char(b)*, if char(b)* parses as a URL
291301
```
292302
Notes:
293-
* Validation requires all import and export `name`s are unique.
303+
* The "parses as a URL" condition is defined by executing the [basic URL
304+
parser] with `char(b)*` as *input*, no optional parameters and non-fatal
305+
validation errors (which coincides with definition of `URL` in JS and `rust-url`).
294306
* Validation requires any exported `sortidx` to have a valid `externdesc`
295307
(which disallows core sorts other than `core module`).
308+
* The `name` fields of `externname` must be unique among imports and exports,
309+
respectively. The `URL` fields of `externname` (that are present) must
310+
independently unique among imports and exports, respectively.
311+
* URLs are compared for equality by plain byte identity.
296312

297313

298314
[`core:u32`]: https://webassembly.github.io/spec/core/binary/values.html#integers
@@ -307,3 +323,5 @@ Notes:
307323

308324
[type-imports]: https://github.com/WebAssembly/proposal-type-imports/blob/master/proposals/type-imports/Overview.md
309325
[module-linking]: https://github.com/WebAssembly/module-linking/blob/main/proposals/module-linking/Explainer.md
326+
327+
[Basic URL Parser]: https://url.spec.whatwg.org/#concept-basic-url-parser

0 commit comments

Comments
 (0)