@@ -5,13 +5,13 @@ use std::{fmt, iter, mem};
5
5
6
6
use rustc_abi:: FieldIdx ;
7
7
use rustc_data_structures:: frozen:: Frozen ;
8
- use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
8
+ use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap , FxIndexSet } ;
9
9
use rustc_errors:: ErrorGuaranteed ;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: DefKind ;
12
12
use rustc_hir:: def_id:: LocalDefId ;
13
13
use rustc_hir:: lang_items:: LangItem ;
14
- use rustc_index:: { IndexSlice , IndexVec } ;
14
+ use rustc_index:: IndexSlice ;
15
15
use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
16
16
use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
17
17
use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
@@ -46,7 +46,7 @@ use crate::member_constraints::MemberConstraintSet;
46
46
use crate :: polonius:: legacy:: { PoloniusFacts , PoloniusLocationTable } ;
47
47
use crate :: polonius:: { PoloniusContext , PoloniusLivenessContext } ;
48
48
use crate :: region_infer:: TypeTest ;
49
- use crate :: region_infer:: values:: { LivenessValues , PlaceholderIndex , PlaceholderIndices } ;
49
+ use crate :: region_infer:: values:: LivenessValues ;
50
50
use crate :: session_diagnostics:: { MoveUnsized , SimdIntrinsicArgConst } ;
51
51
use crate :: type_check:: free_region_relations:: { CreateResult , UniversalRegionRelations } ;
52
52
use crate :: universal_regions:: { DefiningTy , UniversalRegions } ;
@@ -110,8 +110,7 @@ pub(crate) fn type_check<'tcx>(
110
110
location_map : Rc < DenseLocationMap > ,
111
111
) -> MirTypeckResults < ' tcx > {
112
112
let mut constraints = MirTypeckRegionConstraints {
113
- placeholder_indices : PlaceholderIndices :: default ( ) ,
114
- placeholder_index_to_region : IndexVec :: default ( ) ,
113
+ placeholder_to_region : FxHashMap :: default ( ) ,
115
114
liveness_constraints : LivenessValues :: with_specific_points ( Rc :: clone ( & location_map) ) ,
116
115
outlives_constraints : OutlivesConstraintSet :: default ( ) ,
117
116
member_constraints : MemberConstraintSet :: default ( ) ,
@@ -236,16 +235,10 @@ pub(crate) struct MirTypeckResults<'tcx> {
236
235
/// A collection of region constraints that must be satisfied for the
237
236
/// program to be considered well-typed.
238
237
pub ( crate ) struct MirTypeckRegionConstraints < ' tcx > {
239
- /// Maps from a `ty::Placeholder` to the corresponding
240
- /// `PlaceholderIndex` bit that we will use for it.
241
- placeholder_indices : PlaceholderIndices ,
242
-
243
- /// Each time we add a placeholder to `placeholder_indices`, we
244
- /// also create a corresponding "representative" region vid for
245
- /// that wraps it. This vector tracks those. This way, when we
246
- /// convert the same `ty::RePlaceholder(p)` twice, we can map to
247
- /// the same underlying `RegionVid`.
248
- placeholder_index_to_region : IndexVec < PlaceholderIndex , ty:: Region < ' tcx > > ,
238
+ /// For each placeholder we create a corresponding representative region vid.
239
+ /// This map tracks those. This way, when we convert the same `ty::RePlaceholder(p)`
240
+ /// twice, we can map to the same underlying `RegionVid`.
241
+ placeholder_to_region : FxHashMap < ty:: PlaceholderRegion , ty:: Region < ' tcx > > ,
249
242
250
243
/// In general, the type-checker is not responsible for enforcing
251
244
/// liveness constraints; this job falls to the region inferencer,
@@ -273,16 +266,10 @@ impl<'tcx> MirTypeckRegionConstraints<'tcx> {
273
266
infcx : & InferCtxt < ' tcx > ,
274
267
placeholder : ty:: PlaceholderRegion ,
275
268
) -> ty:: Region < ' tcx > {
276
- let placeholder_index = self . placeholder_indices . insert ( placeholder) ;
277
- match self . placeholder_index_to_region . get ( placeholder_index) {
278
- Some ( & v) => v,
279
- None => {
280
- let origin = NllRegionVariableOrigin :: Placeholder ( placeholder) ;
281
- let region = infcx. next_nll_region_var_in_universe ( origin, placeholder. universe ) ;
282
- self . placeholder_index_to_region . push ( region) ;
283
- region
284
- }
285
- }
269
+ * self . placeholder_to_region . entry ( placeholder) . or_insert_with ( || {
270
+ let origin = NllRegionVariableOrigin :: Placeholder ( placeholder) ;
271
+ infcx. next_nll_region_var_in_universe ( origin, placeholder. universe )
272
+ } )
286
273
}
287
274
}
288
275
0 commit comments