Skip to content

Commit

Permalink
Auto merge of #124467 - matthiaskrgr:rollup-1aq98fu, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 28, 2024
2 parents ba00750 + 7ab3997 commit ce609db
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub trait LayoutCalculator {
// If all the non-ZST fields have the same ABI and union ABI optimizations aren't
// disabled, we can use that common ABI for the union as a whole.
struct AbiMismatch;
let mut common_non_zst_abi_and_align = if repr.inhibit_union_abi_opt() {
let mut common_non_zst_abi_and_align = if repr.inhibits_union_abi_opt() {
// Can't optimize
Err(AbiMismatch)
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl ReprOptions {
}

/// Returns `true` if this `#[repr()]` should inhibit union ABI optimisations.
pub fn inhibit_union_abi_opt(&self) -> bool {
pub fn inhibits_union_abi_opt(&self) -> bool {
self.c()
}
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/traits/solve/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ pub enum ProbeStep<'tcx> {
/// used whenever there are multiple candidates to prove the
/// current goalby .
NestedProbe(Probe<'tcx>),
/// A call to `EvalCtxt::evaluate_added_goals_make_canonical_response` with
/// `Certainty` was made. This is the certainty passed in, so it's not unified
/// with the certainty of the `try_evaluate_added_goals` that is done within;
/// if it's `Certainty::Yes`, then we can trust that the candidate is "finished"
/// and we didn't force ambiguity for some reason.
MakeCanonicalResponse { shallow_certainty: Certainty },
}

/// What kind of probe we're in. In case the probe represents a candidate, or
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/traits/solve/inspect/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
}
ProbeStep::EvaluateGoals(eval) => this.format_added_goals_evaluation(eval)?,
ProbeStep::NestedProbe(probe) => this.format_probe(probe)?,
ProbeStep::MakeCanonicalResponse { shallow_certainty } => {
writeln!(this.f, "EVALUATE GOALS AND MAKE RESPONSE: {shallow_certainty:?}")?
}
}
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
previous call to `try_evaluate_added_goals!`"
);

self.inspect.make_canonical_response(certainty);

// When normalizing, we've replaced the expected term with an unconstrained
// inference variable. This means that we dropped information which could
// have been important. We handle this by instead returning the nested goals
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct InspectCandidate<'a, 'tcx> {
nested_goals: Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
final_state: inspect::CanonicalState<'tcx, ()>,
result: QueryResult<'tcx>,
candidate_certainty: Option<Certainty>,
}

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

/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
///
/// If this certainty is `Some(Yes)`, then we must be confident that the candidate
/// must hold iff it's nested goals hold. This is not true if the certainty is
/// `Some(Maybe)`, which suggests we forced ambiguity instead, or if it is `None`,
/// which suggests we may have not assembled any candidates at all.
///
/// This is *not* the certainty of the candidate's nested evaluation, which can be
/// accessed with [`Self::result`] instead.
pub fn candidate_certainty(&self) -> Option<Certainty> {
self.candidate_certainty
}

/// Visit all nested goals of this candidate without rolling
/// back their inference constraints. This function modifies
/// the state of the `infcx`.
Expand Down Expand Up @@ -160,7 +174,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
nested_goals: &mut Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
probe: &inspect::Probe<'tcx>,
) {
let mut candidate_certainty = None;
let num_candidates = candidates.len();

for step in &probe.steps {
match step {
&inspect::ProbeStep::AddGoal(_source, goal) => nested_goals.push(goal),
Expand All @@ -172,6 +188,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
self.candidates_recur(candidates, nested_goals, probe);
nested_goals.truncate(num_goals);
}
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty } => {
assert_eq!(candidate_certainty.replace(*shallow_certainty), None);
}
inspect::ProbeStep::EvaluateGoals(_) => (),
}
}
Expand All @@ -195,6 +214,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
nested_goals: nested_goals.clone(),
final_state: probe.final_state,
result,
candidate_certainty,
})
}
}
Expand All @@ -206,6 +226,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
nested_goals: nested_goals.clone(),
final_state: probe.final_state,
result,
candidate_certainty,
});
}
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_trait_selection/src/solve/inspect/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ enum WipProbeStep<'tcx> {
AddGoal(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
EvaluateGoals(WipAddedGoalsEvaluation<'tcx>),
NestedProbe(WipProbe<'tcx>),
MakeCanonicalResponse { shallow_certainty: Certainty },
}

impl<'tcx> WipProbeStep<'tcx> {
Expand All @@ -249,6 +250,9 @@ impl<'tcx> WipProbeStep<'tcx> {
WipProbeStep::AddGoal(source, goal) => inspect::ProbeStep::AddGoal(source, goal),
WipProbeStep::EvaluateGoals(eval) => inspect::ProbeStep::EvaluateGoals(eval.finalize()),
WipProbeStep::NestedProbe(probe) => inspect::ProbeStep::NestedProbe(probe.finalize()),
WipProbeStep::MakeCanonicalResponse { shallow_certainty } => {
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty }
}
}
}
}
Expand Down Expand Up @@ -530,6 +534,19 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
}
}

pub fn make_canonical_response(&mut self, shallow_certainty: Certainty) {
match self.as_mut() {
Some(DebugSolver::GoalEvaluationStep(state)) => {
state
.current_evaluation_scope()
.steps
.push(WipProbeStep::MakeCanonicalResponse { shallow_certainty });
}
None => {}
_ => {}
}
}

pub fn finish_probe(mut self) -> ProofTreeBuilder<'tcx> {
match self.as_mut() {
None => {}
Expand Down

0 comments on commit ce609db

Please sign in to comment.