Skip to content

Commit

Permalink
Auto merge of rust-lang#84944 - lcnr:obligation-dedup, r=jackh726
Browse files Browse the repository at this point in the history
remove obligation dedup from `impl_or_trait_obligations`

Looking at the examples from rust-lang#38528 they all seem to compile fine even without this and it seems like this might be unnecessary effort
  • Loading branch information
bors committed Mar 3, 2022
2 parents 4566094 + b941485 commit 32cbc76
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2374,28 +2374,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
});
}

// We are performing deduplication here to avoid exponential blowups
// (#38528) from happening, but the real cause of the duplication is
// unknown. What we know is that the deduplication avoids exponential
// amount of predicates being propagated when processing deeply nested
// types.
//
// This code is hot enough that it's worth avoiding the allocation
// required for the FxHashSet when possible. Special-casing lengths 0,
// 1 and 2 covers roughly 75-80% of the cases.
if obligations.len() <= 1 {
// No possibility of duplicates.
} else if obligations.len() == 2 {
// Only two elements. Drop the second if they are equal.
if obligations[0] == obligations[1] {
obligations.truncate(1);
}
} else {
// Three or more elements. Use a general deduplication process.
let mut seen = FxHashSet::default();
obligations.retain(|i| seen.insert(i.clone()));
}

obligations
}
}
Expand Down

0 comments on commit 32cbc76

Please sign in to comment.