step up the optimizations a bit more by inlining a small function
This commit is contained in:
parent
bf429fbdbf
commit
94f383762c
|
@ -5,6 +5,7 @@ pub mod shrinker;
|
||||||
|
|
||||||
pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
||||||
program
|
program
|
||||||
|
.inline_constr_ops()
|
||||||
.builtin_force_reducer()
|
.builtin_force_reducer()
|
||||||
.lambda_reducer()
|
.lambda_reducer()
|
||||||
.inline_reducer()
|
.inline_reducer()
|
||||||
|
|
|
@ -7,6 +7,7 @@ use pallas::ledger::primitives::babbage::{BigInt, PlutusData};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type},
|
ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type},
|
||||||
|
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER},
|
||||||
builtins::DefaultFunction,
|
builtins::DefaultFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1089,7 +1090,7 @@ impl Program<Name> {
|
||||||
pub fn force_delay_reducer(self) -> Self {
|
pub fn force_delay_reducer(self) -> Self {
|
||||||
self.traverse_uplc_with(&mut |_id, term, _arg_stack, _scope| {
|
self.traverse_uplc_with(&mut |_id, term, _arg_stack, _scope| {
|
||||||
if let Term::Force(f) = term {
|
if let Term::Force(f) = term {
|
||||||
let f = Rc::make_mut(f);
|
let f = f.as_ref();
|
||||||
|
|
||||||
if let Term::Delay(body) = f {
|
if let Term::Delay(body) = f {
|
||||||
*term = body.as_ref().clone();
|
*term = body.as_ref().clone();
|
||||||
|
@ -1108,6 +1109,26 @@ impl Program<Name> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inline_constr_ops(self) -> Self {
|
||||||
|
self.traverse_uplc_with(&mut |_, term, _, _| {
|
||||||
|
if let Term::Apply { function, argument } = term {
|
||||||
|
if let Term::Var(name) = function.as_ref() {
|
||||||
|
if name.text == CONSTR_FIELDS_EXPOSER {
|
||||||
|
*term = Term::snd_pair().apply(Term::Apply {
|
||||||
|
function: Term::unconstr_data().into(),
|
||||||
|
argument: argument.clone(),
|
||||||
|
})
|
||||||
|
} else if name.text == CONSTR_INDEX_EXPOSER {
|
||||||
|
*term = Term::fst_pair().apply(Term::Apply {
|
||||||
|
function: Term::unconstr_data().into(),
|
||||||
|
argument: argument.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cast_data_reducer(self) -> Self {
|
pub fn cast_data_reducer(self) -> Self {
|
||||||
let mut applied_ids = vec![];
|
let mut applied_ids = vec![];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue