From 0269409fa11428c772776072ca61c1c42849f8c4 Mon Sep 17 00:00:00 2001 From: Kasey White Date: Fri, 10 Feb 2023 19:24:47 -0500 Subject: [PATCH] case where removing a lam with 0 occurrences is not safe Since a function call can have arbitrary other calls that lead to error and that is difficult to detect. --- crates/uplc/src/optimize/shrinker.rs | 60 +++++++++++----------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/crates/uplc/src/optimize/shrinker.rs b/crates/uplc/src/optimize/shrinker.rs index fbbf4686..eb7181f5 100644 --- a/crates/uplc/src/optimize/shrinker.rs +++ b/crates/uplc/src/optimize/shrinker.rs @@ -151,22 +151,8 @@ fn inline_basic_reduce(term: &mut Term) { | 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(), - ); + *term = + substitute_term(body.as_ref(), parameter_name.clone(), replace_term); } } } @@ -208,27 +194,27 @@ fn var_occurrences(term: &Term, search_for: Rc, occurrences: &mut us } } -fn error_occurrences(term: &Term, 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 error_occurrences(term: &Term, 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) { match term {