From 2d0d243fa85d6cbd43d3944bd970778ce5064994 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Fri, 3 Mar 2023 14:53:48 -0800 Subject: [PATCH 01/13] added include statement Signed-off-by: Jiaxiao Zhou --- design/mvp/WIT.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index cbd51b36..227df9f3 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -699,6 +699,7 @@ keyword ::= 'use' | 'import' | 'export' | 'package' + | 'include' ``` ### Integers @@ -766,7 +767,7 @@ Concretely, the structure of a world is: ```ebnf world-item ::= 'world' id '{' world-items* '}' -world-items ::= export-item | import-item | use-item | typedef-item +world-items ::= export-item | import-item | use-item | typedef-item | include-item export-item ::= 'export' id ':' extern-type | 'export' interface @@ -781,6 +782,25 @@ from the root of a component and used within functions imported and exported. The `interface` item here additionally defines the grammar for IDs used to refer to `interface` items. +## Item: `include` + +A `include` statement enables union the current world with another world. The structure of an `include` statement is: + +```wit +include pkg.my-world-1 with { a as a1, b as b1 } +include self.my-world-2 +``` + +```ebnf +include-item ::= 'include' use-path + | 'include' use-path 'with' '{' include-names-list '}' + +include-names-list ::= include-names-item + | include-names-item ',' include-names-item? + +include-names-item ::= id 'as' id +``` + ## Item: `interface` Interfaces can be defined in a `wit` file. Interfaces have a name and a From 56f6bc268a0f9ccc8bf31cf7f8f2ad7f062c9852 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Mon, 6 Mar 2023 16:34:23 -0800 Subject: [PATCH 02/13] added semantic description of `include` statement Signed-off-by: Jiaxiao Zhou --- design/mvp/WIT.md | 159 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 227df9f3..2db1be4d 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -236,6 +236,165 @@ Kebab names cannot overlap and must be unique, even between imports and exports. IDs, however, can be both imported and exported. The same interface cannot be explicitly imported or exported twice. +### Union of Worlds with `include` + +A World can be created by taking the union of two or more worlds. This operation allows +world builders to form larger worlds from smaller worlds. + +Below is a simple example of a world that includes two other worlds. + +```wit +// worlds.wit +world my-world-1 { + import a: self.a + import b: self.b + export c: self.c +} + +world my-world-2 { + import foo: self.foo + import bar: self.bar + export baz: self.baz +} + +world union-my-world { + include self.my-world-1 + include self.my-world-2 +} +``` + +The `include` statement is used to include the imports and exports of another World to the +current World. It says that the new World should be able to run all components that target +the included worlds and more. + +The `union-my-world` World defined above is equivalent to the following World: + +```wit +world union-my-world { + import a: self.a + import b: self.b + export c: self.c + import foo: self.foo + import bar: self.bar + export baz: self.baz +} +``` + +The `include` statement also works with [WIT package](#wit-packages-and-use) defined below with the same semantics. For example, the following World `union-my-world-1` is equivalent to `union-my-world-2`: + +```wit +// b.wit +interface b { ... } + +// a.wit +interface a { ... } + +world my-world-1 { + import a: self.a + import b: pkg.b + import c: io.c // external package + export d: interface exp { ... } +} + +// union.wit + +world union-my-world-1 { + include pkg.my-world-1 +} + +world union-my-world-2 { + import a: pkg.a + import b: pkg.b + import c: io.c + export d: interface exp { ... } +} +``` + +### Name Conflicts + +When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. + +`with` allows the world author to rename the import or export to a different name. For all the imports and exports that are not explicitly renamed, the name of the import or export from the included world is used. + +The following example shows how to resolve name conflicts where `union-my-world-1` and `union-my-world-2` are equivalent: + +```wit +// my-world-1.wit +world my-world-1 { + import a: self.a + import b: self.b + export d: self.d +} + +// my-world-2.wit +world my-world-2 { + import a: self.a + import b: self.b + export c: self.c +} + +// union.wit +world union-my-world-1 { + include pkg.my-world-1 with { a as a1, b as b1 } + include pkg.my-world-2 +} + +world union-my-world-2 { + // resolve conflicts + import a1: pkg.my-world-1.a + import b1: pkg.my-world-1.b + export d: pkg.my-world-1.d + + import a: pkg.my-world-2.a + import b: pkg.my-world-2.b + export c: pkg.my-world-2.c +} +``` + +### De-duplication (In the future) + +As of now, the `include` statement requires the world author to explicitly rename the imports and exports that have the same name. + +In the future, we may allow to de-duplicate the imports and exports of the included worlds if the yare structurally equivalent following the [Subtyping](Subtyping.md) rules. For example, the following world `union-my-world-3` is equivalent to `union-my-world-4`: + +```wit +// a.wit +// b.wit +// c.wit + +// my-world-1.wit +world my-world-1 { + import a: pkg.a + import b: pkg.b + export c: pkg.c +} + +// my-world-2.wit +world my-world-2 { + import a: pkg.a + import b: pkg.b + export c: pkg.c +} + +// union.wit +world union-my-world-3 { + include pkg.my-world-1 + include pkg.my-world-2 +} + +world union-my-world-4 { + import a: pkg.a + import b: pkg.b + export c: pkg.c +} +``` + +### A Note on SubTyping + +As of now, host bindings are required to implicitly interpret all exports as optional to make a component targeting an included World a subtype of the union World. This [comment](https://github.com/WebAssembly/component-model/issues/169#issuecomment-1446776193) describes the reasoning behind this decision. + +In the future, when `optional` export is supported, the world author may explicitly mark exports as optional to make a component targeting an included World a subtype of the union World. + ## WIT Packages and `use` [use]: #wit-packages-and-use From 988f5ea1508c9c16033b31a532387572fbd57ab5 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Thu, 9 Mar 2023 15:41:46 -0800 Subject: [PATCH 03/13] added deduplication Signed-off-by: Jiaxiao Zhou --- design/mvp/WIT.md | 87 +++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 2db1be4d..d393d02a 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -238,8 +238,7 @@ explicitly imported or exported twice. ### Union of Worlds with `include` -A World can be created by taking the union of two or more worlds. This operation allows -world builders to form larger worlds from smaller worlds. +A World can be created by taking the union of two or more worlds. This operation allows world builders to form larger worlds from smaller worlds. Below is a simple example of a world that includes two other worlds. @@ -263,9 +262,7 @@ world union-my-world { } ``` -The `include` statement is used to include the imports and exports of another World to the -current World. It says that the new World should be able to run all components that target -the included worlds and more. +The `include` statement is used to include the imports and exports of another World to the current World. It says that the new World should be able to run all components that target the included worlds and more. The `union-my-world` World defined above is equivalent to the following World: @@ -321,15 +318,15 @@ The following example shows how to resolve name conflicts where `union-my-world- ```wit // my-world-1.wit world my-world-1 { - import a: self.a - import b: self.b + import a: self.a1 + import b: self.b1 export d: self.d } // my-world-2.wit world my-world-2 { - import a: self.a - import b: self.b + import a: self.a2 + import b: self.b2 export c: self.c } @@ -341,39 +338,34 @@ world union-my-world-1 { world union-my-world-2 { // resolve conflicts - import a1: pkg.my-world-1.a - import b1: pkg.my-world-1.b + import a1: pkg.my-world-1.a1 + import b1: pkg.my-world-1.b1 export d: pkg.my-world-1.d - import a: pkg.my-world-2.a - import b: pkg.my-world-2.b + import a: pkg.my-world-2.a2 + import b: pkg.my-world-2.b2 export c: pkg.my-world-2.c } ``` -### De-duplication (In the future) - -As of now, the `include` statement requires the world author to explicitly rename the imports and exports that have the same name. +### De-duplication -In the future, we may allow to de-duplicate the imports and exports of the included worlds if the yare structurally equivalent following the [Subtyping](Subtyping.md) rules. For example, the following world `union-my-world-3` is equivalent to `union-my-world-4`: +If two interfaces have the same structure, then these two interfaces are considered to be structurally equivalent. The `include` statement can +deduplicate the imports and exports of the included worlds if the they are structurally equivalent following the [Subtyping](Subtyping.md) rules. For example, the following world `union-my-world-3` is equivalent to `union-my-world-4`: ```wit -// a.wit -// b.wit -// c.wit - // my-world-1.wit world my-world-1 { - import a: pkg.a - import b: pkg.b - export c: pkg.c + import a1: pkg.a + import b1: pkg.b + export c1: pkg.c } // my-world-2.wit world my-world-2 { - import a: pkg.a - import b: pkg.b - export c: pkg.c + import a2: pkg.a + import b2: pkg.b + export c2: pkg.c } // union.wit @@ -383,10 +375,47 @@ world union-my-world-3 { } world union-my-world-4 { - import a: pkg.a - import b: pkg.b + import a1: pkg.a + import b1: pkg.b + export c1: pkg.c +} +``` + +As you can see, the names of the imports and exports in "union-my-world-4" are picking up the names from the first included world. This is because the second included world has structurally the same imports and exports and are deduplicated. + +### De-duplication with `with` + +When two worlds have both name conflicts and structurally equivalent imports and exports, the semantics of `include` will do deduplication first and then resolve the name conflicts with `with` statements. For example, the following world `union-my-world-5` is equivalent to `union-my-world-6`: + +```wit + +// my-world-1.wit +world my-world-1 { + import a1: pkg.a + import b1: pkg.b export c: pkg.c } + +// my-world-2.wit +world my-world-2 { + import a1: pkg.a + import b1: pkg.b + export c: pkg.d +} + +// union +world union-my-world-5 { + include pkg.my-world-1 with { c as c1 } + include pkg.my-world-2 +} + +world union-my-world-6 { + import a1: pkg.a + import b1: pkg.b + export c1: pkg.c + export c: pkg.d +} + ``` ### A Note on SubTyping From 8ab01f5832ee69e4ae6b3db71977cac38c4ccc1a Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Thu, 4 May 2023 17:53:08 +0000 Subject: [PATCH 04/13] address comments Signed-off-by: jiaxiao zhou --- design/mvp/WIT.md | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index d393d02a..6116d140 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -363,9 +363,9 @@ world my-world-1 { // my-world-2.wit world my-world-2 { - import a2: pkg.a - import b2: pkg.b - export c2: pkg.c + import a1: pkg.a + import b1: pkg.b + export c1: pkg.c } // union.wit @@ -381,7 +381,29 @@ world union-my-world-4 { } ``` -As you can see, the names of the imports and exports in "union-my-world-4" are picking up the names from the first included world. This is because the second included world has structurally the same imports and exports and are deduplicated. +Notice that if the two included worlds have different names for the same import or export, then it will be considered as an error, even if the interfaces are strcuturally the same. For example, the following worlds `my-world-1` and `my-world-2` are not structurally equivalent, but the `include` statement will report an error: + +```wit +// my-world-1.wit +world my-world-1 { + import a1: pkg.a + import b1: pkg.b + export c1: pkg.c +} + +// my-world-2.wit +world my-world-2 { + import a2: pkg.a + import b2: pkg.b + export c2: pkg.c +} + +// union.wit +world union-my-world-3 { + include pkg.my-world-1 + include pkg.my-world-2 +} +``` ### De-duplication with `with` @@ -420,10 +442,10 @@ world union-my-world-6 { ### A Note on SubTyping -As of now, host bindings are required to implicitly interpret all exports as optional to make a component targeting an included World a subtype of the union World. This [comment](https://github.com/WebAssembly/component-model/issues/169#issuecomment-1446776193) describes the reasoning behind this decision. - In the future, when `optional` export is supported, the world author may explicitly mark exports as optional to make a component targeting an included World a subtype of the union World. +For now, we are not following the subtyping rules for the `include` statement. That is, the `include` statement does not imply any subtyping relationship between the included worlds and the union world. + ## WIT Packages and `use` [use]: #wit-packages-and-use From 1173c28ffa3493405cbb0bcff2db9bd4d0686d2c Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Mon, 8 May 2023 18:46:01 +0000 Subject: [PATCH 05/13] fixed path to interfaces Signed-off-by: jiaxiao zhou --- design/mvp/WIT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 6116d140..9d540528 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -281,10 +281,10 @@ The `include` statement also works with [WIT package](#wit-packages-and-use) def ```wit // b.wit -interface b { ... } +default interface b { ... } // a.wit -interface a { ... } +default interface a { ... } world my-world-1 { import a: self.a @@ -296,7 +296,7 @@ world my-world-1 { // union.wit world union-my-world-1 { - include pkg.my-world-1 + include pkg.a.my-world-1 } world union-my-world-2 { From 7007b26d9a57c5fa95a73ce2381d1e6e2d699f9f Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Thu, 22 Jun 2023 17:38:11 -0700 Subject: [PATCH 06/13] Changed the WIT syntax to the newest package syntax. This commit updates the WIT syntax in all of the examples illustrating the use of the include syntax. Signed-off-by: Jiaxiao Zhou (Mossaka) --- design/mvp/WIT.md | 201 ++++++++++++++-------------------------------- 1 file changed, 62 insertions(+), 139 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 805fbb2f..e03ffb0a 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -243,22 +243,25 @@ A World can be created by taking the union of two or more worlds. This operation Below is a simple example of a world that includes two other worlds. ```wit -// worlds.wit -world my-world-1 { - import a: self.a - import b: self.b - export c: self.c +package local:demo + +// definitions of a, b, c, foo, bar, baz are omitted + +world my-world-a { + import a + import b + export c } -world my-world-2 { - import foo: self.foo - import bar: self.bar - export baz: self.baz +world my-world-b { + import foo + import bar + export baz } world union-my-world { - include self.my-world-1 - include self.my-world-2 + include my-world-a + include my-world-b } ``` @@ -268,176 +271,96 @@ The `union-my-world` World defined above is equivalent to the following World: ```wit world union-my-world { - import a: self.a - import b: self.b - export c: self.c - import foo: self.foo - import bar: self.bar - export baz: self.baz + import a + import b + export c + import foo + import bar + export baz } ``` -The `include` statement also works with [WIT package](#wit-packages-and-use) defined below with the same semantics. For example, the following World `union-my-world-1` is equivalent to `union-my-world-2`: +The `include` statement also works with [WIT package](#wit-packages-and-use) defined below with the same semantics. For example, the following World `union-my-world-a` is equivalent to `union-my-world-b`: ```wit // b.wit -default interface b { ... } +interface b { ... } // a.wit -default interface a { ... } +interface a {} -world my-world-1 { - import a: self.a - import b: pkg.b - import c: io.c // external package - export d: interface exp { ... } +world my-world-a { + import a + import b + import wasi:io/c + export d: interface { ... } } // union.wit +package local:demo -world union-my-world-1 { - include pkg.a.my-world-1 +world union-my-world-a { + include my-world-a } -world union-my-world-2 { - import a: pkg.a - import b: pkg.b - import c: io.c - export d: interface exp { ... } +world union-my-world-b { + import a + import b + import wasi:io/c + + export d: interface { ... } } ``` ### Name Conflicts -When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. +When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. `with` allows the world author to rename the import or export to a different name. -`with` allows the world author to rename the import or export to a different name. For all the imports and exports that are not explicitly renamed, the name of the import or export from the included world is used. - -The following example shows how to resolve name conflicts where `union-my-world-1` and `union-my-world-2` are equivalent: +The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent: ```wit -// my-world-1.wit -world my-world-1 { - import a: self.a1 - import b: self.b1 - export d: self.d -} +package local:demo -// my-world-2.wit -world my-world-2 { - import a: self.a2 - import b: self.b2 - export c: self.c -} +world world-one { import a: func() } +world world-two { import a: func() } -// union.wit -world union-my-world-1 { - include pkg.my-world-1 with { a as a1, b as b1 } - include pkg.my-world-2 +world union-my-world-a { + include foo + include bar with { a as b } } -world union-my-world-2 { - // resolve conflicts - import a1: pkg.my-world-1.a1 - import b1: pkg.my-world-1.b1 - export d: pkg.my-world-1.d - - import a: pkg.my-world-2.a2 - import b: pkg.my-world-2.b2 - export c: pkg.my-world-2.c +world union-my-world-b { + import a: func() + import b: func() } ``` ### De-duplication -If two interfaces have the same structure, then these two interfaces are considered to be structurally equivalent. The `include` statement can -deduplicate the imports and exports of the included worlds if the they are structurally equivalent following the [Subtyping](Subtyping.md) rules. For example, the following world `union-my-world-3` is equivalent to `union-my-world-4`: - -```wit -// my-world-1.wit -world my-world-1 { - import a1: pkg.a - import b1: pkg.b - export c1: pkg.c -} - -// my-world-2.wit -world my-world-2 { - import a1: pkg.a - import b1: pkg.b - export c1: pkg.c -} - -// union.wit -world union-my-world-3 { - include pkg.my-world-1 - include pkg.my-world-2 -} - -world union-my-world-4 { - import a1: pkg.a - import b1: pkg.b - export c1: pkg.c -} -``` - -Notice that if the two included worlds have different names for the same import or export, then it will be considered as an error, even if the interfaces are strcuturally the same. For example, the following worlds `my-world-1` and `my-world-2` are not structurally equivalent, but the `include` statement will report an error: - -```wit -// my-world-1.wit -world my-world-1 { - import a1: pkg.a - import b1: pkg.b - export c1: pkg.c -} - -// my-world-2.wit -world my-world-2 { - import a2: pkg.a - import b2: pkg.b - export c2: pkg.c -} - -// union.wit -world union-my-world-3 { - include pkg.my-world-1 - include pkg.my-world-2 -} -``` - -### De-duplication with `with` - -When two worlds have both name conflicts and structurally equivalent imports and exports, the semantics of `include` will do deduplication first and then resolve the name conflicts with `with` statements. For example, the following world `union-my-world-5` is equivalent to `union-my-world-6`: +If two worlds shared the same set of imports and exports, then the union of the two worlds will only contain one copy of the set of shared imports and exports. For example, the following two worlds `union-my-world-a` and `union-my-world-b` are equivalent: ```wit +package local:demo -// my-world-1.wit -world my-world-1 { - import a1: pkg.a - import b1: pkg.b - export c: pkg.c +world my-world-a { + import a1 + import b1 } -// my-world-2.wit -world my-world-2 { - import a1: pkg.a - import b1: pkg.b - export c: pkg.d +world my-world-b { + import a1 + import b1 } -// union -world union-my-world-5 { - include pkg.my-world-1 with { c as c1 } - include pkg.my-world-2 +world union-my-world-a { + include my-world-a + include my-world-b } -world union-my-world-6 { - import a1: pkg.a - import b1: pkg.b - export c1: pkg.c - export c: pkg.d +world union-my-world-b { + import a1 + import b1 } - ``` ### A Note on SubTyping From be760673a019fbd39a0684ed05587d61f0c1ba59 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Thu, 22 Jun 2023 17:54:20 -0700 Subject: [PATCH 07/13] Update design/mvp/WIT.md Co-authored-by: Guy Bedford --- design/mvp/WIT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index e03ffb0a..f92e4fca 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -914,7 +914,7 @@ to `interface` items. ## Item: `include` -A `include` statement enables union the current world with another world. The structure of an `include` statement is: +A `include` statement enables the union of the current world with another world. The structure of an `include` statement is: ```wit include pkg.my-world-1 with { a as a1, b as b1 } From 926e73f5cca56e2c1164d799b9841846df2c3d17 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Thu, 22 Jun 2023 18:06:15 -0700 Subject: [PATCH 08/13] Add more comments on the deduplication and name conflicts Signed-off-by: Jiaxiao Zhou (Mossaka) --- design/mvp/WIT.md | 50 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index f92e4fca..408f51a6 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -312,10 +312,40 @@ world union-my-world-b { } ``` -### Name Conflicts +### De-duplication of IDs + +If two worlds shared the same set of import and export IDs, then the union of the two worlds will only contain one copy of this set. For example, the following two worlds `union-my-world-a` and `union-my-world-b` are equivalent: + +```wit +package local:demo + +world my-world-a { + import a1 + import b1 +} + +world my-world-b { + import a1 + import b1 +} + +world union-my-world-a { + include my-world-a + include my-world-b +} + +world union-my-world-b { + import a1 + import b1 +} +``` + +### Name Conflicts and `with` When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. `with` allows the world author to rename the import or export to a different name. +Notice that when import or export names are IDs and since IDs are unique, there is no need to resolve name conflicts. Thus the `with` syntax is a no-op in this case. Only when import or export names are kebab names, name conflicts need to be resolved. + The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent: ```wit @@ -335,9 +365,7 @@ world union-my-world-b { } ``` -### De-duplication - -If two worlds shared the same set of imports and exports, then the union of the two worlds will only contain one copy of the set of shared imports and exports. For example, the following two worlds `union-my-world-a` and `union-my-world-b` are equivalent: +The following example shows that `with` is a no-op when the import or export name is an ID: ```wit package local:demo @@ -353,13 +381,13 @@ world my-world-b { } world union-my-world-a { - include my-world-a - include my-world-b + include my-world-a with { a1 as a3 } + include my-world-b with { a1 as a2 } } -world union-my-world-b { - import a1 - import b1 +world union-my-world-a { + import a1 + import b1 } ``` @@ -917,8 +945,8 @@ to `interface` items. A `include` statement enables the union of the current world with another world. The structure of an `include` statement is: ```wit -include pkg.my-world-1 with { a as a1, b as b1 } -include self.my-world-2 +include wasi:io/my-world-1 with { a as a1, b as b1 } +include my-world-2 ``` ```ebnf From 327f3faefa2fda3601f233144e8bad5a1fba6bde Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Fri, 23 Jun 2023 10:36:13 -0700 Subject: [PATCH 09/13] Update design/mvp/WIT.md Co-authored-by: Luke Wagner --- design/mvp/WIT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 408f51a6..88c186a4 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -287,7 +287,7 @@ The `include` statement also works with [WIT package](#wit-packages-and-use) def interface b { ... } // a.wit -interface a {} +interface a { ... } world my-world-a { import a From 0a607ba2808855b74558877bbaa3e75741059035 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Fri, 23 Jun 2023 10:36:22 -0700 Subject: [PATCH 10/13] Update design/mvp/WIT.md Co-authored-by: Luke Wagner --- design/mvp/WIT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 88c186a4..f6783738 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -954,7 +954,7 @@ include-item ::= 'include' use-path | 'include' use-path 'with' '{' include-names-list '}' include-names-list ::= include-names-item - | include-names-item ',' include-names-item? + | include-names-list ',' include-names-item include-names-item ::= id 'as' id ``` From 2d7e6f2b76b760f5b55578e6d6a300b29a8c4c27 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Fri, 23 Jun 2023 10:49:57 -0700 Subject: [PATCH 11/13] made the following case "include with {...}" invalid Signed-off-by: Jiaxiao Zhou (Mossaka) --- design/mvp/WIT.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index f6783738..f4a153a0 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -283,10 +283,9 @@ world union-my-world { The `include` statement also works with [WIT package](#wit-packages-and-use) defined below with the same semantics. For example, the following World `union-my-world-a` is equivalent to `union-my-world-b`: ```wit -// b.wit -interface b { ... } +package local:demo -// a.wit +interface b { ... } interface a { ... } world my-world-a { @@ -296,9 +295,6 @@ world my-world-a { export d: interface { ... } } -// union.wit -package local:demo - world union-my-world-a { include my-world-a } @@ -344,7 +340,7 @@ world union-my-world-b { When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. `with` allows the world author to rename the import or export to a different name. -Notice that when import or export names are IDs and since IDs are unique, there is no need to resolve name conflicts. Thus the `with` syntax is a no-op in this case. Only when import or export names are kebab names, name conflicts need to be resolved. +Notice that when import or export names are IDs and since IDs are unique, there is no need to resolve name conflicts. Thus the `with` syntax is invalid when used with `include `. Only when import or export names are kebab names, name conflicts need to be resolved. The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent: @@ -365,9 +361,9 @@ world union-my-world-b { } ``` -The following example shows that `with` is a no-op when the import or export name is an ID: +The following example shows an invalid example that `with` is used when the import or export name is an ID: -```wit +```wi package local:demo world my-world-a { @@ -384,11 +380,6 @@ world union-my-world-a { include my-world-a with { a1 as a3 } include my-world-b with { a1 as a2 } } - -world union-my-world-a { - import a1 - import b1 -} ``` ### A Note on SubTyping From 5f4f5e041b6d3d4fa796f910f2c2140781ab2dd9 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Fri, 23 Jun 2023 13:14:41 -0700 Subject: [PATCH 12/13] Update design/mvp/WIT.md Co-authored-by: Luke Wagner --- design/mvp/WIT.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index f4a153a0..f7dfedbe 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -338,10 +338,7 @@ world union-my-world-b { ### Name Conflicts and `with` -When two or more included Worlds have the same name for an import or export, the name is considered to be in conflict. The conflict needs to be explicitly resolved by the world author using the `with` keyword. `with` allows the world author to rename the import or export to a different name. - -Notice that when import or export names are IDs and since IDs are unique, there is no need to resolve name conflicts. Thus the `with` syntax is invalid when used with `include `. Only when import or export names are kebab names, name conflicts need to be resolved. - +When two or more included Worlds have the same name for an import or export that does *not* have an ID, automatic de-duplication cannot be used (because the two same-named imports/exports might have different meanings in the different worlds) and thus the conflict has to be resolved manually using the `with` keyword: The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent: ```wit From 0820d22e1783719a904c614952d5bf157af46d7f Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Fri, 23 Jun 2023 13:14:58 -0700 Subject: [PATCH 13/13] Update design/mvp/WIT.md Co-authored-by: Luke Wagner --- design/mvp/WIT.md | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index f7dfedbe..b6c6033e 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -358,26 +358,21 @@ world union-my-world-b { } ``` -The following example shows an invalid example that `with` is used when the import or export name is an ID: - -```wi +`with` cannot be used to rename IDs, however, so the following world would be invalid: +```wit package local:demo -world my-world-a { - import a1 - import b1 +interface a { + foo: func() } -world my-world-b { - import a1 - import b1 +world world-using-a { + import a } -world union-my-world-a { - include my-world-a with { a1 as a3 } - include my-world-b with { a1 as a2 } +world invalid-union-world { + include my-using-a with { a as b } // invalid: 'a', which is short for 'local:demo/a', is an ID } -``` ### A Note on SubTyping