fix: issue with reordering statements caused clause props to not be updated
This commit is contained in:
parent
8702c736d0
commit
575dde9885
|
@ -243,6 +243,71 @@ impl<'a> CodeGenerator<'a> {
|
||||||
context: &[TypedExpr],
|
context: &[TypedExpr],
|
||||||
) -> AirTree {
|
) -> AirTree {
|
||||||
match body {
|
match body {
|
||||||
|
TypedExpr::Assignment {
|
||||||
|
location,
|
||||||
|
tipo,
|
||||||
|
value,
|
||||||
|
pattern,
|
||||||
|
kind,
|
||||||
|
} if !context.is_empty() => {
|
||||||
|
let replaced_type = convert_opaque_type(tipo, &self.data_types);
|
||||||
|
|
||||||
|
let air_value = self.build(value, module_build_name, context);
|
||||||
|
|
||||||
|
let msg_func = match self.tracing {
|
||||||
|
TraceLevel::Silent => None,
|
||||||
|
TraceLevel::Verbose | TraceLevel::Compact => {
|
||||||
|
if kind.is_expect() {
|
||||||
|
let msg = match self.tracing {
|
||||||
|
TraceLevel::Silent => unreachable!("excluded from pattern guards"),
|
||||||
|
TraceLevel::Compact => get_line_columns_by_span(
|
||||||
|
module_build_name,
|
||||||
|
location,
|
||||||
|
&self.module_src,
|
||||||
|
)
|
||||||
|
.to_string(),
|
||||||
|
TraceLevel::Verbose => get_src_code_by_span(
|
||||||
|
module_build_name,
|
||||||
|
location,
|
||||||
|
&self.module_src,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let msg_func_name = msg.split_whitespace().join("");
|
||||||
|
|
||||||
|
self.special_functions.insert_new_function(
|
||||||
|
msg_func_name.clone(),
|
||||||
|
Term::string(msg),
|
||||||
|
string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Some(self.special_functions.use_function_msg(msg_func_name))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let (then, context) = context
|
||||||
|
.split_first()
|
||||||
|
.expect("found an assignment without a next expression?");
|
||||||
|
|
||||||
|
let then = self.build(then, module_build_name, context);
|
||||||
|
|
||||||
|
self.assignment(
|
||||||
|
pattern,
|
||||||
|
air_value,
|
||||||
|
then,
|
||||||
|
&replaced_type,
|
||||||
|
AssignmentProperties {
|
||||||
|
value_type: value.tipo(),
|
||||||
|
kind: *kind,
|
||||||
|
remove_unused: kind.is_let(),
|
||||||
|
full_check: !tipo.is_data() && value.tipo().is_data() && kind.is_expect(),
|
||||||
|
msg_func,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
TypedExpr::UInt { value, .. } => AirTree::int(value),
|
TypedExpr::UInt { value, .. } => AirTree::int(value),
|
||||||
TypedExpr::String { value, .. } => AirTree::string(value),
|
TypedExpr::String { value, .. } => AirTree::string(value),
|
||||||
TypedExpr::ByteArray { bytes, .. } => AirTree::byte_array(bytes.clone()),
|
TypedExpr::ByteArray { bytes, .. } => AirTree::byte_array(bytes.clone()),
|
||||||
|
@ -455,71 +520,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
left.tipo(),
|
left.tipo(),
|
||||||
),
|
),
|
||||||
|
|
||||||
TypedExpr::Assignment {
|
TypedExpr::Assignment { .. } => {
|
||||||
tipo,
|
panic!("Reached assignment with no dangling expressions")
|
||||||
value,
|
|
||||||
pattern,
|
|
||||||
kind,
|
|
||||||
location,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let replaced_type = convert_opaque_type(tipo, &self.data_types);
|
|
||||||
|
|
||||||
let air_value = self.build(value, module_build_name, context);
|
|
||||||
|
|
||||||
let msg_func = match self.tracing {
|
|
||||||
TraceLevel::Silent => None,
|
|
||||||
TraceLevel::Verbose | TraceLevel::Compact => {
|
|
||||||
if kind.is_expect() {
|
|
||||||
let msg = match self.tracing {
|
|
||||||
TraceLevel::Silent => unreachable!("excluded from pattern guards"),
|
|
||||||
TraceLevel::Compact => get_line_columns_by_span(
|
|
||||||
module_build_name,
|
|
||||||
location,
|
|
||||||
&self.module_src,
|
|
||||||
)
|
|
||||||
.to_string(),
|
|
||||||
TraceLevel::Verbose => get_src_code_by_span(
|
|
||||||
module_build_name,
|
|
||||||
location,
|
|
||||||
&self.module_src,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
let msg_func_name = msg.split_whitespace().join("");
|
|
||||||
|
|
||||||
self.special_functions.insert_new_function(
|
|
||||||
msg_func_name.clone(),
|
|
||||||
Term::string(msg),
|
|
||||||
string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Some(self.special_functions.use_function_msg(msg_func_name))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (then, context) = context
|
|
||||||
.split_first()
|
|
||||||
.expect("found an assignment without a next expression?");
|
|
||||||
|
|
||||||
let then = self.build(then, module_build_name, context);
|
|
||||||
|
|
||||||
self.assignment(
|
|
||||||
pattern,
|
|
||||||
air_value,
|
|
||||||
then,
|
|
||||||
&replaced_type,
|
|
||||||
AssignmentProperties {
|
|
||||||
value_type: value.tipo(),
|
|
||||||
kind: *kind,
|
|
||||||
remove_unused: kind.is_let(),
|
|
||||||
full_check: !tipo.is_data() && value.tipo().is_data() && kind.is_expect(),
|
|
||||||
msg_func,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedExpr::Trace {
|
TypedExpr::Trace {
|
||||||
|
@ -2186,12 +2188,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let mut elems = vec![];
|
let mut elems = vec![];
|
||||||
|
|
||||||
let elems_then =
|
let elems_then = elements
|
||||||
elements
|
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.rev()
|
.rfold(then, |then, (index, elem)| {
|
||||||
.fold(then, |then, (index, elem)| {
|
|
||||||
// TODO: Turn 'Pattern' into another type instead of using strings and
|
// TODO: Turn 'Pattern' into another type instead of using strings and
|
||||||
// expecting a special magic string '_'.
|
// expecting a special magic string '_'.
|
||||||
let elem_name = match elem {
|
let elem_name = match elem {
|
||||||
|
@ -2213,11 +2213,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
props.final_clause,
|
props.final_clause,
|
||||||
);
|
);
|
||||||
|
|
||||||
*complex_clause = *complex_clause || elem_props.complex_clause;
|
let then = if elem_name != "_" {
|
||||||
|
|
||||||
elems.push(elem_name.clone());
|
|
||||||
|
|
||||||
if elem_name != "_" {
|
|
||||||
self.nested_clause_condition(
|
self.nested_clause_condition(
|
||||||
elem,
|
elem,
|
||||||
list_elem_type,
|
list_elem_type,
|
||||||
|
@ -2226,7 +2222,13 @@ impl<'a> CodeGenerator<'a> {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
then
|
then
|
||||||
}
|
};
|
||||||
|
|
||||||
|
elems.push(elem_name);
|
||||||
|
|
||||||
|
*complex_clause = *complex_clause || elem_props.complex_clause;
|
||||||
|
|
||||||
|
then
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut list_tail = None;
|
let mut list_tail = None;
|
||||||
|
@ -2252,21 +2254,23 @@ impl<'a> CodeGenerator<'a> {
|
||||||
props.final_clause,
|
props.final_clause,
|
||||||
);
|
);
|
||||||
|
|
||||||
*complex_clause = *complex_clause || elem_props.complex_clause;
|
|
||||||
|
|
||||||
if &elem_name != "_" && !defined_tails.is_empty() {
|
if &elem_name != "_" && !defined_tails.is_empty() {
|
||||||
list_tail = Some((tail.unwrap().to_string(), elem_name.to_string()));
|
list_tail = Some((tail.unwrap().to_string(), elem_name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if props.final_clause && defined_tails.is_empty() {
|
let then = if elem_name != "_" {
|
||||||
elems.push(elem_name.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if elem_name != "_" {
|
|
||||||
self.nested_clause_condition(elem, subject_tipo, &mut elem_props, then)
|
self.nested_clause_condition(elem, subject_tipo, &mut elem_props, then)
|
||||||
} else {
|
} else {
|
||||||
then
|
then
|
||||||
|
};
|
||||||
|
|
||||||
|
if props.final_clause && defined_tails.is_empty() {
|
||||||
|
elems.push(elem_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*complex_clause = *complex_clause || elem_props.complex_clause;
|
||||||
|
|
||||||
|
then
|
||||||
});
|
});
|
||||||
|
|
||||||
let defined_heads = elems.iter().rev().cloned().collect_vec();
|
let defined_heads = elems.iter().rev().cloned().collect_vec();
|
||||||
|
|
Loading…
Reference in New Issue