@@ -33,6 +33,7 @@ more user-focused explanation, take a look at the
33
33
* [ Start definitions] ( #-start-definitions )
34
34
* [ Import and export definitions] ( #import-and-export-definitions )
35
35
* [ Name uniqueness] ( #name-uniqueness )
36
+ * [ Canonical interface name] ( #canonical-interface-name )
36
37
* [ Component invariants] ( #component-invariants )
37
38
* [ JavaScript embedding] ( #JavaScript-embedding )
38
39
* [ JS API] ( #JS-API )
@@ -294,7 +295,7 @@ sort ::= core <core:sort>
294
295
| type
295
296
| component
296
297
| instance
297
- inlineexport ::= (export <exportname> <sortidx>)
298
+ inlineexport ::= (export " <exportname>" <versionsuffix>? <sortidx>)
298
299
```
299
300
Because component-level function, type and instance definitions are different
300
301
than core-level function, type and instance definitions, they are put into
@@ -574,8 +575,8 @@ instancedecl ::= core-prefix(<core:type>)
574
575
| <alias>
575
576
| <exportdecl>
576
577
| <value> 🪙
577
- importdecl ::= (import <importname> bind-id(<externdesc>))
578
- exportdecl ::= (export <exportname> bind-id(<externdesc>))
578
+ importdecl ::= (import " <importname>" <versionsuffix>? bind-id(<externdesc>))
579
+ exportdecl ::= (export " <exportname>" <versionsuffix>? bind-id(<externdesc>))
579
580
externdesc ::= (<sort> (type <u32>) )
580
581
| core-prefix(<core:moduletype>)
581
582
| <functype>
@@ -988,6 +989,10 @@ and `$C1` is a subtype of `$C2`:
988
989
)
989
990
```
990
991
992
+ Note that [ canonical interface names] ( #canonical-interface-name ) may be
993
+ annotated with a ` versionsuffix ` which is ignored for type checking except to
994
+ improve diagnostic messages.
995
+
991
996
When we next consider type imports and exports, there are two distinct
992
997
subcases of ` typebound ` to consider: ` eq ` and ` sub ` .
993
998
@@ -2242,8 +2247,9 @@ the identifier `$x`). In the case of exports, the `<id>?` right after the
2242
2247
preceding definition being exported (e.g., ` (export $x "x" (func $f)) ` binds a
2243
2248
new identifier ` $x ` ).
2244
2249
``` ebnf
2245
- import ::= (import "<importname>" bind-id(<externdesc>))
2246
- export ::= (export <id>? "<exportname>" <sortidx> <externdesc>?)
2250
+ import ::= (import "<importname>" <versionsuffix>? bind-id(<externdesc>))
2251
+ export ::= (export <id>? "<exportname>" <versionsuffix>? <sortidx> <externdesc>?)
2252
+ versionsuffix ::= (versionsuffix "<semversuffix>")
2247
2253
```
2248
2254
All import names are required to be [ strongly-unique] . Separately, all export
2249
2255
names are also required to be [ strongly-unique] . The rest of the grammar for
@@ -2276,17 +2282,24 @@ fragment ::= <word>
2276
2282
| <acronym>
2277
2283
word ::= [a-z] [0-9a-z]*
2278
2284
acronym ::= [A-Z] [0-9A-Z]*
2279
- interfacename ::= <namespace> <label> <projection> <version >?
2280
- | <namespace>+ <label> <projection>+ <version >? 🪺
2285
+ interfacename ::= <namespace> <label> <projection> <interfaceversion >?
2286
+ | <namespace>+ <label> <projection>+ <interfaceversion >? 🪺
2281
2287
namespace ::= <words> ':'
2282
2288
words ::= <word>
2283
2289
| <words> '-' <word>
2284
2290
projection ::= '/' <label>
2285
- version ::= '@' <valid semver>
2291
+ # FIXME: surrounding alignment
2292
+ interfaceversion ::= '@' <valid semver>
2293
+ | '@' <canonversion>
2294
+ canonversion ::= [1-9] [0-9]*
2295
+ | '0.' [1-9] [0-9]*
2296
+ | '0.0.' [1-9] [0-9]*
2297
+ semversuffix ::= [0-9A-Za-z.+-]*
2286
2298
depname ::= 'unlocked-dep=<' <pkgnamequery> '>'
2287
2299
| 'locked-dep=<' <pkgname> '>' ( ',' <hashname> )?
2288
2300
pkgnamequery ::= <pkgpath> <verrange>?
2289
- pkgname ::= <pkgpath> <version>?
2301
+ pkgname ::= <pkgpath> <pkgversion>?
2302
+ pkgversion ::= '@' <valid semver>
2290
2303
pkgpath ::= <namespace> <words>
2291
2304
| <namespace>+ <words> <projection>* 🪺
2292
2305
verrange ::= '@*'
@@ -2372,12 +2385,14 @@ tooling as "registries":
2372
2385
parameter of [ ` WebAssembly.instantiate() ` ] )
2373
2386
2374
2387
The ` valid semver ` production is as defined by the [ Semantic Versioning 2.0]
2375
- spec and is meant to be interpreted according to that specification. The
2376
- ` verrange ` production embeds a minimal subset of the syntax for version ranges
2377
- found in common package managers like ` npm ` and ` cargo ` and is meant to be
2378
- interpreted with the same [ semantics] [ SemVerRange ] . (Mostly this
2379
- interpretation is the usual SemVer-spec-defined ordering, but note the
2380
- particular behavior of pre-release tags.)
2388
+ spec and is meant to be interpreted according to that specification. The use of
2389
+ ` valid semver ` in ` interfaceversion ` is temporary for backward compatibility;
2390
+ see [ Canonical interface name] ( #canonical-interface-name ) below. The ` verrange `
2391
+ production embeds a minimal subset of the syntax for version ranges found in
2392
+ common package managers like ` npm ` and ` cargo ` and is meant to be interpreted
2393
+ with the same [ semantics] [ SemVerRange ] . (Mostly this interpretation is the usual
2394
+ SemVer-spec-defined ordering, but note the particular behavior of pre-release
2395
+ tags.)
2381
2396
2382
2397
The ` plainname ` production captures several language-neutral syntactic hints
2383
2398
that allow bindings generators to produce more idiomatic bindings in their
@@ -2539,6 +2554,53 @@ annotations. For example, the validation rules for `[constructor]foo` require
2539
2554
for details.
2540
2555
2541
2556
2557
+ ### Canonical Interface Name
2558
+
2559
+ An ` interfacename ` (as defined above) is ** canonical** iff it either:
2560
+
2561
+ - has no ` interfaceversion `
2562
+ - has an ` interfaceversion ` matching the ` canonversion ` production
2563
+
2564
+ The purpose of ` canonversion ` is to simplify the matching of compatible import
2565
+ and export versions. For example, if a guest imports some interface from
2566
+ ` wasi:http/[email protected] ` and a host provides the (subtype-compatible) interface
2567
+ ` wasi:http/[email protected] ` , we'd like to make it easy for the host to link with the
2568
+ guest. The ` canonversion ` for both of these interfaces would be ` 0.2 ` , so this
2569
+ linking could be done by matching canonical interface names literally.
2570
+ Symmetrically, if a host provides
` wasi:http/[email protected] ` and a guest imports
2571
+ ` wasi:http/[email protected] ` , so long as the guest only uses the subset of
2572
+ functions defined in
` wasi:http/[email protected] ` (which is checked by normal
2573
+ component type validation), linking succeeds. Thus, including only the
2574
+ canonicalized version in the name allows both backwards and (limited)
2575
+ forwards compatibility using only trivial string equality (as well as the
2576
+ type checking already required).
2577
+
2578
+ Any ` valid semver ` (as used in WIT) can be canonicalized by splitting it into
2579
+ two parts - the ` canonversion ` prefix and the remaining ` semversuffix ` . Using
2580
+ the ` <major>.<minor>.<patch> ` syntax of [ Semantic Versioning 2.0] , the split
2581
+ point is chosen as follows:
2582
+
2583
+ - if ` major ` > 0, split immediately after ` major `
2584
+ - ` 1.2.3 ` &rarr ; ` 1 ` / ` .2.3 `
2585
+ - otherwise if ` minor ` > 0, split immediately after ` minor `
2586
+ - ` 0.2.6-rc.1 ` &rarr ; ` 0.2 ` / ` .6-rc.1 `
2587
+ - otherwise, split immediately after ` patch `
2588
+ - ` 0.0.1-alpha ` &rarr ; ` 0.0.1 ` / ` -alpha `
2589
+
2590
+ When a version is canonicalized, any ` semversuffix ` that was split off of the
2591
+ version should be preserved in the ` versionsuffix ` field of any resulting
2592
+ ` import ` s and ` export ` s. This gives component runtimes and other tools access to
2593
+ the original version for error messages, documentation, and other development
2594
+ purposes. Where a ` versionsuffix ` is present the preceding ` interfacename ` must
2595
+ have a ` canonversion ` , and the concatenation of the ` canonversion ` and
2596
+ ` versionsuffix ` must be a ` valid semver ` .
2597
+
2598
+ For compatibility with older versions of this spec, non-canonical
2599
+ ` interfacename ` s (with ` interfaceversion ` s matching any ` valid semver ` ) are
2600
+ temporarily permitted. These non-canonical names may trigger warnings and will
2601
+ start being rejected some time after after [ WASI Preview 3] is released.
2602
+
2603
+
2542
2604
## Component Invariants
2543
2605
2544
2606
As a consequence of the shared-nothing design described above, all calls into
@@ -2894,6 +2956,7 @@ For some use-case-focused, worked examples, see:
2894
2956
[ `rectype` ] : https://webassembly.github.io/gc/core/text/types.html#text-rectype
2895
2957
[ shared-everything-threads ] : https://github.com/WebAssembly/shared-everything-threads
2896
2958
[ WASI Preview 2 ] : https://github.com/WebAssembly/WASI/tree/main/wasip2#readme
2959
+ [ WASI Preview 3 ] : https://github.com/WebAssembly/WASI/tree/main/wasip2#looking-forward-to-preview-3
2897
2960
[ reference types ] : https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md
2898
2961
2899
2962
[ Strongly-unique ] : #name-uniqueness
0 commit comments