Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 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
13e8313
bootstrap: use specific-purpose ui test path
jieyouxu Dec 17, 2024
c482b31
Fix typo in uint_macros.rs
hkBst Dec 17, 2024
938742e
Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviper
matthiaskrgr Dec 17, 2024
ca5dfa7
Rollup merge of #133801 - Gelbpunkt:powerpc64le-unknown-linux-musl-ti…
matthiaskrgr Dec 17, 2024
e696f5c
Rollup merge of #134323 - Zalathar:dismantle-map-data, r=jieyouxu
matthiaskrgr Dec 17, 2024
264566f
Rollup merge of #134378 - lqd:polonius-next-episode-2, r=jackh726
matthiaskrgr Dec 17, 2024
53635e5
Rollup merge of #134408 - rmehri01:rpit-inherits-lifetime, r=compiler…
matthiaskrgr Dec 17, 2024
4b905c8
Rollup merge of #134423 - jieyouxu:bootstrap-test-valid, r=onur-ozkan
matthiaskrgr Dec 17, 2024
3b0df8c
Rollup merge of #134426 - hkBst:patch-3, r=lqd
matthiaskrgr 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
simplify emit_access_facts and fact generation
- integrate it within existing fact generation instead of being called
  in typeck
- simplify access fact extraction
- also remove single use fact emit functions in root fact generation
  • Loading branch information
lqd committed Dec 15, 2024
commit 1740a5f84a19da866915e53f1dc05a9f929b4b37
33 changes: 9 additions & 24 deletions compiler/rustc_borrowck/src/polonius/legacy/accesses.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
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 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;

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>(
facts: &mut AllFacts,
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
universal_regions: &UniversalRegions<'tcx>,
location_table: &LocationTable,
all_facts: &mut Option<AllFacts>,
) {
let Some(facts) = all_facts.as_mut() else { return };
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,
};
let mut extractor = AccessFactsExtractor { facts, move_data, location_table };
extractor.visit_body(body);

for (local, local_decl) in body.local_decls.iter_enumerated() {
Expand All @@ -44,12 +32,9 @@ pub(crate) fn emit_access_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,
facts: &'a mut AllFacts,
move_data: &'a MoveData<'tcx>,
path_accessed_at_base: &'a mut PathPointRelation,
location_table: &'a LocationTable,
}

impl<'tcx> AccessFactsExtractor<'_, 'tcx> {
Expand All @@ -63,15 +48,15 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
match def_use::categorize(context) {
Some(DefUse::Def) => {
debug!("AccessFactsExtractor - emit def");
self.var_defined_at.push((local, self.location_to_index(location)));
self.facts.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)));
self.facts.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)));
self.facts.var_dropped_at.push((local, self.location_to_index(location)));
}
_ => (),
}
Expand All @@ -91,7 +76,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
}
};
debug!("AccessFactsExtractor - emit path access ({path:?}, {location:?})");
self.path_accessed_at_base.push((path, self.location_to_index(location)));
self.facts.path_accessed_at_base.push((path, self.location_to_index(location)));
}

_ => {}
Expand Down
38 changes: 12 additions & 26 deletions compiler/rustc_borrowck/src/polonius/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ 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
/// - CFG points and edges
/// - loan kills
/// - loan invalidations
/// - access facts such as variable definitions, uses, drops, and path accesses
/// - outlives constraints
///
/// The rest of the facts are emitted during typeck and liveness.
pub(crate) fn emit_facts<'tcx>(
Expand All @@ -49,8 +49,16 @@ pub(crate) fn emit_facts<'tcx>(
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
emit_move_facts(all_facts, move_data, location_table, body);
emit_universal_region_facts(all_facts, borrow_set, universal_region_relations);
emit_cfg_and_loan_kills_facts(all_facts, tcx, location_table, body, borrow_set);
emit_loan_invalidations_facts(all_facts, tcx, location_table, body, borrow_set);
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
loan_invalidations::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
accesses::emit_access_facts(
all_facts,
tcx,
body,
move_data,
&universal_region_relations.universal_regions,
location_table,
);
}

/// Emit facts needed for move/init analysis: moves and assignments.
Expand Down Expand Up @@ -170,28 +178,6 @@ fn emit_universal_region_facts(
}
}

/// Emit facts about loan invalidations.
fn emit_loan_invalidations_facts<'tcx>(
all_facts: &mut AllFacts,
tcx: TyCtxt<'tcx>,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
loan_invalidations::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
}

/// Emit facts about CFG points and edges, as well as locations where loans are killed.
fn emit_cfg_and_loan_kills_facts<'tcx>(
all_facts: &mut AllFacts,
tcx: TyCtxt<'tcx>,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
}

/// For every potentially drop()-touched region `region` in `local`'s type
/// (`kind`), emit a `drop_of_var_derefs_origin(local, origin)` fact.
pub(crate) fn emit_drop_facts<'tcx>(
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ pub(crate) fn type_check<'a, 'tcx>(

liveness::generate(&mut checker, body, &elements, flow_inits, move_data);

polonius::legacy::emit_access_facts(
infcx.tcx,
body,
move_data,
&universal_region_relations.universal_regions,
location_table,
checker.all_facts,
);
polonius::legacy::emit_outlives_facts(
infcx.tcx,
checker.constraints,
Expand Down