Goals and plan
- present some light background material on the borrow-checking code, NLL
- show the NLL scope computation (from a few weeks back), explain what needs to change to use the polonius model
- go over PR #113218 implementing that change
Background
- The root of borrowck,
do_mir_borrowck
: a bunch of sequential steps
- Of interest today, some of the code path emitting errors:
a. setting up some dataflow computations (we'll come back to flow_borrows
)
b. heavy lifting: done by visiting dataflow results
- Most relevant path today: checking accesses to places
access_place
. In particular, ending up in check_access_for_conflict
to emit errors.
- Key point: looking at the set of "borrows in scopes" to ensure there are no conflicting borrows that would prevent the access.
flow_borrows
from above.
Borrows
dataflow computation. gen/kill analysis to compute borrows in scope
- The map of
BorrowIndex
es going out of scope at each location is precomputed, by the NLL OutOfScopePrecomputer
, currently here.
- It's been refactored in the last few weeks. However, my PR was started before that, and I haven't had time to look into the new one, so the PR matches the structure from the previous versions:
precompute_borrows_out_of_scope
, as the basis of my changes.
- For each borrow, walk the CFG (with some subtletly about cycles, we don't need to worry about it) starting at the point where it was introduced: check if the CFG point is contained within the region, if not, the borrow goes out of scope.
- Key point: regions as sets of points. This is the thing we want to change.
PR #113218
(a bunch of -Z
flag work that we can ignore to introduce -Zpolonius=next
)
-Zpolonius=next
enables the new computation, and asserts that it computes the same results as before.
Switch from NLL OutOfScopePrecomputer
to PoloniusOutOfScopePrecomputer
:
- from set-of-points: check whether the region contains a point.
- to set-of-loans: check whether the loan is live at that point. A loan is live if it's contained within a live region. In the location-insensitive analysis, a region contains a loan, if it's outlived by the region that issued it. The PR is about reachability.
We'll want:
- SCCs reachable from a given borrow region
- SCCs are live at a point
Some common data:
The dual function to NLL precomputer is precompute_loans_out_of_scope
:
-
starts with precomputing the reachability of the region whose scope we're computing
- SCCs live at all points
- member constraints
- these loans escape the current function, and can't go out of scope
- regular outlives constraints
-
CFG walk (exactly like the previous precompute_borrows_out_of_scope
we saw earlier)
Thoughts, questions
How do I leave a question?
ferris: How do I leave a question?
Like this! Make a new section, summarize, and then give details