Skip to content

Commit aab97d1

Browse files
authored
Merge pull request #144 from WebAssembly/fix-example
Fix syntax error in example
2 parents 006b97c + 07e1079 commit aab97d1

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

design/mvp/Explainer.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,27 +926,45 @@ bind a fresh abstract type. For example, in the following component:
926926
all four types aliases in the outer component are unequal, reflecting the fact
927927
that each instance of `$C` generates two fresh resource types.
928928

929-
However, even if a single resource type definition is exported twice with `sub`
930-
bounds, clients must *still* treat the two types as abstract and thus unequal;
931-
the fact that the underlying concrete type is the same is kept an encapsulated
932-
implementation detail. For example, in the following component:
929+
If a single resource type definition is exported twice, clients must *still*
930+
treat each export as abstract and thus unequal; the fact that the underlying
931+
concrete type is the same is kept an encapsulated implementation detail. For
932+
example, the following component:
933933
```wasm
934934
(component
935935
(type $r (resource (rep i32)))
936-
(export "r1" (type (sub $r)))
937-
(export "r2" (type (sub $r)))
936+
(export "r1" (type $r))
937+
(export "r2" (type $r))
938938
)
939939
```
940-
Any client of this component will treat `r1` and `r2` as totally distinct
941-
types since this component definition has the `componenttype`:
940+
is assigned the following `componenttype`:
942941
```wasm
943942
(component
944943
(export "r1" (type (sub resource)))
945944
(export "r2" (type (sub resource)))
946945
)
947946
```
948-
The assignment of this type to the above component mirrors the *introduction*
949-
rule of [existential types] (∃T).
947+
Thus, from an external perspective, `r1` and `r2` are completely distinct. The
948+
assignment of this type to the above component mirrors the *introduction* rule
949+
of [existential types] (∃T).
950+
951+
If a component *wants* to publicly export a single private resource type twice
952+
with the second export equal to the first, it can do so by having the second
953+
export refer to the type index introduced by the first export. For example, the
954+
following component:
955+
```wasm
956+
(component
957+
(type $r (resource (rep i32)))
958+
(export $r1 "r1" (type $r))
959+
(export "r2" (type $r1))
960+
```
961+
is assigned the following `componenttype`:
962+
```wasm
963+
(component
964+
(export $r1 "r1" (type (sub resource)))
965+
(export "r2" (type (eq $r1)))
966+
)
967+
```
950968

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

0 commit comments

Comments
 (0)