Skip to content

[borrowck] Do an in-place update of SCCs rather than recomputing#155931

Closed
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:in-place-scc-recompute
Closed

[borrowck] Do an in-place update of SCCs rather than recomputing#155931
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:in-place-scc-recompute

Conversation

@amandasystems
Copy link
Copy Markdown
Contributor

@amandasystems amandasystems commented Apr 28, 2026

Exploit some of the nice properties of 'static in the constraint graph to avoid doing a full recomputation of SCC components when adding : 'static outlives.

Notably, this relies on the fact that adding any 'r: 'static will simply remove 'r's SCC as well as any of its predecessors from the set of SCCs, since they now all participate in a cycle with 'static (which outlives everything and thus has an edge into every region).

r? @lcnr

(who may or may not want to delegate this)

This almost entirely a performance thing so it wants a perf run, but it actually makes some of the code more straightforward.

@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 Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
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: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates

@rustbot rustbot assigned lcnr and unassigned jdonszelmann Apr 28, 2026
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented Apr 28, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 28, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
[borrowck] Do an in-place update of SCCs rather than recomputing
Exploit some of the nice properties of `'static` in the constraint graph
to avoid doing a full recomputation of SCC components when adding `: 'static`
outlives.

Notably, this relies on the fact that adding any `'r: 'static` will simply
remove `'r`'s SCC as well as any of its predecessors from the set of SCCs,
since they now all participate in a cycle with `'static` (which outlives
everything and thus has an edge into every region).
@amandasystems amandasystems force-pushed the in-place-scc-recompute branch from ca79010 to 1593a7d Compare April 28, 2026 15:47
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 28, 2026

☀️ Try build successful (CI)
Build commit: 6dbb4d3 (6dbb4d39316caf969b5bf65444b29a9e255a2d57, parent: 03c609abb6638f9d7f49f34326d4137d07f5cd61)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (6dbb4d3): comparison URL.

Overall result: no relevant changes - 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

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

Max RSS (memory usage)

Results (secondary -2.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 487.089s -> 490.144s (0.63%)
Artifact size: 393.44 MiB -> 393.41 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 28, 2026
@amandasystems
Copy link
Copy Markdown
Contributor Author

Wow. Ok, then I don't see any point in bothering and I can finally lay this intrusive idea to rest. Thanks for coming to my TED talk!

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 30, 2026
@amandasystems
Copy link
Copy Markdown
Contributor Author

amandasystems commented Apr 30, 2026

Probably what you really want is a specialised SCC construction for the outlives graph. That would allow tacking on all the extra annotations (and representatives etc) in a nicer way. It would also allow handling the extra :static constraints during construction. 'static can also be handled as a special case without having to add every SCC as a successor to it explicitly. However, I suspect the potential gains are at best very small for what is a large refactor.

I'm leaving this idea here for anyone who wants to investigate it. Ping me if you do, I'd like to see how it pans out!

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

Labels

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.

6 participants