@@ -32,6 +32,7 @@ more user-focused explanation, take a look at the
32
32
* [ Value definitions] ( #-value-definitions )
33
33
* [ Start definitions] ( #-start-definitions )
34
34
* [ Import and export definitions] ( #import-and-export-definitions )
35
+ * [ Name uniqueness] ( #name-uniqueness )
35
36
* [ Component invariants] ( #component-invariants )
36
37
* [ JavaScript embedding] ( #JavaScript-embedding )
37
38
* [ JS API] ( #JS-API )
@@ -782,8 +783,8 @@ The remaining 4 type constructors in `deftype` use `valtype` to describe
782
783
shared-nothing functions, resources, components, and component instances:
783
784
784
785
The ` func ` type constructor describes a component-level function definition
785
- that takes a list of uniquely-named ` valtype ` parameters and optionally returns
786
- a ` valtype ` .
786
+ that takes a list of ` valtype ` parameters with [ strongly-unique ] names and
787
+ optionally returns a ` valtype ` .
787
788
788
789
The ` resource ` type constructor creates a fresh type for each instance of the
789
790
containing component (with "freshness" and its interaction with general
@@ -2191,16 +2192,17 @@ new identifier `$x`).
2191
2192
import ::= (import "<importname>" bind-id(<externdesc>))
2192
2193
export ::= (export <id>? "<exportname>" <sortidx> <externdesc>?)
2193
2194
```
2194
- All import names are required to be unique and all export names are required to
2195
- be unique. The rest of the grammar for imports and exports defines a structured
2196
- syntax for the contents of import and export names. Syntactically, these names
2197
- appear inside quoted string literals. The grammar thus restricts the contents
2198
- of these string literals to provide more structured information that can be
2199
- mechanically interpreted by toolchains and runtimes to support idiomatic
2200
- developer workflows and source-language bindings. The rules defining this
2201
- structured name syntax below are to be interpreted as a * lexical* grammar
2202
- defining a single token and thus whitespace is not automatically inserted, all
2203
- terminals are single-quoted, and everything unquoted is a meta-character.
2195
+ All import names are required to be [ strongly-unique] . Separately, all export
2196
+ names are also required to be [ strongly-unique] . The rest of the grammar for
2197
+ imports and exports defines a structured syntax for the contents of import and
2198
+ export names. Syntactically, these names appear inside quoted string literals.
2199
+ The grammar thus restricts the contents of these string literals to provide
2200
+ more structured information that can be mechanically interpreted by toolchains
2201
+ and runtimes to support idiomatic developer workflows and source-language
2202
+ bindings. The rules defining this structured name syntax below are to be
2203
+ interpreted as a * lexical* grammar defining a single token and thus whitespace
2204
+ is not automatically inserted, all terminals are single-quoted, and everything
2205
+ unquoted is a meta-character.
2204
2206
``` ebnf
2205
2207
exportname ::= <plainname>
2206
2208
| <interfacename>
@@ -2358,12 +2360,6 @@ mapped to `isXML`, `IsXml`, `is_XML` or `is_xml`, depending on the target
2358
2360
language/convention. The highly-restricted character set ensures that
2359
2361
capitalization is trivial and does not require consulting Unicode tables.
2360
2362
2361
- Because some casing schemes (such as all-lowercase) would lead to clashes if
2362
- two ` label ` s differed only in case, in all cases where "uniqueness" is required
2363
- between a set of names (viz., import/export names, record field labels, variant
2364
- case labels, and function parameter/result names), two ` label ` s that differ
2365
- only in case are considered equal and thus rejected.
2366
-
2367
2363
Components provide two options for naming exports, symmetric to the first two
2368
2364
options for naming imports:
2369
2365
* a ** plain name** that leaves it up to the developer to "read the docs"
@@ -2455,6 +2451,39 @@ The inferred type of this component is:
2455
2451
2456
2452
Note, that the ` url ` value definition is absent from the component type
2457
2453
2454
+ ### Name Uniqueness
2455
+
2456
+ The goal of the ` label ` , ` exportname ` and ` importname ` productions defined and
2457
+ used above is to allow automated bindings generators to map these names into
2458
+ something more idiomatic to the language. For example, the ` plainname `
2459
+ ` [method]my-resource.my-method ` might get mapped to a method named ` myMethod `
2460
+ nested inside a class ` MyResource ` . To unburden bindings generators from having
2461
+ to consider pathological cases where two unique-in-the-component names get
2462
+ mapped to the same source-language identifier, Component Model validation
2463
+ imposes a stronger form of uniquness than simple string equality on all the
2464
+ names that appear within the same scope.
2465
+
2466
+ To determine whether two names (defined as sequences of [ Unicode Scalar
2467
+ Values] ) are ** strongly-unique** :
2468
+ * If one name is ` l ` and the other name is ` [constructor]l ` (for the same
2469
+ ` label ` ` l ` ), they are strongly-unique.
2470
+ * Otherwise:
2471
+ * Lowercase all the ` acronym ` s (uppercase letters) in both names.
2472
+ * Strip any ` [...] ` annotation prefix from both names.
2473
+ * The names are strongly-unique if the resulting strings are unequal.
2474
+
2475
+ Thus, the following names are strongly-unique:
2476
+ * ` foo ` , ` foo-bar ` , ` [constructor]foo ` , ` [method]foo.bar ` , ` [method]foo.baz `
2477
+
2478
+ but attempting to add * any* of the following names would be a validation error:
2479
+ * ` foo ` , ` foo-BAR ` , ` [constructor]foo-BAR ` , ` [async]foo ` , ` [method]foo.BAR `
2480
+
2481
+ Note that additional validation rules involving types apply to names with
2482
+ annotations. For example, the validation rules for ` [constructor]foo ` require
2483
+ ` foo ` to be a resource type. See [ Binary.md] ( Binary.md#import-and-export-definitions )
2484
+ for details.
2485
+
2486
+
2458
2487
## Component Invariants
2459
2488
2460
2489
As a consequence of the shared-nothing design described above, all calls into
@@ -2812,6 +2841,8 @@ For some use-case-focused, worked examples, see:
2812
2841
[ WASI Preview 2 ] : https://github.com/WebAssembly/WASI/tree/main/wasip2#readme
2813
2842
[ reference types ] : https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md
2814
2843
2844
+ [ Strongly-unique ] : #name-uniqueness
2845
+
2815
2846
[ Adapter Functions ] : FutureFeatures.md#custom-abis-via-adapter-functions
2816
2847
[ Canonical ABI explainer ] : CanonicalABI.md
2817
2848
[ `canon_context_get` ] : CanonicalABI.md#-canon-contextget
0 commit comments