Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split SelectionContext::select into fns that take a binder and don't #113308

Merged
merged 4 commits into from
Jul 7, 2023

Conversation

compiler-errors
Copy link
Member

most usages of SelectionContext::select don't need to use a binder, but wrap them in a dummy because of the signature. Let's split this out into SelectionContext::{select,poly_select} and limit the usages of the latter.

Right now, we only have 3 places where we're calling poly_select -- fulfillment, internally within the old solver, and the auto-trait finder.

r? @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 Jul 4, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2023

Some changes occurred to the core trait solver

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

let bound_predicate = obligation.predicate.kind();
let trait_pred = match bound_predicate.skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))
let trait_pred = match obligation.predicate.kind().no_bound_vars() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This could technically affect inference, but CoerceUnsized is an unstable trait and I don't know of a stdlib impl that emits bound predicates :^)

@bors
Copy link
Contributor

bors commented Jul 5, 2023

☔ The latest upstream changes (presumably #113370) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

some nits, then r=me

@@ -292,7 +292,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
new_env,
pred,
));
let result = select.select(&obligation);
let result = select.poly_select(&obligation);
Copy link
Contributor

Choose a reason for hiding this comment

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

feels like we may end up with with placeholders in the environment/output here, so it might be safer to check for no_bound_vars. Doesn't matter much, this keeps the current behavior and we're going to rewrite this code anyways

@@ -123,8 +124,8 @@ pub struct SelectionContext<'cx, 'tcx> {
}

// A stack that walks back up the stack frame.
struct TraitObligationStack<'prev, 'tcx> {
obligation: &'prev TraitObligation<'tcx>,
struct PolyTraitObligationStack<'prev, 'tcx> {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should keep this as TraitObligationStack, the Poly doesn't add any meaningful info imo and makes the code harder to read imo

Copy link
Member Author

Choose a reason for hiding this comment

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

No this is just because I was stupid and used ctrl+f to replace names, and I didn't see this was edited too 🤦

@@ -2946,21 +2962,23 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
}

#[derive(Copy, Clone)]
struct TraitObligationStackList<'o, 'tcx> {
struct PolyTraitObligationStackList<'o, 'tcx> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
struct PolyTraitObligationStackList<'o, 'tcx> {
struct TraitObligationStackList<'o, 'tcx> {

@lcnr
Copy link
Contributor

lcnr commented Jul 6, 2023

also, please run perf after rebasing, I think that not having a Binder in codegen_select_obligation might impact perf

@compiler-errors
Copy link
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 Jul 6, 2023
@bors
Copy link
Contributor

bors commented Jul 6, 2023

⌛ Trying commit 3f8919c with merge 5d2ae64c182026baa066c3144d019b08883a6cbf...

@bors
Copy link
Contributor

bors commented Jul 6, 2023

☀️ Try build successful - checks-actions
Build commit: 5d2ae64c182026baa066c3144d019b08883a6cbf (5d2ae64c182026baa066c3144d019b08883a6cbf)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5d2ae64c182026baa066c3144d019b08883a6cbf): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.8% [0.7%, 1.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

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

Cycles

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

Binary size

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

Bootstrap: 657.995s -> 658.303s (0.05%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 6, 2023
@compiler-errors
Copy link
Member Author

I'm pretty certain that's noise, given it affects doc and check on two random crates.

@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Jul 7, 2023

📌 Commit 3f8919c has been approved by lcnr

It is now in the queue for this repository.

@bors bors 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 Jul 7, 2023
@bors
Copy link
Contributor

bors commented Jul 7, 2023

⌛ Testing commit 3f8919c with merge 1a449dc...

@bors
Copy link
Contributor

bors commented Jul 7, 2023

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 1a449dc to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1a449dc): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.7%, 0.8%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

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

Cycles

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

Binary size

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

Bootstrap: 658.878s -> 657.277s (-0.24%)

@compiler-errors compiler-errors deleted the poly-select branch August 11, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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. 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.

5 participants