fix: Various fixes for FieldsExpose, ListAccessor, TupleAccessor
This commit is contained in:
@@ -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 } => {
|
||||
|
||||
Reference in New Issue
Block a user