Skip to content

Commit

Permalink
Compute upvars lazily.
Browse files Browse the repository at this point in the history
It can be computed from `tcx` on demand, instead of computing it eagerly
and passing it around.
  • Loading branch information
nnethercote committed Nov 19, 2024
1 parent 952c6d5 commit 2709dc8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ fn do_mir_borrowck<'tcx>(
&mut flow_inits,
&move_data,
&borrow_set,
tcx.closure_captures(def),
consumer_options,
);

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -171,7 +170,6 @@ pub(crate) fn type_check<'a, 'tcx>(
all_facts,
borrow_set,
constraints: &mut constraints,
upvars,
};

checker.check_user_type_annotations();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2709dc8

Please sign in to comment.