Skip to content

Commit ce609db

Browse files
committed
Auto merge of #124467 - matthiaskrgr:rollup-1aq98fu, r=matthiaskrgr
Rollup of 2 pull requests Successful merges: - #124444 (Record certainty of `evaluate_added_goals_and_make_canonical_response` call in candidate) - #124463 (Rename `inhibit_union_abi_opt()` to `inhibits_union_abi_opt()`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ba00750 + 7ab3997 commit ce609db

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

compiler/rustc_abi/src/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub trait LayoutCalculator {
251251
// If all the non-ZST fields have the same ABI and union ABI optimizations aren't
252252
// disabled, we can use that common ABI for the union as a whole.
253253
struct AbiMismatch;
254-
let mut common_non_zst_abi_and_align = if repr.inhibit_union_abi_opt() {
254+
let mut common_non_zst_abi_and_align = if repr.inhibits_union_abi_opt() {
255255
// Can't optimize
256256
Err(AbiMismatch)
257257
} else {

compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl ReprOptions {
155155
}
156156

157157
/// Returns `true` if this `#[repr()]` should inhibit union ABI optimisations.
158-
pub fn inhibit_union_abi_opt(&self) -> bool {
158+
pub fn inhibits_union_abi_opt(&self) -> bool {
159159
self.c()
160160
}
161161
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ pub enum ProbeStep<'tcx> {
122122
/// used whenever there are multiple candidates to prove the
123123
/// current goalby .
124124
NestedProbe(Probe<'tcx>),
125+
/// A call to `EvalCtxt::evaluate_added_goals_make_canonical_response` with
126+
/// `Certainty` was made. This is the certainty passed in, so it's not unified
127+
/// with the certainty of the `try_evaluate_added_goals` that is done within;
128+
/// if it's `Certainty::Yes`, then we can trust that the candidate is "finished"
129+
/// and we didn't force ambiguity for some reason.
130+
MakeCanonicalResponse { shallow_certainty: Certainty },
125131
}
126132

127133
/// What kind of probe we're in. In case the probe represents a candidate, or

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

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
132132
}
133133
ProbeStep::EvaluateGoals(eval) => this.format_added_goals_evaluation(eval)?,
134134
ProbeStep::NestedProbe(probe) => this.format_probe(probe)?,
135+
ProbeStep::MakeCanonicalResponse { shallow_certainty } => {
136+
writeln!(this.f, "EVALUATE GOALS AND MAKE RESPONSE: {shallow_certainty:?}")?
137+
}
135138
}
136139
}
137140
Ok(())

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
9898
previous call to `try_evaluate_added_goals!`"
9999
);
100100

101+
self.inspect.make_canonical_response(certainty);
102+
101103
// When normalizing, we've replaced the expected term with an unconstrained
102104
// inference variable. This means that we dropped information which could
103105
// have been important. We handle this by instead returning the nested goals

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

+21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct InspectCandidate<'a, 'tcx> {
4545
nested_goals: Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
4646
final_state: inspect::CanonicalState<'tcx, ()>,
4747
result: QueryResult<'tcx>,
48+
candidate_certainty: Option<Certainty>,
4849
}
4950

5051
impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
@@ -56,6 +57,19 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
5657
self.result.map(|c| c.value.certainty)
5758
}
5859

60+
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
61+
///
62+
/// If this certainty is `Some(Yes)`, then we must be confident that the candidate
63+
/// must hold iff it's nested goals hold. This is not true if the certainty is
64+
/// `Some(Maybe)`, which suggests we forced ambiguity instead, or if it is `None`,
65+
/// which suggests we may have not assembled any candidates at all.
66+
///
67+
/// This is *not* the certainty of the candidate's nested evaluation, which can be
68+
/// accessed with [`Self::result`] instead.
69+
pub fn candidate_certainty(&self) -> Option<Certainty> {
70+
self.candidate_certainty
71+
}
72+
5973
/// Visit all nested goals of this candidate without rolling
6074
/// back their inference constraints. This function modifies
6175
/// the state of the `infcx`.
@@ -160,7 +174,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
160174
nested_goals: &mut Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
161175
probe: &inspect::Probe<'tcx>,
162176
) {
177+
let mut candidate_certainty = None;
163178
let num_candidates = candidates.len();
179+
164180
for step in &probe.steps {
165181
match step {
166182
&inspect::ProbeStep::AddGoal(_source, goal) => nested_goals.push(goal),
@@ -172,6 +188,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
172188
self.candidates_recur(candidates, nested_goals, probe);
173189
nested_goals.truncate(num_goals);
174190
}
191+
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty } => {
192+
assert_eq!(candidate_certainty.replace(*shallow_certainty), None);
193+
}
175194
inspect::ProbeStep::EvaluateGoals(_) => (),
176195
}
177196
}
@@ -195,6 +214,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
195214
nested_goals: nested_goals.clone(),
196215
final_state: probe.final_state,
197216
result,
217+
candidate_certainty,
198218
})
199219
}
200220
}
@@ -206,6 +226,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
206226
nested_goals: nested_goals.clone(),
207227
final_state: probe.final_state,
208228
result,
229+
candidate_certainty,
209230
});
210231
}
211232
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ enum WipProbeStep<'tcx> {
241241
AddGoal(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
242242
EvaluateGoals(WipAddedGoalsEvaluation<'tcx>),
243243
NestedProbe(WipProbe<'tcx>),
244+
MakeCanonicalResponse { shallow_certainty: Certainty },
244245
}
245246

246247
impl<'tcx> WipProbeStep<'tcx> {
@@ -249,6 +250,9 @@ impl<'tcx> WipProbeStep<'tcx> {
249250
WipProbeStep::AddGoal(source, goal) => inspect::ProbeStep::AddGoal(source, goal),
250251
WipProbeStep::EvaluateGoals(eval) => inspect::ProbeStep::EvaluateGoals(eval.finalize()),
251252
WipProbeStep::NestedProbe(probe) => inspect::ProbeStep::NestedProbe(probe.finalize()),
253+
WipProbeStep::MakeCanonicalResponse { shallow_certainty } => {
254+
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty }
255+
}
252256
}
253257
}
254258
}
@@ -530,6 +534,19 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
530534
}
531535
}
532536

537+
pub fn make_canonical_response(&mut self, shallow_certainty: Certainty) {
538+
match self.as_mut() {
539+
Some(DebugSolver::GoalEvaluationStep(state)) => {
540+
state
541+
.current_evaluation_scope()
542+
.steps
543+
.push(WipProbeStep::MakeCanonicalResponse { shallow_certainty });
544+
}
545+
None => {}
546+
_ => {}
547+
}
548+
}
549+
533550
pub fn finish_probe(mut self) -> ProofTreeBuilder<'tcx> {
534551
match self.as_mut() {
535552
None => {}

0 commit comments

Comments
 (0)