Skip to content

Commit 4d5d470

Browse files
committed
Make BorrowSet/BorrowData fields accessible via public getters
1 parent eb10db0 commit 4d5d470

File tree

4 files changed

+71
-18
lines changed

4 files changed

+71
-18
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+56-10
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,37 @@ 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 location_map: FxIndexMap<Location, BorrowData<'tcx>>,
23+
pub(crate) 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 activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
29+
pub(crate) activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
3030

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

34-
pub locals_state_at_exit: LocalsStateAtExit,
34+
pub(crate) locals_state_at_exit: LocalsStateAtExit,
35+
}
36+
37+
// These methods are public to support borrowck consumers.
38+
impl<'tcx> BorrowSet<'tcx> {
39+
pub fn location_map(&self) -> &FxIndexMap<Location, BorrowData<'tcx>> {
40+
&self.location_map
41+
}
42+
43+
pub fn activation_map(&self) -> &FxIndexMap<Location, Vec<BorrowIndex>> {
44+
&self.activation_map
45+
}
46+
47+
pub fn local_map(&self) -> &FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>> {
48+
&self.local_map
49+
}
50+
51+
pub fn locals_state_at_exit(&self) -> &LocalsStateAtExit {
52+
&self.locals_state_at_exit
53+
}
3554
}
3655

3756
impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
@@ -55,17 +74,44 @@ pub enum TwoPhaseActivation {
5574
pub struct BorrowData<'tcx> {
5675
/// Location where the borrow reservation starts.
5776
/// In many cases, this will be equal to the activation location but not always.
58-
pub reserve_location: Location,
77+
pub(crate) reserve_location: Location,
5978
/// Location where the borrow is activated.
60-
pub activation_location: TwoPhaseActivation,
79+
pub(crate) activation_location: TwoPhaseActivation,
6180
/// What kind of borrow this is
62-
pub kind: mir::BorrowKind,
81+
pub(crate) kind: mir::BorrowKind,
6382
/// The region for which this borrow is live
64-
pub region: RegionVid,
83+
pub(crate) region: RegionVid,
6584
/// Place from which we are borrowing
66-
pub borrowed_place: mir::Place<'tcx>,
85+
pub(crate) borrowed_place: mir::Place<'tcx>,
6786
/// Place to which the borrow was stored
68-
pub assigned_place: mir::Place<'tcx>,
87+
pub(crate) assigned_place: mir::Place<'tcx>,
88+
}
89+
90+
// These methods are public to support borrowck consumers.
91+
impl<'tcx> BorrowData<'tcx> {
92+
pub fn reserve_location(&self) -> Location {
93+
self.reserve_location
94+
}
95+
96+
pub fn activation_location(&self) -> TwoPhaseActivation {
97+
self.activation_location
98+
}
99+
100+
pub fn kind(&self) -> mir::BorrowKind {
101+
self.kind
102+
}
103+
104+
pub fn region(&self) -> RegionVid {
105+
self.region
106+
}
107+
108+
pub fn borrowed_place(&self) -> mir::Place<'tcx> {
109+
self.borrowed_place
110+
}
111+
112+
pub fn assigned_place(&self) -> mir::Place<'tcx> {
113+
self.assigned_place
114+
}
69115
}
70116

71117
impl<'tcx> fmt::Display for BorrowData<'tcx> {

compiler/rustc_const_eval/src/interpret/machine.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,14 @@ pub trait Machine<'tcx>: Sized {
540540
interp_ok(ReturnAction::Normal)
541541
}
542542

543-
/// Called immediately after an "immediate" local variable is read
543+
/// Called immediately after an "immediate" local variable is read in a given frame
544544
/// (i.e., this is called for reads that do not end up accessing addressable memory).
545545
#[inline(always)]
546-
fn after_local_read(_ecx: &InterpCx<'tcx, Self>, _local: mir::Local) -> InterpResult<'tcx> {
546+
fn after_local_read(
547+
_ecx: &InterpCx<'tcx, Self>,
548+
_frame: &Frame<'tcx, Self::Provenance, Self::FrameExtra>,
549+
_local: mir::Local,
550+
) -> InterpResult<'tcx> {
547551
interp_ok(())
548552
}
549553

compiler/rustc_const_eval/src/interpret/operand.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
718718
/// Read from a local of a given frame.
719719
/// Will not access memory, instead an indirect `Operand` is returned.
720720
///
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
723-
/// OpTy from a local.
721+
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
722+
/// to get an OpTy from a local.
724723
pub fn local_at_frame_to_op(
725724
&self,
726725
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
@@ -732,7 +731,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
732731
if matches!(op, Operand::Immediate(_)) {
733732
assert!(!layout.is_unsized());
734733
}
735-
M::after_local_read(self, local)?;
734+
M::after_local_read(self, frame, local)?;
736735
interp_ok(OpTy { op, layout })
737736
}
738737

src/tools/miri/src/machine.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
15711571
res
15721572
}
15731573

1574-
fn after_local_read(ecx: &InterpCx<'tcx, Self>, local: mir::Local) -> InterpResult<'tcx> {
1575-
if let Some(data_race) = &ecx.frame().extra.data_race {
1574+
fn after_local_read(
1575+
ecx: &InterpCx<'tcx, Self>,
1576+
frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>,
1577+
local: mir::Local,
1578+
) -> InterpResult<'tcx> {
1579+
if let Some(data_race) = &frame.extra.data_race {
15761580
data_race.local_read(local, &ecx.machine);
15771581
}
15781582
interp_ok(())

0 commit comments

Comments
 (0)