fix: Various fixes for FieldsExpose, ListAccessor, TupleAccessor

This commit is contained in:
Kasey White
2023-02-07 17:42:33 -05:00
committed by Lucas
parent cf7a20b986
commit 986a6009f7
6 changed files with 135 additions and 136 deletions

View File

@@ -142,17 +142,31 @@ fn inline_basic_reduce(term: &mut Term<Name>) {
body,
} = func
{
if let replace_term @ (Term::Var(_)
| Term::Constant(_)
| Term::Error
| Term::Delay(_)
| Term::Lambda { .. }) = argument.as_ref()
{
let mut occurrences = 0;
var_occurrences(body, parameter_name.clone(), &mut occurrences);
if occurrences <= 1 {
*term =
substitute_term(body.as_ref(), parameter_name.clone(), replace_term);
let mut occurrences = 0;
var_occurrences(body, parameter_name.clone(), &mut occurrences);
if occurrences == 1 {
if let replace_term @ (Term::Var(_)
| Term::Constant(_)
| Term::Error
| Term::Delay(_)
| Term::Lambda { .. }) = argument.as_ref()
{
if occurrences == 1 {
*term = substitute_term(
body.as_ref(),
parameter_name.clone(),
replace_term,
);
}
}
} else if occurrences == 0 {
error_occurrences(argument.as_ref(), &mut occurrences);
if occurrences == 0 {
*term = substitute_term(
body.as_ref(),
parameter_name.clone(),
argument.as_ref(),
);
}
}
}
@@ -194,6 +208,28 @@ fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>, occurrences: &mut us
}
}
fn error_occurrences(term: &Term<Name>, occurrences: &mut usize) {
match term {
Term::Delay(body) => {
error_occurrences(body.as_ref(), occurrences);
}
Term::Lambda { body, .. } => {
error_occurrences(body.as_ref(), occurrences);
}
Term::Apply { function, argument } => {
error_occurrences(function.as_ref(), occurrences);
error_occurrences(argument.as_ref(), occurrences);
}
Term::Force(x) => {
error_occurrences(x.as_ref(), occurrences);
}
Term::Error => {
*occurrences += 1;
}
_ => {}
}
}
fn lambda_reduce(term: &mut Term<Name>) {
match term {
Term::Apply { function, argument } => {