From 961168f3b6d08a643013368892b5785e54317752 Mon Sep 17 00:00:00 2001 From: Michael Schimmel Date: Tue, 10 Mar 2026 16:13:39 +0100 Subject: [PATCH] Refactor analyzer to return impurity The `Analyzer` is now responsible for determining the purity of `Define` bindings. Previously, this responsibility was left to the caller. Added a new example `design-flaw.myc` to test this change. Updated `soa_series.myc` due to the purity change. --- examples/design-flaw.myc | 7 +++++++ examples/soa_series.myc | 2 +- src/ast/compiler/analyzer.rs | 3 +-- src/ast/compiler/optimizer/utils.rs | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 examples/design-flaw.myc diff --git a/examples/design-flaw.myc b/examples/design-flaw.myc new file mode 100644 index 0000000..bd5ee60 --- /dev/null +++ b/examples/design-flaw.myc @@ -0,0 +1,7 @@ + +(do + (do + (def x "hh") + ) + (print x) +) diff --git a/examples/soa_series.myc b/examples/soa_series.myc index 3e892a5..a7d9741 100644 --- a/examples/soa_series.myc +++ b/examples/soa_series.myc @@ -1,4 +1,4 @@ -;; Output: 228 +;; Output: 26.7 ;; Benchmark: 1.4us ;; Benchmark-Repeat: 1406 (do diff --git a/src/ast/compiler/analyzer.rs b/src/ast/compiler/analyzer.rs index a95c710..9b18a5b 100644 --- a/src/ast/compiler/analyzer.rs +++ b/src/ast/compiler/analyzer.rs @@ -116,7 +116,6 @@ impl<'a> Analyzer<'a> { captured_by, } => { let val_m = self.visit(value.clone()); - let p = val_m.ty.purity; ( BoundKind::Define { name: name.clone(), @@ -125,7 +124,7 @@ impl<'a> Analyzer<'a> { value: Rc::new(val_m), captured_by: captured_by.clone(), }, - p, + Purity::Impure, ) } diff --git a/src/ast/compiler/optimizer/utils.rs b/src/ast/compiler/optimizer/utils.rs index 97cd27a..d5db130 100644 --- a/src/ast/compiler/optimizer/utils.rs +++ b/src/ast/compiler/optimizer/utils.rs @@ -143,7 +143,8 @@ impl UsageInfo { self.collect(v); } } - BoundKind::Define { value, .. } => { + BoundKind::Define { addr, value, .. } => { + self.assigned.insert(*addr); self.collect(value); } BoundKind::Expansion { bound_expanded, .. } => {