Skip to content

Commit b07d794

Browse files
alexcrichtonsunfishcode
authored andcommitted
Implement Union in terms of Variant
1 parent 1e48303 commit b07d794

File tree

18 files changed

+360
-498
lines changed

18 files changed

+360
-498
lines changed

phases/ephemeral/docs.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -859,20 +859,18 @@ The state of the file descriptor.
859859

860860
Offset: 8
861861

862-
## <a href="#event_u" name="event_u"></a> `event_u`: Union
862+
## <a href="#event_u" name="event_u"></a> `event_u`: Variant
863863
The contents of an [`event`](#event).
864864

865865
Size: 24
866866

867867
Alignment: 8
868868

869-
### Union Layout
869+
### Variant Layout
870+
- size: 24
871+
- align: 8
870872
- tag_size: 1
871-
- tag_align: 1
872-
- contents_offset: 8
873-
- contents_size: 16
874-
- contents_align: 8
875-
### Union variants
873+
### Variant cases
876874
- <a href="#event_u.fd_read" name="event_u.fd_read"></a> `fd_read`: [`event_fd_readwrite`](#event_fd_readwrite)
877875

878876
- <a href="#event_u.fd_write" name="event_u.fd_write"></a> `fd_write`: [`event_fd_readwrite`](#event_fd_readwrite)
@@ -961,20 +959,18 @@ The file descriptor on which to wait for it to become ready for reading or writi
961959

962960
Offset: 0
963961

964-
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Union
962+
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Variant
965963
The contents of a [`subscription`](#subscription).
966964

967965
Size: 40
968966

969967
Alignment: 8
970968

971-
### Union Layout
969+
### Variant Layout
970+
- size: 40
971+
- align: 8
972972
- tag_size: 1
973-
- tag_align: 1
974-
- contents_offset: 8
975-
- contents_size: 32
976-
- contents_align: 8
977-
### Union variants
973+
### Variant cases
978974
- <a href="#subscription_u.clock" name="subscription_u.clock"></a> `clock`: [`subscription_clock`](#subscription_clock)
979975

980976
- <a href="#subscription_u.fd_read" name="subscription_u.fd_read"></a> `fd_read`: [`subscription_fd_readwrite`](#subscription_fd_readwrite)
@@ -1078,20 +1074,18 @@ The length of the directory name for use with `fd_prestat_dir_name`.
10781074

10791075
Offset: 0
10801076

1081-
## <a href="#prestat" name="prestat"></a> `prestat`: Union
1077+
## <a href="#prestat" name="prestat"></a> `prestat`: Variant
10821078
Information about a pre-opened capability.
10831079

10841080
Size: 8
10851081

10861082
Alignment: 4
10871083

1088-
### Union Layout
1084+
### Variant Layout
1085+
- size: 8
1086+
- align: 4
10891087
- tag_size: 1
1090-
- tag_align: 1
1091-
- contents_offset: 4
1092-
- contents_size: 4
1093-
- contents_align: 4
1094-
### Union variants
1088+
### Variant cases
10951089
- <a href="#prestat.dir" name="prestat.dir"></a> `dir`: [`prestat_dir`](#prestat_dir)
10961090
When type is [`preopentype::dir`](#preopentype.dir):
10971091

phases/ephemeral/witx/typenames.witx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,10 @@
562562

563563
;;; The contents of an `event`.
564564
(typename $event_u
565-
(union $eventtype
566-
(field $fd_read $event_fd_readwrite)
567-
(field $fd_write $event_fd_readwrite)
568-
(empty $clock)
565+
(variant (@witx tag $eventtype)
566+
(case $fd_read $event_fd_readwrite)
567+
(case $fd_write $event_fd_readwrite)
568+
(case $clock)
569569
)
570570
)
571571

@@ -620,10 +620,10 @@
620620

621621
;;; The contents of a `subscription`.
622622
(typename $subscription_u
623-
(union $eventtype
624-
(field $clock $subscription_clock)
625-
(field $fd_read $subscription_fd_readwrite)
626-
(field $fd_write $subscription_fd_readwrite)
623+
(union (@witx tag $eventtype)
624+
$subscription_clock
625+
$subscription_fd_readwrite
626+
$subscription_fd_readwrite
627627
)
628628
)
629629

@@ -691,8 +691,8 @@
691691

692692
;;; Information about a pre-opened capability.
693693
(typename $prestat
694-
(union $preopentype
694+
(union (@witx tag $preopentype)
695695
;;; When type is `preopentype::dir`:
696-
(field $dir $prestat_dir)
696+
$prestat_dir
697697
)
698698
)

phases/old/snapshot_0/docs.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -899,20 +899,18 @@ The file descriptor on which to wait for it to become ready for reading or writi
899899

900900
Offset: 0
901901

902-
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Union
902+
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Variant
903903
The contents of a [`subscription`](#subscription).
904904

905905
Size: 48
906906

907907
Alignment: 8
908908

909-
### Union Layout
909+
### Variant Layout
910+
- size: 48
911+
- align: 8
910912
- tag_size: 1
911-
- tag_align: 1
912-
- contents_offset: 8
913-
- contents_size: 40
914-
- contents_align: 8
915-
### Union variants
913+
### Variant cases
916914
- <a href="#subscription_u.clock" name="subscription_u.clock"></a> `clock`: [`subscription_clock`](#subscription_clock)
917915

918916
- <a href="#subscription_u.fd_read" name="subscription_u.fd_read"></a> `fd_read`: [`subscription_fd_readwrite`](#subscription_fd_readwrite)
@@ -1148,20 +1146,18 @@ The length of the directory name for use with [`fd_prestat_dir_name`](#fd_presta
11481146

11491147
Offset: 0
11501148

1151-
## <a href="#prestat" name="prestat"></a> `prestat`: Union
1149+
## <a href="#prestat" name="prestat"></a> `prestat`: Variant
11521150
Information about a pre-opened capability.
11531151

11541152
Size: 8
11551153

11561154
Alignment: 4
11571155

1158-
### Union Layout
1156+
### Variant Layout
1157+
- size: 8
1158+
- align: 4
11591159
- tag_size: 1
1160-
- tag_align: 1
1161-
- contents_offset: 4
1162-
- contents_size: 4
1163-
- contents_align: 4
1164-
### Union variants
1160+
### Variant cases
11651161
- <a href="#prestat.dir" name="prestat.dir"></a> `dir`: [`prestat_dir`](#prestat_dir)
11661162

11671163
# Modules

phases/old/snapshot_0/witx/typenames.witx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,10 @@
570570

571571
;;; The contents of a `subscription`.
572572
(typename $subscription_u
573-
(union $eventtype
574-
(field $clock $subscription_clock)
575-
(field $fd_read $subscription_fd_readwrite)
576-
(field $fd_write $subscription_fd_readwrite)
573+
(union (@witx tag $eventtype)
574+
$subscription_clock
575+
$subscription_fd_readwrite
576+
$subscription_fd_readwrite
577577
)
578578
)
579579

@@ -740,7 +740,7 @@
740740

741741
;;; Information about a pre-opened capability.
742742
(typename $prestat
743-
(union $preopentype
744-
(field $dir $prestat_dir)
743+
(union (@witx tag $preopentype)
744+
$prestat_dir
745745
)
746746
)

phases/snapshot/docs.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -896,20 +896,18 @@ The file descriptor on which to wait for it to become ready for reading or writi
896896

897897
Offset: 0
898898

899-
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Union
899+
## <a href="#subscription_u" name="subscription_u"></a> `subscription_u`: Variant
900900
The contents of a [`subscription`](#subscription).
901901

902902
Size: 40
903903

904904
Alignment: 8
905905

906-
### Union Layout
906+
### Variant Layout
907+
- size: 40
908+
- align: 8
907909
- tag_size: 1
908-
- tag_align: 1
909-
- contents_offset: 8
910-
- contents_size: 32
911-
- contents_align: 8
912-
### Union variants
910+
### Variant cases
913911
- <a href="#subscription_u.clock" name="subscription_u.clock"></a> `clock`: [`subscription_clock`](#subscription_clock)
914912

915913
- <a href="#subscription_u.fd_read" name="subscription_u.fd_read"></a> `fd_read`: [`subscription_fd_readwrite`](#subscription_fd_readwrite)
@@ -1145,20 +1143,18 @@ The length of the directory name for use with [`fd_prestat_dir_name`](#fd_presta
11451143

11461144
Offset: 0
11471145

1148-
## <a href="#prestat" name="prestat"></a> `prestat`: Union
1146+
## <a href="#prestat" name="prestat"></a> `prestat`: Variant
11491147
Information about a pre-opened capability.
11501148

11511149
Size: 8
11521150

11531151
Alignment: 4
11541152

1155-
### Union Layout
1153+
### Variant Layout
1154+
- size: 8
1155+
- align: 4
11561156
- tag_size: 1
1157-
- tag_align: 1
1158-
- contents_offset: 4
1159-
- contents_size: 4
1160-
- contents_align: 4
1161-
### Union variants
1157+
### Variant cases
11621158
- <a href="#prestat.dir" name="prestat.dir"></a> `dir`: [`prestat_dir`](#prestat_dir)
11631159

11641160
# Modules

phases/snapshot/witx/typenames.witx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,11 @@
570570

571571
;;; The contents of a `subscription`.
572572
(typename $subscription_u
573-
(union $eventtype
574-
(field $clock $subscription_clock)
575-
(field $fd_read $subscription_fd_readwrite)
576-
(field $fd_write $subscription_fd_readwrite)
573+
(union
574+
(@witx tag $eventtype)
575+
$subscription_clock
576+
$subscription_fd_readwrite
577+
$subscription_fd_readwrite
577578
)
578579
)
579580

@@ -740,8 +741,8 @@
740741

741742
;;; Information about a pre-opened capability.
742743
(typename $prestat
743-
(union $preopentype
744-
(field $dir $prestat_dir)
744+
(union (@witx tag $preopentype)
745+
$prestat_dir
745746
)
746747
)
747748

tools/witx/src/ast.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ impl NamedType {
187187
pub enum Type {
188188
Record(RecordDatatype),
189189
Variant(Variant),
190-
Union(UnionDatatype),
191190
Handle(HandleDatatype),
192191
List(TypeRef),
193192
Pointer(TypeRef),
@@ -201,7 +200,6 @@ impl Type {
201200
match self {
202201
Record(_) => "record",
203202
Variant(_) => "variant",
204-
Union(_) => "union",
205203
Handle(_) => "handle",
206204
List(_) => "list",
207205
Pointer(_) => "pointer",
@@ -272,19 +270,6 @@ pub struct Case {
272270
pub docs: String,
273271
}
274272

275-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
276-
pub struct UnionDatatype {
277-
pub tag: Rc<NamedType>,
278-
pub variants: Vec<UnionVariant>,
279-
}
280-
281-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
282-
pub struct UnionVariant {
283-
pub name: Id,
284-
pub tref: Option<TypeRef>,
285-
pub docs: String,
286-
}
287-
288273
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
289274
pub struct HandleDatatype {}
290275

tools/witx/src/coretypes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Type {
5050
},
5151
Type::List { .. } => TypePassedBy::PointerLengthPair,
5252
Type::Pointer { .. } | Type::ConstPointer { .. } => TypePassedBy::Value(AtomType::I32),
53-
Type::Record { .. } | Type::Union { .. } => TypePassedBy::Pointer,
53+
Type::Record { .. } => TypePassedBy::Pointer,
5454
Type::Variant(v) => {
5555
if v.cases.iter().all(|c| c.tref.is_none()) {
5656
TypePassedBy::Value(v.tag_repr.into())

0 commit comments

Comments
 (0)