@@ -5,13 +5,13 @@ use std::{fmt, iter, mem};
55
66use rustc_abi:: FieldIdx ;
77use rustc_data_structures:: frozen:: Frozen ;
8- use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
8+ use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap , FxIndexSet } ;
99use rustc_errors:: ErrorGuaranteed ;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: DefKind ;
1212use rustc_hir:: def_id:: LocalDefId ;
1313use rustc_hir:: lang_items:: LangItem ;
14- use rustc_index:: { IndexSlice , IndexVec } ;
14+ use rustc_index:: IndexSlice ;
1515use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
1616use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
1717use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
@@ -46,7 +46,7 @@ use crate::member_constraints::MemberConstraintSet;
4646use crate :: polonius:: legacy:: { PoloniusFacts , PoloniusLocationTable } ;
4747use crate :: polonius:: { PoloniusContext , PoloniusLivenessContext } ;
4848use crate :: region_infer:: TypeTest ;
49- use crate :: region_infer:: values:: { LivenessValues , PlaceholderIndex , PlaceholderIndices } ;
49+ use crate :: region_infer:: values:: LivenessValues ;
5050use crate :: session_diagnostics:: { MoveUnsized , SimdIntrinsicArgConst } ;
5151use crate :: type_check:: free_region_relations:: { CreateResult , UniversalRegionRelations } ;
5252use crate :: universal_regions:: { DefiningTy , UniversalRegions } ;
@@ -110,8 +110,7 @@ pub(crate) fn type_check<'tcx>(
110110 location_map : Rc < DenseLocationMap > ,
111111) -> MirTypeckResults < ' tcx > {
112112 let mut constraints = MirTypeckRegionConstraints {
113- placeholder_indices : PlaceholderIndices :: default ( ) ,
114- placeholder_index_to_region : IndexVec :: default ( ) ,
113+ placeholder_to_region : FxHashMap :: default ( ) ,
115114 liveness_constraints : LivenessValues :: with_specific_points ( Rc :: clone ( & location_map) ) ,
116115 outlives_constraints : OutlivesConstraintSet :: default ( ) ,
117116 member_constraints : MemberConstraintSet :: default ( ) ,
@@ -236,16 +235,10 @@ pub(crate) struct MirTypeckResults<'tcx> {
236235/// A collection of region constraints that must be satisfied for the
237236/// program to be considered well-typed.
238237pub ( 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 > > ,
249242
250243 /// In general, the type-checker is not responsible for enforcing
251244 /// liveness constraints; this job falls to the region inferencer,
@@ -273,16 +266,10 @@ impl<'tcx> MirTypeckRegionConstraints<'tcx> {
273266 infcx : & InferCtxt < ' tcx > ,
274267 placeholder : ty:: PlaceholderRegion ,
275268 ) -> 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+ } )
286273 }
287274}
288275
0 commit comments