Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4318bfe

Browse files
committed
Auto merge of rust-lang#3843 - JoJoDeveloping:tb-bottom-up-iteration, r=RalfJung
Make TB tree traversal bottom-up In preparation for rust-lang#3837, the tree traversal needs to be made bottom-up, because the current top-down tree traversal, coupled with that PR's changes to the garbage collector, can introduce non-deterministic error messages if the GC removes a parent tag of the accessed tag that would have triggered the error first. This is a breaking change for the diagnostics emitted by TB. The implemented semantics stay the same.
2 parents 9b82f3b + 5be5cec commit 4318bfe

20 files changed

+306
-272
lines changed

src/tools/miri/src/borrow_tracker/tree_borrows/tree.rs

Lines changed: 246 additions & 120 deletions
Large diffs are not rendered by default.

src/tools/miri/src/borrow_tracker/tree_borrows/unimap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ impl<'a, V> UniEntry<'a, V> {
221221
}
222222
self.inner.as_mut().unwrap()
223223
}
224+
225+
pub fn get(&self) -> Option<&V> {
226+
self.inner.as_ref()
227+
}
224228
}
225229

226230
mod tests {

src/tools/miri/tests/fail/both_borrows/alias_through_mutation.tree.stderr

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@ LL | let _val = *target_alias;
55
| ^^^^^^^^^^^^^ read access through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child read access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child read access
9+
help: the accessed tag <TAG> was created here, in the initial state Frozen
1110
--> $DIR/alias_through_mutation.rs:LL:CC
1211
|
1312
LL | *x = &mut *(target as *mut _);
1413
| ^^^^^^^^^^^^^^^^^^^^^^^^
15-
help: the conflicting tag <TAG> was created here, in the initial state Reserved
16-
--> $DIR/alias_through_mutation.rs:LL:CC
17-
|
18-
LL | retarget(&mut target_alias, target);
19-
| ^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/alias_through_mutation.rs:LL:CC
2216
|
2317
LL | *target = 13;
2418
| ^^^^^^^^^^^^
25-
= help: this transition corresponds to a loss of read and write permissions
19+
= help: this transition corresponds to a loss of read permissions
2620
= note: BACKTRACE (of the first span):
2721
= note: inside `main` at $DIR/alias_through_mutation.rs:LL:CC
2822

src/tools/miri/tests/fail/both_borrows/box_exclusive_violation1.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | *LEAK = 7;
55
| ^^^^^^^^^ write access through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child write access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child write access
9+
help: the accessed tag <TAG> was created here, in the initial state Frozen
1110
--> $DIR/box_exclusive_violation1.rs:LL:CC
1211
|
1312
LL | fn unknown_code_1(x: &i32) {
1413
| ^
15-
help: the conflicting tag <TAG> was created here, in the initial state Frozen
16-
--> $DIR/box_exclusive_violation1.rs:LL:CC
17-
|
18-
LL | unknown_code_1(&*our);
19-
| ^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/box_exclusive_violation1.rs:LL:CC
2216
|
2317
LL | *our = 5;

src/tools/miri/tests/fail/both_borrows/buggy_as_mut_slice.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | v2[1] = 7;
55
| ^^^^^^^^^ write access through <TAG> at ALLOC[0x4] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child write access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child write access
9+
help: the accessed tag <TAG> was created here, in the initial state Reserved
1110
--> $DIR/buggy_as_mut_slice.rs:LL:CC
1211
|
1312
LL | let v2 = safe::as_mut_slice(&v);
1413
| ^^^^^^^^^^^^^^^^^^^^^^
15-
help: the conflicting tag <TAG> was created here, in the initial state Reserved
16-
--> $DIR/buggy_as_mut_slice.rs:LL:CC
17-
|
18-
LL | unsafe { from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len()) }
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x4..0x8]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x4..0x8]
2115
--> $DIR/buggy_as_mut_slice.rs:LL:CC
2216
|
2317
LL | v1[1] = 5;

src/tools/miri/tests/fail/both_borrows/buggy_split_at_mut.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | b[1] = 6;
55
| ^^^^^^^^ write access through <TAG> at ALLOC[0x4] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child write access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child write access
9+
help: the accessed tag <TAG> was created here, in the initial state Reserved
1110
--> $DIR/buggy_split_at_mut.rs:LL:CC
1211
|
1312
LL | let (a, b) = safe::split_at_mut(&mut array, 0);
1413
| ^
15-
help: the conflicting tag <TAG> was created here, in the initial state Reserved
16-
--> $DIR/buggy_split_at_mut.rs:LL:CC
17-
|
18-
LL | from_raw_parts_mut(ptr.offset(mid as isize), len - mid),
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x4..0x8]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x4..0x8]
2115
--> $DIR/buggy_split_at_mut.rs:LL:CC
2216
|
2317
LL | a[1] = 5;

src/tools/miri/tests/fail/both_borrows/illegal_write5.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | let _val = *xref;
55
| ^^^^^ read access through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child read access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child read access
9+
help: the accessed tag <TAG> was created here, in the initial state Reserved
1110
--> $DIR/illegal_write5.rs:LL:CC
1211
|
1312
LL | let xref = unsafe { &mut *xraw };
1413
| ^^^^^^^^^^
15-
help: the conflicting tag <TAG> was created here, in the initial state Reserved
16-
--> $DIR/illegal_write5.rs:LL:CC
17-
|
18-
LL | let xref = unsafe { &mut *xraw };
19-
| ^^^^^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/illegal_write5.rs:LL:CC
2216
|
2317
LL | unsafe { *xraw = 15 };

src/tools/miri/tests/fail/both_borrows/load_invalid_shr.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | let _val = *xref_in_mem;
55
| ^^^^^^^^^^^^ reborrow through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this reborrow (acting as a child read access)
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this reborrow (acting as a child read access)
9+
help: the accessed tag <TAG> was created here, in the initial state Frozen
1110
--> $DIR/load_invalid_shr.rs:LL:CC
1211
|
1312
LL | let xref_in_mem = Box::new(xref);
1413
| ^^^^^^^^^^^^^^
15-
help: the conflicting tag <TAG> was created here, in the initial state Frozen
16-
--> $DIR/load_invalid_shr.rs:LL:CC
17-
|
18-
LL | let xref = unsafe { &*xraw };
19-
| ^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/load_invalid_shr.rs:LL:CC
2216
|
2317
LL | unsafe { *xraw = 42 }; // unfreeze

src/tools/miri/tests/fail/both_borrows/mut_exclusive_violation1.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | *LEAK = 7;
55
| ^^^^^^^^^ write access through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child write access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child write access
9+
help: the accessed tag <TAG> was created here, in the initial state Frozen
1110
--> $DIR/mut_exclusive_violation1.rs:LL:CC
1211
|
1312
LL | fn unknown_code_1(x: &i32) {
1413
| ^
15-
help: the conflicting tag <TAG> was created here, in the initial state Frozen
16-
--> $DIR/mut_exclusive_violation1.rs:LL:CC
17-
|
18-
LL | unknown_code_1(&*our);
19-
| ^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/mut_exclusive_violation1.rs:LL:CC
2216
|
2317
LL | *our = 5;

src/tools/miri/tests/fail/both_borrows/mut_exclusive_violation2.tree.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ LL | *raw1 = 3;
55
| ^^^^^^^^^ write access through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8-
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG>
9-
= help: the conflicting tag <TAG> has state Disabled which forbids this child write access
10-
help: the accessed tag <TAG> was created here
8+
= help: the accessed tag <TAG> has state Disabled which forbids this child write access
9+
help: the accessed tag <TAG> was created here, in the initial state Reserved
1110
--> $DIR/mut_exclusive_violation2.rs:LL:CC
1211
|
1312
LL | let raw1 = ptr1.as_mut();
1413
| ^^^^^^^^^^^^^
15-
help: the conflicting tag <TAG> was created here, in the initial state Reserved
16-
--> $DIR/mut_exclusive_violation2.rs:LL:CC
17-
|
18-
LL | let raw1 = ptr1.as_mut();
19-
| ^^^^^^^^^^^^^
20-
help: the conflicting tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
14+
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x4]
2115
--> $DIR/mut_exclusive_violation2.rs:LL:CC
2216
|
2317
LL | *raw2 = 2;

0 commit comments

Comments
 (0)