Skip to content

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Sep 19, 2025

Reduces the compile time of wg-grammar from more than 70s to about 40s. So a >30% perf improvement for that crate.

r? @BoxyUwU @compiler-errors

@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

changes to inspect_obligations.rs

cc @compiler-errors, @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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 19, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Sep 19, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 19, 2025
obligations_for_self_ty: skip irrelevant goals
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 19, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Sep 19, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 19, 2025
obligations_for_self_ty: skip irrelevant goals
@rust-bors
Copy link

rust-bors bot commented Sep 19, 2025

☀️ Try build successful (CI)
Build commit: ba651ad (ba651ad1746c1435192a5568cd8732d36f8536ce, parent: 2f4dfc753fd86c672aa4145940db075a8a149f17)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ba651ad): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.0%, -0.3%] 7
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (secondary -3.0%)

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)
-3.0% [-3.8%, -2.2%] 2
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

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.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 470.95s -> 473.304s (0.50%)
Artifact size: 389.99 MiB -> 390.01 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 19, 2025
Comment on lines +79 to +90
let sub_root_var = self.sub_unification_table_root_var(self_ty);
let obligations = self
.fulfillment_cx
.borrow()
.pending_obligations_potentially_referencing_sub_root(sub_root_var);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 24, 2025

Is this like, important, or is it "just" a small perf win?

@BoxyUwU BoxyUwU 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 Sep 24, 2025
@lcnr lcnr force-pushed the obligations_for_self_ty-perf branch from 452fdbf to 9926fa3 Compare October 1, 2025 14:52
@lcnr
Copy link
Contributor Author

lcnr commented Oct 13, 2025

@rustbot ready

see pr descr

@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 Oct 13, 2025
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

I feel relatively uneasy about this. I don't like that this optimization makes obligations_for_self_ty wrong if try_evaluate_obligations hasn't been previously called in order to update all the stalled_on vars.

If this were only a theoretical issue it'd still be pretty bad since I don't think we'd be able to expect it to not happen in practice in the long term. In practice it should be possible for unsize coercion to hit this with its custom obligation evaluation loop and inability to call try_evaluate_goals.

I think the only way I could approve this if I thought it was ok to have obligations_for_self_ty have incorrect behaviour in some edge cases and I think that is not the case.

I'm not sure what the right fix is here given that unsize coercion does actually hit this in theory, so asserting that we're always calling obligations_for_self_ty in "good" cases doesn't actually work ^^'

View changes since this review

@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 Oct 13, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Oct 13, 2025

I think the only way I could approve this if I thought it was ok to have obligations_for_self_ty have incorrect behaviour in some edge cases and I think that is not the case.

It is totally okay for obligations_for_self_ty to have incorrect behavior, e.g. we currently bail at depth 4 or 8 and don't recur any deeper.

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

Labels

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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants