Skip to content

Commit 9d8f58a

Browse files
committed
clean up emit_drop_facts
- remove dependency on `TypeChecker` - move to legacy fact generation module - remove polonius module from liveness
1 parent 2fd4438 commit 9d8f58a

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

compiler/rustc_borrowck/src/polonius/legacy/mod.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
//! Will be removed in the future, once the in-tree `-Zpolonius=next` implementation reaches feature
44
//! parity.
55
6-
use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
7-
use rustc_middle::ty::TyCtxt;
6+
use rustc_middle::mir::{Body, Local, LocalKind, Location, START_BLOCK};
7+
use rustc_middle::ty::{GenericArg, TyCtxt};
88
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
99
use tracing::debug;
1010

1111
use crate::borrow_set::BorrowSet;
1212
use crate::facts::{AllFacts, PoloniusRegionVid};
1313
use crate::location::LocationTable;
1414
use crate::type_check::free_region_relations::UniversalRegionRelations;
15+
use crate::universal_regions::UniversalRegions;
1516

1617
mod accesses;
1718
mod loan_invalidations;
@@ -185,3 +186,22 @@ fn emit_cfg_and_loan_kills_facts<'tcx>(
185186
) {
186187
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
187188
}
189+
190+
/// For every potentially drop()-touched region `region` in `local`'s type
191+
/// (`kind`), emit a `drop_of_var_derefs_origin(local, origin)` fact.
192+
pub(crate) fn emit_drop_facts<'tcx>(
193+
tcx: TyCtxt<'tcx>,
194+
local: Local,
195+
kind: &GenericArg<'tcx>,
196+
universal_regions: &UniversalRegions<'tcx>,
197+
all_facts: &mut Option<AllFacts>,
198+
) {
199+
debug!("emit_drop_facts(local={:?}, kind={:?}", local, kind);
200+
if let Some(facts) = all_facts.as_mut() {
201+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
202+
tcx.for_each_free_region(kind, |drop_live_region| {
203+
let region_vid = universal_regions.to_region_vid(drop_live_region);
204+
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));
205+
});
206+
}
207+
}

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use tracing::debug;
1313

1414
use super::TypeChecker;
1515
use crate::constraints::OutlivesConstraintSet;
16+
use crate::polonius;
1617
use crate::region_infer::values::LivenessValues;
1718
use crate::universal_regions::UniversalRegions;
1819

1920
mod local_use_map;
20-
mod polonius;
2121
mod trace;
2222

2323
/// Combines liveness analysis with initialization analysis to
@@ -45,7 +45,7 @@ pub(super) fn generate<'a, 'tcx>(
4545
let (relevant_live_locals, boring_locals) =
4646
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
4747

48-
crate::polonius::legacy::emit_access_facts(
48+
polonius::legacy::emit_access_facts(
4949
typeck.tcx(),
5050
body,
5151
move_data,

compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

-23
This file was deleted.

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_trait_selection::traits::query::type_op::{DropckOutlives, TypeOp, Type
1515
use tracing::debug;
1616

1717
use crate::location::RichLocation;
18+
use crate::polonius;
1819
use crate::region_infer::values::{self, LiveLoans};
1920
use crate::type_check::liveness::local_use_map::LocalUseMap;
20-
use crate::type_check::liveness::polonius;
2121
use crate::type_check::{NormalizeLocation, TypeChecker};
2222

2323
/// This is the heart of the liveness computation. For each variable X
@@ -590,7 +590,13 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
590590
// the destructor and must be live at this point.
591591
for &kind in &drop_data.dropck_result.kinds {
592592
Self::make_all_regions_live(self.elements, self.typeck, kind, live_at);
593-
polonius::emit_drop_facts(self.typeck, dropped_local, &kind);
593+
polonius::legacy::emit_drop_facts(
594+
self.typeck.tcx(),
595+
dropped_local,
596+
&kind,
597+
self.typeck.universal_regions,
598+
self.typeck.all_facts,
599+
);
594600
}
595601
}
596602

0 commit comments

Comments
 (0)