BIR and CFG Drop analysis ยท PR #4730
Add straight-line BIR Drop-style analysis
Objective
Add an initial BIR Drop-state analysis for whole local variables in straight-line control flow. Classify each Drop point as Static or Dead.
Why it was needed
After a non-Copy move such as let y = x, x no longer owns the value and must not be dropped.
gccrs needed an analysis to check if a local was still initialized at each Drop point.
This first step handled whole locals in straight-line code. PR #4748 later connected the result to backend cleanup.
Main changes
- Fixes the sized
IndexVecconstructor so it creates the requested elements instead of only reserving space. - Adds BIR Drop statements at scope exits and for function arguments.
- Tracks assignments, whole-local moves, and
Copyvalues. - Prints the
StaticandDeadclassifications in BIR dumps.
Test case
- drop_analysis_whole_move.rs: Checks a static local, a whole-local move, a
Copyassignment, and a function argument in the BIR dump.
Scope of this PR
This first patch covers straight-line functions, whole-local moves,
Copyversus move assignments, function arguments, andStaticorDeadDrops.Branches, loops, partial moves,
needs_dropfiltering, and backend integration were left for follow-up patches.