Skip to content

Commit 8c7ffa9

Browse files
Auto merge of #142090 - compiler-errors:perf-stable-root-var, r=<try>
Make root vars more stable Never resolve a ty/ct vid to a higher vid as its root. This should make the optimization in #141500 more "stable" when there are a lot of vars flying around. r? `@ghost`
2 parents c31cccb + e1567df commit 8c7ffa9

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ impl<'tcx> ut::UnifyKey for TyVidEqKey<'tcx> {
238238
fn tag() -> &'static str {
239239
"TyVidEqKey"
240240
}
241+
fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
242+
if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
243+
}
241244
}
242245

243246
impl<'tcx> ut::UnifyValue for TypeVariableValue<'tcx> {

compiler/rustc_infer/src/infer/unify_key.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
137137
fn tag() -> &'static str {
138138
"ConstVidKey"
139139
}
140+
fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
141+
if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
142+
}
140143
}
141144

142145
impl<'tcx> UnifyValue for ConstVariableValue<'tcx> {

compiler/rustc_type_ir/src/ty_kind.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -771,23 +771,6 @@ pub enum InferTy {
771771
FreshFloatTy(u32),
772772
}
773773

774-
/// Raw `TyVid` are used as the unification key for `sub_relations`;
775-
/// they carry no values.
776-
impl UnifyKey for TyVid {
777-
type Value = ();
778-
#[inline]
779-
fn index(&self) -> u32 {
780-
self.as_u32()
781-
}
782-
#[inline]
783-
fn from_index(i: u32) -> TyVid {
784-
TyVid::from_u32(i)
785-
}
786-
fn tag() -> &'static str {
787-
"TyVid"
788-
}
789-
}
790-
791774
impl UnifyValue for IntVarValue {
792775
type Error = NoError;
793776

0 commit comments

Comments
 (0)