Make some types and methods related to Polonius + Miri public.
This commit is contained in:
parent
1f3bf231e1
commit
eb10db0a76
4 changed files with 36 additions and 24 deletions
|
@ -20,18 +20,18 @@ pub struct BorrowSet<'tcx> {
|
|||
/// by the `Location` of the assignment statement in which it
|
||||
/// appears on the right hand side. Thus the location is the map
|
||||
/// key, and its position in the map corresponds to `BorrowIndex`.
|
||||
pub(crate) location_map: FxIndexMap<Location, BorrowData<'tcx>>,
|
||||
pub location_map: FxIndexMap<Location, BorrowData<'tcx>>,
|
||||
|
||||
/// Locations which activate borrows.
|
||||
/// NOTE: a given location may activate more than one borrow in the future
|
||||
/// when more general two-phase borrow support is introduced, but for now we
|
||||
/// only need to store one borrow index.
|
||||
pub(crate) activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
|
||||
/// Map from local to all the borrows on that local.
|
||||
pub(crate) local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
|
||||
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
|
||||
|
||||
pub(crate) locals_state_at_exit: LocalsStateAtExit,
|
||||
pub locals_state_at_exit: LocalsStateAtExit,
|
||||
}
|
||||
|
||||
impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
|
||||
|
@ -45,7 +45,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
|
|||
/// Location where a two-phase borrow is activated, if a borrow
|
||||
/// is in fact a two-phase borrow.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub(crate) enum TwoPhaseActivation {
|
||||
pub enum TwoPhaseActivation {
|
||||
NotTwoPhase,
|
||||
NotActivated,
|
||||
ActivatedAt(Location),
|
||||
|
@ -55,17 +55,17 @@ pub(crate) enum TwoPhaseActivation {
|
|||
pub struct BorrowData<'tcx> {
|
||||
/// Location where the borrow reservation starts.
|
||||
/// In many cases, this will be equal to the activation location but not always.
|
||||
pub(crate) reserve_location: Location,
|
||||
pub reserve_location: Location,
|
||||
/// Location where the borrow is activated.
|
||||
pub(crate) activation_location: TwoPhaseActivation,
|
||||
pub activation_location: TwoPhaseActivation,
|
||||
/// What kind of borrow this is
|
||||
pub(crate) kind: mir::BorrowKind,
|
||||
pub kind: mir::BorrowKind,
|
||||
/// The region for which this borrow is live
|
||||
pub(crate) region: RegionVid,
|
||||
pub region: RegionVid,
|
||||
/// Place from which we are borrowing
|
||||
pub(crate) borrowed_place: mir::Place<'tcx>,
|
||||
pub borrowed_place: mir::Place<'tcx>,
|
||||
/// Place to which the borrow was stored
|
||||
pub(crate) assigned_place: mir::Place<'tcx>,
|
||||
pub assigned_place: mir::Place<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Display for BorrowData<'tcx> {
|
||||
|
@ -120,7 +120,7 @@ impl LocalsStateAtExit {
|
|||
}
|
||||
|
||||
impl<'tcx> BorrowSet<'tcx> {
|
||||
pub(crate) fn build(
|
||||
pub fn build(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
locals_are_invalidated_at_exit: bool,
|
||||
|
|
|
@ -5,15 +5,15 @@ use rustc_index::{IndexSlice, IndexVec};
|
|||
use rustc_middle::mir::{Body, Promoted};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
pub use super::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
|
||||
pub use super::constraints::OutlivesConstraint;
|
||||
pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_at_location};
|
||||
pub use super::facts::{AllFacts as PoloniusInput, RustcFacts};
|
||||
pub use super::facts::{AllFacts as PoloniusInput, PoloniusRegionVid, RustcFacts};
|
||||
pub use super::location::{LocationTable, RichLocation};
|
||||
pub use super::nll::PoloniusOutput;
|
||||
pub use super::place_ext::PlaceExt;
|
||||
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
|
||||
pub use super::region_infer::RegionInferenceContext;
|
||||
use crate::borrow_set::BorrowSet;
|
||||
|
||||
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
|
||||
///
|
||||
|
|
|
@ -15,9 +15,9 @@ use rustc_middle::{bug, mir, span_bug, ty};
|
|||
use tracing::trace;
|
||||
|
||||
use super::{
|
||||
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, OffsetMode,
|
||||
PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub, from_known_layout,
|
||||
interp_ok, mir_assign_valid_types, throw_ub,
|
||||
CtfeProvenance, Frame, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta,
|
||||
OffsetMode, PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub,
|
||||
from_known_layout, interp_ok, mir_assign_valid_types, throw_ub,
|
||||
};
|
||||
|
||||
/// An `Immediate` represents a single immediate self-contained Rust value.
|
||||
|
@ -706,17 +706,27 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
interp_ok(str)
|
||||
}
|
||||
|
||||
/// Read from a local of the current frame.
|
||||
/// Will not access memory, instead an indirect `Operand` is returned.
|
||||
///
|
||||
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
|
||||
/// OpTy from a local.
|
||||
/// Read from a local of the current frame. Convenience method for [`InterpCx::local_at_frame_to_op`].
|
||||
pub fn local_to_op(
|
||||
&self,
|
||||
local: mir::Local,
|
||||
layout: Option<TyAndLayout<'tcx>>,
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||
let frame = self.frame();
|
||||
self.local_at_frame_to_op(self.frame(), local, layout)
|
||||
}
|
||||
|
||||
/// Read from a local of a given frame.
|
||||
/// Will not access memory, instead an indirect `Operand` is returned.
|
||||
///
|
||||
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) and
|
||||
/// [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/) to get an
|
||||
/// OpTy from a local.
|
||||
pub fn local_at_frame_to_op(
|
||||
&self,
|
||||
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
|
||||
local: mir::Local,
|
||||
layout: Option<TyAndLayout<'tcx>>,
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||
let layout = self.layout_of_local(frame, local, layout)?;
|
||||
let op = *frame.locals[local].access()?;
|
||||
if matches!(op, Operand::Immediate(_)) {
|
||||
|
|
|
@ -584,8 +584,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
interp_ok(())
|
||||
}
|
||||
|
||||
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
|
||||
/// to analyze all the locals in a stack frame.
|
||||
#[inline(always)]
|
||||
pub(super) fn layout_of_local(
|
||||
pub fn layout_of_local(
|
||||
&self,
|
||||
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
|
||||
local: mir::Local,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue