Skip to content

Commit eb80be2

Browse files
committed
Auto merge of #122824 - oli-obk:no_ord_def_id2, r=estebank,michaelwoerister
Stop sorting via `DefId`s in region resolution hopefully maintains the perf improvement from #118824 works towards #90317
2 parents 7762adc + 208582f commit eb80be2

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

Diff for: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_data_structures::graph::implementation::{
1313
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
1414
};
1515
use rustc_data_structures::intern::Interned;
16+
use rustc_data_structures::unord::UnordSet;
1617
use rustc_index::{IndexSlice, IndexVec};
1718
use rustc_middle::ty::fold::TypeFoldable;
1819
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -139,8 +140,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
139140
let mut var_data = self.construct_var_data();
140141

141142
// Deduplicating constraints is shown to have a positive perf impact.
142-
self.data.constraints.sort_by_key(|(constraint, _)| *constraint);
143-
self.data.constraints.dedup_by_key(|(constraint, _)| *constraint);
143+
let mut seen = UnordSet::default();
144+
self.data.constraints.retain(|(constraint, _)| seen.insert(*constraint));
144145

145146
if cfg!(debug_assertions) {
146147
self.dump_constraints();
@@ -888,12 +889,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
888889
}
889890

890891
Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => {
891-
let constraint_idx =
892-
this.constraints.binary_search_by(|(c, _)| c.cmp(&edge.data)).unwrap();
893-
state.result.push(RegionAndOrigin {
894-
region,
895-
origin: this.constraints[constraint_idx].1.clone(),
896-
});
892+
let origin = this
893+
.constraints
894+
.iter()
895+
.find(|(c, _)| *c == edge.data)
896+
.unwrap()
897+
.1
898+
.clone();
899+
state.result.push(RegionAndOrigin { region, origin });
897900
}
898901

899902
Constraint::RegSubReg(..) => panic!(

Diff for: compiler/rustc_infer/src/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct RegionConstraintData<'tcx> {
104104
}
105105

106106
/// Represents a constraint that influences the inference process.
107-
#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)]
107+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
108108
pub enum Constraint<'tcx> {
109109
/// A region variable is a subregion of another.
110110
VarSubVar(RegionVid, RegionVid),

Diff for: tests/ui/issues/issue-27942.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ LL | fn select(&self) -> BufferViewHandle<R>;
66
|
77
= note: expected trait `Resources<'_>`
88
found trait `Resources<'a>`
9-
note: the anonymous lifetime defined here...
10-
--> $DIR/issue-27942.rs:5:15
11-
|
12-
LL | fn select(&self) -> BufferViewHandle<R>;
13-
| ^^^^^
14-
note: ...does not necessarily outlive the lifetime `'a` as defined here
9+
note: the lifetime `'a` as defined here...
1510
--> $DIR/issue-27942.rs:3:18
1611
|
1712
LL | pub trait Buffer<'a, R: Resources<'a>> {
1813
| ^^
14+
note: ...does not necessarily outlive the anonymous lifetime defined here
15+
--> $DIR/issue-27942.rs:5:15
16+
|
17+
LL | fn select(&self) -> BufferViewHandle<R>;
18+
| ^^^^^
1919

2020
error[E0308]: mismatched types
2121
--> $DIR/issue-27942.rs:5:25
@@ -25,16 +25,16 @@ LL | fn select(&self) -> BufferViewHandle<R>;
2525
|
2626
= note: expected trait `Resources<'_>`
2727
found trait `Resources<'a>`
28-
note: the lifetime `'a` as defined here...
29-
--> $DIR/issue-27942.rs:3:18
30-
|
31-
LL | pub trait Buffer<'a, R: Resources<'a>> {
32-
| ^^
33-
note: ...does not necessarily outlive the anonymous lifetime defined here
28+
note: the anonymous lifetime defined here...
3429
--> $DIR/issue-27942.rs:5:15
3530
|
3631
LL | fn select(&self) -> BufferViewHandle<R>;
3732
| ^^^^^
33+
note: ...does not necessarily outlive the lifetime `'a` as defined here
34+
--> $DIR/issue-27942.rs:3:18
35+
|
36+
LL | pub trait Buffer<'a, R: Resources<'a>> {
37+
| ^^
3838

3939
error: aborting due to 2 previous errors
4040

Diff for: tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d
44
LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
55
| ^^^^^^^^^
66
|
7-
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
8-
--> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6
9-
|
10-
LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
11-
| ^^
12-
note: ...but the lifetime must also be valid for the lifetime `'b` as defined here...
7+
note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
138
--> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9
149
|
1510
LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
1611
| ^^
12+
note: ...but the lifetime must also be valid for the lifetime `'a` as defined here...
13+
--> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6
14+
|
15+
LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
16+
| ^^
1717
note: ...so that the types are compatible
1818
--> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:28
1919
|

Diff for: tests/ui/traits/matching-lifetimes.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ LL | fn foo(x: Foo<'b,'a>) {
66
|
77
= note: expected signature `fn(Foo<'a, 'b>)`
88
found signature `fn(Foo<'b, 'a>)`
9-
note: the lifetime `'b` as defined here...
10-
--> $DIR/matching-lifetimes.rs:13:9
11-
|
12-
LL | impl<'a,'b> Tr for Foo<'a,'b> {
13-
| ^^
14-
note: ...does not necessarily outlive the lifetime `'a` as defined here
9+
note: the lifetime `'a` as defined here...
1510
--> $DIR/matching-lifetimes.rs:13:6
1611
|
1712
LL | impl<'a,'b> Tr for Foo<'a,'b> {
1813
| ^^
14+
note: ...does not necessarily outlive the lifetime `'b` as defined here
15+
--> $DIR/matching-lifetimes.rs:13:9
16+
|
17+
LL | impl<'a,'b> Tr for Foo<'a,'b> {
18+
| ^^
1919

2020
error[E0308]: method not compatible with trait
2121
--> $DIR/matching-lifetimes.rs:14:5
@@ -25,16 +25,16 @@ LL | fn foo(x: Foo<'b,'a>) {
2525
|
2626
= note: expected signature `fn(Foo<'a, 'b>)`
2727
found signature `fn(Foo<'b, 'a>)`
28-
note: the lifetime `'a` as defined here...
29-
--> $DIR/matching-lifetimes.rs:13:6
30-
|
31-
LL | impl<'a,'b> Tr for Foo<'a,'b> {
32-
| ^^
33-
note: ...does not necessarily outlive the lifetime `'b` as defined here
28+
note: the lifetime `'b` as defined here...
3429
--> $DIR/matching-lifetimes.rs:13:9
3530
|
3631
LL | impl<'a,'b> Tr for Foo<'a,'b> {
3732
| ^^
33+
note: ...does not necessarily outlive the lifetime `'a` as defined here
34+
--> $DIR/matching-lifetimes.rs:13:6
35+
|
36+
LL | impl<'a,'b> Tr for Foo<'a,'b> {
37+
| ^^
3838

3939
error: aborting due to 2 previous errors
4040

0 commit comments

Comments
 (0)