Skip to content

Commit 5a6edde

Browse files
Auto merge of #142735 - lcnr:search_graph-5, r=<try>
lazily reevaluate nested goals It sure is a tragedy. Opening just so I have something to show for the last few weeks. This does not yet fix the perf regression in rayon. However, it does pass fuzzing and implements the simplest version of what I want this to be long term. r? ghost
2 parents 8de4c72 + 5dc471c commit 5a6edde

File tree

6 files changed

+735
-157
lines changed

6 files changed

+735
-157
lines changed

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,25 +425,27 @@ where
425425
//
426426
// The actual solver logic happens in `ecx.compute_goal`.
427427
let result = ensure_sufficient_stack(|| {
428-
search_graph.with_new_goal(
429-
cx,
430-
canonical_input,
431-
step_kind_from_parent,
432-
&mut canonical_goal_evaluation,
433-
|search_graph, canonical_goal_evaluation| {
434-
EvalCtxt::enter_canonical(
435-
cx,
436-
search_graph,
437-
canonical_input,
438-
canonical_goal_evaluation,
439-
|ecx, goal| {
440-
let result = ecx.compute_goal(goal);
441-
ecx.inspect.query_result(result);
442-
result
443-
},
444-
)
445-
},
446-
)
428+
search_graph
429+
.with_new_goal(
430+
cx,
431+
canonical_input,
432+
step_kind_from_parent,
433+
&mut canonical_goal_evaluation,
434+
|search_graph, cx, canonical_input, canonical_goal_evaluation| {
435+
EvalCtxt::enter_canonical(
436+
cx,
437+
search_graph,
438+
canonical_input,
439+
canonical_goal_evaluation,
440+
|ecx, goal| {
441+
let result = ecx.compute_goal(goal);
442+
ecx.inspect.query_result(result);
443+
result
444+
},
445+
)
446+
},
447+
)
448+
.1
447449
});
448450

449451
canonical_goal_evaluation.query_result(result);

compiler/rustc_type_ir/src/data_structures/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::hash::BuildHasherDefault;
22

33
pub use ena::unify::{NoError, UnifyKey, UnifyValue};
44
use rustc_hash::FxHasher;
5-
pub use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
5+
pub use rustc_hash::{FxBuildHasher as BuildHasher, FxHashMap as HashMap, FxHashSet as HashSet};
66

77
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
88
pub type IndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use derive_where::derive_where;
22

33
use super::{AvailableDepth, Cx, NestedGoals};
44
use crate::data_structures::HashMap;
5+
use crate::search_graph::EvaluationResult;
56

67
struct Success<X: Cx> {
78
required_depth: usize,
@@ -43,28 +44,32 @@ impl<X: Cx> GlobalCache<X> {
4344
&mut self,
4445
cx: X,
4546
input: X::Input,
46-
47-
origin_result: X::Result,
47+
evaluation_result: EvaluationResult<X>,
4848
dep_node: X::DepNodeIndex,
49-
50-
required_depth: usize,
51-
encountered_overflow: bool,
52-
nested_goals: NestedGoals<X>,
5349
) {
54-
let result = cx.mk_tracked(origin_result, dep_node);
50+
let EvaluationResult {
51+
node_id: _,
52+
encountered_overflow,
53+
required_depth,
54+
heads,
55+
nested_goals,
56+
result,
57+
} = evaluation_result;
58+
debug_assert!(heads.is_empty());
59+
let result = cx.mk_tracked(result, dep_node);
5560
let entry = self.map.entry(input).or_default();
5661
if encountered_overflow {
5762
let with_overflow = WithOverflow { nested_goals, result };
5863
let prev = entry.with_overflow.insert(required_depth, with_overflow);
5964
if let Some(prev) = &prev {
6065
assert!(cx.evaluation_is_concurrent());
61-
assert_eq!(cx.get_tracked(&prev.result), origin_result);
66+
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6267
}
6368
} else {
6469
let prev = entry.success.replace(Success { required_depth, nested_goals, result });
6570
if let Some(prev) = &prev {
6671
assert!(cx.evaluation_is_concurrent());
67-
assert_eq!(cx.get_tracked(&prev.result), origin_result);
72+
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6873
}
6974
}
7075
}

0 commit comments

Comments
 (0)