Skip to content

Commit 9ea76e4

Browse files
authored
Rollup merge of #135250 - lqd:simple-cleanups, r=matthewjasper
A couple simple borrowck cleanups This PR has a couple simple renamings: - it's been a long time since the mapping from `Location`s to `PointIndex`es was extracted from `RegionElements` into the `DenseLocationMap`, but only the types were renamed at the time. borrowck still refers to this map as `elements`. That's confusing, especially since sometimes we also use the mapping via `LivenessValues`, and makes more sense as `location_map` instead. - to clarify `LocationTable` is not as general as it sounds, and is only for datalog polonius. In this branch I didn't rename the handful of `location_table` fields and params to `polonius_table`, but can do that to differentiate it even more from `location_map`. I did try it locally and it looks worthwhile, so if you'd prefer I can also push it here. (Or we could even switch these datalog types and fields to even more explicit names) - to clarify the incomprehensible `AllFacts`, it is renamed to `PoloniusFacts`. These can be referred to as `facts` within the legacy polonius module, but as `polonius_facts` outside of it to make it clear that they're not about NLLs (nor are they about in-tree polonius but that'll be magically fixed when they're removed in the future) r? `@matthewjasper`
2 parents 748effd + 36ea00c commit 9ea76e4

15 files changed

Lines changed: 153 additions & 146 deletions

File tree

‎compiler/rustc_borrowck/src/consumers.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_a
1111
pubusesuper::place_ext::PlaceExt;
1212
pubusesuper::places_conflict::{PlaceConflictBias, places_conflict};
1313
pubusesuper::polonius::legacy::{
14-
AllFactsasPoloniusInput,LocationTable,PoloniusOutput,PoloniusRegionVid,RichLocation,
15-
RustcFacts,
14+
PoloniusFactsasPoloniusInput,PoloniusLocationTable,PoloniusOutput,PoloniusRegionVid,
15+
RichLocation,RustcFacts,
1616
};
1717
pubusesuper::region_infer::RegionInferenceContext;
1818

@@ -33,7 +33,7 @@ pub enum ConsumerOptions {
3333
/// without significant slowdowns.
3434
///
3535
/// Implies [`RegionInferenceContext`](ConsumerOptions::RegionInferenceContext),
36-
/// and additionally retrieve the [`LocationTable`] and [`PoloniusInput`] that
36+
/// and additionally retrieve the [`PoloniusLocationTable`] and [`PoloniusInput`] that
3737
/// would be given to Polonius. Critically, this does not run Polonius, which
3838
/// one may want to avoid due to performance issues on large bodies.
3939
PoloniusInputFacts,
@@ -71,7 +71,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {
7171
/// The table that maps Polonius points to locations in the table.
7272
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
7373
/// or [`ConsumerOptions::PoloniusOutputFacts`].
74-
publocation_table:Option<LocationTable>,
74+
publocation_table:Option<PoloniusLocationTable>,
7575
/// Polonius input facts.
7676
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
7777
/// or [`ConsumerOptions::PoloniusOutputFacts`].

‎compiler/rustc_borrowck/src/lib.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use crate::diagnostics::{
5757
usecrate::path_utils::*;
5858
usecrate::place_ext::PlaceExt;
5959
usecrate::places_conflict::{PlaceConflictBias, places_conflict};
60-
usecrate::polonius::legacy::{LocationTable,PoloniusOutput};
60+
usecrate::polonius::legacy::{PoloniusLocationTable,PoloniusOutput};
6161
usecrate::prefixes::PrefixSet;
6262
usecrate::region_infer::RegionInferenceContext;
6363
usecrate::renumber::RegionCtxt;
@@ -176,7 +176,7 @@ fn do_mir_borrowck<'tcx>(
176176
infcx.register_predefined_opaques_for_next_solver(def);
177177
}
178178

179-
let location_table = LocationTable::new(body);
179+
let location_table = PoloniusLocationTable::new(body);
180180

181181
let move_data = MoveData::gather_moves(body, tcx, |_| true);
182182
let promoted_move_data = promoted
@@ -247,7 +247,8 @@ fn do_mir_borrowck<'tcx>(
247247
infcx:&infcx,
248248
body: promoted_body,
249249
move_data:&move_data,
250-
location_table:&location_table,// no need to create a real one for the promoted, it is not used
250+
// no need to create a real location table for the promoted, it is not used
251+
location_table:&location_table,
251252
movable_coroutine,
252253
fn_self_span_reported:Default::default(),
253254
locals_are_invalidated_at_exit,
@@ -513,7 +514,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
513514

514515
/// Map from MIR `Location` to `LocationIndex`; created
515516
/// when MIR borrowck begins.
516-
location_table:&'aLocationTable,
517+
location_table:&'aPoloniusLocationTable,
517518

518519
movable_coroutine:bool,
519520
/// This keeps track of whether local variables are free-ed when the function

‎compiler/rustc_borrowck/src/nll.rs‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use crate::borrow_set::BorrowSet;
2828
usecrate::consumers::ConsumerOptions;
2929
usecrate::diagnostics::{BorrowckDiagnosticsBuffer,RegionErrors};
3030
usecrate::polonius::LocalizedOutlivesConstraintSet;
31-
usecrate::polonius::legacy::{AllFacts,AllFactsExt,LocationTable,PoloniusOutput};
31+
usecrate::polonius::legacy::{
32+
PoloniusFacts,PoloniusFactsExt,PoloniusLocationTable,PoloniusOutput,
33+
};
3234
usecrate::region_infer::RegionInferenceContext;
3335
usecrate::type_check::{self,MirTypeckResults};
3436
usecrate::universal_regions::UniversalRegions;
@@ -39,7 +41,7 @@ use crate::{BorrowckInferCtxt, polonius, renumber};
3941
pub(crate)structNllOutput<'tcx>{
4042
pubregioncx:RegionInferenceContext<'tcx>,
4143
pubopaque_type_values:FxIndexMap<LocalDefId,OpaqueHiddenType<'tcx>>,
42-
pubpolonius_input:Option<Box<AllFacts>>,
44+
pubpolonius_input:Option<Box<PoloniusFacts>>,
4345
pubpolonius_output:Option<Box<PoloniusOutput>>,
4446
pubopt_closure_req:Option<ClosureRegionRequirements<'tcx>>,
4547
pubnll_errors:RegionErrors<'tcx>,
@@ -80,7 +82,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
8082
universal_regions:UniversalRegions<'tcx>,
8183
body:&Body<'tcx>,
8284
promoted:&IndexSlice<Promoted,Body<'tcx>>,
83-
location_table:&LocationTable,
85+
location_table:&PoloniusLocationTable,
8486
flow_inits:ResultsCursor<'a,'tcx,MaybeInitializedPlaces<'a,'tcx>>,
8587
move_data:&MoveData<'tcx>,
8688
borrow_set:&BorrowSet<'tcx>,
@@ -91,10 +93,10 @@ pub(crate) fn compute_regions<'a, 'tcx>(
9193
|| is_polonius_legacy_enabled;
9294
let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default()
9395
|| is_polonius_legacy_enabled;
94-
letmutall_facts =
95-
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
96+
letmutpolonius_facts =
97+
(polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());
9698

97-
letelements = Rc::new(DenseLocationMap::new(body));
99+
letlocation_map = Rc::new(DenseLocationMap::new(body));
98100

99101
// Run the MIR type-checker.
100102
letMirTypeckResults{
@@ -109,10 +111,10 @@ pub(crate) fn compute_regions<'a, 'tcx>(
109111
universal_regions,
110112
location_table,
111113
borrow_set,
112-
&mutall_facts,
114+
&mutpolonius_facts,
113115
flow_inits,
114116
move_data,
115-
Rc::clone(&elements),
117+
Rc::clone(&location_map),
116118
);
117119

118120
// Create the region inference context, taking ownership of the
@@ -122,7 +124,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
122124

123125
// If requested, emit legacy polonius facts.
124126
polonius::legacy::emit_facts(
125-
&mutall_facts,
127+
&mutpolonius_facts,
126128
infcx.tcx,
127129
location_table,
128130
body,
@@ -137,7 +139,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
137139
var_infos,
138140
constraints,
139141
universal_region_relations,
140-
elements,
142+
location_map,
141143
);
142144

143145
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives
@@ -147,13 +149,13 @@ pub(crate) fn compute_regions<'a, 'tcx>(
147149
});
148150

149151
// If requested: dump NLL facts, and run legacy polonius analysis.
150-
let polonius_output = all_facts.as_ref().and_then(|all_facts| {
152+
let polonius_output = polonius_facts.as_ref().and_then(|polonius_facts| {
151153
if infcx.tcx.sess.opts.unstable_opts.nll_facts{
152154
let def_id = body.source.def_id();
153155
let def_path = infcx.tcx.def_path(def_id);
154156
let dir_path = PathBuf::from(&infcx.tcx.sess.opts.unstable_opts.nll_facts_dir)
155157
.join(def_path.to_filename_friendly_no_crate());
156-
all_facts.write_to_dir(dir_path, location_table).unwrap();
158+
polonius_facts.write_to_dir(dir_path, location_table).unwrap();
157159
}
158160

159161
if polonius_output {
@@ -162,7 +164,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
162164
let algorithm = Algorithm::from_str(&algorithm).unwrap();
163165
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
164166
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");
165-
Some(Box::new(Output::compute(all_facts, algorithm,false)))
167+
Some(Box::new(Output::compute(polonius_facts, algorithm,false)))
166168
}else{
167169
None
168170
}
@@ -182,7 +184,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
182184
NllOutput{
183185
regioncx,
184186
opaque_type_values: remapped_opaque_tys,
185-
polonius_input:all_facts.map(Box::new),
187+
polonius_input:polonius_facts.map(Box::new),
186188
polonius_output,
187189
opt_closure_req: closure_region_requirements,
188190
nll_errors,

‎compiler/rustc_borrowck/src/polonius/legacy/accesses.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use rustc_middle::ty::TyCtxt;
44
use rustc_mir_dataflow::move_paths::{LookupResult,MoveData};
55
use tracing::debug;
66

7-
usesuper::{AllFacts,LocationIndex,LocationTable};
7+
usesuper::{LocationIndex,PoloniusFacts,PoloniusLocationTable};
88
usecrate::def_use::{self,DefUse};
99
usecrate::universal_regions::UniversalRegions;
1010

1111
/// Emit polonius facts for variable defs, uses, drops, and path accesses.
1212
pub(crate)fnemit_access_facts<'tcx>(
1313
tcx:TyCtxt<'tcx>,
14-
facts:&mutAllFacts,
14+
facts:&mutPoloniusFacts,
1515
body:&Body<'tcx>,
16-
location_table:&LocationTable,
16+
location_table:&PoloniusLocationTable,
1717
move_data:&MoveData<'tcx>,
1818
universal_regions:&UniversalRegions<'tcx>,
1919
){
@@ -31,9 +31,9 @@ pub(crate) fn emit_access_facts<'tcx>(
3131

3232
/// MIR visitor extracting point-wise facts about accesses.
3333
structAccessFactsExtractor<'a,'tcx>{
34-
facts:&'amutAllFacts,
34+
facts:&'amutPoloniusFacts,
3535
move_data:&'aMoveData<'tcx>,
36-
location_table:&'aLocationTable,
36+
location_table:&'aPoloniusLocationTable,
3737
}
3838

3939
impl<'tcx>AccessFactsExtractor<'_,'tcx>{

‎compiler/rustc_borrowck/src/polonius/legacy/facts.rs‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::fs::{self, File};
44
use std::io::Write;
55
use std::path::Path;
66

7-
use polonius_engine::{AllFactsasPoloniusFacts,Atom,Output};
7+
use polonius_engine::{AllFacts,Atom,Output};
88
use rustc_macros::extension;
99
use rustc_middle::mir::Local;
1010
use rustc_middle::ty::{RegionVid,TyCtxt};
1111
use rustc_mir_dataflow::move_paths::MovePathIndex;
1212

13-
usesuper::{LocationIndex,LocationTable};
13+
usesuper::{LocationIndex,PoloniusLocationTable};
1414
usecrate::BorrowIndex;
1515

1616
#[derive(Copy,Clone,Debug)]
@@ -49,11 +49,11 @@ impl polonius_engine::FactTypes for RustcFacts {
4949
typePath = MovePathIndex;
5050
}
5151

52-
pubtypeAllFacts = PoloniusFacts<RustcFacts>;
52+
pubtypePoloniusFacts = AllFacts<RustcFacts>;
5353

54-
#[extension(pub(crate)traitAllFactsExt)]
55-
implAllFacts{
56-
/// Returns `true` if there is a need to gather `AllFacts` given the
54+
#[extension(pub(crate)traitPoloniusFactsExt)]
55+
implPoloniusFacts{
56+
/// Returns `true` if there is a need to gather `PoloniusFacts` given the
5757
/// current `-Z` flags.
5858
fnenabled(tcx:TyCtxt<'_>) -> bool{
5959
tcx.sess.opts.unstable_opts.nll_facts
@@ -63,7 +63,7 @@ impl AllFacts {
6363
fnwrite_to_dir(
6464
&self,
6565
dir:implAsRef<Path>,
66-
location_table:&LocationTable,
66+
location_table:&PoloniusLocationTable,
6767
) -> Result<(),Box<dynError>>{
6868
let dir:&Path = dir.as_ref();
6969
fs::create_dir_all(dir)?;
@@ -119,7 +119,7 @@ impl Atom for LocationIndex {
119119
}
120120

121121
structFactWriter<'w>{
122-
location_table:&'wLocationTable,
122+
location_table:&'wPoloniusLocationTable,
123123
dir:&'wPath,
124124
}
125125

@@ -141,15 +141,15 @@ trait FactRow {
141141
fnwrite(
142142
&self,
143143
out:&mutdynWrite,
144-
location_table:&LocationTable,
144+
location_table:&PoloniusLocationTable,
145145
) -> Result<(),Box<dynError>>;
146146
}
147147

148148
implFactRowforPoloniusRegionVid{
149149
fnwrite(
150150
&self,
151151
out:&mutdynWrite,
152-
location_table:&LocationTable,
152+
location_table:&PoloniusLocationTable,
153153
) -> Result<(),Box<dynError>>{
154154
write_row(out, location_table,&[self])
155155
}
@@ -163,7 +163,7 @@ where
163163
fnwrite(
164164
&self,
165165
out:&mutdynWrite,
166-
location_table:&LocationTable,
166+
location_table:&PoloniusLocationTable,
167167
) -> Result<(),Box<dynError>>{
168168
write_row(out, location_table,&[&self.0,&self.1])
169169
}
@@ -178,7 +178,7 @@ where
178178
fnwrite(
179179
&self,
180180
out:&mutdynWrite,
181-
location_table:&LocationTable,
181+
location_table:&PoloniusLocationTable,
182182
) -> Result<(),Box<dynError>>{
183183
write_row(out, location_table,&[&self.0,&self.1,&self.2])
184184
}
@@ -194,15 +194,15 @@ where
194194
fnwrite(
195195
&self,
196196
out:&mutdynWrite,
197-
location_table:&LocationTable,
197+
location_table:&PoloniusLocationTable,
198198
) -> Result<(),Box<dynError>>{
199199
write_row(out, location_table,&[&self.0,&self.1,&self.2,&self.3])
200200
}
201201
}
202202

203203
fnwrite_row(
204204
out:&mutdynWrite,
205-
location_table:&LocationTable,
205+
location_table:&PoloniusLocationTable,
206206
columns:&[&dynFactCell],
207207
) -> Result<(),Box<dynError>>{
208208
for(index, c)in columns.iter().enumerate(){
@@ -213,41 +213,41 @@ fn write_row(
213213
}
214214

215215
traitFactCell{
216-
fnto_string(&self,location_table:&LocationTable) -> String;
216+
fnto_string(&self,location_table:&PoloniusLocationTable) -> String;
217217
}
218218

219219
implFactCellforBorrowIndex{
220-
fnto_string(&self,_location_table:&LocationTable) -> String{
220+
fnto_string(&self,_location_table:&PoloniusLocationTable) -> String{
221221
format!("{self:?}")
222222
}
223223
}
224224

225225
implFactCellforLocal{
226-
fnto_string(&self,_location_table:&LocationTable) -> String{
226+
fnto_string(&self,_location_table:&PoloniusLocationTable) -> String{
227227
format!("{self:?}")
228228
}
229229
}
230230

231231
implFactCellforMovePathIndex{
232-
fnto_string(&self,_location_table:&LocationTable) -> String{
232+
fnto_string(&self,_location_table:&PoloniusLocationTable) -> String{
233233
format!("{self:?}")
234234
}
235235
}
236236

237237
implFactCellforPoloniusRegionVid{
238-
fnto_string(&self,_location_table:&LocationTable) -> String{
238+
fnto_string(&self,_location_table:&PoloniusLocationTable) -> String{
239239
format!("{self:?}")
240240
}
241241
}
242242

243243
implFactCellforRegionVid{
244-
fnto_string(&self,_location_table:&LocationTable) -> String{
244+
fnto_string(&self,_location_table:&PoloniusLocationTable) -> String{
245245
format!("{self:?}")
246246
}
247247
}
248248

249249
implFactCellforLocationIndex{
250-
fnto_string(&self,location_table:&LocationTable) -> String{
250+
fnto_string(&self,location_table:&PoloniusLocationTable) -> String{
251251
format!("{:?}", location_table.to_rich_location(*self))
252252
}
253253
}

‎compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::{
1111
use rustc_middle::ty::TyCtxt;
1212
use tracing::debug;
1313

14-
usesuper::{AllFacts,LocationTable};
14+
usesuper::{PoloniusFacts,PoloniusLocationTable};
1515
usecrate::borrow_set::BorrowSet;
1616
usecrate::path_utils::*;
1717
usecrate::{
@@ -22,9 +22,9 @@ use crate::{
2222
/// Emit `loan_invalidated_at` facts.
2323
pub(super)fnemit_loan_invalidations<'tcx>(
2424
tcx:TyCtxt<'tcx>,
25-
facts:&mutAllFacts,
25+
facts:&mutPoloniusFacts,
2626
body:&Body<'tcx>,
27-
location_table:&LocationTable,
27+
location_table:&PoloniusLocationTable,
2828
borrow_set:&BorrowSet<'tcx>,
2929
){
3030
let dominators = body.basic_blocks.dominators();
@@ -35,9 +35,9 @@ pub(super) fn emit_loan_invalidations<'tcx>(
3535

3636
structLoanInvalidationsGenerator<'a,'tcx>{
3737
tcx:TyCtxt<'tcx>,
38-
facts:&'amutAllFacts,
38+
facts:&'amutPoloniusFacts,
3939
body:&'aBody<'tcx>,
40-
location_table:&'aLocationTable,
40+
location_table:&'aPoloniusLocationTable,
4141
dominators:&'aDominators<BasicBlock>,
4242
borrow_set:&'aBorrowSet<'tcx>,
4343
}

0 commit comments

Comments
 (0)