fix: inline_direct_reduce now works properly
This commit is contained in:
parent
0b7d217bd0
commit
016634fc38
|
@ -19,12 +19,11 @@ pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
||||||
|
|
||||||
program
|
program
|
||||||
.lambda_reduce()
|
.lambda_reduce()
|
||||||
.inline_basic_reduce()
|
.inline_reduce()
|
||||||
.lambda_reduce()
|
.lambda_reduce()
|
||||||
.inline_basic_reduce()
|
.inline_reduce()
|
||||||
.force_delay_reduce()
|
.force_delay_reduce()
|
||||||
.wrap_data_reduce()
|
.wrap_data_reduce()
|
||||||
.lambda_reduce()
|
.lambda_reduce()
|
||||||
.inline_basic_reduce()
|
.inline_reduce()
|
||||||
.inline_direct_reduce()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,9 @@ impl Program<Name> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inline_basic_reduce(self) -> Program<Name> {
|
pub fn inline_reduce(self) -> Program<Name> {
|
||||||
let mut term = self.term;
|
let mut term = self.term;
|
||||||
inline_basic_reduce(&mut term);
|
inline_basic_reduce(&mut term);
|
||||||
|
|
||||||
Program {
|
|
||||||
version: self.version,
|
|
||||||
term,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inline_direct_reduce(self) -> Program<Name> {
|
|
||||||
let mut term = self.term;
|
|
||||||
inline_direct_reduce(&mut term);
|
inline_direct_reduce(&mut term);
|
||||||
|
|
||||||
Program {
|
Program {
|
||||||
|
@ -177,25 +168,30 @@ fn inline_direct_reduce(term: &mut Term<Name>) {
|
||||||
let d = Rc::make_mut(d);
|
let d = Rc::make_mut(d);
|
||||||
inline_direct_reduce(d);
|
inline_direct_reduce(d);
|
||||||
}
|
}
|
||||||
Term::Lambda {
|
Term::Lambda { body, .. } => {
|
||||||
parameter_name,
|
|
||||||
body,
|
|
||||||
} => {
|
|
||||||
let body = Rc::make_mut(body);
|
let body = Rc::make_mut(body);
|
||||||
inline_direct_reduce(body);
|
inline_direct_reduce(body);
|
||||||
|
|
||||||
if let Term::Var(name) = body {
|
|
||||||
if name.as_ref() == parameter_name.as_ref() {
|
|
||||||
*term = body.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Term::Apply { function, argument } => {
|
Term::Apply { function, argument } => {
|
||||||
let func = Rc::make_mut(function);
|
let func = Rc::make_mut(function);
|
||||||
let arg = Rc::make_mut(argument);
|
let arg = Rc::make_mut(argument);
|
||||||
inline_direct_reduce(func);
|
|
||||||
|
|
||||||
|
inline_direct_reduce(func);
|
||||||
inline_direct_reduce(arg);
|
inline_direct_reduce(arg);
|
||||||
|
|
||||||
|
let Term::Lambda { parameter_name, body } = arg
|
||||||
|
else{
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let Term::Var(name) = body.as_ref()
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if name.as_ref() == parameter_name.as_ref() {
|
||||||
|
*term = arg.clone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Term::Force(f) => {
|
Term::Force(f) => {
|
||||||
let f = Rc::make_mut(f);
|
let f = Rc::make_mut(f);
|
||||||
|
|
Loading…
Reference in New Issue