|
1 | 1 | pub mod convert; |
2 | 2 |
|
| 3 | +use std::cmp; |
3 | 4 | use std::mem; |
4 | 5 | use std::num::NonZeroUsize; |
5 | 6 | use std::time::Duration; |
@@ -908,24 +909,25 @@ impl<'a, 'mir: 'a, 'tcx: 'a + 'mir> CurrentSpan<'a, 'mir, 'tcx> { |
908 | 909 | /// This function is backed by a cache, and can be assumed to be very fast. |
909 | 910 | pub fn get(&mut self) -> Span { |
910 | 911 | let idx = self.current_frame_idx(); |
911 | | - Self::frame_span(self.machine, idx) |
| 912 | + self.stack().get(idx).map(Frame::current_span).unwrap_or(rustc_span::DUMMY_SP) |
912 | 913 | } |
913 | 914 |
|
914 | | - /// Similar to `CurrentSpan::get`, but retrieves the parent frame of the first non-local frame. |
| 915 | + /// Returns the span of the *caller* of the current operation, again |
| 916 | + /// walking down the stack to find the closest frame in a local crate, if the caller of the |
| 917 | + /// current operation is not in a local crate. |
915 | 918 | /// This is useful when we are processing something which occurs on function-entry and we want |
916 | 919 | /// to point at the call to the function, not the function definition generally. |
917 | | - pub fn get_parent(&mut self) -> Span { |
918 | | - let idx = self.current_frame_idx(); |
919 | | - Self::frame_span(self.machine, idx.wrapping_sub(1)) |
| 920 | + pub fn get_caller(&mut self) -> Span { |
| 921 | + // We need to go down at least to the caller (len - 2), or however |
| 922 | + // far we have to go to find a frame in a local crate. |
| 923 | + let local_frame_idx = self.current_frame_idx(); |
| 924 | + let stack = self.stack(); |
| 925 | + let idx = cmp::min(local_frame_idx, stack.len().saturating_sub(2)); |
| 926 | + stack.get(idx).map(Frame::current_span).unwrap_or(rustc_span::DUMMY_SP) |
920 | 927 | } |
921 | 928 |
|
922 | | - fn frame_span(machine: &MiriMachine<'_, '_>, idx: usize) -> Span { |
923 | | - machine |
924 | | - .threads |
925 | | - .active_thread_stack() |
926 | | - .get(idx) |
927 | | - .map(Frame::current_span) |
928 | | - .unwrap_or(rustc_span::DUMMY_SP) |
| 929 | + fn stack(&self) -> &[Frame<'mir, 'tcx, Provenance, machine::FrameData<'tcx>>] { |
| 930 | + self.machine.threads.active_thread_stack() |
929 | 931 | } |
930 | 932 |
|
931 | 933 | fn current_frame_idx(&mut self) -> usize { |
|
0 commit comments