Skip to content

Conversation

@amandasystems
Copy link
Contributor

This ensures all of region inference is immutable, and makes every operation that requires region inference to have been executed to run explicitly require the results.

I have chosen to newtype the results and lightly abstract it from outside viewers, since it's required by some consumers of the compiler internal APIs. Those should be able to find what they need to exercise the features they used to need.

r? @lcnr

@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 Jan 26, 2026
@rust-log-analyzer

This comment has been minimized.

@amandasystems amandasystems force-pushed the split-region-inference branch from 6befd69 to 13a57f6 Compare January 26, 2026 14:50
@rust-log-analyzer

This comment has been minimized.

@amandasystems amandasystems force-pushed the split-region-inference branch from 13a57f6 to 00e8121 Compare January 26, 2026 16:12
@@ -618,7 +624,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why split out the scc_values but not the scc graph itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require a larger change to RegionInferenceContext, since it uses it for almost everything. I could try though and see where that goes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be more elegant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the best approach would probably be that RegionInferenceContext borrows a bunch of stuff, does its computation and then dies once inference is complete, and the results are what's stored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: that is more elegant, but it also requires moving the SCCs out of RegionInferenceContext, which collapses like a soufflé and the change becomes enormous. I'm trying that, because I suspect the more decentralised architecture might help with Polonius not recomputing things in the future, but it turns out that everyone kind of expect regioncx to be around absolutely everywhere and use it to pilfer various data they need, usually not many things.

The good news are that data dependencies are now much easier to see for humans (and maybe also the compiler).

This ensures all of region inference is immutable, and makes every
operation that requires region inference to have been executed to run
explicitly require the results.
Since this collapses `RegionInferenceContext`, `::solve()` now
consumes the inference context.
@amandasystems amandasystems force-pushed the split-region-inference branch from 00e8121 to 454f98a Compare January 28, 2026 22:21
@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    354d02aa29ac   9 days ago   783MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:596da3f22bcbdff2c96fd7126001278022c834c1621c5efa2ad1a7794590636c
deleted: sha256:354d02aa29acf525570c732b6e006ecf138de6d63ca525d552eb4b24880ddc6c
deleted: sha256:8b7af0e426bc2cbeeacfd96b8354d3b80016991520977197e62090e47abaede8
deleted: sha256:cadf11ef1de7fdd5eab563757942353684047f09b212dc99d6ed48e8acf34d62
deleted: sha256:569b0caf9d5285db44ccd2629a3470139eea755be423a33a54d8a24cb3926bfa
deleted: sha256:f9dc5feb048d8f9fd43137e3998f59e9acfbd76c47a4e14984d109654119e282
---
    Checking rustc_passes v0.0.0 (/checkout/compiler/rustc_passes)
[RUSTC-TIMING] rustc_mir_build test:false 2.425
[RUSTC-TIMING] rustc_passes test:false 1.391
[RUSTC-TIMING] rustc_codegen_llvm test:false 3.115
warning: type `LivenessValues` is more private than the item `Borrows::<'a, 'tcx>::new`
   --> compiler/rustc_borrowck/src/dataflow.rs:427:5
    |
427 | /     pub fn new(
428 | |         tcx: TyCtxt<'tcx>,
429 | |         body: &'a Body<'tcx>,
430 | |         liveness_values: &'a LivenessValues,
431 | |         scc_values: &InferredRegions<'tcx>,
432 | |         borrow_set: &'a BorrowSet<'tcx>,
433 | |     ) -> Self {
    | |_____________^ associated function `Borrows::<'a, 'tcx>::new` is reachable at visibility `pub`
    |
note: but type `LivenessValues` is only usable at visibility `pub(crate)`
   --> compiler/rustc_borrowck/src/region_infer/values.rs:41:1
    |
 41 | pub(crate) struct LivenessValues {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: `#[warn(private_interfaces)]` on by default

warning: type `RegionValues<'tcx, constraints::ConstraintSccIndex>` is more private than the item `RegionInferenceContext::<'a, 'tcx>::eval_equal`
   --> compiler/rustc_borrowck/src/region_infer/mod.rs:882:5
    |
882 | /     pub fn eval_equal(
883 | |         &self,
884 | |         scc_values: &RegionValues<'tcx, ConstraintSccIndex>,
885 | |         r1: RegionVid,
886 | |         r2: RegionVid,
887 | |     ) -> bool {
    | |_____________^ method `RegionInferenceContext::<'a, 'tcx>::eval_equal` is reachable at visibility `pub`
    |
note: but type `RegionValues<'tcx, constraints::ConstraintSccIndex>` is only usable at visibility `pub(crate)`
   --> compiler/rustc_borrowck/src/region_infer/values.rs:247:1
    |
247 | pub(crate) struct RegionValues<'tcx, N: Idx> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type `RegionValues<'tcx, constraints::ConstraintSccIndex>` is more private than the item `RegionInferenceContext::<'a, 'tcx>::eval_outlives`
   --> compiler/rustc_borrowck/src/region_infer/mod.rs:895:5
    |
895 | /     pub fn eval_outlives(
896 | |         &self,
897 | |         scc_values: &RegionValues<'tcx, ConstraintSccIndex>,
898 | |         sup_region: RegionVid,
899 | |         sub_region: RegionVid,
900 | |     ) -> bool {
    | |_____________^ method `RegionInferenceContext::<'a, 'tcx>::eval_outlives` is reachable at visibility `pub`
    |
note: but type `RegionValues<'tcx, constraints::ConstraintSccIndex>` is only usable at visibility `pub(crate)`
   --> compiler/rustc_borrowck/src/region_infer/values.rs:247:1
    |
247 | pub(crate) struct RegionValues<'tcx, N: Idx> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: methods `constraint_path_to`, `region_definition`, and `is_loan_live_at` are never used
    --> compiler/rustc_borrowck/src/region_infer/mod.rs:1354:8
     |
 354 | impl<'a, 'tcx> RegionInferenceContext<'a, 'tcx> {
     | ----------------------------------------------- methods in this implementation
...
1354 |     fn constraint_path_to(
     |        ^^^^^^^^^^^^^^^^^^
...
1366 |     pub(crate) fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx> {
     |                   ^^^^^^^^^^^^^^^^^
...
1407 |     pub(crate) fn is_loan_live_at(&self, loan_idx: BorrowIndex, location: Location) -> bool {
     |                   ^^^^^^^^^^^^^^^
     |
     = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

[RUSTC-TIMING] rustc_borrowck test:false 4.164

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.

4 participants