Skip to content

Commit 2203082

Browse files
committed
wording in test comments
1 parent b148f42 commit 2203082

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

tests/fail/tree_borrows/children-can-alias.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ unsafe fn raw_children_of_unique_can_alias(x: Unique<u8>) {
4141
let child2 = x.as_ptr();
4242
// Under `-Zmiri-unique-is-unique`, `Unique` accidentally offers more guarantees
4343
// than `&mut`. Not because it responds differently to accesses but because
44-
// there is no way to obtain a copy with the same tag.
44+
// there is no easy way to obtain a copy with the same tag.
4545
//
46-
// The closest attempt (and one that works without `-Zmiri-unique-is-unique`)
47-
// is two calls to `as_ptr` that return cousin pointers, not writeable
48-
// interchangeably.
49-
// This is an unexpected consequence of retagging all `Unique` and we
50-
// should find a way to make `Unique` no more strict than `&mut`.
46+
// The closest (non-hack) attempt is two calls to `as_ptr`.
47+
// - Without `-Zmiri-unique-is-unique`, independent `as_ptr` calls return pointers
48+
// with the same tag that can thus be used interchangeably.
49+
// - With the current implementation of `-Zmiri-unique-is-unique`, they return cousin
50+
// tags with permissions that do not tolerate aliasing.
51+
// Eventually we should make such aliasing allowed in some situations
52+
// (e.g. when there is no protector), which will probably involve
53+
// introducing a new kind of permission.
5154
child1.write(1);
5255
child2.write(2);
5356
//~[uniq]^ ERROR: /write access through .* is forbidden/

tests/pass/tree_borrows/unique.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ fn main() {
2525
// and uninitialized permissions.
2626
let uniq = Unique::new_unchecked(raw);
2727

28-
// The usage of `-Zmiri-unique-is-unique` disturbs the internal
29-
// structure of the tree: pointers that used to have the same tag
30-
// under `-Zmiri-tree-borrows` are now cousins under
31-
// `-Zmiri-tree-borrows -Zmiri-unique-is-unique`.
28+
// With `-Zmiri-unique-is-unique`, `Unique::as_ptr` (which is called by
29+
// `Vec::as_ptr`) generates pointers with a fresh tag, so to name the actual
30+
// `base` pointer we care about we have to walk up the tree a bit.
3231
//
33-
// This is an unintended consequence of the way we currently
34-
// retag `Unique`, and we should look for a way to make these return
35-
// the same pointer. In the meantime we hardcode the distance at which
36-
// we expect the nearest common ancestor to be (which is the tag of
37-
// the actual root `Unique` pointer) and name that.
32+
// We care about naming this specific parent tag because it is the one
33+
// that stays `Active` during the entire execution, unlike the leaves
34+
// that will be invalidated the next time `as_ptr` is called.
3835
//
3936
// (We name it twice so that we have an indicator in the output of
4037
// whether we got the distance correct:
41-
//
4238
// If the output shows
4339
//
4440
// |- <XYZ: uniq>
@@ -50,6 +46,10 @@ fn main() {
5046
//
5147
// '- <XYZ: uniq, uniq>
5248
// )
49+
//
50+
// Ultimately we want pointers obtained through independent
51+
// calls of `as_ptr` to be able to alias, which will probably involve
52+
// a new permission that allows aliasing when there is no protector.
5353
let nth_parent = if cfg!(uniq) { 2 } else { 0 };
5454
name!(uniq.as_ptr()=>nth_parent, "uniq");
5555
name!(uniq.as_ptr()=>nth_parent, "uniq");

tests/pass/tree_borrows/vec_unique.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ fn main() {
1717
let base = vec![0u8, 1];
1818
let alloc_id = alloc_id!(base.as_ptr());
1919

20-
// The usage of `-Zmiri-unique-is-unique` disturbs the internal
21-
// structure of the tree: pointers that used to have the same tag
22-
// under `-Zmiri-tree-borrows` are now cousins under
23-
// `-Zmiri-tree-borrows -Zmiri-unique-is-unique`.
20+
// With `-Zmiri-unique-is-unique`, `Unique::as_ptr` (which is called by
21+
// `Vec::as_ptr`) generates pointers with a fresh tag, so to name the actual
22+
// `base` pointer we care about we have to walk up the tree a bit.
2423
//
25-
// This is an unintended consequence of the way we currently
26-
// retag `Unique`, and we should look for a way to make these return
27-
// the same pointer. In the meantime we hardcode the distance at which
28-
// we expect the nearest common ancestor to be (which is the tag of
29-
// the actual root `Unique` pointer) and name that.
24+
// We care about naming this specific parent tag because it is the one
25+
// that stays `Active` during the entire execution, unlike the leaves
26+
// that will be invalidated the next time `as_ptr` is called.
3027
//
3128
// (We name it twice so that we have an indicator in the output of
3229
// whether we got the distance correct:
33-
//
3430
// If the output shows
3531
//
36-
// |- <XYZ: base.as_ptr()>
37-
// '- <XYZ: base.as_ptr()>
32+
// |- <XYZ: uniq>
33+
// '- <XYZ: uniq>
3834
//
3935
// then `nth_parent` is not big enough.
4036
// The correct value for `nth_parent` should be the minimum
4137
// integer for which the output shows
4238
//
43-
// '- <XYZ: base.as_ptr(), base.as_ptr()>
39+
// '- <XYZ: uniq, uniq>
4440
// )
41+
//
42+
// Ultimately we want pointers obtained through independent
43+
// calls of `as_ptr` to be able to alias, which will probably involve
44+
// a new permission that allows aliasing when there is no protector.
4545
let nth_parent = if cfg!(uniq) { 2 } else { 0 };
4646
name!(base.as_ptr()=>nth_parent);
4747
name!(base.as_ptr()=>nth_parent);

0 commit comments

Comments
 (0)