Skip to content

Commit 13bd7e0

Browse files
committed
eagerly intiatialize definitions in sub-fn
1 parent 15e3f81 commit 13bd7e0

File tree

1 file changed

+19
-18
lines changed
  • compiler/rustc_borrowck/src/region_infer

1 file changed

+19
-18
lines changed

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct RegionInferenceContext<'tcx> {
145145
/// variables are identified by their index (`RegionVid`). The
146146
/// definition contains information about where the region came
147147
/// from as well as its final inferred value.
148-
pub(crate) definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
148+
pub(crate) definitions: Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>>,
149149

150150
/// The liveness constraints added to each region. For most
151151
/// regions, these start out empty and steadily grow, though for
@@ -385,6 +385,23 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
385385
debug!("SCC edges {:#?}", scc_node_to_edges);
386386
}
387387

388+
fn create_definitions<'tcx>(
389+
var_infos: &VarInfos,
390+
universal_regions: &UniversalRegions<'tcx>,
391+
) -> Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>> {
392+
// Create a RegionDefinition for each inference variable.
393+
let mut definitions: IndexVec<_, _> =
394+
var_infos.iter().map(|info| RegionDefinition::new(info.universe, info.origin)).collect();
395+
396+
// Add the external name for all universal regions.
397+
for (external_name, variable) in universal_regions.named_universal_regions_iter() {
398+
debug!("region {variable:?} has external name {external_name:?}");
399+
definitions[variable].external_name = Some(external_name);
400+
}
401+
402+
Frozen::freeze(definitions)
403+
}
404+
388405
impl<'tcx> RegionInferenceContext<'tcx> {
389406
/// Creates a new region inference context with a total of
390407
/// `num_region_variables` valid inference variables; the first N
@@ -426,11 +443,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
426443
infcx.set_tainted_by_errors(guar);
427444
}
428445

429-
// Create a RegionDefinition for each inference variable.
430-
let definitions: IndexVec<_, _> = var_infos
431-
.iter()
432-
.map(|info| RegionDefinition::new(info.universe, info.origin))
433-
.collect();
446+
let definitions = create_definitions(&var_infos, &universal_regions);
434447

435448
let constraint_sccs =
436449
outlives_constraints.add_outlives_static(&universal_regions, &definitions);
@@ -526,18 +539,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
526539
/// means that the `R1: !1` constraint here will cause
527540
/// `R1` to become `'static`.
528541
fn init_free_and_bound_regions(&mut self) {
529-
// Update the names (if any)
530-
// This iterator has unstable order but we collect it all into an IndexVec
531-
for (external_name, variable) in
532-
self.universal_region_relations.universal_regions.named_universal_regions_iter()
533-
{
534-
debug!(
535-
"init_free_and_bound_regions: region {:?} has external name {:?}",
536-
variable, external_name
537-
);
538-
self.definitions[variable].external_name = Some(external_name);
539-
}
540-
541542
for variable in self.definitions.indices() {
542543
let scc = self.constraint_sccs.scc(variable);
543544

0 commit comments

Comments
 (0)