Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26c03e2

Browse files
committed
dont assemble shadowed impl candidates
1 parent 64ca23b commit 26c03e2

File tree

1 file changed

+24
-3
lines changed
  • compiler/rustc_next_trait_solver/src/solve/assembly

1 file changed

+24
-3
lines changed

‎compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::delegate::SolverDelegate;
2121
use crate::solve::inspect::ProbeKind;
2222
use crate::solve::{
2323
BuiltinImplSource, CandidateSource, CanonicalResponse, Certainty, EvalCtxt, Goal, GoalSource,
24-
MaybeCause, NoSolution, ParamEnvSource, QueryResult,
24+
MaybeCause, NoSolution, ParamEnvSource, QueryResult, has_no_inference_or_external_constraints,
2525
};
2626

2727
enum AliasBoundKind {
@@ -395,9 +395,30 @@ where
395395

396396
match assemble_from {
397397
AssembleCandidatesFrom::All => {
398-
self.assemble_impl_candidates(goal, &mut candidates);
399398
self.assemble_builtin_impl_candidates(goal, &mut candidates);
400-
self.assemble_object_bound_candidates(goal, &mut candidates);
399+
// For performance we only assemble impls if there are no candidates
400+
// which would shadow them. This is necessary to avoid hangs in rayon,
401+
// see trait-system-refactor-initiative#109 for more details.
402+
//
403+
// We always assemble builtin impls as trivial builtin impls have a higher
404+
// priority than where-clauses.
405+
//
406+
// We only do this if any such candidate applies without any constraints
407+
// as we may want to weaken inference guidance in the future and don't want
408+
// to worry about causing major performance regressions when doing so.
409+
// See trait-system-refactor-initiative#226 for some ideas here.
410+
if TypingMode::Coherence == self.typing_mode()
411+
|| !candidates.iter().any(|c| {
412+
matches!(
413+
c.source,
414+
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
415+
| CandidateSource::AliasBound
416+
) && has_no_inference_or_external_constraints(c.result)
417+
})
418+
{
419+
self.assemble_impl_candidates(goal, &mut candidates);
420+
self.assemble_object_bound_candidates(goal, &mut candidates);
421+
}
401422
}
402423
AssembleCandidatesFrom::EnvAndBounds => {}
403424
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /