Skip to content

Region inference: Simplify initialisation of region values#157672

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
amandasystems:region-inference-initialisation
Jun 12, 2026
Merged

Region inference: Simplify initialisation of region values#157672
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
amandasystems:region-inference-initialisation

Conversation

@amandasystems

@amandasystems amandasystems commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This PR simplifies the initialisation of region values in region_infer

  • RegionInferenceContext::init_free_and_bound_regions() is inlined into ::new() and pulled to before initial SCC values are assigned
  • A couple of iteration-then-index patterns are changed into iter_enumerated()-style patterns
  • Some leftover code comments are removed and revised to actually describe the initialisation
  • Free regions are now marked as live everywhere in liveness constraints, then copied to scc_values upon initialisation, avoiding performing that logic twice
  • The trait used to index into SCC values goes away and the relevant methods are monomorphised and static-dispatched. This makes it easier to follow what's going on where, and possibly also shows a potential optimiser how insanely inline:able those methods are since they are used in exactly one place with exactly one type of value (though maybe it already saw that).

It should do strictly less work, but almost all of it would only happen on free regions, and there shouldn't be large numbers of those. Depending on the cleverness of the optimiser most of the option/some checks should have been compiled away anyway.

The key advantage as I see it is clearer flow: first liveness constraints are set up, then initial values are initialised, then region inference is ready to run.

@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 Jun 9, 2026
@rustbot

rustbot commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
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 73 candidates
  • Random selection from 17 candidates

@amandasystems amandasystems marked this pull request as draft June 9, 2026 15:43
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 9, 2026
@amandasystems

Copy link
Copy Markdown
Contributor Author

Dammit, it seems to be weirdly based on something. I'll have to rebase it.

@amandasystems amandasystems force-pushed the region-inference-initialisation branch from ffc1eec to 9602230 Compare June 9, 2026 16:00
@rustbot rustbot added A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 9, 2026
- `RegionInferenceContext::init_free_and_bound_regions()` is inlined into `::new()` and pulled to before initial SCC values are assigned
- A couple of iteration-then-index patterns are changed into `iter_enumerated()`-style patterns
- Some leftover code comments are removed and revised to actually describe the initialisation
- Free regions are now marked as live everywhere in liveness constraints, then copied to scc_values upon initialisation, avoiding performing that logic twice

It should do strictly less work, but almost all of it would only happen on free regions, and there shouldn't be large numbers of those. Depending on the cleverness of the optimiser most of the option/some checks should have been compiled away anyway.

The key advantage as I see it is clearer flow: first liveness constraints are set up, then initial values are initialised, then region inference is ready to run.
@amandasystems amandasystems force-pushed the region-inference-initialisation branch from 9602230 to 219a65f Compare June 9, 2026 16:15
@amandasystems amandasystems marked this pull request as ready for review June 9, 2026 16:15
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 9, 2026

// Add all nodes in the CFG to liveness constraints
self.liveness_constraints.add_all_points(variable);
self.scc_values.add_all_points(scc);

@amandasystems amandasystems Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@amandasystems amandasystems force-pushed the region-inference-initialisation branch from 610be6c to 0b6f400 Compare June 10, 2026 13:45

@davidtwco davidtwco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@davidtwco

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5c35f31 has been approved by davidtwco

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 12, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 12, 2026
…tialisation, r=davidtwco

Region inference: Simplify initialisation of region values

This PR simplifies the initialisation of region values in `region_infer`

- `RegionInferenceContext::init_free_and_bound_regions()` is inlined into `::new()` and pulled to before initial SCC values are assigned
- A couple of iteration-then-index patterns are changed into `iter_enumerated()`-style patterns
- Some leftover code comments are removed and revised to actually describe the initialisation
- Free regions are now marked as live everywhere in liveness constraints, then copied to scc_values upon initialisation, avoiding performing that logic twice
- The trait used to index into SCC values goes away and the relevant methods are monomorphised and static-dispatched. This makes it easier to follow what's going on where, and possibly also shows a potential optimiser how insanely inline:able those methods are since they are used in exactly one place with exactly one type of value (though maybe it already saw that).

It should do strictly less work, but almost all of it would only happen on free regions, and there shouldn't be large numbers of those. Depending on the cleverness of the optimiser most of the option/some checks should have been compiled away anyway.

The key advantage as I see it is clearer flow: first liveness constraints are set up, then initial values are initialised, then region inference is ready to run.
rust-bors Bot pushed a commit that referenced this pull request Jun 12, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #144220 (Add powerpc64-unknown-linux-gnuelfv2 target)
 - #153238 (debuginfo: slices are DW_TAG_array_type's)
 - #157112 (Update aarch64-unknown-freebsd target description)
 - #157322 (test pre-stabilization items on CI)
 - #157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation)
 - #157490 (Add field-wise CoerceShared reborrow tests)
 - #157655 (Make Share::share final and improve docs)
 - #157672 (Region inference: Simplify initialisation of region values)
 - #157680 (Require `#[pin_v2]` for explicit pin-projection patterns)
 - #157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images)
 - #157796 (rustdoc: Some more lazy formatting)
 - #157818 (miri subtree update)
 - #157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT)
 - #157079 (Don't recover `&raw EXPR` as a missing comma)
 - #157202 (add #[rustc_no_writable] to slice::get_unchecked_mut)
 - #157622 (Disable retagging for variadic arguments in const-eval)
 - #157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver)
 - #157695 (Extend capabilities of `TypeFoldable_Generic`)
 - #157766 (interpret: avoid computing layout of sized raw pointee)
 - #157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia)
 - #157795 (revert 157013)
 - #157798 (Prevent approving PRs that wait for Crater or formal decisions)
 - #157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N))

Failed merges:

 - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
@rust-bors rust-bors Bot merged commit af8cbe7 into rust-lang:main Jun 12, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 12, 2026
rust-timer added a commit that referenced this pull request Jun 13, 2026
Rollup merge of #157672 - amandasystems:region-inference-initialisation, r=davidtwco

Region inference: Simplify initialisation of region values

This PR simplifies the initialisation of region values in `region_infer`

- `RegionInferenceContext::init_free_and_bound_regions()` is inlined into `::new()` and pulled to before initial SCC values are assigned
- A couple of iteration-then-index patterns are changed into `iter_enumerated()`-style patterns
- Some leftover code comments are removed and revised to actually describe the initialisation
- Free regions are now marked as live everywhere in liveness constraints, then copied to scc_values upon initialisation, avoiding performing that logic twice
- The trait used to index into SCC values goes away and the relevant methods are monomorphised and static-dispatched. This makes it easier to follow what's going on where, and possibly also shows a potential optimiser how insanely inline:able those methods are since they are used in exactly one place with exactly one type of value (though maybe it already saw that).

It should do strictly less work, but almost all of it would only happen on free regions, and there shouldn't be large numbers of those. Depending on the cleverness of the optimiser most of the option/some checks should have been compiled away anyway.

The key advantage as I see it is clearer flow: first liveness constraints are set up, then initial values are initialised, then region inference is ready to run.
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jun 13, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#144220 (Add powerpc64-unknown-linux-gnuelfv2 target)
 - rust-lang/rust#153238 (debuginfo: slices are DW_TAG_array_type's)
 - rust-lang/rust#157112 (Update aarch64-unknown-freebsd target description)
 - rust-lang/rust#157322 (test pre-stabilization items on CI)
 - rust-lang/rust#157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation)
 - rust-lang/rust#157490 (Add field-wise CoerceShared reborrow tests)
 - rust-lang/rust#157655 (Make Share::share final and improve docs)
 - rust-lang/rust#157672 (Region inference: Simplify initialisation of region values)
 - rust-lang/rust#157680 (Require `#[pin_v2]` for explicit pin-projection patterns)
 - rust-lang/rust#157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images)
 - rust-lang/rust#157796 (rustdoc: Some more lazy formatting)
 - rust-lang/rust#157818 (miri subtree update)
 - rust-lang/rust#157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT)
 - rust-lang/rust#157079 (Don't recover `&raw EXPR` as a missing comma)
 - rust-lang/rust#157202 (add #[rustc_no_writable] to slice::get_unchecked_mut)
 - rust-lang/rust#157622 (Disable retagging for variadic arguments in const-eval)
 - rust-lang/rust#157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver)
 - rust-lang/rust#157695 (Extend capabilities of `TypeFoldable_Generic`)
 - rust-lang/rust#157766 (interpret: avoid computing layout of sized raw pointee)
 - rust-lang/rust#157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia)
 - rust-lang/rust#157795 (revert 157013)
 - rust-lang/rust#157798 (Prevent approving PRs that wait for Crater or formal decisions)
 - rust-lang/rust#157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N))

Failed merges:

 - rust-lang/rust#157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure 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