diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 5b60545b..4db0707f 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -162,7 +162,7 @@ intertype ::= pit: => pit | 0x69 t: u: => (expected t u) field ::= n: t: => (field n t) case ::= n: t: 0x0 => (case n t) - | n: t: 0x1 i: => (case n t (defaults-to case-label[i])) + | n: t: 0x1 i: => (case n t (refines case-label[i])) ``` Notes: * Reused Core binary rules: [`core:import`], [`core:importdesc`], [`core:functype`] diff --git a/design/mvp/CanonicalABI.md b/design/mvp/CanonicalABI.md index eca2100f..96c45923 100644 --- a/design/mvp/CanonicalABI.md +++ b/design/mvp/CanonicalABI.md @@ -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 @@ -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 @@ -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 @@ -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)) diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index 351fbd0c..85d418a1 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -332,7 +332,7 @@ intertype ::= unit | bool | float32 | float64 | char | string | (record (field )*) - | (variant (case (defaults-to )?)+) + | (variant (case (refines )?)+) | (list ) | (tuple *) | (flags *) @@ -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 diff --git a/design/mvp/Subtyping.md b/design/mvp/Subtyping.md index 36c6277b..608dc088 100644 --- a/design/mvp/Subtyping.md +++ b/design/mvp/Subtyping.md @@ -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)` | diff --git a/design/mvp/canonical-abi/definitions.py b/design/mvp/canonical-abi/definitions.py index a664d2c9..949ae02e 100644 --- a/design/mvp/canonical-abi/definitions.py +++ b/design/mvp/canonical-abi/definitions.py @@ -60,7 +60,7 @@ class Flags(InterfaceType): class Case: label: str t: InterfaceType - defaults_to: str = None + refines: str = None @dataclass class Variant(InterfaceType): @@ -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 @@ -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))