Skip to content

Commit 2b1365b

Browse files
committed
Auto merge of rust-lang#119735 - lcnr:provisional-cache-readd, r=compiler-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`
2 parents 5431404 + 13aa900 commit 2b1365b

File tree

13 files changed

+445
-111
lines changed

13 files changed

+445
-111
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4574,6 +4574,7 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
45744574
name = "rustc_trait_selection"
45754575
version = "0.0.0"
45764576
dependencies = [
4577+
"bitflags 2.4.1",
45774578
"itertools",
45784579
"rustc_ast",
45794580
"rustc_attr",

compiler/rustc_middle/src/traits/solve/inspect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub struct CanonicalGoalEvaluation<'tcx> {
7373
pub enum CanonicalGoalEvaluationKind<'tcx> {
7474
Overflow,
7575
CycleInStack,
76+
ProvisionalCacheHit,
7677
Evaluation { revisions: &'tcx [GoalEvaluationStep<'tcx>] },
7778
}
7879
impl Debug for GoalEvaluation<'_> {

compiler/rustc_middle/src/traits/solve/inspect/format.rs

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
7777
CanonicalGoalEvaluationKind::CycleInStack => {
7878
writeln!(self.f, "CYCLE IN STACK: {:?}", eval.result)
7979
}
80+
CanonicalGoalEvaluationKind::ProvisionalCacheHit => {
81+
writeln!(self.f, "PROVISIONAL CACHE HIT: {:?}", eval.result)
82+
}
8083
CanonicalGoalEvaluationKind::Evaluation { revisions } => {
8184
for (n, step) in revisions.iter().enumerate() {
8285
writeln!(self.f, "REVISION {n}")?;

compiler/rustc_trait_selection/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
bitflags = "2.4.1"
89
itertools = "0.11.0"
910
rustc_ast = { path = "../rustc_ast" }
1011
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_trait_selection/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(control_flow_enum)]
2020
#![feature(extract_if)]
2121
#![feature(let_chains)]
22+
#![feature(option_take_if)]
2223
#![feature(if_let_guard)]
2324
#![feature(never_type)]
2425
#![feature(type_alias_impl_trait)]

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
171171
let mut candidates = vec![];
172172
let last_eval_step = match self.evaluation.evaluation.kind {
173173
inspect::CanonicalGoalEvaluationKind::Overflow
174-
| inspect::CanonicalGoalEvaluationKind::CycleInStack => {
174+
| inspect::CanonicalGoalEvaluationKind::CycleInStack
175+
| inspect::CanonicalGoalEvaluationKind::ProvisionalCacheHit => {
175176
warn!("unexpected root evaluation: {:?}", self.evaluation);
176177
return vec![];
177178
}

compiler/rustc_trait_selection/src/solve/inspect/build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub(in crate::solve) enum WipGoalEvaluationKind<'tcx> {
118118
pub(in crate::solve) enum WipCanonicalGoalEvaluationKind<'tcx> {
119119
Overflow,
120120
CycleInStack,
121+
ProvisionalCacheHit,
121122
Interned { revisions: &'tcx [inspect::GoalEvaluationStep<'tcx>] },
122123
}
123124

@@ -126,6 +127,7 @@ impl std::fmt::Debug for WipCanonicalGoalEvaluationKind<'_> {
126127
match self {
127128
Self::Overflow => write!(f, "Overflow"),
128129
Self::CycleInStack => write!(f, "CycleInStack"),
130+
Self::ProvisionalCacheHit => write!(f, "ProvisionalCacheHit"),
129131
Self::Interned { revisions: _ } => f.debug_struct("Interned").finish_non_exhaustive(),
130132
}
131133
}
@@ -151,6 +153,9 @@ impl<'tcx> WipCanonicalGoalEvaluation<'tcx> {
151153
WipCanonicalGoalEvaluationKind::CycleInStack => {
152154
inspect::CanonicalGoalEvaluationKind::CycleInStack
153155
}
156+
WipCanonicalGoalEvaluationKind::ProvisionalCacheHit => {
157+
inspect::CanonicalGoalEvaluationKind::ProvisionalCacheHit
158+
}
154159
WipCanonicalGoalEvaluationKind::Interned { revisions } => {
155160
inspect::CanonicalGoalEvaluationKind::Evaluation { revisions }
156161
}

0 commit comments

Comments
 (0)