@@ -31,26 +31,14 @@ use crate::traits::query::OutlivesBound;
3131pub struct OutlivesEnvironment < ' tcx > {
3232 pub param_env : ty:: ParamEnv < ' tcx > ,
3333 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.
5340 region_bound_pairs : RegionBoundPairs < ' tcx > ,
41+ known_type_outlives : Vec < ty:: PolyTypeOutlivesPredicate < ' tcx > > ,
5442}
5543
5644/// "Region-bound pairs" tracks outlives relations that are known to
@@ -59,9 +47,10 @@ pub struct OutlivesEnvironment<'tcx> {
5947pub type RegionBoundPairs < ' tcx > = FxIndexSet < ty:: OutlivesPredicate < ' tcx , GenericKind < ' tcx > > > ;
6048
6149impl < ' 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 (
6452 param_env : ty:: ParamEnv < ' tcx > ,
53+ known_type_outlives : Vec < ty:: PolyTypeOutlivesPredicate < ' tcx > > ,
6554 extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
6655 ) -> Self {
6756 let mut region_relation = TransitiveRelationBuilder :: default ( ) ;
@@ -96,18 +85,21 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
9685
9786 OutlivesEnvironment {
9887 param_env,
88+ known_type_outlives,
9989 free_region_map : FreeRegionMap { relation : region_relation. freeze ( ) } ,
10090 region_bound_pairs,
10191 }
10292 }
10393
104- /// Borrows current value of the `free_region_map`.
10594 pub fn free_region_map ( & self ) -> & FreeRegionMap < ' tcx > {
10695 & self . free_region_map
10796 }
10897
109- /// Borrows current `region_bound_pairs`.
11098 pub fn region_bound_pairs ( & self ) -> & RegionBoundPairs < ' tcx > {
11199 & self . region_bound_pairs
112100 }
101+
102+ pub fn known_type_outlives ( & self ) -> & [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] {
103+ & self . known_type_outlives
104+ }
113105}
0 commit comments