Skip to content

Commit 8f0a917

Browse files
authored
Remove 'union' types (#237)
1 parent a380d77 commit 8f0a917

File tree

7 files changed

+2
-76
lines changed

7 files changed

+2
-76
lines changed

design/mvp/Binary.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ defvaltype ::= pvt:<primvaltype> => pvt
202202
| 0x6f t*:vec(<valtype>) => (tuple t+) (if |t*| > 0)
203203
| 0x6e l*:vec(<label>) => (flags l+) (if |l*| > 0)
204204
| 0x6d l*:vec(<label>) => (enum l*)
205-
| 0x6c t*:vec(<valtype>) => (union t*)
206205
| 0x6b t:<valtype> => (option t)
207206
| 0x6a t?:<valtype>? u?:<valtype>? => (result t? (error u)?)
208207
| 0x69 i:<typeidx> => (own i)

design/mvp/CanonicalABI.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function to replace specialized value types with their expansion:
7474
def despecialize(t):
7575
match t:
7676
case Tuple(ts) : return Record([ Field(str(i), t) for i,t in enumerate(ts) ])
77-
case Union(ts) : return Variant([ Case(str(i), t) for i,t in enumerate(ts) ])
7877
case Enum(labels) : return Variant([ Case(l, None) for l in labels ])
7978
case Option(t) : return Variant([ Case("none", None), Case("some", t) ])
8079
case Result(ok, error) : return Variant([ Case("ok", ok), Case("error", error) ])

design/mvp/Explainer.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ defvaltype ::= bool
493493
| (tuple <valtype>+)
494494
| (flags <label>+)
495495
| (enum <label>+)
496-
| (union <valtype>+)
497496
| (option <valtype>)
498497
| (result <valtype>? (error <valtype>)?)
499498
| (own <typeidx>)
@@ -588,7 +587,6 @@ defined by the following mapping:
588587
(flags <label>*) ↦ (record (field <label> bool)*)
589588
(enum <label>+) ↦ (variant (case <label>)+)
590589
(option <valtype>) ↦ (variant (case "none") (case "some" <valtype>))
591-
(union <valtype>+) ↦ (variant (case "𝒊" <valtype>)+) for 𝒊=0,1,...
592590
(result <valtype>? (error <valtype>)?) ↦ (variant (case "ok" <valtype>?) (case "error" <valtype>?))
593591
string ↦ (list char)
594592
```
@@ -1666,7 +1664,6 @@ At a high level, the additional coercions would be:
16661664
| `flags` | TBD: maybe a [JS Record]? | same as [`dictionary`] of optional `boolean` fields with default values of `false` |
16671665
| `enum` | same as [`enum`] | same as [`enum`] |
16681666
| `option` | same as [`T?`] | same as [`T?`] |
1669-
| `union` | same as [`union`] | same as [`union`] |
16701667
| `result` | same as `variant`, but coerce a top-level `error` return value to a thrown exception | same as `variant`, but coerce uncaught exceptions to top-level `error` return values |
16711668
| `own`, `borrow` | see below | see below |
16721669

@@ -1682,7 +1679,7 @@ Notes:
16821679
would need to define its own custom binding built from objects. As a sketch,
16831680
the JS values accepted by `(variant (case "a" u32) (case "b" string))` could
16841681
include `{ tag: 'a', value: 42 }` and `{ tag: 'b', value: "hi" }`.
1685-
* For `union` and `option`, when Web IDL doesn't support particular type
1682+
* For `option`, when Web IDL doesn't support particular type
16861683
combinations (e.g., `(option (option u32))`), the JS API would fall back to
16871684
the JS API of the unspecialized `variant` (e.g.,
16881685
`(variant (case "some" (option u32)) (case "none"))`, despecializing only
@@ -1838,7 +1835,6 @@ and will be added over the coming months to complete the MVP proposal:
18381835
[`dictionary`]: https://webidl.spec.whatwg.org/#es-dictionary
18391836
[`enum`]: https://webidl.spec.whatwg.org/#es-enumeration
18401837
[`T?`]: https://webidl.spec.whatwg.org/#es-nullable-type
1841-
[`union`]: https://webidl.spec.whatwg.org/#es-union
18421838
[`Get`]: https://tc39.es/ecma262/#sec-get-o-p
18431839
[JS NaN]: https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type
18441840
[Import Reflection]: https://github.com/tc39-transfer/proposal-import-reflection

design/mvp/Subtyping.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ But roughly speaking:
1616
| `tuple` | `(tuple T ...) <: T` |
1717
| `option` | `T <: (option T)` |
1818
| `result` | `T <: (result T _)` |
19-
| `union` | `T <: (union ... T ...)` |
2019
| `own`, `borrow` | none (although resource subtyping may be introduced in the future which would imply handle subtyping) |
2120
| `func` | parameter names must match in order; contravariant parameter subtyping; superfluous parameters can be ignored in the subtype; `option` parameters can be ignored in the supertype; covariant result subtyping |
2221
| `component` | all imports in the subtype must be present in the supertype with matching types; all exports in the supertype must be present in the subtype |

design/mvp/WIT.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,6 @@ interface foo {
712712
too-slow,
713713
}
714714
715-
// similar to `variant`, but doesn't require naming cases and all variants
716-
// have a type payload -- note that this is not a C union, it still has a
717-
// discriminant
718-
union input {
719-
u64,
720-
string,
721-
}
722-
723715
// a bitflags type
724716
flags permissions {
725717
read,
@@ -742,7 +734,7 @@ interface foo {
742734
}
743735
```
744736

745-
The `record`, `variant`, `enum`, `union`, and `flags` types must all have names
737+
The `record`, `variant`, `enum`, and `flags` types must all have names
746738
associated with them. The `list`, `option`, `result`, `tuple`, and primitive
747739
types do not need a name and can be mentioned in any context. This restriction
748740
is in place to assist with code generation in all languages to leverage
@@ -839,7 +831,6 @@ keyword ::= 'use'
839831
| 'enum'
840832
| 'flags'
841833
| 'variant'
842-
| 'union'
843834
| 'static'
844835
| 'interface'
845836
| 'world'
@@ -964,7 +955,6 @@ interface-items ::= typedef-item
964955
typedef-item ::= resource-item
965956
| variant-items
966957
| record-item
967-
| union-items
968958
| flags-items
969959
| enum-items
970960
| type-item
@@ -1143,29 +1133,6 @@ enum-cases ::= id
11431133
| id ',' enum-cases?
11441134
```
11451135

1146-
### Item: `union` (variant but with no case names)
1147-
1148-
A `union` statement defines a new type which is semantically equivalent to a
1149-
`variant` where all of the cases have a payload type and the case names are
1150-
numerical. This is special-cased, however, to have a different representation
1151-
in the language ABIs or have different bindings generated in for languages.
1152-
1153-
```wit
1154-
union configuration {
1155-
string,
1156-
list<string>,
1157-
}
1158-
```
1159-
1160-
Specifically the structure of this is:
1161-
1162-
```ebnf
1163-
union-items ::= 'union' id '{' union-cases '}'
1164-
1165-
union-cases ::= ty
1166-
| ty ',' union-cases?
1167-
```
1168-
11691136
### Item: `resource`
11701137

11711138
A `resource` statement defines a new abstract type for a *resource*, which is

design/mvp/canonical-abi/definitions.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ class Variant(ValType):
141141
class Enum(ValType):
142142
labels: [str]
143143

144-
@dataclass
145-
class Union(ValType):
146-
ts: [ValType]
147-
148144
@dataclass
149145
class Option(ValType):
150146
t: ValType
@@ -171,7 +167,6 @@ class Borrow(ValType):
171167
def despecialize(t):
172168
match t:
173169
case Tuple(ts) : return Record([ Field(str(i), t) for i,t in enumerate(ts) ])
174-
case Union(ts) : return Variant([ Case(str(i), t) for i,t in enumerate(ts) ])
175170
case Enum(labels) : return Variant([ Case(l, None) for l in labels ])
176171
case Option(t) : return Variant([ Case("none", None), Case("some", t) ])
177172
case Result(ok, error) : return Variant([ Case("ok", ok), Case("error", error) ])

design/mvp/canonical-abi/run_tests.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,6 @@ def test_name():
114114
test(t, [0,256], {'x': 0})
115115
test(t, [1,0x4048f5c3], {'y': 3.140000104904175})
116116
test(t, [2,0xffffffff], {'z': None})
117-
t = Union([U32(),U64()])
118-
test(t, [0,42], {'0':42})
119-
test(t, [0,(1<<35)], {'0':0})
120-
test(t, [1,(1<<35)], {'1':(1<<35)})
121-
t = Union([Float32(), U64()])
122-
test(t, [0,0x4048f5c3], {'0': 3.140000104904175})
123-
test(t, [0,(1<<35)], {'0': 0})
124-
test(t, [1,(1<<35)], {'1': (1<<35)})
125-
t = Union([Float64(), U64()])
126-
test(t, [0,0x40091EB851EB851F], {'0': 3.14})
127-
test(t, [0,(1<<35)], {'0': 1.69759663277e-313})
128-
test(t, [1,(1<<35)], {'1': (1<<35)})
129-
t = Union([U8()])
130-
test(t, [0,42], {'0':42})
131-
test(t, [1,256], None)
132-
test(t, [0,256], {'0':0})
133-
t = Union([Tuple([U8(),Float32()]), U64()])
134-
test(t, [0,42,3.14], {'0': {'0':42, '1':3.14}})
135-
test(t, [1,(1<<35),0], {'1': (1<<35)})
136117
t = Option(Float32())
137118
test(t, [0,3.14], {'none':None})
138119
test(t, [1,3.14], {'some':3.14})
@@ -279,16 +260,6 @@ def test_heap(t, expect, args, byte_array):
279260
[6,0, 7, 0x0ff, 8,0, 9, 0xff])
280261
test_heap(List(Tuple([Tuple([U16(),U8()]),U8()])), [mk_tup([4,5],6),mk_tup([7,8],9)], [0,2],
281262
[4,0, 5,0xff, 6,0xff, 7,0, 8,0xff, 9,0xff])
282-
# Empty record types are not permitted yet.
283-
#test_heap(List(Union([Record([]),U8(),Tuple([U8(),U16()])])), [{'0':{}}, {'1':42}, {'2':mk_tup(6,7)}], [0,3],
284-
# [0,0xff,0xff,0xff,0xff,0xff, 1,0xff,42,0xff,0xff,0xff, 2,0xff,6,0xff,7,0])
285-
test_heap(List(Union([U32(),U8()])), [{'0':256}, {'1':42}], [0,2],
286-
[0,0xff,0xff,0xff,0,1,0,0, 1,0xff,0xff,0xff,42,0xff,0xff,0xff])
287-
test_heap(List(Tuple([Union([U8(),Tuple([U16(),U8()])]),U8()])),
288-
[mk_tup({'1':mk_tup(5,6)},7),mk_tup({'0':8},9)], [0,2],
289-
[1,0xff,5,0,6,0xff,7,0xff, 0,0xff,8,0xff,0xff,0xff,9,0xff])
290-
test_heap(List(Union([U8()])), [{'0':6},{'0':7},{'0':8}], [0,3],
291-
[0,6, 0,7, 0,8])
292263
# Empty flags types are not permitted yet.
293264
#t = List(Flags([]))
294265
#test_heap(t, [{},{},{}], [0,3],

0 commit comments

Comments
 (0)