Skip to content

Commit

Permalink
Closes #945
Browse files Browse the repository at this point in the history
Switch to depth first optimization passes instead of breadth first for inlining. Need to think more on how to do breadth first optimization passes
  • Loading branch information
MicroProofs committed May 21, 2024
1 parent e28b0df commit 489eff7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crates/uplc/src/optimize/shrinker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ impl Program<Name> {
pub fn lambda_reducer(self) -> Self {
let mut lambda_applied_ids = vec![];

self.traverse_uplc_with(true, &mut |id, term, mut arg_stack, _scope| {
self.traverse_uplc_with(false, &mut |id, term, mut arg_stack, _scope| {
match term {
Term::Apply { function, .. } => {
// We are applying some arg so now we unwrap the id of the applied arg
Expand Down Expand Up @@ -904,7 +904,7 @@ impl Program<Name> {
pub fn builtin_force_reducer(self) -> Self {
let mut builtin_map = IndexMap::new();

let program = self.traverse_uplc_with(true, &mut |_id, term, _arg_stack, _scope| {
let program = self.traverse_uplc_with(false, &mut |_id, term, _arg_stack, _scope| {
if let Term::Force(f) = term {
let f = Rc::make_mut(f);
match f {
Expand Down Expand Up @@ -964,7 +964,7 @@ impl Program<Name> {

pub fn identity_reducer(self) -> Self {
let mut identity_applied_ids = vec![];
self.traverse_uplc_with(true, &mut |id, term, mut arg_stack, _scope| {
self.traverse_uplc_with(false, &mut |id, term, mut arg_stack, _scope| {
match term {
Term::Apply { function, .. } => {
// We are applying some arg so now we unwrap the id of the applied arg
Expand Down Expand Up @@ -1073,7 +1073,7 @@ impl Program<Name> {
pub fn inline_reducer(self) -> Self {
let mut lambda_applied_ids = vec![];

self.traverse_uplc_with(true, &mut |id, term, mut arg_stack, _scope| match term {
self.traverse_uplc_with(false, &mut |id, term, mut arg_stack, _scope| match term {
Term::Apply { function, .. } => {
// We are applying some arg so now we unwrap the id of the applied arg
let id = id.unwrap();
Expand Down Expand Up @@ -1139,7 +1139,7 @@ impl Program<Name> {
}

pub fn force_delay_reducer(self) -> Self {
self.traverse_uplc_with(true, &mut |_id, term, _arg_stack, _scope| {
self.traverse_uplc_with(false, &mut |_id, term, _arg_stack, _scope| {
if let Term::Force(f) = term {
let f = f.as_ref();

Expand All @@ -1151,7 +1151,7 @@ impl Program<Name> {
}

pub fn remove_no_inlines(self) -> Self {
self.traverse_uplc_with(true, &mut |_, term, _, _| match term {
self.traverse_uplc_with(false, &mut |_, term, _, _| match term {
Term::Lambda {
parameter_name,
body,
Expand All @@ -1161,7 +1161,7 @@ impl Program<Name> {
}

pub fn inline_constr_ops(self) -> Self {
self.traverse_uplc_with(true, &mut |_, term, _, _| {
self.traverse_uplc_with(false, &mut |_, term, _, _| {
if let Term::Apply { function, argument } = term {
if let Term::Var(name) = function.as_ref() {
if name.text == CONSTR_FIELDS_EXPOSER {
Expand All @@ -1183,7 +1183,7 @@ impl Program<Name> {
pub fn cast_data_reducer(self) -> Self {
let mut applied_ids = vec![];

self.traverse_uplc_with(true, &mut |id, term, mut arg_stack, _scope| {
self.traverse_uplc_with(false, &mut |id, term, mut arg_stack, _scope| {
match term {
Term::Apply { function, .. } => {
// We are apply some arg so now we unwrap the id of the applied arg
Expand Down Expand Up @@ -1311,7 +1311,7 @@ impl Program<Name> {
pub fn convert_arithmetic_ops(self) -> Self {
let mut constants_to_flip = vec![];

self.traverse_uplc_with(true, &mut |id, term, arg_stack, _scope| match term {
self.traverse_uplc_with(false, &mut |id, term, arg_stack, _scope| match term {
Term::Apply { argument, .. } => {
let id = id.unwrap();

Expand Down

0 comments on commit 489eff7

Please sign in to comment.