Try   HackMD

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

  1. The root of borrowck, do_mir_borrowck: a bunch of sequential steps
  2. 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
  3. Most relevant path today: checking accesses to places access_place. In particular, ending up in check_access_for_conflict to emit errors.
  4. 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.
  5. Borrows dataflow computation. gen/kill analysis to compute borrows in scope
  6. The map of BorrowIndexes going out of scope at each location is precomputed, by the NLL OutOfScopePrecomputer, currently here.
  7. 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.
  8. 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.
  9. 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:

  1. 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
  2. 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