From a6bcb9102a12213cd88f1aa655e737ce39bf08c5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 21 Mar 2024 11:54:38 +0000 Subject: [PATCH] Stop sorting via `DefId`s in region resolution --- .../src/infer/lexical_region_resolve/mod.rs | 18 +++++++------- .../src/infer/region_constraints/mod.rs | 2 +- tests/ui/issues/issue-27942.stderr | 24 +++++++++---------- ...trait-has-wrong-lifetime-parameters.stderr | 12 +++++----- tests/ui/traits/matching-lifetimes.stderr | 24 +++++++++---------- 5 files changed, 41 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index c39d0425f7e25..0be7bf8a8498d 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -139,8 +139,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let mut var_data = self.construct_var_data(); // Deduplicating constraints is shown to have a positive perf impact. - self.data.constraints.sort_by_key(|(constraint, _)| *constraint); - self.data.constraints.dedup_by_key(|(constraint, _)| *constraint); + let mut seen = FxHashSet::default(); + self.data.constraints.retain(|(constraint, _)| seen.insert(*constraint)); if cfg!(debug_assertions) { self.dump_constraints(); @@ -888,12 +888,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => { - let constraint_idx = - this.constraints.binary_search_by(|(c, _)| c.cmp(&edge.data)).unwrap(); - state.result.push(RegionAndOrigin { - region, - origin: this.constraints[constraint_idx].1.clone(), - }); + let origin = this + .constraints + .iter() + .find(|(c, _)| *c == edge.data) + .unwrap() + .1 + .clone(); + state.result.push(RegionAndOrigin { region, origin }); } Constraint::RegSubReg(..) => panic!( diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 0f3f2bc5fa634..3d6b54721d039 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -104,7 +104,7 @@ pub struct RegionConstraintData<'tcx> { } /// Represents a constraint that influences the inference process. -#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum Constraint<'tcx> { /// A region variable is a subregion of another. VarSubVar(RegionVid, RegionVid), diff --git a/tests/ui/issues/issue-27942.stderr b/tests/ui/issues/issue-27942.stderr index 7ea9345a668a8..8ea46bae26d4f 100644 --- a/tests/ui/issues/issue-27942.stderr +++ b/tests/ui/issues/issue-27942.stderr @@ -6,16 +6,16 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected trait `Resources<'_>` found trait `Resources<'a>` -note: the anonymous lifetime defined here... - --> $DIR/issue-27942.rs:5:15 - | -LL | fn select(&self) -> BufferViewHandle; - | ^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here +note: the lifetime `'a` as defined here... --> $DIR/issue-27942.rs:3:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ +note: ...does not necessarily outlive the anonymous lifetime defined here + --> $DIR/issue-27942.rs:5:15 + | +LL | fn select(&self) -> BufferViewHandle; + | ^^^^^ error[E0308]: mismatched types --> $DIR/issue-27942.rs:5:25 @@ -25,16 +25,16 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected trait `Resources<'_>` found trait `Resources<'a>` -note: the lifetime `'a` as defined here... - --> $DIR/issue-27942.rs:3:18 - | -LL | pub trait Buffer<'a, R: Resources<'a>> { - | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined here +note: the anonymous lifetime defined here... --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; | ^^^^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/issue-27942.rs:3:18 + | +LL | pub trait Buffer<'a, R: Resources<'a>> { + | ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr index 092776edea77d..8bf8536c74e46 100644 --- a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr +++ b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr @@ -4,16 +4,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 - | -LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { - | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9 | LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^ +note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... + --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 + | +LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { + | ^^ note: ...so that the types are compatible --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:28 | diff --git a/tests/ui/traits/matching-lifetimes.stderr b/tests/ui/traits/matching-lifetimes.stderr index f8119ed415d03..8a802d57f5ccc 100644 --- a/tests/ui/traits/matching-lifetimes.stderr +++ b/tests/ui/traits/matching-lifetimes.stderr @@ -6,16 +6,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'b` as defined here... - --> $DIR/matching-lifetimes.rs:13:9 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here +note: the lifetime `'a` as defined here... --> $DIR/matching-lifetimes.rs:13:6 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'b` as defined here + --> $DIR/matching-lifetimes.rs:13:9 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error[E0308]: method not compatible with trait --> $DIR/matching-lifetimes.rs:14:5 @@ -25,16 +25,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'a` as defined here... - --> $DIR/matching-lifetimes.rs:13:6 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined here +note: the lifetime `'b` as defined here... --> $DIR/matching-lifetimes.rs:13:9 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/matching-lifetimes.rs:13:6 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error: aborting due to 2 previous errors