Auto merge of #107717 - nnethercote:opt-TyKind-eq, r=compiler-errors
Optimize `TyKind::eq`. r? `@ghost`
This commit is contained in:
commit
575d424c94
@ -310,8 +310,13 @@ fn clone(&self) -> Self {
|
||||
impl<I: Interner> PartialEq for TyKind<I> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &TyKind<I>) -> bool {
|
||||
tykind_discriminant(self) == tykind_discriminant(other)
|
||||
&& match (self, other) {
|
||||
// You might expect this `match` to be preceded with this:
|
||||
//
|
||||
// tykind_discriminant(self) == tykind_discriminant(other) &&
|
||||
//
|
||||
// but the data patterns in practice are such that a comparison
|
||||
// succeeds 99%+ of the time, and it's faster to omit it.
|
||||
match (self, other) {
|
||||
(Int(a_i), Int(b_i)) => a_i == b_i,
|
||||
(Uint(a_u), Uint(b_u)) => a_u == b_u,
|
||||
(Float(a_f), Float(b_f)) => a_f == b_f,
|
||||
@ -331,10 +336,9 @@ fn eq(&self, other: &TyKind<I>) -> bool {
|
||||
a_d == b_d && a_s == b_s && a_m == b_m
|
||||
}
|
||||
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
|
||||
(
|
||||
&GeneratorWitnessMIR(ref a_d, ref a_s),
|
||||
&GeneratorWitnessMIR(ref b_d, ref b_s),
|
||||
) => a_d == b_d && a_s == b_s,
|
||||
(&GeneratorWitnessMIR(ref a_d, ref a_s), &GeneratorWitnessMIR(ref b_d, ref b_s)) => {
|
||||
a_d == b_d && a_s == b_s
|
||||
}
|
||||
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
|
||||
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p,
|
||||
(Param(a_p), Param(b_p)) => a_p == b_p,
|
||||
@ -345,10 +349,10 @@ fn eq(&self, other: &TyKind<I>) -> bool {
|
||||
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => true,
|
||||
_ => {
|
||||
debug_assert!(
|
||||
false,
|
||||
tykind_discriminant(self) != tykind_discriminant(other),
|
||||
"This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"
|
||||
);
|
||||
true
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -408,7 +412,7 @@ fn cmp(&self, other: &TyKind<I>) -> Ordering {
|
||||
(Error(a_e), Error(b_e)) => a_e.cmp(b_e),
|
||||
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal,
|
||||
_ => {
|
||||
debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}");
|
||||
debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}");
|
||||
Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user