Skip to content

Commit 6ecf80e

Browse files
committed
Merge BorrowCheckContext into TypeChecker.
Because there is no real reason for it to be a separate struct. - It has no methods. - It's easy to confuse with the nearby `BorrowckInferContext` (which does have methods). - The `mut` ref to it in `TypeChecker` makes it seem like any of the fields within might be mutable, but only two (`all_facts` and `constraints`) actually are. - Two of the fields are `pub(crate)` but can be private. This change makes a lot of code more concise and readable.
1 parent f86c76a commit 6ecf80e

File tree

7 files changed

+88
-173
lines changed

7 files changed

+88
-173
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
6262
{
6363
let universe_info = error_info.to_universe_info(old_universe);
6464
for u in (old_universe + 1)..=universe {
65-
self.borrowck_context.constraints.universe_causes.insert(u, universe_info.clone());
65+
self.constraints.universe_causes.insert(u, universe_info.clone());
6666
}
6767
}
6868

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
4848
// FIXME(async_closures): It's kind of wacky that we must apply this
4949
// transformation here, since we do the same thing in HIR typeck.
5050
// Maybe we could just fix up the canonicalized signature during HIR typeck?
51-
if let DefiningTy::CoroutineClosure(_, args) =
52-
self.borrowck_context.universal_regions.defining_ty
53-
{
51+
if let DefiningTy::CoroutineClosure(_, args) = self.universal_regions.defining_ty {
5452
assert_matches!(
5553
self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(mir_def_id)),
5654
Some(hir::CoroutineKind::Desugared(

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub(super) fn generate<'a, 'tcx>(
3939

4040
let free_regions = regions_that_outlive_free_regions(
4141
typeck.infcx.num_region_vars(),
42-
typeck.borrowck_context.universal_regions,
43-
&typeck.borrowck_context.constraints.outlives_constraints,
42+
typeck.universal_regions,
43+
&typeck.constraints.outlives_constraints,
4444
);
4545
let (relevant_live_locals, boring_locals) =
4646
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
@@ -59,11 +59,7 @@ pub(super) fn generate<'a, 'tcx>(
5959

6060
// Mark regions that should be live where they appear within rvalues or within a call: like
6161
// args, regions, and types.
62-
record_regular_live_regions(
63-
typeck.tcx(),
64-
&mut typeck.borrowck_context.constraints.liveness_constraints,
65-
body,
66-
);
62+
record_regular_live_regions(typeck.tcx(), &mut typeck.constraints.liveness_constraints, body);
6763
}
6864

6965
// The purpose of `compute_relevant_live_locals` is to define the subset of `Local`

compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
8888
body: &Body<'tcx>,
8989
move_data: &MoveData<'tcx>,
9090
) {
91-
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
91+
if let Some(facts) = typeck.all_facts.as_mut() {
9292
debug!("populate_access_facts()");
93-
let location_table = typeck.borrowck_context.location_table;
93+
let location_table = typeck.location_table;
9494

9595
let mut extractor = UseFactsExtractor {
9696
var_defined_at: &mut facts.var_defined_at,
@@ -108,7 +108,7 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
108108
local, local_decl.ty
109109
);
110110
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
111-
let universal_regions = &typeck.borrowck_context.universal_regions;
111+
let universal_regions = &typeck.universal_regions;
112112
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
113113
let region_vid = universal_regions.to_region_vid(region);
114114
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
@@ -125,9 +125,9 @@ pub(super) fn add_drop_of_var_derefs_origin<'tcx>(
125125
kind: &GenericArg<'tcx>,
126126
) {
127127
debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind);
128-
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
128+
if let Some(facts) = typeck.all_facts.as_mut() {
129129
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
130-
let universal_regions = &typeck.borrowck_context.universal_regions;
130+
let universal_regions = &typeck.universal_regions;
131131
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
132132
let region_vid = universal_regions.to_region_vid(drop_live_region);
133133
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ pub(super) fn trace<'a, 'tcx>(
4747

4848
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
4949
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
50-
let borrowck_context = &mut typeck.borrowck_context;
51-
let borrow_set = &borrowck_context.borrow_set;
50+
let borrow_set = &typeck.borrow_set;
5251
let mut live_loans = LiveLoans::new(borrow_set.len());
53-
let outlives_constraints = &borrowck_context.constraints.outlives_constraints;
52+
let outlives_constraints = &typeck.constraints.outlives_constraints;
5453
let graph = outlives_constraints.graph(typeck.infcx.num_region_vars());
5554
let region_graph =
56-
graph.region_graph(outlives_constraints, borrowck_context.universal_regions.fr_static);
55+
graph.region_graph(outlives_constraints, typeck.universal_regions.fr_static);
5756

5857
// Traverse each issuing region's constraints, and record the loan as flowing into the
5958
// outlived region.
@@ -73,7 +72,7 @@ pub(super) fn trace<'a, 'tcx>(
7372

7473
// Store the inflowing loans in the liveness constraints: they will be used to compute live
7574
// loans when liveness data is recorded there.
76-
borrowck_context.constraints.liveness_constraints.loans = Some(live_loans);
75+
typeck.constraints.liveness_constraints.loans = Some(live_loans);
7776
};
7877

7978
let cx = LivenessContext {
@@ -222,7 +221,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
222221
// It may be necessary to just pick out the parts of
223222
// `add_drop_live_facts_for()` that make sense.
224223
let facts_to_add: Vec<_> = {
225-
let drop_used = &self.cx.typeck.borrowck_context.all_facts.as_ref()?.var_dropped_at;
224+
let drop_used = &self.cx.typeck.all_facts.as_ref()?.var_dropped_at;
226225

227226
let relevant_live_locals: FxIndexSet<_> =
228227
relevant_live_locals.iter().copied().collect();
@@ -235,12 +234,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
235234
return None;
236235
}
237236

238-
let location = match self
239-
.cx
240-
.typeck
241-
.borrowck_context
242-
.location_table
243-
.to_location(*location_index)
237+
let location = match self.cx.typeck.location_table.to_location(*location_index)
244238
{
245239
RichLocation::Start(l) => l,
246240
RichLocation::Mid(l) => l,
@@ -616,13 +610,9 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
616610
tcx: typeck.tcx(),
617611
param_env: typeck.param_env,
618612
op: |r| {
619-
let live_region_vid = typeck.borrowck_context.universal_regions.to_region_vid(r);
613+
let live_region_vid = typeck.universal_regions.to_region_vid(r);
620614

621-
typeck
622-
.borrowck_context
623-
.constraints
624-
.liveness_constraints
625-
.add_points(live_region_vid, live_at);
615+
typeck.constraints.liveness_constraints.add_points(live_region_vid, live_at);
626616
},
627617
});
628618
}

0 commit comments

Comments
 (0)