Skip to content

Commit de68911

Browse files
committed
Auto merge of rust-lang#115929 - matthiaskrgr:rollup-hhasy22, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#115558 (issue has since been fixed) - rust-lang#115724 (Add myself to the mailmap) - rust-lang#115811 (Make AIX known by bootstrap) - rust-lang#115838 (inspect: closer to proof trees for coherence) - rust-lang#115902 (Fix up a few CI images) - rust-lang#115907 (nop_lift macros: ensure that we are using the right interner) - rust-lang#115908 (Do not clone MIR for const-prop lint.) - rust-lang#115916 (Add me as on vacation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 078eb11 + 5290cc9 commit de68911

File tree

16 files changed

+202
-118
lines changed

16 files changed

+202
-118
lines changed

Diff for: .mailmap

+2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ Timothy Maloney <[email protected]>
549549
Tomas Koutsky <[email protected]>
550550
Torsten Weber <[email protected]>
551551
552+
553+
552554
553555
Tshepang Mbambo <[email protected]>
554556
Ty Overby <[email protected]>

Diff for: compiler/rustc_middle/src/traits/solve/inspect.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@ pub enum CacheHit {
1414
Global,
1515
}
1616

17+
#[derive(Eq, PartialEq)]
18+
pub enum GoalEvaluationKind {
19+
Root,
20+
Nested { is_normalizes_to_hack: IsNormalizesToHack },
21+
}
22+
1723
#[derive(Eq, PartialEq)]
1824
pub struct GoalEvaluation<'tcx> {
1925
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
20-
pub is_normalizes_to_hack: IsNormalizesToHack,
26+
pub kind: GoalEvaluationKind,
2127
pub evaluation: CanonicalGoalEvaluation<'tcx>,
2228
pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
2329
}
2430

2531
#[derive(Eq, PartialEq)]
2632
pub struct CanonicalGoalEvaluation<'tcx> {
2733
pub goal: CanonicalInput<'tcx>,
28-
pub kind: GoalEvaluationKind<'tcx>,
34+
pub kind: CanonicalGoalEvaluationKind<'tcx>,
2935
pub result: QueryResult<'tcx>,
3036
}
3137

3238
#[derive(Eq, PartialEq)]
33-
pub enum GoalEvaluationKind<'tcx> {
39+
pub enum CanonicalGoalEvaluationKind<'tcx> {
3440
Overflow,
3541
CacheHit(CacheHit),
3642
Uncached { revisions: Vec<GoalEvaluationStep<'tcx>> },
@@ -52,22 +58,31 @@ pub struct GoalEvaluationStep<'tcx> {
5258
pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
5359

5460
/// The actual evaluation of the goal, always `ProbeKind::Root`.
55-
pub evaluation: GoalCandidate<'tcx>,
61+
pub evaluation: Probe<'tcx>,
5662
}
5763

64+
/// A self-contained computation during trait solving. This either
65+
/// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation
66+
/// of a goal.
5867
#[derive(Eq, PartialEq)]
59-
pub struct GoalCandidate<'tcx> {
60-
pub added_goals_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
61-
pub candidates: Vec<GoalCandidate<'tcx>>,
68+
pub struct Probe<'tcx> {
69+
pub steps: Vec<ProbeStep<'tcx>>,
6270
pub kind: ProbeKind<'tcx>,
6371
}
6472

65-
impl Debug for GoalCandidate<'_> {
73+
impl Debug for Probe<'_> {
6674
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67-
ProofTreeFormatter::new(f).format_candidate(self)
75+
ProofTreeFormatter::new(f).format_probe(self)
6876
}
6977
}
7078

79+
#[derive(Eq, PartialEq)]
80+
pub enum ProbeStep<'tcx> {
81+
AddGoal(Goal<'tcx, ty::Predicate<'tcx>>),
82+
EvaluateGoals(AddedGoalsEvaluation<'tcx>),
83+
NestedProbe(Probe<'tcx>),
84+
}
85+
7186
#[derive(Debug, PartialEq, Eq)]
7287
pub enum ProbeKind<'tcx> {
7388
/// The root inference context while proving a goal.

Diff for: compiler/rustc_middle/src/traits/solve/inspect/format.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
4040
}
4141

4242
pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<'_>) -> std::fmt::Result {
43-
let goal_text = match eval.is_normalizes_to_hack {
44-
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
45-
IsNormalizesToHack::No => "GOAL",
43+
let goal_text = match eval.kind {
44+
GoalEvaluationKind::Root => "ROOT GOAL",
45+
GoalEvaluationKind::Nested { is_normalizes_to_hack } => match is_normalizes_to_hack {
46+
IsNormalizesToHack::No => "GOAL",
47+
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
48+
},
4649
};
4750
writeln!(self.f, "{}: {:?}", goal_text, eval.uncanonicalized_goal)?;
4851
self.nested(|this| this.format_canonical_goal_evaluation(&eval.evaluation))?;
@@ -68,16 +71,16 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
6871
writeln!(self.f, "GOAL: {:?}", eval.goal)?;
6972

7073
match &eval.kind {
71-
GoalEvaluationKind::Overflow => {
74+
CanonicalGoalEvaluationKind::Overflow => {
7275
writeln!(self.f, "OVERFLOW: {:?}", eval.result)
7376
}
74-
GoalEvaluationKind::CacheHit(CacheHit::Global) => {
77+
CanonicalGoalEvaluationKind::CacheHit(CacheHit::Global) => {
7578
writeln!(self.f, "GLOBAL CACHE HIT: {:?}", eval.result)
7679
}
77-
GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
80+
CanonicalGoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
7881
writeln!(self.f, "PROVISIONAL CACHE HIT: {:?}", eval.result)
7982
}
80-
GoalEvaluationKind::Uncached { revisions } => {
83+
CanonicalGoalEvaluationKind::Uncached { revisions } => {
8184
for (n, step) in revisions.iter().enumerate() {
8285
writeln!(self.f, "REVISION {n}")?;
8386
self.nested(|this| this.format_evaluation_step(step))?;
@@ -92,11 +95,11 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
9295
evaluation_step: &GoalEvaluationStep<'_>,
9396
) -> std::fmt::Result {
9497
writeln!(self.f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
95-
self.format_candidate(&evaluation_step.evaluation)
98+
self.format_probe(&evaluation_step.evaluation)
9699
}
97100

98-
pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
99-
match &candidate.kind {
101+
pub(super) fn format_probe(&mut self, probe: &Probe<'_>) -> std::fmt::Result {
102+
match &probe.kind {
100103
ProbeKind::Root { result } => {
101104
writeln!(self.f, "ROOT RESULT: {result:?}")
102105
}
@@ -118,11 +121,12 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
118121
}?;
119122

120123
self.nested(|this| {
121-
for candidate in &candidate.candidates {
122-
this.format_candidate(candidate)?;
123-
}
124-
for nested in &candidate.added_goals_evaluations {
125-
this.format_added_goals_evaluation(nested)?;
124+
for step in &probe.steps {
125+
match step {
126+
ProbeStep::AddGoal(goal) => writeln!(this.f, "ADDED GOAL: {goal:?}")?,
127+
ProbeStep::EvaluateGoals(eval) => this.format_added_goals_evaluation(eval)?,
128+
ProbeStep::NestedProbe(probe) => this.format_probe(probe)?,
129+
}
126130
}
127131
Ok(())
128132
})

Diff for: compiler/rustc_middle/src/ty/context.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,25 @@ macro_rules! nop_lift {
12141214
impl<'a, 'tcx> Lift<'tcx> for $ty {
12151215
type Lifted = $lifted;
12161216
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1217+
// Assert that the set has the right type.
1218+
// Given an argument that has an interned type, the return type has the type of
1219+
// the corresponding interner set. This won't actually return anything, we're
1220+
// just doing this to compute said type!
1221+
fn _intern_set_ty_from_interned_ty<'tcx, Inner>(
1222+
_x: Interned<'tcx, Inner>,
1223+
) -> InternedSet<'tcx, Inner> {
1224+
unreachable!()
1225+
}
1226+
fn _type_eq<T>(_x: &T, _y: &T) {}
1227+
fn _test<'tcx>(x: $lifted, tcx: TyCtxt<'tcx>) {
1228+
// If `x` is a newtype around an `Interned<T>`, then `interner` is an
1229+
// interner of appropriate type. (Ideally we'd also check that `x` is a
1230+
// newtype with just that one field. Not sure how to do that.)
1231+
let interner = _intern_set_ty_from_interned_ty(x.0);
1232+
// Now check that this is the same type as `interners.$set`.
1233+
_type_eq(&interner, &tcx.interners.$set);
1234+
}
1235+
12171236
tcx.interners
12181237
.$set
12191238
.contains_pointer_to(&InternedInSet(&*self.0.0))
@@ -1230,6 +1249,11 @@ macro_rules! nop_list_lift {
12301249
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
12311250
type Lifted = &'tcx List<$lifted>;
12321251
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1252+
// Assert that the set has the right type.
1253+
if false {
1254+
let _x: &InternedSet<'tcx, List<$lifted>> = &tcx.interners.$set;
1255+
}
1256+
12331257
if self.is_empty() {
12341258
return Some(List::empty());
12351259
}

Diff for: compiler/rustc_mir_transform/src/const_prop_lint.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,12 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
105105

106106
trace!("ConstProp starting for {:?}", def_id);
107107

108-
let dummy_body = &Body::new(
109-
body.source,
110-
(*body.basic_blocks).to_owned(),
111-
body.source_scopes.clone(),
112-
body.local_decls.clone(),
113-
Default::default(),
114-
body.arg_count,
115-
Default::default(),
116-
body.span,
117-
body.generator_kind(),
118-
body.tainted_by_errors,
119-
);
120-
121108
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
122109
// constants, instead of just checking for const-folding succeeding.
123110
// That would require a uniform one-def no-mutation analysis
124111
// and RPO (or recursing when needing the value of a local).
125-
let mut optimization_finder = ConstPropagator::new(body, dummy_body, tcx);
126-
optimization_finder.visit_body(body);
112+
let mut linter = ConstPropagator::new(body, tcx);
113+
linter.visit_body(body);
127114

128115
trace!("ConstProp done for {:?}", def_id);
129116
}
@@ -169,11 +156,7 @@ impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> {
169156
}
170157

171158
impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
172-
fn new(
173-
body: &Body<'tcx>,
174-
dummy_body: &'mir Body<'tcx>,
175-
tcx: TyCtxt<'tcx>,
176-
) -> ConstPropagator<'mir, 'tcx> {
159+
fn new(body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>) -> ConstPropagator<'mir, 'tcx> {
177160
let def_id = body.source.def_id();
178161
let args = &GenericArgs::identity_for_item(tcx, def_id);
179162
let param_env = tcx.param_env_reveal_all_normalized(def_id);
@@ -204,7 +187,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
204187

205188
ecx.push_stack_frame(
206189
Instance::new(def_id, args),
207-
dummy_body,
190+
body,
208191
&ret,
209192
StackPopCleanup::Root { cleanup: false },
210193
)

Diff for: compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use std::ops::ControlFlow;
2828
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
2929

3030
use super::inspect::ProofTreeBuilder;
31-
use super::search_graph;
3231
use super::SolverMode;
32+
use super::{search_graph, GoalEvaluationKind};
3333
use super::{search_graph::SearchGraph, Goal};
3434
pub use select::InferCtxtSelectExt;
3535

@@ -85,7 +85,7 @@ pub struct EvalCtxt<'a, 'tcx> {
8585
// evaluation code.
8686
tainted: Result<(), NoSolution>,
8787

88-
inspect: ProofTreeBuilder<'tcx>,
88+
pub(super) inspect: ProofTreeBuilder<'tcx>,
8989
}
9090

9191
#[derive(Debug, Clone)]
@@ -164,7 +164,7 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
164164
Option<inspect::GoalEvaluation<'tcx>>,
165165
) {
166166
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
167-
ecx.evaluate_goal(IsNormalizesToHack::No, goal)
167+
ecx.evaluate_goal(GoalEvaluationKind::Root, goal)
168168
})
169169
}
170170
}
@@ -340,11 +340,11 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
340340
/// been constrained and the certainty of the result.
341341
fn evaluate_goal(
342342
&mut self,
343-
is_normalizes_to_hack: IsNormalizesToHack,
343+
goal_evaluation_kind: GoalEvaluationKind,
344344
goal: Goal<'tcx, ty::Predicate<'tcx>>,
345345
) -> Result<(bool, Certainty, Vec<Goal<'tcx, ty::Predicate<'tcx>>>), NoSolution> {
346346
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
347-
let mut goal_evaluation = self.inspect.new_goal_evaluation(goal, is_normalizes_to_hack);
347+
let mut goal_evaluation = self.inspect.new_goal_evaluation(goal, goal_evaluation_kind);
348348
let encountered_overflow = self.search_graph.encountered_overflow();
349349
let canonical_response = EvalCtxt::evaluate_canonical_goal(
350350
self.tcx(),
@@ -389,7 +389,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
389389
// solver cycle.
390390
if cfg!(debug_assertions)
391391
&& has_changed
392-
&& is_normalizes_to_hack == IsNormalizesToHack::No
392+
&& !matches!(
393+
goal_evaluation_kind,
394+
GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::Yes }
395+
)
393396
&& !self.search_graph.in_cycle()
394397
{
395398
// The nested evaluation has to happen with the original state
@@ -561,8 +564,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
561564
},
562565
);
563566

564-
let (_, certainty, instantiate_goals) =
565-
self.evaluate_goal(IsNormalizesToHack::Yes, unconstrained_goal)?;
567+
let (_, certainty, instantiate_goals) = self.evaluate_goal(
568+
GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::Yes },
569+
unconstrained_goal,
570+
)?;
566571
self.add_goals(instantiate_goals);
567572

568573
// Finally, equate the goal's RHS with the unconstrained var.
@@ -596,8 +601,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
596601
}
597602

598603
for goal in goals.goals.drain(..) {
599-
let (has_changed, certainty, instantiate_goals) =
600-
self.evaluate_goal(IsNormalizesToHack::No, goal)?;
604+
let (has_changed, certainty, instantiate_goals) = self.evaluate_goal(
605+
GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::No },
606+
goal,
607+
)?;
601608
self.add_goals(instantiate_goals);
602609
if has_changed {
603610
unchanged_certainty = None;

Diff for: compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ where
2424
search_graph: outer_ecx.search_graph,
2525
nested_goals: outer_ecx.nested_goals.clone(),
2626
tainted: outer_ecx.tainted,
27-
inspect: outer_ecx.inspect.new_goal_candidate(),
27+
inspect: outer_ecx.inspect.new_probe(),
2828
};
2929
let r = nested_ecx.infcx.probe(|_| f(&mut nested_ecx));
3030
if !outer_ecx.inspect.is_noop() {
3131
let probe_kind = probe_kind(&r);
3232
nested_ecx.inspect.probe_kind(probe_kind);
33-
outer_ecx.inspect.goal_candidate(nested_ecx.inspect);
33+
outer_ecx.inspect.finish_probe(nested_ecx.inspect);
3434
}
3535
r
3636
}

0 commit comments

Comments
 (0)