Skip to content

Commit 581b9d4

Browse files
tamer: Use .. for tuple unimportant variant matches
Tbh, I was unaware that this was supported by tuple variants until reading over the Rustc source code for something. (Which I had previously read, but I must have missed it.) This is more proper, in the sense that in a lot of cases we not only care about how many values a tuple has, but if we explicitly match on them using `_`, then any time we modify the number of values, it would _break_ any code doing so. Using this method, we improve maintainability by not causing breakages under those circumstances. But, consequently, it's important that we use this only when we _really_ don't care and don't want to be notified by the compiler. I did not use `..` as a prefix, even where supported, because the intent is to append additional information to tuples. Consequently, I also used `..` in places where no additional fields currently exist, since they may in the future (e.g. introducing `Span` for `IdentObject`).
1 parent 739cf7e commit 581b9d4

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

tamer/src/ir/asg/ident.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,16 @@ pub enum IdentKind {
149149
impl IdentKind {
150150
pub fn as_sym(&self) -> SymbolId {
151151
match self {
152-
Self::Cgen(_) => st::L_CGEN.as_sym(),
153-
Self::Class(_) => st::L_CLASS.as_sym(),
154-
Self::Const(_, _) => st::L_CONST.as_sym(),
155-
Self::Func(_, _) => st::L_FUNC.as_sym(),
156-
Self::Gen(_, _) => st::L_GEN.as_sym(),
157-
Self::Lparam(_, _) => st::L_LPARAM.as_sym(),
158-
Self::Param(_, _) => st::L_PARAM.as_sym(),
159-
Self::Rate(_) => st::L_RATE.as_sym(),
152+
Self::Cgen(..) => st::L_CGEN.as_sym(),
153+
Self::Class(..) => st::L_CLASS.as_sym(),
154+
Self::Const(..) => st::L_CONST.as_sym(),
155+
Self::Func(..) => st::L_FUNC.as_sym(),
156+
Self::Gen(..) => st::L_GEN.as_sym(),
157+
Self::Lparam(..) => st::L_LPARAM.as_sym(),
158+
Self::Param(..) => st::L_PARAM.as_sym(),
159+
Self::Rate(..) => st::L_RATE.as_sym(),
160160
Self::Tpl => st::L_TPL.as_sym(),
161-
Self::Type(_) => st::L_TYPE.as_sym(),
161+
Self::Type(..) => st::L_TYPE.as_sym(),
162162
Self::MapHead => st::L_MAP_HEAD.as_sym(),
163163
Self::Map => st::L_MAP.as_sym(),
164164
Self::MapTail => st::L_MAP_TAIL.as_sym(),

tamer/src/ir/asg/object.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,34 @@ pub enum IdentObject {
8383
impl IdentObject {
8484
pub fn name(&self) -> SymbolId {
8585
match self {
86-
Self::Missing(name)
87-
| Self::Ident(name, _, _)
88-
| Self::Extern(name, _, _)
89-
| Self::IdentFragment(name, _, _, _) => *name,
86+
Self::Missing(name, ..)
87+
| Self::Ident(name, ..)
88+
| Self::Extern(name, ..)
89+
| Self::IdentFragment(name, ..) => *name,
9090
}
9191
}
9292

9393
pub fn kind(&self) -> Option<&IdentKind> {
9494
match self {
95-
Self::Missing(_) => None,
96-
Self::Ident(_, kind, _)
97-
| Self::Extern(_, kind, _)
98-
| Self::IdentFragment(_, kind, _, _) => Some(kind),
95+
Self::Missing(..) => None,
96+
Self::Ident(_, kind, ..)
97+
| Self::Extern(_, kind, ..)
98+
| Self::IdentFragment(_, kind, ..) => Some(kind),
9999
}
100100
}
101101

102102
pub fn src(&self) -> Option<&Source> {
103103
match self {
104-
Self::Missing(_) | Self::Extern(_, _, _) => None,
105-
Self::Ident(_, _, src) | Self::IdentFragment(_, _, src, _) => {
104+
Self::Missing(..) | Self::Extern(..) => None,
105+
Self::Ident(_, _, src, ..) | Self::IdentFragment(_, _, src, ..) => {
106106
Some(src)
107107
}
108108
}
109109
}
110110

111111
pub fn fragment(&self) -> Option<FragmentText> {
112112
match self {
113-
Self::Missing(_) | Self::Ident(_, _, _) | Self::Extern(_, _, _) => {
114-
None
115-
}
113+
Self::Missing(..) | Self::Ident(..) | Self::Extern(..) => None,
116114
Self::IdentFragment(_, _, _, text) => Some(*text),
117115
}
118116
}
@@ -379,12 +377,14 @@ impl IdentObjectState<IdentObject> for IdentObject {
379377

380378
// These represent the prolog and epilogue of maps. This
381379
// situation will be resolved in the future.
382-
IdentObject::IdentFragment(_, IdentKind::MapHead, _, _)
383-
| IdentObject::IdentFragment(_, IdentKind::MapTail, _, _)
384-
| IdentObject::IdentFragment(_, IdentKind::RetMapHead, _, _)
385-
| IdentObject::IdentFragment(_, IdentKind::RetMapTail, _, _) => {
386-
Ok(self)
387-
}
380+
IdentObject::IdentFragment(
381+
_,
382+
IdentKind::MapHead
383+
| IdentKind::MapTail
384+
| IdentKind::RetMapHead
385+
| IdentKind::RetMapTail,
386+
..,
387+
) => Ok(self),
388388

389389
IdentObject::Missing(name) => {
390390
Ok(IdentObject::Ident(name, kind, src))
@@ -412,8 +412,7 @@ impl IdentObjectState<IdentObject> for IdentObject {
412412
})
413413
}
414414

415-
IdentObject::Ident(_, _, _)
416-
| IdentObject::IdentFragment(_, _, _, _) => Ok(self),
415+
IdentObject::Ident(..) | IdentObject::IdentFragment(..) => Ok(self),
417416
}
418417
}
419418

@@ -456,18 +455,20 @@ impl IdentObjectState<IdentObject> for IdentObject {
456455
// If this is not permissable, then we should have already
457456
// prevented the `resolve` transition before this fragment was
458457
// encountered.
459-
IdentObject::IdentFragment(_, _, ref src, _) if src.override_ => {
458+
IdentObject::IdentFragment(_, _, ref src, ..) if src.override_ => {
460459
Ok(self)
461460
}
462461

463462
// These represent the prolog and epilogue of maps. This
464463
// situation will be resolved in the future.
465-
IdentObject::IdentFragment(_, IdentKind::MapHead, _, _)
466-
| IdentObject::IdentFragment(_, IdentKind::MapTail, _, _)
467-
| IdentObject::IdentFragment(_, IdentKind::RetMapHead, _, _)
468-
| IdentObject::IdentFragment(_, IdentKind::RetMapTail, _, _) => {
469-
Ok(self)
470-
}
464+
IdentObject::IdentFragment(
465+
_,
466+
IdentKind::MapHead
467+
| IdentKind::MapTail
468+
| IdentKind::RetMapHead
469+
| IdentKind::RetMapTail,
470+
..,
471+
) => Ok(self),
471472

472473
_ => {
473474
let msg = format!(

tamer/src/ld/xmle/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ where
124124

125125
let is_all_funcs = scc.iter().all(|nx| {
126126
let ident = Asg::get(asg, *nx).expect("missing node");
127-
matches!(ident.kind(), Some(IdentKind::Func(_, _)))
127+
matches!(ident.kind(), Some(IdentKind::Func(..)))
128128
});
129129

130130
if is_all_funcs {

tamer/src/ld/xmle/section.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ impl<'a> XmleSections<'a> for Sections<'a> {
116116

117117
match ident.resolved()?.kind() {
118118
Some(kind) => match kind {
119-
IdentKind::Cgen(_)
120-
| IdentKind::Gen(_, _)
121-
| IdentKind::Lparam(_, _) => {
119+
IdentKind::Cgen(..)
120+
| IdentKind::Gen(..)
121+
| IdentKind::Lparam(..) => {
122122
// These types do not have fragments.
123123
}
124124
IdentKind::Meta
125125
| IdentKind::Worksheet
126-
| IdentKind::Param(_, _)
127-
| IdentKind::Type(_)
128-
| IdentKind::Func(_, _)
129-
| IdentKind::Const(_, _) => {
126+
| IdentKind::Param(..)
127+
| IdentKind::Type(..)
128+
| IdentKind::Func(..)
129+
| IdentKind::Const(..) => {
130130
self.st.push(expect_frag(name, frag)?)
131131
}
132132
IdentKind::MapHead | IdentKind::Map | IdentKind::MapTail => {
@@ -144,7 +144,7 @@ impl<'a> XmleSections<'a> for Sections<'a> {
144144
self.retmap.push(expect_frag(name, frag)?)
145145
}
146146
// TODO: Why do templates have fragments?
147-
IdentKind::Class(_) | IdentKind::Rate(_) | IdentKind::Tpl => {
147+
IdentKind::Class(..) | IdentKind::Rate(..) | IdentKind::Tpl => {
148148
self.exec.push(expect_frag(name, frag)?)
149149
}
150150
},

0 commit comments

Comments
 (0)