diff --git a/.jules/bolt.md b/.jules/bolt.md index a1e28467..e69de29b 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,4 +0,0 @@ -## 2024-01-20 - Lifetime Refactoring in Parser to Eliminate Token Cloning -**Learning:** In the Rust parser (`compiler/parser/src/parser.rs`), methods like `advance()` and `previous()` originally returned a reference tied to `&mut self`. Because `Token` was still borrowing `self` mutably, the parser couldn't call methods like `self.parse_prefix` (which requires another `&mut self` borrow) without first calling `.clone()` on the token to drop the initial borrow. -**Action:** By explicitly defining the return lifetime as `&'a Token` (tied to the lifetime of the underlying token slice `&'a [Token]`, rather than the `Parser` instance), the mutable borrow of `self` ends immediately. This elegantly satisfies the borrow checker while removing the overhead of cloning tokens throughout `expressions.rs` and `statements.rs`. Look for similar lifetime constraints elsewhere in the compiler that force unnecessary copies. - diff --git a/compiler/optimizer/src/pass_manager.rs b/compiler/optimizer/src/pass_manager.rs index 7407822c..1dd1969f 100644 --- a/compiler/optimizer/src/pass_manager.rs +++ b/compiler/optimizer/src/pass_manager.rs @@ -50,7 +50,7 @@ impl PassManager { let res = pass.run(module, &mut self.analyses); let duration = start.elapsed(); - let mut pass_stats = res.stats.clone(); + let mut pass_stats = res.stats; pass_stats.time_taken_ns = duration.as_nanos(); self.stats.combine(&pass_stats); diff --git a/compiler/optimizer/src/passes/dead_code.rs b/compiler/optimizer/src/passes/dead_code.rs index b25a8b18..cce939e7 100644 --- a/compiler/optimizer/src/passes/dead_code.rs +++ b/compiler/optimizer/src/passes/dead_code.rs @@ -19,7 +19,7 @@ impl OptimizationPass for DeadCode { for func in &mut module.functions { // Retrieve Use-Def analysis - let use_def = analyses.get_use_def(func).clone(); + let use_def = analyses.get_use_def(func); for block in &mut func.blocks { block.instructions.retain(|inst| { diff --git a/compiler/optimizer/src/pipeline.rs b/compiler/optimizer/src/pipeline.rs index bb319b9a..eb4827c9 100644 --- a/compiler/optimizer/src/pipeline.rs +++ b/compiler/optimizer/src/pipeline.rs @@ -74,7 +74,7 @@ impl OptimizationPipeline { } if overall_changed { - OptimizationResult::changed(self.manager.stats.clone()) + OptimizationResult::changed(self.manager.stats) } else { OptimizationResult::unchanged("pipeline") }