Skip to content

Commit 3cd53eb

Browse files
committed
Factor out the cache-related parts of Stack
1 parent 017e687 commit 3cd53eb

File tree

5 files changed

+409
-253
lines changed

5 files changed

+409
-253
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ pub use crate::mono_hash_map::MonoHashMap;
8686
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
8787
pub use crate::range_map::RangeMap;
8888
pub use crate::stacked_borrows::{
89-
CallId, EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId, SbTag, Stack,
90-
Stacks,
89+
stack::Stack, CallId, EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId,
90+
SbTag, Stacks,
9191
};
9292
pub use crate::sync::{CondvarId, EvalContextExt as SyncEvalContextExt, MutexId, RwLockId};
9393
pub use crate::thread::{

src/machine.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::{
2525
},
2626
};
2727
use rustc_span::def_id::{CrateNum, DefId};
28-
use rustc_span::Symbol;
28+
use rustc_span::{Span, Symbol};
2929
use rustc_target::abi::Size;
3030
use rustc_target::spec::abi::Abi;
3131

@@ -415,6 +415,10 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
415415
let def_id = frame.instance.def_id();
416416
def_id.is_local() || self.local_crates.contains(&def_id.krate)
417417
}
418+
419+
pub(crate) fn current_span(&self) -> CurrentSpan<'_, 'mir, 'tcx> {
420+
CurrentSpan { span: None, machine: self }
421+
}
418422
}
419423

420424
/// A rustc InterpCx for Miri.
@@ -580,8 +584,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
580584
alloc.size(),
581585
stacked_borrows,
582586
kind,
583-
&ecx.machine.threads,
584-
ecx.machine.local_crates.clone(),
587+
ecx.machine.current_span(),
585588
))
586589
} else {
587590
None
@@ -663,7 +666,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
663666
tag,
664667
range,
665668
machine.stacked_borrows.as_ref().unwrap(),
666-
&machine.threads,
669+
machine.current_span(),
667670
)
668671
} else {
669672
Ok(())
@@ -687,7 +690,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
687690
tag,
688691
range,
689692
machine.stacked_borrows.as_ref().unwrap(),
690-
&machine.threads,
693+
machine.current_span(),
691694
)
692695
} else {
693696
Ok(())
@@ -789,3 +792,33 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
789792
res
790793
}
791794
}
795+
796+
#[derive(Clone)]
797+
pub struct CurrentSpan<'a, 'tcx, 'mir> {
798+
span: Option<Span>,
799+
machine: &'a Evaluator<'tcx, 'mir>,
800+
}
801+
802+
impl<'a, 'tcx, 'mir> CurrentSpan<'a, 'tcx, 'mir> {
803+
pub fn get(&mut self) -> rustc_span::Span {
804+
if self.span.is_none() {
805+
self.span = Some(self.current_span());
806+
}
807+
self.span.unwrap()
808+
}
809+
810+
#[inline(never)]
811+
fn current_span(&self) -> Span {
812+
self.machine
813+
.threads
814+
.active_thread_stack()
815+
.into_iter()
816+
.rev()
817+
.find(|frame| {
818+
let def_id = frame.instance.def_id();
819+
def_id.is_local() || self.machine.local_crates.contains(&def_id.krate)
820+
})
821+
.map(|frame| frame.current_span())
822+
.unwrap_or(rustc_span::DUMMY_SP)
823+
}
824+
}

0 commit comments

Comments
 (0)