Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion design/mvp/Binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ intertype ::= pit:<primintertype> => pit
| 0x69 t:<intertypeuse> u:<intertypeuse> => (expected t u)
field ::= n:<name> t:<intertypeuse> => (field n t)
case ::= n:<name> t:<intertypeuse> 0x0 => (case n t)
| n:<name> t:<intertypeuse> 0x1 i:<varu32> => (case n t (defaults-to case-label[i]))
| n:<name> t:<intertypeuse> 0x1 i:<varu32> => (case n t (refines case-label[i]))
```
Notes:
* Reused Core binary rules: [`core:import`], [`core:importdesc`], [`core:functype`]
Expand Down
18 changes: 9 additions & 9 deletions design/mvp/CanonicalABI.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ guaranteed to be a no-op on the first iteration because the record as
a whole starts out aligned (as asserted at the top of `load`).

Variants are loaded using the order of the cases in the type to determine the
case index. To support the subtyping allowed by `defaults-to`, a lifted variant
value semantically includes a full ordered list of its `defaults-to` case
case index. To support the subtyping allowed by `refines`, a lifted variant
value semantically includes a full ordered list of its `refines` case
labels so that the lowering code (defined below) can search this list to find a
case label it knows about. While the code below appears to perform case-label
lookup at runtime, a normal implementation can build the appropriate index
Expand All @@ -362,12 +362,12 @@ def load_variant(opts, ptr, cases):
trap_if(disc >= len(cases))
case = cases[disc]
ptr = align_to(ptr, max_alignment(types_of(cases)))
return { case_label_with_defaults(case, cases): load(opts, ptr, case.t) }
return { case_label_with_refinements(case, cases): load(opts, ptr, case.t) }

def case_label_with_defaults(case, cases):
def case_label_with_refinements(case, cases):
label = case.label
while case.defaults_to is not None:
case = cases[find_case(case.defaults_to, cases)]
while case.refines is not None:
case = cases[find_case(case.refines, cases)]
label += '|' + case.label
return label

Expand Down Expand Up @@ -665,8 +665,8 @@ def store_record(opts, v, ptr, fields):
ptr += size(f.t)
```

Variants are stored using the `|`-separated list of `defaults-to` cases built
by `case_label_with_default` (above) to iteratively find a matching case (which
Variants are stored using the `|`-separated list of `refines` cases built
by `case_label_with_refinements` (above) to iteratively find a matching case (which
validation guarantees will succeed). While this code appears to do O(n) string
matching, a normal implementation can statically fuse `store_variant` with its
matching `load_variant` to ultimately build a dense array that maps producer's
Expand Down Expand Up @@ -924,7 +924,7 @@ def lift_flat_variant(opts, vi, cases):
v = lift_flat(opts, CoerceValueIter(), case.t)
for have in flat_types:
_ = vi.next(have)
return { case_label_with_defaults(case, cases): v }
return { case_label_with_refinements(case, cases): v }

def narrow_i64_to_i32(i):
assert(0 <= i < (1 << 64))
Expand Down
6 changes: 3 additions & 3 deletions design/mvp/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ intertype ::= unit | bool
| float32 | float64
| char | string
| (record (field <name> <intertype>)*)
| (variant (case <name> <intertype> (defaults-to <name>)?)+)
| (variant (case <name> <intertype> (refines <name>)?)+)
| (list <intertype>)
| (tuple <intertype>*)
| (flags <name>*)
Expand Down Expand Up @@ -378,9 +378,9 @@ NaN values are canonicalized to a single value so that:

The subtyping between all these types is described in a separate
[subtyping explainer](Subtyping.md). Of note here, though: the optional
`defaults-to` field in the `case`s of `variant`s is exclusively concerned with
`refines` field in the `case`s of `variant`s is exclusively concerned with
subtyping. In particular, a `variant` subtype can contain a `case` not present
in the supertype if the subtype's `case` `defaults-to` (directly or transitively)
in the supertype if the subtype's `case` `refines` (directly or transitively)
some `case` in the supertype.

The sets of values allowed for the remaining *specialized* interface types are
Expand Down
2 changes: 1 addition & 1 deletion design/mvp/Subtyping.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ But roughly speaking:
| `float32`, `float64` | `float32 <: float64` |
| `char` | |
| `record` | fields can be reordered; covariant field payload subtyping; superfluous fields can be ignored in the subtype; `option` fields can be ignored in the supertype |
| `variant` | cases can be reordered; covariant case payload subtyping; superfluous cases can be ignored in the supertype; `defaults-to` cases can be ignored in the subtype |
| `variant` | cases can be reordered; covariant case payload subtyping; superfluous cases can be ignored in the supertype; `refines` cases can be ignored in the subtype |
| `list` | covariant element subtyping |
| `tuple` | `(tuple T ...) <: T` |
| `option` | `T <: (option T)` |
Expand Down
12 changes: 6 additions & 6 deletions design/mvp/canonical-abi/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Flags(InterfaceType):
class Case:
label: str
t: InterfaceType
defaults_to: str = None
refines: str = None

@dataclass
class Variant(InterfaceType):
Expand Down Expand Up @@ -325,12 +325,12 @@ def load_variant(opts, ptr, cases):
trap_if(disc >= len(cases))
case = cases[disc]
ptr = align_to(ptr, max_alignment(types_of(cases)))
return { case_label_with_defaults(case, cases): load(opts, ptr, case.t) }
return { case_label_with_refinements(case, cases): load(opts, ptr, case.t) }

def case_label_with_defaults(case, cases):
def case_label_with_refinements(case, cases):
label = case.label
while case.defaults_to is not None:
case = cases[find_case(case.defaults_to, cases)]
while case.refines is not None:
case = cases[find_case(case.refines, cases)]
label += '|' + case.label
return label

Expand Down Expand Up @@ -743,7 +743,7 @@ def next(self, want):
v = lift_flat(opts, CoerceValueIter(), case.t)
for have in flat_types:
_ = vi.next(have)
return { case_label_with_defaults(case, cases): v }
return { case_label_with_refinements(case, cases): v }

def narrow_i64_to_i32(i):
assert(0 <= i < (1 << 64))
Expand Down