@@ -61,7 +61,10 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
61
61
value,
62
62
Some ( self ) ,
63
63
self . tcx ,
64
- CanonicalizeAllFreeRegions ( true ) ,
64
+ CanonicalizeRegionMode {
65
+ static_region : true ,
66
+ other_free_regions : true ,
67
+ } ,
65
68
)
66
69
}
67
70
@@ -101,7 +104,43 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
101
104
value,
102
105
Some ( self ) ,
103
106
self . tcx ,
104
- CanonicalizeAllFreeRegions ( false ) ,
107
+ CanonicalizeRegionMode {
108
+ static_region : false ,
109
+ other_free_regions : false ,
110
+ } ,
111
+ )
112
+ }
113
+
114
+ /// A hacky variant of `canonicalize_query` that does not
115
+ /// canonicalize `'static`. Unfortunately, the existing leak
116
+ /// check treaks `'static` differently in some cases (see also
117
+ /// #33684), so if we are performing an operation that may need to
118
+ /// prove "leak-check" related things, we leave `'static`
119
+ /// alone.
120
+ ///
121
+ /// FIXME(#48536) -- once we have universes, we can remove this and just use
122
+ /// `canonicalize_query`.
123
+ pub fn canonicalize_hr_query_hack < V > (
124
+ & self ,
125
+ value : & V ,
126
+ ) -> ( Canonicalized < ' gcx , V > , CanonicalVarValues < ' tcx > )
127
+ where
128
+ V : TypeFoldable < ' tcx > + Lift < ' gcx > ,
129
+ {
130
+ self . tcx
131
+ . sess
132
+ . perf_stats
133
+ . queries_canonicalized
134
+ . fetch_add ( 1 , Ordering :: Relaxed ) ;
135
+
136
+ Canonicalizer :: canonicalize (
137
+ value,
138
+ Some ( self ) ,
139
+ self . tcx ,
140
+ CanonicalizeRegionMode {
141
+ static_region : false ,
142
+ other_free_regions : true ,
143
+ } ,
105
144
)
106
145
}
107
146
}
@@ -110,15 +149,24 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
110
149
/// a canonical var. This is used to make queries as generic as
111
150
/// possible. For example, the query `F: Foo<'static>` would be
112
151
/// canonicalized to `F: Foo<'0>`.
113
- struct CanonicalizeAllFreeRegions ( pub bool ) ;
152
+ struct CanonicalizeRegionMode {
153
+ static_region : bool ,
154
+ other_free_regions : bool ,
155
+ }
156
+
157
+ impl CanonicalizeRegionMode {
158
+ fn any ( & self ) -> bool {
159
+ self . static_region || self . other_free_regions
160
+ }
161
+ }
114
162
115
163
struct Canonicalizer < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
116
164
infcx : Option < & ' cx InferCtxt < ' cx , ' gcx , ' tcx > > ,
117
165
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
118
166
variables : IndexVec < CanonicalVar , CanonicalVarInfo > ,
119
167
indices : FxHashMap < Kind < ' tcx > , CanonicalVar > ,
120
168
var_values : IndexVec < CanonicalVar , Kind < ' tcx > > ,
121
- canonicalize_all_free_regions : CanonicalizeAllFreeRegions ,
169
+ canonicalize_region_mode : CanonicalizeRegionMode ,
122
170
needs_canonical_flags : TypeFlags ,
123
171
}
124
172
@@ -152,14 +200,25 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
152
200
self . tcx ( ) . mk_region ( ty:: ReCanonical ( cvar) )
153
201
}
154
202
155
- ty:: ReStatic
156
- | ty:: ReEarlyBound ( ..)
203
+ ty:: ReStatic => {
204
+ if self . canonicalize_region_mode . static_region {
205
+ let info = CanonicalVarInfo {
206
+ kind : CanonicalVarKind :: Region ,
207
+ } ;
208
+ let cvar = self . canonical_var ( info, r. into ( ) ) ;
209
+ self . tcx ( ) . mk_region ( ty:: ReCanonical ( cvar) )
210
+ } else {
211
+ r
212
+ }
213
+ }
214
+
215
+ ty:: ReEarlyBound ( ..)
157
216
| ty:: ReFree ( _)
158
217
| ty:: ReScope ( _)
159
218
| ty:: ReSkolemized ( ..)
160
219
| ty:: ReEmpty
161
220
| ty:: ReErased => {
162
- if self . canonicalize_all_free_regions . 0 {
221
+ if self . canonicalize_region_mode . other_free_regions {
163
222
let info = CanonicalVarInfo {
164
223
kind : CanonicalVarKind :: Region ,
165
224
} ;
@@ -235,7 +294,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
235
294
value : & V ,
236
295
infcx : Option < & ' cx InferCtxt < ' cx , ' gcx , ' tcx > > ,
237
296
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
238
- canonicalize_all_free_regions : CanonicalizeAllFreeRegions ,
297
+ canonicalize_region_mode : CanonicalizeRegionMode ,
239
298
) -> ( Canonicalized < ' gcx , V > , CanonicalVarValues < ' tcx > )
240
299
where
241
300
V : TypeFoldable < ' tcx > + Lift < ' gcx > ,
@@ -246,7 +305,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
246
305
value,
247
306
) ;
248
307
249
- let needs_canonical_flags = if canonicalize_all_free_regions . 0 {
308
+ let needs_canonical_flags = if canonicalize_region_mode . any ( ) {
250
309
TypeFlags :: HAS_FREE_REGIONS | TypeFlags :: KEEP_IN_LOCAL_TCX
251
310
} else {
252
311
TypeFlags :: KEEP_IN_LOCAL_TCX
@@ -270,7 +329,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
270
329
let mut canonicalizer = Canonicalizer {
271
330
infcx,
272
331
tcx,
273
- canonicalize_all_free_regions ,
332
+ canonicalize_region_mode ,
274
333
needs_canonical_flags,
275
334
variables : IndexVec :: default ( ) ,
276
335
indices : FxHashMap :: default ( ) ,
0 commit comments