Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion compiler/optimizer/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/src/passes/dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl OptimizationPipeline {
}

if overall_changed {
OptimizationResult::changed(self.manager.stats.clone())
OptimizationResult::changed(self.manager.stats)
} else {
OptimizationResult::unchanged("pipeline")
}
Expand Down
Loading