Skip to content

-Znext-solver filter out some uninteresting opaques while canonicalization - #164368

Open
ShoyuVanilla wants to merge 1 commit into
rust-lang:mainfrom
ShoyuVanilla:opaca-parva
Open

ShoyuVanilla wants to merge 1 commit into
rust-lang:mainfrom
ShoyuVanilla:opaca-parva

Conversation

@ShoyuVanilla

@ShoyuVanilla ShoyuVanilla commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Context: #t-types/trait-system-refactor > higher ranked opaque type perf

Partially extracted from #161414

Fixes #151806

rust-lang/trait-system-refactor-initiative#242 is not fixed by this. The overflow goes away by this, but as I wrote in the above zulip stream, hr opaque types aren't replaced by infer vars and that prevents the pending obligation containing it from being fully normalized and solved in the root context.

r? adwinwhite as we've talked on this in the zulip stream (cc @lcnr I guess you might be busy in EuroRust 😅)

@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 Oct 15, 2026
@rustbot

rustbot commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

adwinwhite is currently at their maximum review capacity.
They may take a while to respond.


fn build_multiple<'a>() -> impl Sized {
spawn(async { build_dependencies().await });
//[next]~^ ERROR overflow evaluating the requirement

@ShoyuVanilla ShoyuVanilla Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This isn't overflowing anymore and I guess this is an unexpected improvement

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, this was in the triage list as a regression 😅
https://hackmd.io/RQF9zqx8R3aBl_-gr2YU6w?view#Pass--gt-Regular-Fail

@ShoyuVanilla

Copy link
Copy Markdown
Member Author

@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 Oct 15, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 15, 2026
`-Znext-solver` filter out some uninteresting opaques while canonicalization
@rust-bors

rust-bors Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 307e94e (307e94edc04512006422385a8ce280bca6e7ed55)
Base parent: 3b13d3f (3b13d3fd58d21a6ffd3aa6dec7ae6b299405acd1)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (307e94e): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

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

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=iffy rustc-perf
@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.3% [0.2%, 0.4%] 6
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-1.7% [-3.5%, -0.6%] 7
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Max RSS (memory usage)

Results (primary 1.2%, secondary 3.5%)

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

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
3.5% [3.1%, 4.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.2% [1.2%, 1.2%] 1

Cycles

Results (primary -2.5%, secondary 1.6%)

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)
7.3% [6.7%, 8.5%] 3
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
-2.7% [-3.4%, -2.0%] 4
All ❌✅ (primary) -2.5% [-2.5%, -2.5%] 1

Binary size

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

Bootstrap: 492.307s -> 489.052s (-0.66%)
Artifact size: 407.14 MiB -> 409.22 MiB (0.51%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 15, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor

Does this help with other compile-time regressions in the ui test triage table?

@ShoyuVanilla

ShoyuVanilla commented Oct 16, 2026 •

Copy link
Copy Markdown
Member Author

Let me check (completely forgot about it while pondering upon hr opaques 😅 )

@ShoyuVanilla

Copy link
Copy Markdown
Member Author

Yeah, all four tests in compiletime and one test in hang for it compiles instataneously

@adwinwhite adwinwhite left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, not much actionable feedback. I guess this needs some discussions to make the impl easier to reason.

View changes since this review

Comment on lines +455 to +459
/// Filter out not-so-useful opaque types, i.e. whose hidden type is not
/// mentioned in `variables` so far and has any var within opaque type key
/// that is not mentioned in the same manner. This helps the perf by avoiding
/// having many inputs/outputs differing only on some not interesting opaques
/// and even saves us from overflowing due to having too many opaques.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the reasoning of defining not-so-useful like this? 🤔

I thought we could drop opaques whose hidden types are infers and not in var_values. And we'd also keep opaques whose hidden infers are mentioned in other opaque keys for the reason you said above the fixpoint computation. The latter part feels slightly hacky though.

} else {
predefined_opaques_in_body
};
rest_canonicalizer.filter_and_canonicalize_opaque_types(predefined_opaques_in_body);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

filtering in response should be enough to prevent overflows?
uncertain about whether this filters out "useful` opaques. I need to think more on this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that would be enough for preventing overflows and from the input side it would help only the perf due to better cache hits.
On what is useful and what is useless opaque (for both this and your above comment), yeah, I have sth in my mind but haven't tried to clearly state them anywhere. I'll try that 😅

}
}

// This should be synced with `Canonicalizer`'s `TypeFolder` implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also have a mentioned_region visitor in filter_irrelevant_region_constraints.
It feels disorganized to have them in multiple places.

@adwinwhite

Copy link
Copy Markdown
Contributor

Yeah, all four tests in compiletime and one test in hang for it compiles instataneously

We could add next solver revisions for them then :>

This branch has not been deployed

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

Labels

perf-regression Performance regression. 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next-solver hang: infinite recursion during hidden type inference for TAIT + unconstrained region

4 participants