Skip to content

Commit

Permalink
Super visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 2, 2024
1 parent 5de29df commit f6bfe28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 4 additions & 9 deletions compiler/rustc_trait_selection/src/solve/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ fn fulfillment_error_for_no_solution<'tcx>(
}
ty::PredicateKind::Subtype(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe(
root_obligation.predicate.kind().rebind((pred.a, pred.b)),
obligation.predicate.kind().rebind((pred.a, pred.b)),
);
let expected_found = ExpectedFound::new(true, a, b);
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
}
ty::PredicateKind::Coerce(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe(
root_obligation.predicate.kind().rebind((pred.a, pred.b)),
obligation.predicate.kind().rebind((pred.a, pred.b)),
);
let expected_found = ExpectedFound::new(false, a, b);
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
Expand Down Expand Up @@ -298,13 +298,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
}

fn visit_goal(&mut self, goal: &super::inspect::InspectGoal<'_, 'tcx>) -> Self::Result {
let candidates = goal.candidates();
// FIXME: Throw out candidates that have no failing WC and >1 failing misc goal.

// HACK:
if self.obligation.recursion_depth > 3 {
return ControlFlow::Break(self.obligation.clone());
}
let candidates = goal.candidates();

let [candidate] = candidates.as_slice() else {
return ControlFlow::Break(self.obligation.clone());
Expand Down Expand Up @@ -376,7 +371,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
recursion_depth: self_.obligation.recursion_depth + 1,
}
},
|self_| self_.visit_goal(&nested_goal),
|self_| nested_goal.visit_with(self),
)?;
}

Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
source,
}
}

pub(crate) fn visit_with<V: ProofTreeVisitor<'tcx>>(&self, visitor: &mut V) -> V::Result {
if self.goal.depth < visitor.config().max_depth {
try_visit!(visitor.visit_goal(self));
}

V::Result::output()
}
}

/// The public API to interact with proof trees.
Expand Down

0 comments on commit f6bfe28

Please sign in to comment.