Skip to content

Move region constraint search into a separate module - #162699

Open
amandasystems wants to merge 1 commit into
rust-lang:mainfrom
amandasystems:region-constraint-search-weights
Open

Move region constraint search into a separate module#162699
amandasystems wants to merge 1 commit into
rust-lang:mainfrom
amandasystems:region-constraint-search-weights

Conversation

@amandasystems

@amandasystems amandasystems commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

This PR moves constraint search out of region inference, for three reasons:

It has two, minor, changes to logic:

  1. It decouples region liveness search from path search, since it shares none of its complexities, and uses this to simplify it by using less bookkeeping.
  2. It changes the interface to search from a path between two regions to try, in order:
    1. Using no member constraints and no higher-ranked lowered constraints
    2. Using higher-rank lowering constraints (but no opaques)
    3. Using all constraints available

This simplifies the interface and some of the logic, but risks restarting once too often. Maybe.

Note that we have three distinct tasks for this module, previously shoehorned into the same path search:

  • Find a live region (a reachability problem)
  • Find a blame constraint (an optimisation problem that may be a shortest path problem)
  • Find the shortest (by number of hops) path between two regions (a shortest path problem)

My long term plan is to use this as a basis for a two planned improvements:

  1. Rewrite the restarts to avoid undesirable constraints in searches if possible to use weights instead to avoid them in one search
  2. Break out blame constraint finding into its own max flow/min cut problem where the desired best-score is the cut, and/or use a similar logic as above to pick paths with high-value constraints

(2) is particularly interesting because it promises make blame constraint finding a lot less brittle, implicit, and ad hoc (note the comments in the method).

This probably wants a perf run just to make sure I didn’t mess up inlining since I did move hot code. It should be an obvious net win except possibly when doing a blame search, which may restart slightly more often, but we’ve already established that to be non-performance critical.

This also inlines some of the region graph search methods
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 12, 2026
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: borrowck, compiler
  • borrowck, compiler expanded to 76 candidates
  • Random selection from 21 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants