You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(analyzer): borrow HIR body in LocalAnalysis instead of double-cloning (Phase 5)
LocalAnalysis::new cloned the HIR function body (`let body = body.cloned()`),
but checks/body/mod.rs already clones each body into an owned `hir_body`
(detached from analyzer.hir, which must stay borrowable for the downstream
check_*(&mut analyzer, ...) calls). LocalAnalysis then cloned that owned copy a
SECOND time. Make LocalAnalysis borrow instead — `struct LocalAnalysis<'a>` with
`body: Option<&'a HirFunctionBody>` — so it references the already-owned body.
Halves per-function body cloning during semantic analysis; all 5 index traversals
and the initial_state/moved_uses/retained/fresh_return methods only read the body.
Behavior-identical: cascade was a mechanical lifetime annotation on the 13
`&LocalAnalysis` params across body/{semantics,resource_pool,effects,binding}.rs;
no diagnostic message/order/span change. Verified: build+clippy clean, runtime
455/0, differential 33/0, checks lib 16/0.
Scope was clone-removal only (pass-fusion deferred). Left load-bearing clones:
checks/calls.rs items.clone() and body/mod.rs functions/hir_body clones (transitive
reads of syntax_program.items / detachment from analyzer.hir make mem::take unsafe),
and hir/infer.rs value_types.cloned() (Cow/&str would cascade across 47 call sites).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments