From 2479dbd9a6562f05e43d61195891896d1a7ee09e Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 17 Mar 2024 10:19:50 -0400 Subject: [PATCH] Expand let elimination to work on some simple expression types regardless of use count --- opt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opt.py b/opt.py index a906dfe..e322f39 100644 --- a/opt.py +++ b/opt.py @@ -10,8 +10,9 @@ Optimization: TypeAlias = Callable[[Expression], Option[Expression]] def eliminate_single_let(expr: Expression) -> Option[Expression]: match expr: case LetBinding(lhs, rhs, body): - if count_uses(lhs, body) <= 1: - # RHS is used at most once i nthe body + rhs_is_simple = isinstance(rhs, Int | Variable | Builtin) + if count_uses(lhs, body) <= 1 or rhs_is_simple: + # RHS is used at most once i nthe body or replication wouldnt be costly if count_uses(lhs, rhs) > 0: # RHS is recursive if not isinstance(body, Variable):