Compute upvars lazily.

It can be computed from `tcx` on demand, instead of computing it eagerly
and passing it around.
This commit is contained in:
Nicholas Nethercote 2024-10-29 15:01:35 +11:00
parent 952c6d5c96
commit 2709dc8a13
3 changed files with 3 additions and 7 deletions

View File

@ -217,7 +217,6 @@ fn do_mir_borrowck<'tcx>(
&mut flow_inits,
&move_data,
&borrow_set,
tcx.closure_captures(def),
consumer_options,
);

View File

@ -85,7 +85,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
move_data: &MoveData<'tcx>,
borrow_set: &BorrowSet<'tcx>,
upvars: &[&ty::CapturedPlace<'tcx>],
consumer_options: Option<ConsumerOptions>,
) -> NllOutput<'tcx> {
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
@ -112,7 +111,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
flow_inits,
move_data,
Rc::clone(&elements),
upvars,
);
// Create the region inference context, taking ownership of the

View File

@ -128,7 +128,6 @@ pub(crate) fn type_check<'a, 'tcx>(
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
move_data: &MoveData<'tcx>,
elements: Rc<DenseLocationMap>,
upvars: &[&ty::CapturedPlace<'tcx>],
) -> MirTypeckResults<'tcx> {
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
let mut constraints = MirTypeckRegionConstraints {
@ -171,7 +170,6 @@ pub(crate) fn type_check<'a, 'tcx>(
all_facts,
borrow_set,
constraints: &mut constraints,
upvars,
};
checker.check_user_type_annotations();
@ -852,7 +850,6 @@ struct TypeChecker<'a, 'tcx> {
all_facts: &'a mut Option<AllFacts>,
borrow_set: &'a BorrowSet<'tcx>,
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
upvars: &'a [&'a ty::CapturedPlace<'tcx>],
}
/// Holder struct for passing results from MIR typeck to the rest of the non-lexical regions
@ -2631,8 +2628,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
let tcx = self.infcx.tcx;
let def = self.body.source.def_id().expect_local();
let upvars = tcx.closure_captures(def);
let field =
path_utils::is_upvar_field_projection(tcx, self.upvars, borrowed_place.as_ref(), body);
path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), body);
let category = if let Some(field) = field {
ConstraintCategory::ClosureUpvar(field)
} else {