Skip to content

Commit 22fbfc5

Browse files
committed
Add canonical interface name
1 parent e362068 commit 22fbfc5

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

design/mvp/Binary.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,13 @@ flags are set.
371371
(See [Import and Export Definitions](Explainer.md#import-and-export-definitions)
372372
in the explainer.)
373373
```ebnf
374-
import ::= in:<importname'> ed:<externdesc> => (import in ed)
375-
export ::= en:<exportname'> si:<sortidx> ed?:<externdesc>? => (export en si ed?)
376-
importname' ::= 0x00 len:<u32> in:<importname> => in (if len = |in|)
377-
exportname' ::= 0x00 len:<u32> en:<exportname> => en (if len = |en|)
374+
import ::= in:<importname'> ed:<externdesc> => (import in ed)
375+
export ::= en:<exportname'> si:<sortidx> ed?:<externdesc>? => (export en si ed?)
376+
importname' ::= 0x00 len:<u32> in:<importname> => in (if len = |in|)
377+
| 0x01 len:<u32> in:<importname> vs:<versionsuffix'> => in vs (if len = |in|)
378+
exportname' ::= 0x00 len:<u32> en:<exportname> => en (if len = |en|)
379+
| 0x01 len:<u32> en:<exportname> vs:<versionsuffix'> => in vs (if len = |in|)
380+
versionsuffix' ::= len:<u32> vs:<semver suffix> => (versionsuffix vs) (if len = |vs|)
378381
```
379382

380383
Notes:
@@ -399,7 +402,10 @@ Notes:
399402
`(result (own $R))`, where `$R` is the resource labeled `r`.
400403
* Validation of `[method]` names requires the first parameter of the function
401404
to be `(param "self" (borrow $R))`, where `$R` is the resource labeled `r`.
402-
* `<valid semver>` is as defined by [https://semver.org](https://semver.org/)
405+
* Validation requires that `versionsuffix`es are preceded by an
406+
`interfaceversion` with a `canonversion` and that the concatenation of the
407+
`canonversion` and the `versionsuffix` results in a `valid semver` as defined
408+
by [https://semver.org](https://semver.org/)
403409
* `<integrity-metadata>` is as defined by the
404410
[SRI](https://www.w3.org/TR/SRI/#dfn-integrity-metadata) spec.
405411

@@ -494,7 +500,9 @@ named once.
494500

495501
* The opcodes (for types, canon built-ins, etc) should be re-sorted
496502
* The two `list` type codes should be merged into one with an optional immediate.
497-
* The `0x00` prefix byte of `importname'` and `exportname'` will be removed or repurposed.
503+
* The `0x00` variant of `importname'` and `exportname'` will be removed. Any
504+
remaining variant(s) will be renumbered or the prefix byte will be removed or
505+
repurposed.
498506

499507

500508
[`core:byte`]: https://webassembly.github.io/spec/core/binary/values.html#binary-byte

design/mvp/Explainer.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ more user-focused explanation, take a look at the
3333
* [Start definitions](#-start-definitions)
3434
* [Import and export definitions](#import-and-export-definitions)
3535
* [Name uniqueness](#name-uniqueness)
36+
* [Canonical interface name](#canonical-interface-name)
3637
* [Component invariants](#component-invariants)
3738
* [JavaScript embedding](#JavaScript-embedding)
3839
* [JS API](#JS-API)
@@ -294,7 +295,7 @@ sort ::= core <core:sort>
294295
| type
295296
| component
296297
| instance
297-
inlineexport ::= (export <exportname> <sortidx>)
298+
inlineexport ::= (export "<exportname>" <versionsuffix>? <sortidx>)
298299
```
299300
Because component-level function, type and instance definitions are different
300301
than core-level function, type and instance definitions, they are put into
@@ -574,8 +575,8 @@ instancedecl ::= core-prefix(<core:type>)
574575
| <alias>
575576
| <exportdecl>
576577
| <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>))
579580
externdesc ::= (<sort> (type <u32>) )
580581
| core-prefix(<core:moduletype>)
581582
| <functype>
@@ -2242,8 +2243,9 @@ the identifier `$x`). In the case of exports, the `<id>?` right after the
22422243
preceding definition being exported (e.g., `(export $x "x" (func $f))` binds a
22432244
new identifier `$x`).
22442245
```ebnf
2245-
import ::= (import "<importname>" bind-id(<externdesc>))
2246-
export ::= (export <id>? "<exportname>" <sortidx> <externdesc>?)
2246+
import ::= (import "<importname>" <versionsuffix>? bind-id(<externdesc>))
2247+
export ::= (export <id>? "<exportname>" <versionsuffix>? <sortidx> <externdesc>?)
2248+
versionsuffix ::= (versionsuffix "<semver suffix>")
22472249
```
22482250
All import names are required to be [strongly-unique]. Separately, all export
22492251
names are also required to be [strongly-unique]. The rest of the grammar for
@@ -2276,17 +2278,23 @@ fragment ::= <word>
22762278
| <acronym>
22772279
word ::= [a-z] [0-9a-z]*
22782280
acronym ::= [A-Z] [0-9A-Z]*
2279-
interfacename ::= <namespace> <label> <projection> <version>?
2280-
| <namespace>+ <label> <projection>+ <version>? 🪺
2281+
interfacename ::= <namespace> <label> <projection> <interfaceversion>?
2282+
| <namespace>+ <label> <projection>+ <interfaceversion>? 🪺
22812283
namespace ::= <words> ':'
22822284
words ::= <word>
22832285
| <words> '-' <word>
22842286
projection ::= '/' <label>
2285-
version ::= '@' <valid semver>
2287+
# FIXME: surrounding alignment
2288+
interfaceversion ::= '@' <valid semver>
2289+
| '@' <canonversion>
2290+
canonversion ::= [1-9] [0-9]*
2291+
| '0.' [1-9] [0-9]*
2292+
| '0.0.' [1-9] [0-9]*
22862293
depname ::= 'unlocked-dep=<' <pkgnamequery> '>'
22872294
| 'locked-dep=<' <pkgname> '>' ( ',' <hashname> )?
22882295
pkgnamequery ::= <pkgpath> <verrange>?
2289-
pkgname ::= <pkgpath> <version>?
2296+
pkgname ::= <pkgpath> <pkgversion>?
2297+
pkgversion ::= '@' <valid semver>
22902298
pkgpath ::= <namespace> <words>
22912299
| <namespace>+ <words> <projection>* 🪺
22922300
verrange ::= '@*'
@@ -2539,6 +2547,42 @@ annotations. For example, the validation rules for `[constructor]foo` require
25392547
for details.
25402548

25412549

2550+
### Canonical Interface Name
2551+
2552+
An `interfacename` (as defined above) is **canonical** iff it either:
2553+
2554+
- has no `interfaceversion`
2555+
- has an `interfaceversion` matching the `canonversion` production
2556+
2557+
The purpose of `canonversion` is to simplify the matching of compatible import
2558+
and export versions. For example, if a guest imports some interface from
2559+
`wasi:http/types@0.2.1` and a host provides the (subtype-compatible) interface
2560+
`wasi:http/types@0.2.6`, we'd like to make it easy for the host to link with the
2561+
guest. The `canonversion` for both of these interfaces would be `0.2`, so this
2562+
linking could be done by matching the interface names literally.
2563+
2564+
A `valid semver` (as used in WIT) can be canonicalized by splitting it into two
2565+
parts - the `canonversion` prefix and the remaining `semver suffix`. Using the
2566+
`<major>.<minor>.<patch>` syntax of [Semantic Versioning 2.0]:
2567+
2568+
- if `major` > 0, split immediately after `major`
2569+
- `1.2.3` &rarr; `1` / `.2.3`
2570+
- otherwise if `minor` > 0, split immediately after `minor`
2571+
- `0.2.6-rc.1` &rarr; `0.2` / `.6-rc.1`
2572+
- otherwise, split immediately after `patch`
2573+
- `0.0.1-alpha` &rarr; `0.0.1` / `-alpha`
2574+
2575+
When component tooling canonicalizes a version, any `semver suffix` portion of the interface
2576+
name removed should be preserved in imports / exports in the `versionsuffix`
2577+
field. This gives component runtimes and other tools access to the original
2578+
version for error messages, documentation, and other development purposes.
2579+
2580+
For compatibility with older versions of this spec, non-canonical
2581+
`interfacename`s (with `interfaceversion`s matching any `valid semver`) are
2582+
temporarily permitted. These non-canonical names may trigger warnings and will
2583+
start being rejected some time after after [WASI Preview 3] is released.
2584+
2585+
25422586
## Component Invariants
25432587

25442588
As a consequence of the shared-nothing design described above, all calls into
@@ -2894,6 +2938,7 @@ For some use-case-focused, worked examples, see:
28942938
[`rectype`]: https://webassembly.github.io/gc/core/text/types.html#text-rectype
28952939
[shared-everything-threads]: https://github.com/WebAssembly/shared-everything-threads
28962940
[WASI Preview 2]: https://github.com/WebAssembly/WASI/tree/main/wasip2#readme
2941+
[WASI Preview 3]: https://github.com/WebAssembly/WASI/tree/main/wasip2#looking-forward-to-preview-3
28972942
[reference types]: https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md
28982943

28992944
[Strongly-unique]: #name-uniqueness

0 commit comments

Comments
 (0)