Skip to content

Commit 57f9d09

Browse files
committed
make some Frame fields more private
1 parent b02aa4f commit 57f9d09

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

Diff for: compiler/rustc_const_eval/src/interpret/stack.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
6161
// Function and callsite information
6262
////////////////////////////////////////////////////////////////////////////////
6363
/// The MIR for the function called on this frame.
64-
pub body: &'tcx mir::Body<'tcx>,
64+
pub(super) body: &'tcx mir::Body<'tcx>,
6565

6666
/// The def_id and args of the current function.
67-
pub instance: ty::Instance<'tcx>,
67+
pub(super) instance: ty::Instance<'tcx>,
6868

6969
/// Extra data for the machine.
7070
pub extra: Extra,
@@ -73,7 +73,7 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
7373
// Return place and locals
7474
////////////////////////////////////////////////////////////////////////////////
7575
/// Work to perform when returning from this function.
76-
pub return_to_block: StackPopCleanup,
76+
return_to_block: StackPopCleanup,
7777

7878
/// The location where the result of the current stack frame should be written to,
7979
/// and its layout in the caller.
@@ -101,7 +101,7 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
101101
/// frames without cleanup code).
102102
///
103103
/// Needs to be public because ConstProp does unspeakable things to it.
104-
pub loc: Either<mir::Location, Span>,
104+
pub(super) loc: Either<mir::Location, Span>,
105105
}
106106

107107
#[derive(Clone, Copy, Eq, PartialEq, Debug)] // Miri debug-prints these
@@ -269,6 +269,14 @@ impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
269269
self.loc
270270
}
271271

272+
pub fn body(&self) -> &'tcx mir::Body<'tcx> {
273+
self.body
274+
}
275+
276+
pub fn instance(&self) -> ty::Instance<'tcx> {
277+
self.instance
278+
}
279+
272280
/// Return the `SourceInfo` of the current instruction.
273281
pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
274282
self.loc.left().map(|loc| self.body.source_info(loc))

Diff for: src/tools/miri/src/concurrency/thread.rs

-4
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ impl VisitProvenance for Frame<'_, Provenance, FrameExtra<'_>> {
377377
return_place,
378378
locals,
379379
extra,
380-
body: _,
381-
instance: _,
382-
return_to_block: _,
383-
loc: _,
384380
// There are some private fields we cannot access; they contain no tags.
385381
..
386382
} = self;

Diff for: src/tools/miri/src/helpers.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11051105
// Make an attempt to get at the instance of the function this is inlined from.
11061106
let instance: Option<_> = try {
11071107
let scope = frame.current_source_info()?.scope;
1108-
let inlined_parent = frame.body.source_scopes[scope].inlined_parent_scope?;
1109-
let source = &frame.body.source_scopes[inlined_parent];
1108+
let inlined_parent = frame.body().source_scopes[scope].inlined_parent_scope?;
1109+
let source = &frame.body().source_scopes[inlined_parent];
11101110
source.inlined.expect("inlined_parent_scope points to scope without inline info").0
11111111
};
11121112
// Fall back to the instance of the function itself.
1113-
let instance = instance.unwrap_or(frame.instance);
1113+
let instance = instance.unwrap_or(frame.instance());
11141114
// Now check the crate it is in. We could try to be clever here and e.g. check if this is
11151115
// the same crate as `start_fn`, but that would not work for running std tests in Miri, so
11161116
// we'd need some more hacks anyway. So we just check the name of the crate. If someone
@@ -1350,9 +1350,9 @@ impl<'tcx> MiriMachine<'tcx> {
13501350

13511351
/// This is the source of truth for the `is_user_relevant` flag in our `FrameExtra`.
13521352
pub fn is_user_relevant(&self, frame: &Frame<'tcx, Provenance>) -> bool {
1353-
let def_id = frame.instance.def_id();
1353+
let def_id = frame.instance().def_id();
13541354
(def_id.is_local() || self.local_crates.contains(&def_id.krate))
1355-
&& !frame.instance.def.requires_caller_location(self.tcx)
1355+
&& !frame.instance().def.requires_caller_location(self.tcx)
13561356
}
13571357
}
13581358

Diff for: src/tools/miri/src/machine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13491349
) -> InterpResult<'tcx, Frame<'tcx, Provenance, FrameExtra<'tcx>>> {
13501350
// Start recording our event before doing anything else
13511351
let timing = if let Some(profiler) = ecx.machine.profiler.as_ref() {
1352-
let fn_name = frame.instance.to_string();
1352+
let fn_name = frame.instance().to_string();
13531353
let entry = ecx.machine.string_cache.entry(fn_name.clone());
13541354
let name = entry.or_insert_with(|| profiler.alloc_string(&*fn_name));
13551355

@@ -1440,7 +1440,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14401440
// tracing-tree can autoamtically annotate scope changes, but it gets very confused by our
14411441
// concurrency and what it prints is just plain wrong. So we print our own information
14421442
// instead. (Cc https://github.com./rust-lang/miri/issues/2266)
1443-
info!("Leaving {}", ecx.frame().instance);
1443+
info!("Leaving {}", ecx.frame().instance());
14441444
Ok(())
14451445
}
14461446

@@ -1470,7 +1470,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14701470
// Needs to be done after dropping frame to show up on the right nesting level.
14711471
// (Cc https://github.com./rust-lang/miri/issues/2266)
14721472
if !ecx.active_thread_stack().is_empty() {
1473-
info!("Continuing in {}", ecx.frame().instance);
1473+
info!("Continuing in {}", ecx.frame().instance());
14741474
}
14751475
res
14761476
}
@@ -1483,7 +1483,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14831483
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr().provenance else {
14841484
panic!("after_local_allocated should only be called on fresh allocations");
14851485
};
1486-
let local_decl = &ecx.frame().body.local_decls[local];
1486+
let local_decl = &ecx.frame().body().local_decls[local];
14871487
let span = local_decl.source_info.span;
14881488
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
14891489
Ok(())

Diff for: src/tools/miri/src/shims/backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4646
let mut data = Vec::new();
4747
for frame in this.active_thread_stack().iter().rev() {
4848
// Match behavior of debuginfo (`FunctionCx::adjusted_span_and_dbg_scope`).
49-
let span = hygiene::walk_chain_collapsed(frame.current_span(), frame.body.span);
50-
data.push((frame.instance, span.lo()));
49+
let span = hygiene::walk_chain_collapsed(frame.current_span(), frame.body().span);
50+
data.push((frame.instance(), span.lo()));
5151
}
5252

5353
let ptrs: Vec<_> = data

Diff for: src/tools/miri/src/shims/panic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4848
fn handle_miri_start_unwind(&mut self, payload: &OpTy<'tcx>) -> InterpResult<'tcx> {
4949
let this = self.eval_context_mut();
5050

51-
trace!("miri_start_unwind: {:?}", this.frame().instance);
51+
trace!("miri_start_unwind: {:?}", this.frame().instance());
5252

5353
let payload = this.read_immediate(payload)?;
5454
let thread = this.active_thread_mut();
@@ -124,7 +124,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
124124
// and we are unwinding, so we should catch that.
125125
trace!(
126126
"unwinding: found catch_panic frame during unwinding: {:?}",
127-
this.frame().instance
127+
this.frame().instance()
128128
);
129129

130130
// We set the return value of `try` to 1, since there was a panic.

0 commit comments

Comments
 (0)