Skip to content

Commit ad0347a

Browse files
committed
stacked_borrows moved to borrow_tracker/stacked
1 parent 455ea20 commit ad0347a

File tree

5 files changed

+120
-282
lines changed

5 files changed

+120
-282
lines changed

src/stacked_borrows/diagnostics.rs renamed to src/borrow_tracker/stacked/diagnostics.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
use smallvec::SmallVec;
22
use std::fmt;
33

4-
use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange};
4+
use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange, InterpError};
55
use rustc_span::{Span, SpanData};
66
use rustc_target::abi::Size;
77

8+
use crate::borrow_tracker::{
9+
stacked::{err_sb_ub, Permission},
10+
AccessKind, GlobalStateInner,
11+
ProtectorKind,
12+
};
813
use crate::helpers::CurrentSpan;
9-
use crate::stacked_borrows::{err_sb_ub, AccessKind, GlobalStateInner, Permission, ProtectorKind};
1014
use crate::*;
1115

12-
use rustc_middle::mir::interpret::InterpError;
13-
1416
#[derive(Clone, Debug)]
1517
pub struct AllocHistory {
1618
id: AllocId,
@@ -52,7 +54,7 @@ impl Creation {
5254

5355
#[derive(Clone, Debug)]
5456
struct Invalidation {
55-
tag: SbTag,
57+
tag: BorTag,
5658
range: AllocRange,
5759
span: Span,
5860
cause: InvalidationCause,
@@ -99,7 +101,7 @@ impl fmt::Display for InvalidationCause {
99101

100102
#[derive(Clone, Debug)]
101103
struct Protection {
102-
tag: SbTag,
104+
tag: BorTag,
103105
span: Span,
104106
}
105107

@@ -147,7 +149,7 @@ impl<'span, 'ecx, 'mir, 'tcx> DiagnosticCxBuilder<'span, 'ecx, 'mir, 'tcx> {
147149
current_span: &'span mut CurrentSpan<'ecx, 'mir, 'tcx>,
148150
threads: &'ecx ThreadManager<'mir, 'tcx>,
149151
cause: RetagCause,
150-
new_tag: SbTag,
152+
new_tag: BorTag,
151153
orig_tag: ProvenanceExtra,
152154
range: AllocRange,
153155
) -> Self {
@@ -207,7 +209,7 @@ enum Operation {
207209
#[derive(Debug, Clone)]
208210
struct RetagOp {
209211
cause: RetagCause,
210-
new_tag: SbTag,
212+
new_tag: BorTag,
211213
orig_tag: ProvenanceExtra,
212214
range: AllocRange,
213215
permission: Option<Permission>,
@@ -277,7 +279,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
277279
self.history.creations.push(Creation { retag: op.clone(), span: self.current_span.get() });
278280
}
279281

280-
pub fn log_invalidation(&mut self, tag: SbTag) {
282+
pub fn log_invalidation(&mut self, tag: BorTag) {
281283
let mut span = self.current_span.get();
282284
let (range, cause) = match &self.operation {
283285
Operation::Retag(RetagOp { cause, range, permission, .. }) => {
@@ -306,8 +308,8 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
306308

307309
pub fn get_logs_relevant_to(
308310
&self,
309-
tag: SbTag,
310-
protector_tag: Option<SbTag>,
311+
tag: BorTag,
312+
protector_tag: Option<BorTag>,
311313
) -> Option<TagHistory> {
312314
let Some(created) = self.history
313315
.creations
@@ -422,7 +424,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
422424
.all_stacks()
423425
.flatten()
424426
.map(|frame| {
425-
frame.extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data")
427+
frame.extra.borrow_tracker.as_ref().expect("we should have Stacked Borrows data")
426428
})
427429
.find(|frame| frame.protected_tags.contains(&item.tag()))
428430
.map(|frame| frame.call_id)

src/stacked_borrows/item.rs renamed to src/borrow_tracker/stacked/item.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::stacked_borrows::SbTag;
1+
use crate::borrow_tracker::BorTag;
22
use std::fmt;
3-
use std::num::NonZeroU64;
43

54
/// An item in the per-location borrow stack.
65
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
76
pub struct Item(u64);
87

98
// An Item contains 3 bitfields:
10-
// * Bits 0-61 store an SbTag
9+
// * Bits 0-61 store a BorTag
1110
// * Bits 61-63 store a Permission
1211
// * Bit 64 stores a flag which indicates if we have a protector
1312
const TAG_MASK: u64 = u64::MAX >> 3;
@@ -18,9 +17,9 @@ const PERM_SHIFT: u64 = 61;
1817
const PROTECTED_SHIFT: u64 = 63;
1918

2019
impl Item {
21-
pub fn new(tag: SbTag, perm: Permission, protected: bool) -> Self {
22-
assert!(tag.0.get() <= TAG_MASK);
23-
let packed_tag = tag.0.get();
20+
pub fn new(tag: BorTag, perm: Permission, protected: bool) -> Self {
21+
assert!(tag.get() <= TAG_MASK);
22+
let packed_tag = tag.get();
2423
let packed_perm = perm.to_bits() << PERM_SHIFT;
2524
let packed_protected = u64::from(protected) << PROTECTED_SHIFT;
2625

@@ -34,8 +33,8 @@ impl Item {
3433
}
3534

3635
/// The pointers the permission is granted to.
37-
pub fn tag(self) -> SbTag {
38-
SbTag(NonZeroU64::new(self.0 & TAG_MASK).unwrap())
36+
pub fn tag(self) -> BorTag {
37+
BorTag::new(self.0 & TAG_MASK).unwrap()
3938
}
4039

4140
/// The permission this item grants.

0 commit comments

Comments
 (0)