Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
68ce659
Promote powerpc64le-unknown-linux-musl to tier 2 with host tools
Gelbpunkt Nov 18, 2024
3e3ee4c
Fix markdown link
Gelbpunkt Dec 3, 2024
8bb0fd5
Update src/doc/rustc/src/platform-support/powerpc64le-unknown-linux-m…
Gelbpunkt Dec 3, 2024
286de9f
Move dist-powerpc64le-linux to job-linux-4c-largedisk
Gelbpunkt Dec 9, 2024
2fd4438
clean up `emit_access_facts`
lqd Dec 11, 2024
9d8f58a
clean up `emit_drop_facts`
lqd Dec 11, 2024
afbe101
clean up `translate_outlives_facts`
lqd Dec 11, 2024
5486857
use let else more consistently in fact generation
lqd Dec 11, 2024
1740a5f
simplify `emit_access_facts` and fact generation
lqd Dec 11, 2024
2024c5d
simplify `emit_outlives_facts`
lqd Dec 11, 2024
7ad1f5b
refactor `type_check` module slightly
lqd Dec 11, 2024
8562497
improve consistency within fact gen
lqd Dec 11, 2024
ab6ad1a
Add a range argument to vec.extract_if
the8472 Nov 20, 2024
03f1b73
remove bounds from vec and linkedlist ExtractIf
the8472 Nov 20, 2024
fe52150
update uses of extract_if in the compiler
the8472 Nov 20, 2024
44790c4
remove obsolete comment and pub(super) visibility
the8472 Nov 20, 2024
fe412af
coverage: Use `is_eligible_for_coverage` to filter unused functions
Zalathar Dec 14, 2024
154fae1
coverage: Build the global file table on the fly
Zalathar Dec 13, 2024
252276a
coverage: Pull expression conversion out of `map_data.rs`
Zalathar Dec 12, 2024
527f812
coverage: Pull region conversion out of `map_data.rs`
Zalathar Dec 12, 2024
d34c365
coverage: Pull function source hash out of `map_data.rs`
Zalathar Dec 14, 2024
541d4e8
coverage: Track used functions in a set instead of a map
Zalathar Dec 14, 2024
a7f61ca
Regression test for RPIT inheriting lifetime
rmehri01 Dec 17, 2024
9c7593e
Pass FnAbi to find_mir_or_eval_fn
tiif Nov 16, 2024
13e8313
bootstrap: use specific-purpose ui test path
jieyouxu Dec 17, 2024
c482b31
Fix typo in uint_macros.rs
hkBst Dec 17, 2024
d7f80f6
Rollup merge of #133103 - tiif:fnabi, r=RalfJung
jieyouxu Dec 17, 2024
18989bc
Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviper
jieyouxu Dec 17, 2024
21b8fe1
Rollup merge of #133801 - Gelbpunkt:powerpc64le-unknown-linux-musl-ti…
jieyouxu Dec 17, 2024
2a2adf7
Rollup merge of #134323 - Zalathar:dismantle-map-data, r=jieyouxu
jieyouxu Dec 17, 2024
bdcfcbf
Rollup merge of #134378 - lqd:polonius-next-episode-2, r=jackh726
jieyouxu Dec 17, 2024
a8139c7
Rollup merge of #134408 - rmehri01:rpit-inherits-lifetime, r=compiler…
jieyouxu Dec 17, 2024
f99cfe0
Rollup merge of #134423 - jieyouxu:bootstrap-test-valid, r=onur-ozkan
jieyouxu Dec 17, 2024
65bdba6
Rollup merge of #134426 - hkBst:patch-3, r=lqd
jieyouxu Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up emit_access_facts
- remove dependency on `TypeChecker`
- move to legacy fact generation module
  • Loading branch information
lqd committed Dec 15, 2024
commit 2fd443888e3157786c5602ceb80adfce43061353
106 changes: 106 additions & 0 deletions compiler/rustc_borrowck/src/polonius/legacy/accesses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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, MovePathIndex};
use tracing::debug;

use crate::def_use::{self, DefUse};
use crate::facts::AllFacts;
use crate::location::{LocationIndex, LocationTable};
use crate::universal_regions::UniversalRegions;

type VarPointRelation = Vec<(Local, LocationIndex)>;
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;

/// Emit polonius facts for variable defs, uses, drops, and path accesses.
pub(crate) fn emit_access_facts<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
universal_regions: &UniversalRegions<'tcx>,
location_table: &LocationTable,
all_facts: &mut Option<AllFacts>,
) {
if let Some(facts) = all_facts.as_mut() {
debug!("emit_access_facts()");

let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let mut extractor = AccessFactsExtractor {
var_defined_at: &mut facts.var_defined_at,
var_used_at: &mut facts.var_used_at,
var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table,
move_data,
};
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> {
var_defined_at: &'a mut VarPointRelation,
var_used_at: &'a mut VarPointRelation,
location_table: &'a LocationTable,
var_dropped_at: &'a mut VarPointRelation,
move_data: &'a MoveData<'tcx>,
path_accessed_at_base: &'a mut PathPointRelation,
}

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.var_defined_at.push((local, self.location_to_index(location)));
}
Some(DefUse::Use) => {
debug!("AccessFactsExtractor - emit use");
self.var_used_at.push((local, self.location_to_index(location)));
}
Some(DefUse::Drop) => {
debug!("AccessFactsExtractor - emit drop");
self.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.path_accessed_at_base.push((path, self.location_to_index(location)));
}

_ => {}
}
}
}
3 changes: 3 additions & 0 deletions compiler/rustc_borrowck/src/polonius/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ use crate::facts::{AllFacts, PoloniusRegionVid};
use crate::location::LocationTable;
use crate::type_check::free_region_relations::UniversalRegionRelations;

mod accesses;
mod loan_invalidations;
mod loan_kills;

pub(crate) use accesses::emit_access_facts;

/// When requested, emit most of the facts needed by polonius:
/// - moves and assignments
/// - universal regions and their relations
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_borrowck/src/type_check/liveness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ pub(super) fn generate<'a, 'tcx>(
let (relevant_live_locals, boring_locals) =
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);

polonius::emit_access_facts(typeck, body, move_data);
crate::polonius::legacy::emit_access_facts(
typeck.tcx(),
body,
move_data,
typeck.universal_regions,
typeck.location_table,
typeck.all_facts,
);

trace::trace(
typeck,
Expand Down
106 changes: 3 additions & 103 deletions compiler/rustc_borrowck/src/type_check/liveness/polonius.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location, Place};
use rustc_middle::mir::Local;
use rustc_middle::ty::GenericArg;
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
use tracing::debug;

use super::TypeChecker;
use crate::def_use::{self, DefUse};
use crate::location::{LocationIndex, LocationTable};

type VarPointRelation = Vec<(Local, LocationIndex)>;
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;

/// Emit polonius facts for variable defs, uses, drops, and path accesses.
pub(super) fn emit_access_facts<'a, 'tcx>(
typeck: &mut TypeChecker<'a, 'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
) {
if let Some(facts) = typeck.all_facts.as_mut() {
debug!("emit_access_facts()");

let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
let location_table = typeck.location_table;

let mut extractor = AccessFactsExtractor {
var_defined_at: &mut facts.var_defined_at,
var_used_at: &mut facts.var_used_at,
var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table,
move_data,
};
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
);
let universal_regions = &typeck.universal_regions;
typeck.infcx.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()));
});
}
}
}
use crate::type_check::TypeChecker;

/// For every potentially drop()-touched region `region` in `local`'s type
/// (`kind`), emit a Polonius `use_of_var_derefs_origin(local, origin)` fact.
/// (`kind`), emit a Polonius `drop_of_var_derefs_origin(local, origin)` fact.
pub(super) fn emit_drop_facts<'tcx>(
typeck: &mut TypeChecker<'_, 'tcx>,
local: Local,
Expand All @@ -64,60 +21,3 @@ pub(super) fn emit_drop_facts<'tcx>(
});
}
}

/// MIR visitor extracting point-wise facts about accesses.
struct AccessFactsExtractor<'a, 'tcx> {
var_defined_at: &'a mut VarPointRelation,
var_used_at: &'a mut VarPointRelation,
location_table: &'a LocationTable,
var_dropped_at: &'a mut VarPointRelation,
move_data: &'a MoveData<'tcx>,
path_accessed_at_base: &'a mut PathPointRelation,
}

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.var_defined_at.push((local, self.location_to_index(location)));
}
Some(DefUse::Use) => {
debug!("AccessFactsExtractor - emit use");
self.var_used_at.push((local, self.location_to_index(location)));
}
Some(DefUse::Drop) => {
debug!("AccessFactsExtractor - emit drop");
self.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.path_accessed_at_base.push((path, self.location_to_index(location)));
}

_ => {}
}
}
}