Skip to content

Commit 5923b1e

Browse files
authored
Unrolled build for rust-lang#129785
Rollup merge of rust-lang#129785 - RalfJung:miri-sync, r=RalfJung Miri subtree update r? ```@ghost```
2 parents 9649706 + f03c7b2 commit 5923b1e

File tree

68 files changed

+1197
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1197
-441
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "slice-chunked"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "slice-chunked"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! This is a small example using slice::chunks, which creates a very large Tree Borrows tree.
2+
//! Thanks to ##3837, the GC now compacts the tree, so this test can be run in a reasonable time again.
3+
//! The actual code is adapted from tiny_skia, see https://github.com/RazrFalcon/tiny-skia/blob/master/src/pixmap.rs#L121
4+
//! To make this benchmark demonstrate the effectiveness, run with MIRIFLAGS="-Zmiri-tree-borrows -Zmiri-provenance-gc=100"
5+
6+
const N: usize = 1000;
7+
8+
fn input_vec() -> Vec<u8> {
9+
vec![0; N]
10+
}
11+
12+
fn main() {
13+
let data_len = 2 * N;
14+
let mut rgba_data = Vec::with_capacity(data_len);
15+
let img_data = input_vec();
16+
for slice in img_data.chunks(2) {
17+
let gray = slice[0];
18+
let alpha = slice[1];
19+
rgba_data.push(gray);
20+
rgba_data.push(gray);
21+
rgba_data.push(gray);
22+
rgba_data.push(alpha);
23+
}
24+
25+
assert_eq!(rgba_data.len(), data_len);
26+
}

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fdf61d499c8a8421ecf98e7924bb87caf43a9938
1+
0d634185dfddefe09047881175f35c65d68dcff1

src/tools/miri/src/borrow_tracker/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ pub struct FrameState {
7171

7272
impl VisitProvenance for FrameState {
7373
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
74+
// Visit all protected tags. At least in Tree Borrows,
75+
// protected tags can not be GC'd because they still have
76+
// an access coming when the protector ends. Additionally,
77+
// the tree compacting mechanism of TB's GC relies on the fact
78+
// that all protected tags are marked as live for correctness,
79+
// so we _have_ to visit them here.
7480
for (id, tag) in &self.protected_tags {
7581
visit(Some(*id), Some(*tag));
7682
}

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod transition {
130130
Active =>
131131
if protected {
132132
// We wrote, someone else reads -- that's bad.
133-
// (If this is initialized, this move-to-protected will mean insta-UB.)
133+
// (Since Active is always initialized, this move-to-protected will mean insta-UB.)
134134
Disabled
135135
} else {
136136
// We don't want to disable here to allow read-read reordering: it is crucial
@@ -267,6 +267,44 @@ impl Permission {
267267
transition::perform_access(kind, rel_pos, old_state, protected)
268268
.map(|new_state| PermTransition { from: old_state, to: new_state })
269269
}
270+
271+
/// During a provenance GC, we want to compact the tree.
272+
/// For this, we want to merge nodes upwards if they have a singleton parent.
273+
/// But we need to be careful: If the parent is Frozen, and the child is Reserved,
274+
/// we can not do such a merge. In general, such a merge is possible if the parent
275+
/// allows similar accesses, and in particular if the parent never causes UB on its
276+
/// own. This is enforced by a test, namely `tree_compacting_is_sound`. See that
277+
/// test for more information.
278+
/// This method is only sound if the parent is not protected. We never attempt to
279+
/// remove protected parents.
280+
pub fn can_be_replaced_by_child(self, child: Self) -> bool {
281+
match (self.inner, child.inner) {
282+
// ReservedIM can be replaced by anything, as it allows all
283+
// transitions.
284+
(ReservedIM, _) => true,
285+
// Reserved (as parent, where conflictedness does not matter)
286+
// can be replaced by all but ReservedIM,
287+
// since ReservedIM alone would survive foreign writes
288+
(ReservedFrz { .. }, ReservedIM) => false,
289+
(ReservedFrz { .. }, _) => true,
290+
// Active can not be replaced by something surviving
291+
// foreign reads and then remaining writable.
292+
(Active, ReservedIM) => false,
293+
(Active, ReservedFrz { .. }) => false,
294+
// Replacing a state by itself is always okay, even if the child state is protected.
295+
(Active, Active) => true,
296+
// Active can be replaced by Frozen, since it is not protected.
297+
(Active, Frozen) => true,
298+
(Active, Disabled) => true,
299+
// Frozen can only be replaced by Disabled (and itself).
300+
(Frozen, Frozen) => true,
301+
(Frozen, Disabled) => true,
302+
(Frozen, _) => false,
303+
// Disabled can not be replaced by anything else.
304+
(Disabled, Disabled) => true,
305+
(Disabled, _) => false,
306+
}
307+
}
270308
}
271309

272310
impl PermTransition {

0 commit comments

Comments
 (0)