From b0ccfc6309388e5ef2915cdb8506b91165b7de87 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sat, 16 Mar 2024 22:23:06 -0400 Subject: [PATCH] Optimization: Special case for simplying recursive let bindings codegen --- ir.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ir.py b/ir.py index 48797a9..bbf5fd9 100644 --- a/ir.py +++ b/ir.py @@ -183,7 +183,10 @@ class LetBinding: def codegen(self) -> str: rhs_cg = self.rhs.codegen_named(self.lhs) if isinstance(self.rhs, MonoFunc) else self.rhs.codegen() - return f'({self.lhs}=>{self.body.codegen()})({rhs_cg})' + if self.body == Variable(self.lhs): + return rhs_cg + else: + return f'({self.lhs}=>{self.body.codegen()})({rhs_cg})' @dataclass class Application: