Skip to content

[perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation #142647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub enum ScrubbedTraitError<'tcx> {
TrueError,
/// An ambiguity. This goal may hold if further inference is done.
Ambiguity,
/// An old-solver-style cycle error, which will fatal.
/// An old-solver-style cycle error, which will fatal. This is not
/// returned by the new solver.
Cycle(PredicateObligations<'tcx>),
}

Expand Down
43 changes: 26 additions & 17 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,29 +356,38 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
return IntersectionHasImpossibleObligations::Yes;
}

let ocx = ObligationCtxt::new_with_diagnostics(infcx);
let ocx = ObligationCtxt::new(infcx);
ocx.register_obligations(obligations.iter().cloned());
let hard_errors = ocx.select_where_possible();
if !hard_errors.is_empty() {
assert!(
hard_errors.iter().all(|e| e.is_true_error()),
"should not have detected ambiguity during first pass"
);
return IntersectionHasImpossibleObligations::Yes;
}

// Make a new `ObligationCtxt` and re-prove the ambiguities with a richer
// `FulfillmentError`. This is so that we can detect overflowing obligations
// without needing to run the `BestBestObligation` visitor on true errors.
let ambiguities = ocx.into_pending_obligations();
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
ocx.register_obligations(ambiguities);
let errors_and_ambiguities = ocx.select_all_or_error();
// We only care about the obligations that are *definitely* true errors.
// Ambiguities do not prove the disjointness of two impls.
let (errors, ambiguities): (Vec<_>, Vec<_>) =
errors_and_ambiguities.into_iter().partition(|error| error.is_true_error());

if errors.is_empty() {
IntersectionHasImpossibleObligations::No {
overflowing_predicates: ambiguities
.into_iter()
.filter(|error| {
matches!(
error.code,
FulfillmentErrorCode::Ambiguity { overflow: Some(true) }
)
})
.map(|e| infcx.resolve_vars_if_possible(e.obligation.predicate))
.collect(),
}
} else {
IntersectionHasImpossibleObligations::Yes
assert!(errors.is_empty(), "should not have ambiguities during second pass");

IntersectionHasImpossibleObligations::No {
overflowing_predicates: ambiguities
.into_iter()
.filter(|error| {
matches!(error.code, FulfillmentErrorCode::Ambiguity { overflow: Some(true) })
})
.map(|e| infcx.resolve_vars_if_possible(e.obligation.predicate))
.collect(),
}
} else {
for obligation in obligations {
Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/139905.rs

This file was deleted.

Loading