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

new solver: remove provisional cache #115843

Merged
merged 1 commit into from
Sep 29, 2023
Merged

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Sep 14, 2023

The provisional cache is a performance optimization if there are large, interleaving cycles. Such cycles generally do not exist. It is incredibly complex and unsound in all trait solvers which have one: the old solver, chalk, and the new solver (link).

Given the assumption that it is not perf-critical and also incredibly complex, remove it from the new solver, only checking whether a goal is on the stack. While writing this, I uncovered two additional soundness bugs, see the inline comments for them.

r? @compiler-errors

@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 14, 2023
@lcnr lcnr force-pushed the bb-provisional-cache branch 3 times, most recently from 77aaab2 to 90a69ea Compare September 15, 2023 12:10
entry.cycle_root_depth = root_depth;
root.cycle_participants.insert(entry.input);
#[allow(rustc::potential_query_instability)]
root.cycle_participants.extend(entry.cycle_participants.drain());
Copy link
Contributor Author

@lcnr lcnr Sep 15, 2023

Choose a reason for hiding this comment

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

we also have to add cycle participants from previous roots to the new root, this was previously incorrect.

Writing a regression test here is awful 😅 I am going to take the risk that this regresses in the future to be theoretically unsound again.

@lcnr lcnr marked this pull request as ready for review September 15, 2023 12:25
@rustbot
Copy link
Collaborator

rustbot commented Sep 15, 2023

Some changes occurred to the core trait solver

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

@lcnr lcnr force-pushed the bb-provisional-cache branch from 87ff2bf to d71501f Compare September 15, 2023 12:31
// `root` goal of this cycle.
//
// See tests/ui/traits/new-solver/cycles/fixpoint-rerun-all-cycle-heads.rs
// for an example.
self.stack[stack_depth].has_been_used = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stack_depth was previously the depth of the root, resulting in tests/ui/traits/new-solver/cycles/fixpoint-rerun-all-cycle-heads.rs.

@bors
Copy link
Contributor

bors commented Sep 18, 2023

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

@lcnr lcnr force-pushed the bb-provisional-cache branch from d71501f to e8b8ddd Compare September 18, 2023 15:01
@@ -47,7 +50,7 @@ pub(super) struct SearchGraph<'tcx> {
///
/// An element is *deeper* in the stack if its index is *lower*.
stack: IndexVec<StackDepth, StackEntry<'tcx>>,
provisional_cache: ProvisionalCache<'tcx>,
stack_entries: FxHashMap<CanonicalInput<'tcx>, StackDepth>,
Copy link
Member

Choose a reason for hiding this comment

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

side-note: maybe we should use an FxIndexMap to prevent that query instability lint.

@compiler-errors
Copy link
Member

very cool and awesome comments

@bors r+

@bors
Copy link
Contributor

bors commented Sep 28, 2023

📌 Commit e8b8ddd has been approved by compiler-errors

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

bors commented Sep 29, 2023

⌛ Testing commit e8b8ddd with merge 60bb519...

@bors
Copy link
Contributor

bors commented Sep 29, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 60bb519 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 29, 2023
@bors bors merged commit 60bb519 into rust-lang:master Sep 29, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 29, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (60bb519): 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.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 1

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)
5.0% [5.0%, 5.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.1%, -2.7%] 2
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 630.657s -> 630.048s (-0.10%)
Artifact size: 317.28 MiB -> 317.24 MiB (-0.01%)

@lcnr lcnr deleted the bb-provisional-cache branch September 29, 2023 08:12
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 12, 2024
…iler-errors

next solver: provisional cache

this adds the cache removed in rust-lang#115843. However, it should now correctly track whether a provisional result depends on an inductive or coinductive stack.

While working on this, I was using the following doc: https://hackmd.io/VsQPjW3wSTGUSlmgwrDKOA. I don't think it's too helpful to understanding this, but am somewhat hopeful that the inline comments are more useful.

There are quite a few future perf improvements here. Given that this is already very involved I don't believe it is worth it (for now). While working on this PR one of my few attempts to significantly improve perf ended up being unsound again because I was not careful enough ✨

r? `@compiler-errors`
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