Skip to content

A series of Polonius Alpha refactors - #161937

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
jackh726:polonius-cleanups-2
Sep 1, 2026
Merged

A series of Polonius Alpha refactors#161937
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
jackh726:polonius-cleanups-2

Conversation

@jackh726

@jackh726 jackh726 commented Aug 28, 2026

Copy link
Copy Markdown
Member

Based on #161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2026
@jackh726

Copy link
Copy Markdown
Member Author

Disclosure: An LLM was used for experiments here, but all code here is written fresh.

Comment thread compiler/rustc_borrowck/src/polonius/mod.rs Outdated
Comment thread compiler/rustc_borrowck/src/type_check/liveness/trace.rs Outdated
Comment thread compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Comment thread compiler/rustc_borrowck/src/type_check/liveness/trace.rs Outdated
@lqd

lqd commented Aug 31, 2026

Copy link
Copy Markdown
Member

The rationale is not clear for a handful of these (in the code, comments, or the commit message). I expect them to make sense in light of #161938, so I'll have to review them later when I look at that PR.

We can land the straightforward commits soon, and leave the other two for later.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the polonius-cleanups-2 branch 3 times, most recently from fa3ac07 to 3df5c72 Compare August 31, 2026 15:53
@jackh726

jackh726 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

commit 3: this feels like it could be simplified, and I imagine it makes more sense seen together with Defer extra liveness calculation for Polonius Alpha #161938, so let's remove it from this PR.

commit 7: I imagine it's same as commit 3; the split into a third context (liveness results, liveness context, liveness calculation) feels suboptimal, let's remove it from this PR as well.

Indeed, these make more sense in the context of #161938. In short, the LivenessCalculation struct factors essentially the logic to calculate the liveness for a single Local. This is helpful because we eagerly calculate not just liveness for the set NLL-relevant locals, but also things like dropck region constraints and legacy polonius facts (that's all in LivenessResults); but, we lazily only need the use/drop liveness points, which LivenessCalculation does. There is no longer a LivenessContext - it was LivenessContext and LivenessResults, now it's LivenessResults and LivenessCalculation.

The visitor -> visitor+traversal split is basically just type-safety around ensuring that liveness is calculated for a given region prior to liveness values being used; LocalizedConstraintGraphTraversal could almost just be replaced by an impl FnMut(RegionVid) -> impl LocalizedConstraintGraphVisitor.

Anyways, removed them from this PR - we can see if/how they fit later.

commit 5: I'm not sure why, but ok, why not.

Because when computing deferred liveness, I'm passing in just liveness: &mut LivenessValues and live_region_variances: &mut BTreeMap<RegionVid, ConstraintDirection>, not PoloniusContext.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the polonius-cleanups-2 branch from 3df5c72 to b58ee5b Compare August 31, 2026 18:07
@jackh726
jackh726 marked this pull request as ready for review August 31, 2026 18:12
@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 Aug 31, 2026
@lqd

lqd commented Aug 31, 2026

Copy link
Copy Markdown
Member

I think we’ll need to do a handful of passes to simplify the entire process afterwards. The end state is starting to feel less like a series of high level steps than it is today, and while that is somewhat expected to allow liveness to be produced from two different places, we probably would benefit from clearly defined components/pieces of state.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b58ee5b has been approved by lqd

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 Aug 31, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 31, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 31, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 31, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 31, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #162045 (`rust-analyzer` subtree update)
 - #162077 (compiler-builtins subtree update)
 - #137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - #160534 (stabilize smart pointer map functions)
 - #160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering)
 - #161929 (explicitly track inherent const generic args kind)
 - #162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux)
 - #161937 (A series of Polonius Alpha refactors)
 - #162014 (Move more `rustdoc-html` tests using `--test` into the right folder)
 - #162051 (`rustc_feature` cleanups)
 - #162055 (remove `_{style}` recovery for diagnostic structs)
 - #162075 (Move track_caller on closures gating to attribute parsing)
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
A series of Polonius Alpha refactors

Based on rust-lang#161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - #160534 (stabilize smart pointer map functions)
 - #160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering)
 - #160989 (Make sin, cos, exp, exp2, log, log2, log10 generic)
 - #161861 (mir_build: Clarify parts of if-condition lowering)
 - #161929 (explicitly track inherent const generic args kind)
 - #162040 (bootstrap: stage0 to cbae9b4)
 - #162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux)
 - #161353 (Add test for parallel compiler reproducible build)
 - #161937 (A series of Polonius Alpha refactors)
 - #162051 (`rustc_feature` cleanups)
 - #162055 (remove `_{style}` recovery for diagnostic structs)
 - #162075 (Move track_caller on closures gating to attribute parsing)
 - #162079 (std: implement `File::fsync` for Hermit)
 - #162097 (Deduplicate `InstrumentFnAttr`)
 - #162115 (fix typo in feature documentation)
rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
Rollup merge of #161937 - jackh726:polonius-cleanups-2, r=lqd

A series of Polonius Alpha refactors

Based on #161776

Best reviewed by commit.

This is a series of refactors to enable lazy liveness calculation. Each commit is relatively targeted.

r? lqd
@rust-bors
rust-bors Bot merged commit 5329773 into rust-lang:main Sep 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 1, 2026
@jackh726
jackh726 deleted the polonius-cleanups-2 branch September 1, 2026 15:43
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7dfde5a): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.1%, 0.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: missing data
Artifact size: 400.59 MiB -> 402.55 MiB (0.49%)

pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Sep 2, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - rust-lang/rust#160534 (stabilize smart pointer map functions)
 - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering)
 - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic)
 - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering)
 - rust-lang/rust#161929 (explicitly track inherent const generic args kind)
 - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463)
 - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux)
 - rust-lang/rust#161353 (Add test for parallel compiler reproducible build)
 - rust-lang/rust#161937 (A series of Polonius Alpha refactors)
 - rust-lang/rust#162051 (`rustc_feature` cleanups)
 - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs)
 - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing)
 - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit)
 - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`)
 - rust-lang/rust#162115 (fix typo in feature documentation)
asukaminato0721 pushed a commit to asukaminato0721/rust-analyzer that referenced this pull request Sep 2, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - rust-lang/rust#160534 (stabilize smart pointer map functions)
 - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering)
 - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic)
 - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering)
 - rust-lang/rust#161929 (explicitly track inherent const generic args kind)
 - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463)
 - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux)
 - rust-lang/rust#161353 (Add test for parallel compiler reproducible build)
 - rust-lang/rust#161937 (A series of Polonius Alpha refactors)
 - rust-lang/rust#162051 (`rustc_feature` cleanups)
 - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs)
 - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing)
 - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit)
 - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`)
 - rust-lang/rust#162115 (fix typo in feature documentation)
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Sep 4, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - rust-lang/rust#160534 (stabilize smart pointer map functions)
 - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering)
 - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic)
 - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering)
 - rust-lang/rust#161929 (explicitly track inherent const generic args kind)
 - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463)
 - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux)
 - rust-lang/rust#161353 (Add test for parallel compiler reproducible build)
 - rust-lang/rust#161937 (A series of Polonius Alpha refactors)
 - rust-lang/rust#162051 (`rustc_feature` cleanups)
 - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs)
 - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing)
 - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit)
 - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`)
 - rust-lang/rust#162115 (fix typo in feature documentation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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