Skip to content

Commit f4242a6

Browse files
committed
Make some types and methods related to Polonius + Miri public.
1 parent 1f3bf23 commit f4242a6

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ pub struct BorrowSet<'tcx> {
2020
/// by the `Location` of the assignment statement in which it
2121
/// appears on the right hand side. Thus the location is the map
2222
/// key, and its position in the map corresponds to `BorrowIndex`.
23-
pub(crate) location_map: FxIndexMap<Location, BorrowData<'tcx>>,
23+
pub location_map: FxIndexMap<Location, BorrowData<'tcx>>,
2424

2525
/// Locations which activate borrows.
2626
/// NOTE: a given location may activate more than one borrow in the future
2727
/// when more general two-phase borrow support is introduced, but for now we
2828
/// only need to store one borrow index.
29-
pub(crate) activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
29+
pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
3030

3131
/// Map from local to all the borrows on that local.
32-
pub(crate) local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
32+
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
3333

34-
pub(crate) locals_state_at_exit: LocalsStateAtExit,
34+
pub locals_state_at_exit: LocalsStateAtExit,
3535
}
3636

3737
impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
@@ -45,7 +45,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
4545
/// Location where a two-phase borrow is activated, if a borrow
4646
/// is in fact a two-phase borrow.
4747
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
48-
pub(crate) enum TwoPhaseActivation {
48+
pub enum TwoPhaseActivation {
4949
NotTwoPhase,
5050
NotActivated,
5151
ActivatedAt(Location),
@@ -55,17 +55,17 @@ pub(crate) enum TwoPhaseActivation {
5555
pub struct BorrowData<'tcx> {
5656
/// Location where the borrow reservation starts.
5757
/// In many cases, this will be equal to the activation location but not always.
58-
pub(crate) reserve_location: Location,
58+
pub reserve_location: Location,
5959
/// Location where the borrow is activated.
60-
pub(crate) activation_location: TwoPhaseActivation,
60+
pub activation_location: TwoPhaseActivation,
6161
/// What kind of borrow this is
62-
pub(crate) kind: mir::BorrowKind,
62+
pub kind: mir::BorrowKind,
6363
/// The region for which this borrow is live
64-
pub(crate) region: RegionVid,
64+
pub region: RegionVid,
6565
/// Place from which we are borrowing
66-
pub(crate) borrowed_place: mir::Place<'tcx>,
66+
pub borrowed_place: mir::Place<'tcx>,
6767
/// Place to which the borrow was stored
68-
pub(crate) assigned_place: mir::Place<'tcx>,
68+
pub assigned_place: mir::Place<'tcx>,
6969
}
7070

7171
impl<'tcx> fmt::Display for BorrowData<'tcx> {
@@ -120,7 +120,7 @@ impl LocalsStateAtExit {
120120
}
121121

122122
impl<'tcx> BorrowSet<'tcx> {
123-
pub(crate) fn build(
123+
pub fn build(
124124
tcx: TyCtxt<'tcx>,
125125
body: &Body<'tcx>,
126126
locals_are_invalidated_at_exit: bool,

compiler/rustc_borrowck/src/consumers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use rustc_index::{IndexSlice, IndexVec};
55
use rustc_middle::mir::{Body, Promoted};
66
use rustc_middle::ty::TyCtxt;
77

8+
pub use super::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
89
pub use super::constraints::OutlivesConstraint;
910
pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_at_location};
10-
pub use super::facts::{AllFacts as PoloniusInput, RustcFacts};
11+
pub use super::facts::{AllFacts as PoloniusInput, PoloniusRegionVid, RustcFacts};
1112
pub use super::location::{LocationTable, RichLocation};
1213
pub use super::nll::PoloniusOutput;
1314
pub use super::place_ext::PlaceExt;
1415
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
1516
pub use super::region_infer::RegionInferenceContext;
16-
use crate::borrow_set::BorrowSet;
1717

1818
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
1919
///

compiler/rustc_const_eval/src/interpret/operand.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::{bug, mir, span_bug, ty};
1515
use tracing::trace;
1616

1717
use super::{
18-
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, OffsetMode,
19-
PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub, from_known_layout,
20-
interp_ok, mir_assign_valid_types, throw_ub,
18+
CtfeProvenance, Frame, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta,
19+
OffsetMode, PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub,
20+
from_known_layout, interp_ok, mir_assign_valid_types, throw_ub,
2121
};
2222

2323
/// An `Immediate` represents a single immediate self-contained Rust value.
@@ -706,17 +706,27 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
706706
interp_ok(str)
707707
}
708708

709-
/// Read from a local of the current frame.
709+
/// Read from a local of the current frame. Convenience method for [`local_at_frame_to_op`].
710+
pub fn local_to_op(
711+
&self,
712+
local: mir::Local,
713+
layout: Option<TyAndLayout<'tcx>>,
714+
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
715+
self.local_at_frame_to_op(self.frame(), local, layout)
716+
}
717+
718+
/// Read from a local of a given frame.
710719
/// Will not access memory, instead an indirect `Operand` is returned.
711720
///
712-
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
721+
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) and
722+
/// [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/) to get an
713723
/// OpTy from a local.
714-
pub fn local_to_op(
724+
pub fn local_at_frame_to_op(
715725
&self,
726+
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
716727
local: mir::Local,
717728
layout: Option<TyAndLayout<'tcx>>,
718729
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
719-
let frame = self.frame();
720730
let layout = self.layout_of_local(frame, local, layout)?;
721731
let op = *frame.locals[local].access()?;
722732
if matches!(op, Operand::Immediate(_)) {

compiler/rustc_const_eval/src/interpret/stack.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
584584
interp_ok(())
585585
}
586586

587+
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
588+
/// to analyze all the locals in a stack frame.
587589
#[inline(always)]
588-
pub(super) fn layout_of_local(
590+
pub fn layout_of_local(
589591
&self,
590592
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
591593
local: mir::Local,

0 commit comments

Comments
 (0)