Skip to content

Commit 18399df

Browse files
authored
Merge pull request #27 from badeend/rename-defaults-to
Avoid potential name clash with default values.
2 parents 06cc296 + d4a0c42 commit 18399df

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

design/mvp/Binary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ intertype ::= pit:<primintertype> => pit
162162
| 0x69 t:<intertypeuse> u:<intertypeuse> => (expected t u)
163163
field ::= n:<name> t:<intertypeuse> => (field n t)
164164
case ::= n:<name> t:<intertypeuse> 0x0 => (case n t)
165-
| n:<name> t:<intertypeuse> 0x1 i:<varu32> => (case n t (defaults-to case-label[i]))
165+
| n:<name> t:<intertypeuse> 0x1 i:<varu32> => (case n t (refines case-label[i]))
166166
```
167167
Notes:
168168
* Reused Core binary rules: [`core:import`], [`core:importdesc`], [`core:functype`]

design/mvp/CanonicalABI.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ guaranteed to be a no-op on the first iteration because the record as
347347
a whole starts out aligned (as asserted at the top of `load`).
348348

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

367-
def case_label_with_defaults(case, cases):
367+
def case_label_with_refinements(case, cases):
368368
label = case.label
369-
while case.defaults_to is not None:
370-
case = cases[find_case(case.defaults_to, cases)]
369+
while case.refines is not None:
370+
case = cases[find_case(case.refines, cases)]
371371
label += '|' + case.label
372372
return label
373373

@@ -665,8 +665,8 @@ def store_record(opts, v, ptr, fields):
665665
ptr += size(f.t)
666666
```
667667

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

929929
def narrow_i64_to_i32(i):
930930
assert(0 <= i < (1 << 64))

design/mvp/Explainer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ intertype ::= unit | bool
332332
| float32 | float64
333333
| char | string
334334
| (record (field <name> <intertype>)*)
335-
| (variant (case <name> <intertype> (defaults-to <name>)?)+)
335+
| (variant (case <name> <intertype> (refines <name>)?)+)
336336
| (list <intertype>)
337337
| (tuple <intertype>*)
338338
| (flags <name>*)
@@ -378,9 +378,9 @@ NaN values are canonicalized to a single value so that:
378378

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

386386
The sets of values allowed for the remaining *specialized* interface types are

design/mvp/Subtyping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ But roughly speaking:
1212
| `float32`, `float64` | `float32 <: float64` |
1313
| `char` | |
1414
| `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 |
15-
| `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 |
15+
| `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 |
1616
| `list` | covariant element subtyping |
1717
| `tuple` | `(tuple T ...) <: T` |
1818
| `option` | `T <: (option T)` |

design/mvp/canonical-abi/definitions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Flags(InterfaceType):
6060
class Case:
6161
label: str
6262
t: InterfaceType
63-
defaults_to: str = None
63+
refines: str = None
6464

6565
@dataclass
6666
class Variant(InterfaceType):
@@ -325,12 +325,12 @@ def load_variant(opts, ptr, cases):
325325
trap_if(disc >= len(cases))
326326
case = cases[disc]
327327
ptr = align_to(ptr, max_alignment(types_of(cases)))
328-
return { case_label_with_defaults(case, cases): load(opts, ptr, case.t) }
328+
return { case_label_with_refinements(case, cases): load(opts, ptr, case.t) }
329329

330-
def case_label_with_defaults(case, cases):
330+
def case_label_with_refinements(case, cases):
331331
label = case.label
332-
while case.defaults_to is not None:
333-
case = cases[find_case(case.defaults_to, cases)]
332+
while case.refines is not None:
333+
case = cases[find_case(case.refines, cases)]
334334
label += '|' + case.label
335335
return label
336336

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

748748
def narrow_i64_to_i32(i):
749749
assert(0 <= i < (1 << 64))

0 commit comments

Comments
 (0)