You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: design/mvp/WIT.md
+58-29Lines changed: 58 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,8 +187,7 @@ explicitly chosen then bindings cannot be generated.
187
187
188
188
### Union of Worlds with `include`
189
189
190
-
A World can be created by taking the union of two or more worlds. This operation allows
191
-
world builders to form larger worlds from smaller worlds.
190
+
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.
192
191
193
192
Below is a simple example of a world that includes two other worlds.
194
193
@@ -212,9 +211,7 @@ world union-my-world {
212
211
}
213
212
```
214
213
215
-
The `include` statement is used to include the imports and exports of another World to the
216
-
current World. It says that the new World should be able to run all components that target
217
-
the included worlds and more.
214
+
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.
218
215
219
216
The `union-my-world` World defined above is equivalent to the following World:
220
217
@@ -270,15 +267,15 @@ The following example shows how to resolve name conflicts where `union-my-world-
270
267
```wit
271
268
// my-world-1.wit
272
269
world my-world-1 {
273
-
import a: self.a
274
-
import b: self.b
270
+
import a: self.a1
271
+
import b: self.b1
275
272
export d: self.d
276
273
}
277
274
278
275
// my-world-2.wit
279
276
world my-world-2 {
280
-
import a: self.a
281
-
import b: self.b
277
+
import a: self.a2
278
+
import b: self.b2
282
279
export c: self.c
283
280
}
284
281
@@ -290,39 +287,34 @@ world union-my-world-1 {
290
287
291
288
world union-my-world-2 {
292
289
// resolve conflicts
293
-
import a1: pkg.my-world-1.a
294
-
import b1: pkg.my-world-1.b
290
+
import a1: pkg.my-world-1.a1
291
+
import b1: pkg.my-world-1.b1
295
292
export d: pkg.my-world-1.d
296
293
297
-
import a: pkg.my-world-2.a
298
-
import b: pkg.my-world-2.b
294
+
import a: pkg.my-world-2.a2
295
+
import b: pkg.my-world-2.b2
299
296
export c: pkg.my-world-2.c
300
297
}
301
298
```
302
299
303
-
### De-duplication (In the future)
304
-
305
-
As of now, the `include` statement requires the world author to explicitly rename the imports and exports that have the same name.
300
+
### De-duplication
306
301
307
-
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`:
302
+
If two interfaces have the same structure, then these two interfaces are considered to be structurally equivalent. The `include` statement can
303
+
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`:
308
304
309
305
```wit
310
-
// a.wit
311
-
// b.wit
312
-
// c.wit
313
-
314
306
// my-world-1.wit
315
307
world my-world-1 {
316
-
import a: pkg.a
317
-
import b: pkg.b
318
-
export c: pkg.c
308
+
import a1: pkg.a
309
+
import b1: pkg.b
310
+
export c1: pkg.c
319
311
}
320
312
321
313
// my-world-2.wit
322
314
world my-world-2 {
323
-
import a: pkg.a
324
-
import b: pkg.b
325
-
export c: pkg.c
315
+
import a2: pkg.a
316
+
import b2: pkg.b
317
+
export c2: pkg.c
326
318
}
327
319
328
320
// union.wit
@@ -332,10 +324,47 @@ world union-my-world-3 {
332
324
}
333
325
334
326
world union-my-world-4 {
335
-
import a: pkg.a
336
-
import b: pkg.b
327
+
import a1: pkg.a
328
+
import b1: pkg.b
329
+
export c1: pkg.c
330
+
}
331
+
```
332
+
333
+
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.
334
+
335
+
### De-duplication with `with`
336
+
337
+
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`:
0 commit comments