forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#134380 - matthiaskrgr:rollup-a47jc6z, r=matth…
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#134202 (Remove `rustc::existing_doc_keyword` lint) - rust-lang#134354 (Handle fndef rendering together with signature rendering) - rust-lang#134368 (Use links to edition guide for edition migrations) - rust-lang#134371 (Check for array lengths that aren't actually `usize`) - rust-lang#134378 (An octuple of polonius fact generation cleanups) Failed merges: - rust-lang#134365 (Rename `rustc_mir_build::build` to `builder`) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
83 changed files
with
631 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; | ||
use rustc_middle::mir::{Body, Local, Location, Place}; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData}; | ||
use tracing::debug; | ||
|
||
use crate::def_use::{self, DefUse}; | ||
use crate::facts::AllFacts; | ||
use crate::location::{LocationIndex, LocationTable}; | ||
use crate::universal_regions::UniversalRegions; | ||
|
||
/// Emit polonius facts for variable defs, uses, drops, and path accesses. | ||
pub(crate) fn emit_access_facts<'tcx>( | ||
tcx: TyCtxt<'tcx>, | ||
facts: &mut AllFacts, | ||
body: &Body<'tcx>, | ||
location_table: &LocationTable, | ||
move_data: &MoveData<'tcx>, | ||
universal_regions: &UniversalRegions<'tcx>, | ||
) { | ||
let mut extractor = AccessFactsExtractor { facts, move_data, location_table }; | ||
extractor.visit_body(body); | ||
|
||
for (local, local_decl) in body.local_decls.iter_enumerated() { | ||
debug!("add use_of_var_derefs_origin facts - local={:?}, type={:?}", local, local_decl.ty); | ||
tcx.for_each_free_region(&local_decl.ty, |region| { | ||
let region_vid = universal_regions.to_region_vid(region); | ||
facts.use_of_var_derefs_origin.push((local, region_vid.into())); | ||
}); | ||
} | ||
} | ||
|
||
/// MIR visitor extracting point-wise facts about accesses. | ||
struct AccessFactsExtractor<'a, 'tcx> { | ||
facts: &'a mut AllFacts, | ||
move_data: &'a MoveData<'tcx>, | ||
location_table: &'a LocationTable, | ||
} | ||
|
||
impl<'tcx> AccessFactsExtractor<'_, 'tcx> { | ||
fn location_to_index(&self, location: Location) -> LocationIndex { | ||
self.location_table.mid_index(location) | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> { | ||
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { | ||
match def_use::categorize(context) { | ||
Some(DefUse::Def) => { | ||
debug!("AccessFactsExtractor - emit def"); | ||
self.facts.var_defined_at.push((local, self.location_to_index(location))); | ||
} | ||
Some(DefUse::Use) => { | ||
debug!("AccessFactsExtractor - emit use"); | ||
self.facts.var_used_at.push((local, self.location_to_index(location))); | ||
} | ||
Some(DefUse::Drop) => { | ||
debug!("AccessFactsExtractor - emit drop"); | ||
self.facts.var_dropped_at.push((local, self.location_to_index(location))); | ||
} | ||
_ => (), | ||
} | ||
} | ||
|
||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) { | ||
self.super_place(place, context, location); | ||
|
||
match context { | ||
PlaceContext::NonMutatingUse(_) | ||
| PlaceContext::MutatingUse(MutatingUseContext::Borrow) => { | ||
let path = match self.move_data.rev_lookup.find(place.as_ref()) { | ||
LookupResult::Exact(path) | LookupResult::Parent(Some(path)) => path, | ||
_ => { | ||
// There's no path access to emit. | ||
return; | ||
} | ||
}; | ||
debug!("AccessFactsExtractor - emit path access ({path:?}, {location:?})"); | ||
self.facts.path_accessed_at_base.push((path, self.location_to_index(location))); | ||
} | ||
|
||
_ => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.