Skip to content

Commit 4b7e5f5

Browse files
committed
Make multiple exports of the same type definition equal by default
Merge pull request #180 from WebAssembly/change-multiple-type-export
1 parent ba5ce25 commit 4b7e5f5

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

design/mvp/Explainer.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,9 @@ bind a fresh abstract type. For example, in the following component:
930930
all four types aliases in the outer component are unequal, reflecting the fact
931931
that each instance of `$C` generates two fresh resource types.
932932

933-
If a single resource type definition is exported twice, clients must *still*
934-
treat each export as abstract and thus unequal; the fact that the underlying
935-
concrete type is the same is kept an encapsulated implementation detail. For
936-
example, the following component:
933+
If a single resource type definition is exported greater than once, the exports
934+
after the first are equality-bound to the first export. For example, the
935+
following component:
937936
```wasm
938937
(component
939938
(type $r (resource (rep i32)))
@@ -944,32 +943,34 @@ example, the following component:
944943
is assigned the following `componenttype`:
945944
```wasm
946945
(component
947-
(export "r1" (type (sub resource)))
948-
(export "r2" (type (sub resource)))
946+
(export $r1 "r1" (type (sub resource)))
947+
(export "r2" (type (eq $r1)))
949948
)
950949
```
951-
Thus, from an external perspective, `r1` and `r2` are completely distinct. The
952-
assignment of this type to the above component mirrors the *introduction* rule
953-
of [existential types] (∃T).
950+
Thus, from an external perspective, `r1` and `r2` are two labels for the same
951+
type.
954952

955-
If a component *wants* to publicly export a single private resource type twice
956-
with the second export equal to the first, it can do so by having the second
957-
export refer to the type index introduced by the first export. For example, the
958-
following component:
953+
If a component wants to hide this fact and force clients to assume `r1` and
954+
`r2` are distinct types (thereby allowing the implementation to actually use
955+
separate types in the future without breaking clients), an explicit type can be
956+
ascribed to the export that replaces the `eq` bound with a less-precise `sub`
957+
bound.
959958
```wasm
960959
(component
961960
(type $r (resource (rep i32)))
962-
(export $r1 "r1" (type $r))
963-
(export "r2" (type $r1))
961+
(export "r1" (type $r)
962+
(export "r2" (type $r) (type (sub resource)))
964963
)
965964
```
966-
is assigned the following `componenttype`:
965+
This component is assigned the following `componenttype`:
967966
```wasm
968967
(component
969-
(export $r1 "r1" (type (sub resource)))
970-
(export "r2" (type (eq $r1)))
968+
(export "r1" (type (sub resource)))
969+
(export "r2" (type (sub resource)))
971970
)
972971
```
972+
The assignment of this type to the above component mirrors the *introduction*
973+
rule of [existential types] (∃T).
973974

974975
When supplying a resource type (imported *or* defined) to a type import via
975976
`instantiate`, type checking performs a substitution, replacing all uses of the

0 commit comments

Comments
 (0)