Skip to content

Region inference: split results from RegionInferenceContext#151688

Open
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:split-region-inference
Open

Region inference: split results from RegionInferenceContext#151688
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:split-region-inference

Conversation

@amandasystems
Copy link
Copy Markdown
Contributor

@amandasystems amandasystems commented Jan 26, 2026

What?

This PR turns RegionInferenceContext into a builder that produces the inferred region values, InferredRegions. The resulting struct implements the public API of RegionInferenceContext and replaces it in consumers.rs. RegionInferenceContext::solve() now consumes (moves) the inference context. It is completely private to region inference.

Why?

  • RegionInferenceContext has become a huge dump for various values people want to access.
  • region_infer itself is a very large file that's difficult to find your way around.
  • Polonius wants to skip as much of region inference as possible, since most of it is redundant. This makes that possible
  • No method now need warnings about being called after region inference or else they'll panic
  • RegionInferenceContext now takes almost all of its fields by reference
  • We can probably drop at least some stuff earlier
  • Data dependencies during region inference are now made more explicit

Knock-on effects

  • Region constraint (blame) search is now independent of a RegionInferenceContext
  • Less data is retained after region inference. This may or may not lead to minor improvements in memory use.
  • RegionInferenceContext now almost exclusively contains references to values, as opposed to owning them. This addresses most of fn compute_closure_requirements_modulo_opaques shouldn't clone all its inputs #146079
  • This reduces the coupling between region inference and Polonius-next, making it possible to skip region inference if it is not needed to check universal regions or type tests.
  • region_infer gains two child modules and becomes a lot less of a behemoth.

Detailed overview of changes

  • new modules: region_infer::constraint_search and region_infer::universal_regions.
  • handle_placeholders now consumes less input and does constraint rewriting via mutable references
  • consumers.rs now has a InferenceResults instead of a RegionInferenceContext
  • The public methods eval_{equal, outlives} are moved to InferredRegions
  • Constraint (blame) search, MIR dumping, graphviz rendering, and checking universal regions now all get their own builder-style structs, and the methods for their respective tasks are moved onto them
  • The option for region inference results in ConsumerOptions is now called InferredRegions
  • calculate_borrows_out_of_scope_at_location of course now takes InferredRegions
  • LivenessValues for free regions is now initialised as live at all points along with the constraint rewriting during placeholder handling, as opposed to during construction of RegionInferenceContext
  • Some trace logging, especially during constraint search, is lost since the data required to print the logs was only necessary to print the logs and never used otherwise.

r? @lcnr

Closes #146079.

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

Labels

perf-regression Performance regression. 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.

fn compute_closure_requirements_modulo_opaques shouldn't clone all its inputs

5 participants