Skip to content

Commit 9f44f6a

Browse files
giacomocavalierilpil
authored andcommitted
pick better names
1 parent 08ee0c5 commit 9f44f6a

File tree

3 files changed

+72
-69
lines changed

3 files changed

+72
-69
lines changed

compiler-core/src/exhaustiveness.rs

+49-43
Original file line numberDiff line numberDiff line change
@@ -428,22 +428,22 @@ pub enum RuntimeCheck {
428428
},
429429
StringPrefix {
430430
prefix: EcoString,
431-
rest_arg: Variable,
431+
rest: Variable,
432432
},
433433
Tuple {
434434
size: usize,
435-
args: Vec<Variable>,
435+
elements: Vec<Variable>,
436436
},
437437
BitArray {
438438
value: EcoString,
439439
},
440440
Variant {
441441
index: usize,
442-
args: Vec<Variable>,
442+
fields: Vec<Variable>,
443443
},
444444
NonEmptyList {
445-
first_arg: Variable,
446-
rest_arg: Variable,
445+
first: Variable,
446+
rest: Variable,
447447
},
448448
EmptyList,
449449
}
@@ -460,22 +460,18 @@ impl RuntimeCheck {
460460
RuntimeCheck::String { value } => RuntimeCheckKind::String {
461461
value: value.clone(),
462462
},
463-
RuntimeCheck::StringPrefix {
464-
prefix,
465-
rest_arg: _,
466-
} => RuntimeCheckKind::StringPrefix {
463+
RuntimeCheck::StringPrefix { prefix, rest: _ } => RuntimeCheckKind::StringPrefix {
467464
prefix: prefix.clone(),
468465
},
469-
RuntimeCheck::Tuple { size, args: _ } => RuntimeCheckKind::Tuple { size: *size },
466+
RuntimeCheck::Tuple { size, elements: _ } => RuntimeCheckKind::Tuple { size: *size },
470467
RuntimeCheck::BitArray { value } => RuntimeCheckKind::BitArray {
471468
value: value.clone(),
472469
},
473-
RuntimeCheck::Variant { index, args: _ } => RuntimeCheckKind::Variant { index: *index },
470+
RuntimeCheck::Variant { index, fields: _ } => {
471+
RuntimeCheckKind::Variant { index: *index }
472+
}
474473
RuntimeCheck::EmptyList => RuntimeCheckKind::EmptyList,
475-
RuntimeCheck::NonEmptyList {
476-
first_arg: _,
477-
rest_arg: _,
478-
} => RuntimeCheckKind::NonEmptyList,
474+
RuntimeCheck::NonEmptyList { first: _, rest: _ } => RuntimeCheckKind::NonEmptyList,
479475
}
480476
}
481477
}
@@ -993,7 +989,7 @@ impl<'a> Compiler<'a> {
993989
},
994990
(RuntimeCheckKind::StringPrefix { prefix }, _) => RuntimeCheck::StringPrefix {
995991
prefix: prefix.clone(),
996-
rest_arg: self.fresh_variable(string()),
992+
rest: self.fresh_variable(string()),
997993
},
998994
(RuntimeCheckKind::Tuple { .. }, BranchMode::Tuple { elements }) => {
999995
self.is_tuple_check(elements)
@@ -1047,32 +1043,47 @@ impl<'a> Compiler<'a> {
10471043
// After making sure a value is not an empty list we'll have to perform
10481044
// additional checks on its first item and on the tail.
10491045
(
1050-
Pattern::NonEmptyList { first, rest },
1046+
Pattern::NonEmptyList {
1047+
first: first_pattern,
1048+
rest: rest_pattern,
1049+
},
10511050
RuntimeCheck::NonEmptyList {
1052-
first_arg,
1053-
rest_arg,
1051+
first: first_variable,
1052+
rest: rest_variable,
10541053
},
1055-
) => vec![first_arg.is(*first), rest_arg.is(*rest)],
1054+
) => vec![
1055+
first_variable.is(*first_pattern),
1056+
rest_variable.is(*rest_pattern),
1057+
],
10561058

10571059
// After making sure a value is a specific variant we'll have to check each
10581060
// of its arguments respects the given patterns (as shown in the doc example for
10591061
// this function!)
1060-
(Pattern::Variant { fields, .. }, RuntimeCheck::Variant { args, .. }) => {
1061-
(args.iter().zip(fields))
1062-
.map(|(arg, pattern)| arg.is(*pattern))
1063-
.collect_vec()
1064-
}
1062+
(
1063+
Pattern::Variant {
1064+
fields: patterns, ..
1065+
},
1066+
RuntimeCheck::Variant {
1067+
fields: variables, ..
1068+
},
1069+
) => (variables.iter().zip(patterns))
1070+
.map(|(field, pattern)| field.is(*pattern))
1071+
.collect_vec(),
10651072

10661073
// Tuples are exactly the same as variants: after making sure we're dealing with
10671074
// a tuple, we will have to check that each of its elements matches the given
10681075
// pattern: `a is #(1, _)` will result in the following checks
10691076
// `a0 is 1, a1 is _` (where `a0` and `a1` are fresh variable names we use to
10701077
// refer to each of the tuple's elements).
1071-
(Pattern::Tuple { elements }, RuntimeCheck::Tuple { args, .. }) => {
1072-
(args.iter().zip(elements))
1073-
.map(|(arg, pattern)| arg.is(*pattern))
1074-
.collect_vec()
1075-
}
1078+
(
1079+
Pattern::Tuple { elements: patterns },
1080+
RuntimeCheck::Tuple {
1081+
elements: variables,
1082+
..
1083+
},
1084+
) => (variables.iter().zip(patterns))
1085+
.map(|(element, pattern)| element.is(*pattern))
1086+
.collect_vec(),
10761087

10771088
// Strings are quite fun: if we've checked at runtime a string starts with a given
10781089
// prefix and we want to check that it's some overlapping literal value we'll still
@@ -1082,14 +1093,9 @@ impl<'a> Compiler<'a> {
10821093
// and we've just successfully ran the runtime check for `a is "wib" <> rest`.
10831094
// So we know the string already starts with `"wib"` what we have to check now
10841095
// is that the remaining part `rest` is `"ble"`.
1085-
(
1086-
Pattern::String { value },
1087-
RuntimeCheck::StringPrefix {
1088-
prefix, rest_arg, ..
1089-
},
1090-
) => {
1096+
(Pattern::String { value }, RuntimeCheck::StringPrefix { prefix, rest, .. }) => {
10911097
let remaining = value.strip_prefix(prefix.as_str()).unwrap_or(value);
1092-
vec![rest_arg.is(self.string_pattern(remaining))]
1098+
vec![rest.is(self.string_pattern(remaining))]
10931099
}
10941100

10951101
// String prefixes are similar to strings, but a bit more involved. Let's say we're
@@ -1120,7 +1126,7 @@ impl<'a> Compiler<'a> {
11201126
},
11211127
RuntimeCheck::StringPrefix {
11221128
prefix: prefix0,
1123-
rest_arg: rest0,
1129+
rest: rest0,
11241130
},
11251131
) => {
11261132
let remaining = prefix1.strip_prefix(prefix0.as_str()).unwrap_or(prefix1);
@@ -1141,10 +1147,10 @@ impl<'a> Compiler<'a> {
11411147
) -> RuntimeCheck {
11421148
RuntimeCheck::Variant {
11431149
index,
1144-
args: constructor
1150+
fields: constructor
11451151
.parameters
11461152
.iter()
1147-
.map(|p| p.type_.clone())
1153+
.map(|parameter| parameter.type_.clone())
11481154
.map(|type_| self.fresh_variable(type_))
11491155
.collect_vec(),
11501156
}
@@ -1155,8 +1161,8 @@ impl<'a> Compiler<'a> {
11551161
///
11561162
fn is_list_check(&mut self, inner_type: Arc<Type>) -> RuntimeCheck {
11571163
RuntimeCheck::NonEmptyList {
1158-
first_arg: self.fresh_variable(inner_type.clone()),
1159-
rest_arg: self.fresh_variable(Arc::new(Type::list(inner_type))),
1164+
first: self.fresh_variable(inner_type.clone()),
1165+
rest: self.fresh_variable(Arc::new(Type::list(inner_type))),
11601166
}
11611167
}
11621168

@@ -1166,7 +1172,7 @@ impl<'a> Compiler<'a> {
11661172
fn is_tuple_check(&mut self, elements: &[Arc<Type>]) -> RuntimeCheck {
11671173
RuntimeCheck::Tuple {
11681174
size: elements.len(),
1169-
args: elements
1175+
elements: elements
11701176
.iter()
11711177
.map(|type_| self.fresh_variable(type_.clone()))
11721178
.collect_vec(),

compiler-core/src/exhaustiveness/missing_patterns.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ pub enum Term {
3131
variable: Variable,
3232
name: EcoString,
3333
module: EcoString,
34-
arguments: Vec<Variable>,
34+
fields: Vec<Variable>,
3535
},
3636
Tuple {
3737
variable: Variable,
38-
arguments: Vec<Variable>,
38+
elements: Vec<Variable>,
3939
},
4040
Infinite {
4141
variable: Variable,
@@ -136,12 +136,12 @@ fn check_to_term(variable: Variable, check: &RuntimeCheck, env: &Environment<'_>
136136
| RuntimeCheck::BitArray { .. }
137137
| RuntimeCheck::StringPrefix { .. } => Term::Infinite { variable },
138138

139-
RuntimeCheck::Tuple { args, .. } => Term::Tuple {
139+
RuntimeCheck::Tuple { elements, .. } => Term::Tuple {
140140
variable,
141-
arguments: args.clone(),
141+
elements: elements.clone(),
142142
},
143143

144-
RuntimeCheck::Variant { index, args } => {
144+
RuntimeCheck::Variant { index, fields } => {
145145
let (module, name) = variable
146146
.type_
147147
.named_type_name()
@@ -160,17 +160,14 @@ fn check_to_term(variable: Variable, check: &RuntimeCheck, env: &Environment<'_>
160160
variable,
161161
name,
162162
module,
163-
arguments: args.clone(),
163+
fields: fields.clone(),
164164
}
165165
}
166166

167-
RuntimeCheck::NonEmptyList {
168-
first_arg,
169-
rest_arg,
170-
} => Term::List {
167+
RuntimeCheck::NonEmptyList { first, rest } => Term::List {
171168
variable,
172-
first: first_arg.clone(),
173-
rest: rest_arg.clone(),
169+
first: first.clone(),
170+
rest: rest.clone(),
174171
},
175172

176173
RuntimeCheck::EmptyList => Term::EmptyList { variable },

compiler-core/src/exhaustiveness/printer.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a> Printer<'a> {
5050
Term::Variant {
5151
name,
5252
module,
53-
arguments,
53+
fields,
5454
..
5555
} => {
5656
let (module, name) = match self.names.named_constructor(module, name) {
@@ -67,11 +67,11 @@ impl<'a> Printer<'a> {
6767
}
6868
buffer.push_str(name);
6969

70-
if arguments.is_empty() {
70+
if fields.is_empty() {
7171
return;
7272
}
7373
buffer.push('(');
74-
for (i, variable) in arguments.iter().enumerate() {
74+
for (i, variable) in fields.iter().enumerate() {
7575
if i != 0 {
7676
buffer.push_str(", ");
7777
}
@@ -89,9 +89,9 @@ impl<'a> Printer<'a> {
8989
}
9090
buffer.push(')');
9191
}
92-
Term::Tuple { arguments, .. } => {
92+
Term::Tuple { elements, .. } => {
9393
buffer.push_str("#(");
94-
for (i, variable) in arguments.iter().enumerate() {
94+
for (i, variable) in elements.iter().enumerate() {
9595
if i != 0 {
9696
buffer.push_str(", ");
9797
}
@@ -201,7 +201,7 @@ mod tests {
201201
variable: subjects[0].clone(),
202202
name: "Wibble".into(),
203203
module: "module".into(),
204-
arguments: Vec::new(),
204+
fields: Vec::new(),
205205
};
206206

207207
let terms = &[term];
@@ -227,7 +227,7 @@ mod tests {
227227
variable: subjects[0].clone(),
228228
name: "Wibble".into(),
229229
module: "module".into(),
230-
arguments: vec![var1.clone(), var2.clone()],
230+
fields: vec![var1.clone(), var2.clone()],
231231
};
232232

233233
let terms = &[
@@ -256,7 +256,7 @@ mod tests {
256256
variable: subjects[0].clone(),
257257
name: "Rectangle".into(),
258258
module: "mod".into(),
259-
arguments: Vec::new(),
259+
fields: Vec::new(),
260260
};
261261

262262
let terms = &[term];
@@ -283,7 +283,7 @@ mod tests {
283283
variable: subjects[0].clone(),
284284
name: "Regex".into(),
285285
module: "regex".into(),
286-
arguments: vec![arg.clone()],
286+
fields: vec![arg.clone()],
287287
};
288288

289289
let terms = &[term, Term::Infinite { variable: arg }];
@@ -308,7 +308,7 @@ mod tests {
308308
variable: subjects[0].clone(),
309309
name: "Regex".into(),
310310
module: "regex".into(),
311-
arguments: vec![arg.clone()],
311+
fields: vec![arg.clone()],
312312
};
313313

314314
let terms = &[
@@ -317,7 +317,7 @@ mod tests {
317317
variable: arg,
318318
name: "None".into(),
319319
module: "gleam".into(),
320-
arguments: vec![],
320+
fields: vec![],
321321
},
322322
];
323323
let mapping = get_mapping(terms);
@@ -350,7 +350,7 @@ mod tests {
350350
variable: var1,
351351
name: "Type".into(),
352352
module: "module".into(),
353-
arguments: Vec::new(),
353+
fields: Vec::new(),
354354
},
355355
Term::List {
356356
variable: var2,
@@ -383,13 +383,13 @@ mod tests {
383383
variable: subjects[0].clone(),
384384
name: "Ok".into(),
385385
module: "gleam".into(),
386-
arguments: vec![make_variable(3)],
386+
fields: vec![make_variable(3)],
387387
},
388388
Term::Variant {
389389
variable: subjects[2].clone(),
390390
name: "False".into(),
391391
module: "gleam".into(),
392-
arguments: Vec::new(),
392+
fields: Vec::new(),
393393
},
394394
];
395395
let mapping = get_mapping(terms);

0 commit comments

Comments
 (0)