fix issue with final clause producing clauseguard air

This commit is contained in:
Kasey White 2023-02-12 16:44:04 -05:00 committed by Lucas
parent e9883adf12
commit 4c838defd1
2 changed files with 34 additions and 4 deletions

View File

@ -67,6 +67,7 @@ pub enum ClauseProperties {
needs_constr_var: bool,
is_complex_clause: bool,
original_subject_name: String,
final_clause: bool,
},
ListClause {
clause_var_name: String,
@ -74,6 +75,7 @@ pub enum ClauseProperties {
is_complex_clause: bool,
original_subject_name: String,
current_index: i64,
final_clause: bool,
},
TupleClause {
clause_var_name: String,
@ -81,6 +83,7 @@ pub enum ClauseProperties {
is_complex_clause: bool,
original_subject_name: String,
defined_tuple_indices: IndexSet<(usize, String)>,
final_clause: bool,
},
}
@ -93,6 +96,7 @@ impl ClauseProperties {
is_complex_clause: false,
original_subject_name: subject_name,
current_index: -1,
final_clause: false,
}
} else if t.is_tuple() {
ClauseProperties::TupleClause {
@ -101,6 +105,7 @@ impl ClauseProperties {
is_complex_clause: false,
original_subject_name: subject_name,
defined_tuple_indices: IndexSet::new(),
final_clause: false,
}
} else {
ClauseProperties::ConstrClause {
@ -108,6 +113,7 @@ impl ClauseProperties {
needs_constr_var: false,
is_complex_clause: false,
original_subject_name: subject_name,
final_clause: false,
}
}
}
@ -139,6 +145,14 @@ impl ClauseProperties {
}
}
pub fn is_final_clause(&mut self) -> &mut bool {
match self {
ClauseProperties::ConstrClause { final_clause, .. }
| ClauseProperties::ListClause { final_clause, .. }
| ClauseProperties::TupleClause { final_clause, .. } => final_clause,
}
}
pub fn clause_var_name(&mut self) -> &mut String {
match self {
ClauseProperties::ConstrClause {

View File

@ -401,9 +401,11 @@ impl<'a> CodeGenerator<'a> {
final_scope.push(self.id_gen.next());
if !matches!(clause_properties, ClauseProperties::TupleClause { .. }) {
pattern_vec.push(Air::Finally {
scope: final_scope.clone(),
});
}
let mut final_clause_vec = vec![];
@ -413,6 +415,8 @@ impl<'a> CodeGenerator<'a> {
final_scope.clone(),
);
*clause_properties.is_final_clause() = true;
self.when_ir(
last_pattern,
&mut pattern_vec,
@ -1079,6 +1083,7 @@ impl<'a> CodeGenerator<'a> {
&mut nested_pattern,
items_type,
scope.clone(),
*clause_properties.is_final_clause(),
);
names.push(name.unwrap_or_else(|| "_".to_string()))
@ -1190,6 +1195,7 @@ impl<'a> CodeGenerator<'a> {
.into(),
),
scope.clone(),
*clause_properties.is_final_clause(),
);
var_name.map_or(
@ -1233,6 +1239,7 @@ impl<'a> CodeGenerator<'a> {
&mut nested_pattern,
type_map.get(&index).unwrap(),
scope.clone(),
*clause_properties.is_final_clause(),
);
var_name.map_or(Some(("_".to_string(), index)), |var_name| {
@ -1271,6 +1278,7 @@ impl<'a> CodeGenerator<'a> {
&mut nested_pattern,
&items_type[index],
scope.clone(),
*clause_properties.is_final_clause(),
);
names.push((name.unwrap_or_else(|| "_".to_string()), index))
@ -1343,6 +1351,7 @@ impl<'a> CodeGenerator<'a> {
pattern_vec: &mut Vec<Air>,
pattern_type: &Arc<Type>,
scope: Vec<u64>,
final_clause: bool,
) -> Option<String> {
match pattern {
Pattern::Var { name, .. } => Some(name.clone()),
@ -1375,6 +1384,7 @@ impl<'a> CodeGenerator<'a> {
is_complex_clause: false,
original_subject_name: item_name.clone(),
current_index: index as i64,
final_clause
};
let tail_name = format!("{new_tail_name}_{index}");
@ -1466,18 +1476,23 @@ impl<'a> CodeGenerator<'a> {
let data_type = lookup_data_type_by_tipo(self.data_types.clone(), tipo).unwrap();
if data_type.constructors.len() > 1 {
if final_clause{
pattern_vec.push(Air::Finally { scope: scope.clone() });
} else {
pattern_vec.push(Air::ClauseGuard {
scope: scope.clone(),
tipo: tipo.clone(),
subject_name: constr_var_name.clone(),
});
}
}
let mut clause_properties = ClauseProperties::ConstrClause {
clause_var_name: constr_var_name.clone(),
needs_constr_var: false,
is_complex_clause: false,
original_subject_name: constr_var_name.clone(),
final_clause
};
self.when_ir(
@ -1500,6 +1515,7 @@ impl<'a> CodeGenerator<'a> {
is_complex_clause: false,
original_subject_name: item_name.clone(),
defined_tuple_indices: IndexSet::new(),
final_clause
};
let mut inner_pattern_vec = vec![];