inline is actually cheaper in a lot of cases
This commit is contained in:
parent
a2068ff062
commit
fb2ca0e3e0
|
@ -334,9 +334,7 @@ fn inline_single_occurrence_reducer(term: &mut Term<Name>) {
|
||||||
let occurrences = var_occurrences(body, parameter_name.clone());
|
let occurrences = var_occurrences(body, parameter_name.clone());
|
||||||
|
|
||||||
let delays = delayed_execution(body.as_ref());
|
let delays = delayed_execution(body.as_ref());
|
||||||
let recursive = is_recursive(arg);
|
if occurrences == 1 {
|
||||||
// We don't want to inline recursive functions
|
|
||||||
if occurrences == 1 && !recursive {
|
|
||||||
if delays == 0 {
|
if delays == 0 {
|
||||||
*term = substitute_term(body.as_ref(), parameter_name.clone(), arg);
|
*term = substitute_term(body.as_ref(), parameter_name.clone(), arg);
|
||||||
} else if let Term::Var(_)
|
} else if let Term::Var(_)
|
||||||
|
@ -525,24 +523,6 @@ fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> usize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_recursive(term: &Term<Name>) -> bool {
|
|
||||||
match term {
|
|
||||||
Term::Delay(body) => is_recursive(body.as_ref()),
|
|
||||||
Term::Lambda { body, .. } => is_recursive(body.as_ref()),
|
|
||||||
Term::Apply { function, argument } => {
|
|
||||||
if let (Term::Var(a), Term::Var(b)) = (function.as_ref(), argument.as_ref()) {
|
|
||||||
a.as_ref() == b.as_ref()
|
|
||||||
} else {
|
|
||||||
is_recursive(function.as_ref()) || is_recursive(argument.as_ref())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Term::Force(x) => is_recursive(x.as_ref()),
|
|
||||||
Term::Case { .. } => todo!(),
|
|
||||||
Term::Constr { .. } => todo!(),
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delayed_execution(term: &Term<Name>) -> usize {
|
fn delayed_execution(term: &Term<Name>) -> usize {
|
||||||
match term {
|
match term {
|
||||||
Term::Delay(body) => 1 + delayed_execution(body.as_ref()),
|
Term::Delay(body) => 1 + delayed_execution(body.as_ref()),
|
||||||
|
|
Loading…
Reference in New Issue