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#134439 - matthiaskrgr:rollup-grmmmx2, r=matth…
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#133265 (Add a range argument to vec.extract_if) - rust-lang#133801 (Promote powerpc64le-unknown-linux-musl to tier 2 with host tools) - rust-lang#134323 (coverage: Dismantle `map_data.rs` by moving its responsibilities elsewhere) - rust-lang#134378 (An octuple of polonius fact generation cleanups) - rust-lang#134408 (Regression test for RPIT inheriting lifetime from projection) - rust-lang#134423 (bootstrap: use specific-purpose ui test path for `test_valid` self-test) - rust-lang#134426 (Fix typo in uint_macros.rs) Failed merges: - rust-lang#133103 (Pass FnAbi to find_mir_or_eval_fn) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
40 changed files
with
612 additions
and
550 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
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.