@@ -31,26 +31,14 @@ use crate::traits::query::OutlivesBound;
31
31
pub struct OutlivesEnvironment < ' tcx > {
32
32
pub param_env : ty:: ParamEnv < ' tcx > ,
33
33
free_region_map : FreeRegionMap < ' tcx > ,
34
-
35
- // Contains the implied region bounds in scope for our current body.
36
- //
37
- // Example:
38
- //
39
- // ```
40
- // fn foo<'a, 'b, T>(x: &'a T, y: &'b ()) {
41
- // bar(x, y, |y: &'b T| { .. } // body B1)
42
- // } // body B0
43
- // ```
44
- //
45
- // Here, when checking the body B0, the list would be `[T: 'a]`, because we
46
- // infer that `T` must outlive `'a` from the implied bounds on the
47
- // fn declaration.
48
- //
49
- // For the body B1 however, the list would be `[T: 'a, T: 'b]`, because we
50
- // also can see that -- within the closure body! -- `T` must
51
- // outlive `'b`. This is not necessarily true outside the closure
52
- // body, since the closure may never be called.
34
+ /// FIXME: Your first reaction may be that this is a bit strange. `RegionBoundPairs`
35
+ /// does not contain lifetimes, which are instead in the `FreeRegionMap`, and other
36
+ /// known type outlives are stored in the `known_type_outlives` set. So why do we
37
+ /// have these at all? It turns out that removing these and using `known_type_outlives`
38
+ /// everywhere is just enough of a perf regression to matter. This can/should be
39
+ /// optimized in the future, though.
53
40
region_bound_pairs : RegionBoundPairs < ' tcx > ,
41
+ known_type_outlives : Vec < ty:: PolyTypeOutlivesPredicate < ' tcx > > ,
54
42
}
55
43
56
44
/// "Region-bound pairs" tracks outlives relations that are known to
@@ -59,9 +47,10 @@ pub struct OutlivesEnvironment<'tcx> {
59
47
pub type RegionBoundPairs < ' tcx > = FxIndexSet < ty:: OutlivesPredicate < ' tcx , GenericKind < ' tcx > > > ;
60
48
61
49
impl < ' tcx > OutlivesEnvironment < ' tcx > {
62
- /// Create a new `OutlivesEnvironment` with extra outlives bounds.
63
- pub fn with_bounds (
50
+ /// Create a new `OutlivesEnvironment` from normalized outlives bounds.
51
+ pub fn from_normalized_bounds (
64
52
param_env : ty:: ParamEnv < ' tcx > ,
53
+ known_type_outlives : Vec < ty:: PolyTypeOutlivesPredicate < ' tcx > > ,
65
54
extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
66
55
) -> Self {
67
56
let mut region_relation = TransitiveRelationBuilder :: default ( ) ;
@@ -96,18 +85,21 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
96
85
97
86
OutlivesEnvironment {
98
87
param_env,
88
+ known_type_outlives,
99
89
free_region_map : FreeRegionMap { relation : region_relation. freeze ( ) } ,
100
90
region_bound_pairs,
101
91
}
102
92
}
103
93
104
- /// Borrows current value of the `free_region_map`.
105
94
pub fn free_region_map ( & self ) -> & FreeRegionMap < ' tcx > {
106
95
& self . free_region_map
107
96
}
108
97
109
- /// Borrows current `region_bound_pairs`.
110
98
pub fn region_bound_pairs ( & self ) -> & RegionBoundPairs < ' tcx > {
111
99
& self . region_bound_pairs
112
100
}
101
+
102
+ pub fn known_type_outlives ( & self ) -> & [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] {
103
+ & self . known_type_outlives
104
+ }
113
105
}
0 commit comments