bitvec icon indicating copy to clipboard operation
bitvec copied to clipboard

[Stacked Borrows] Recent miri reports failed retag converting a `BitSlice` to a `BitSpan`

Open CraftSpider opened this issue 3 years ago • 6 comments

Not 100% sure how this would be fixed, it appears to be due to pulling a field pointer out of the ZST slice stored in BitSpan. However, due to the comment on the _mem field, this looks like it may be UB to do any other way as well. Feel free to close this if this is considered out-of-scope.

The full error I'm getting (running just miri):

Miri Output
cargo +nightly miri test --features atomic,serde,std -q --lib --tests 
Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done

running 149 tests
...error: Undefined Behavior: trying to retag from <488660> for SharedReadOnly permission at alloc191983[0x0], but that tag does not exist in the borrow stack for this location
    --> src/ptr/single.rs:776:3
     |
776  |         (*self.ptr.to_const()).load_value().get_bit::<O>(self.bit)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <488660> for SharedReadOnly permission at alloc191983[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc191983[0x0..0x1]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <488660> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> src/slice.rs:1563:30
     |
1563 |         BitSpan::from_bitslice_ptr(self)
     |                                    ^^^^
     = note: backtrace:
     = note: inside `ptr::single::BitPtr::<wyz::Const, u8>::read` at src/ptr/single.rs:776:3
note: inside closure at src/slice/iter.rs:578:39
    --> src/slice/iter.rs:578:39
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |                                             ^^^^^^^^^
     = note: inside `std::option::Option::<ptr::single::BitPtr<wyz::Const, u8>>::map::<bool, [closure@src/slice/iter.rs:578:25: 578:29]>` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:929:29
note: inside `<slice::iter::BitValIter<u8, order::Lsb0> as std::iter::Iterator>::next` at src/slice/iter.rs:578:3
    --> src/slice/iter.rs:578:3
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `<std::iter::Map<slice::iter::BitValIter<u8, order::Lsb0>, [closure@src/slice/traits.rs:384:39: 384:42]> as std::iter::Iterator>::next` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:103:9
     = note: inside `std::fmt::DebugList::entries::<i32, std::iter::Map<slice::iter::BitValIter<u8, order::Lsb0>, [closure@src/slice/traits.rs:384:39: 384:42]>>` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:642:22
note: inside `slice::traits::<impl std::fmt::Display for slice::BitSlice<u8>>::fmt` at src/slice/traits.rs:383:3
    --> src/slice/traits.rs:383:3
     |
383  | /         fmt.debug_list()
384  | |             .entries(self.iter().by_vals().map(|b| if b { 1 } else { 0 }))
     | |__________________________________________________________________________^
note: inside `array::traits::<impl std::fmt::Display for array::BitArray<u8>>::fmt` at src/devel.rs:21:5
    --> src/devel.rs:21:5
     |
21   |                   core::fmt::$fmt::fmt(self.as_bitslice(), fmt)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
    ::: src/array/traits.rs:261:1
     |
261  | / easy_fmt! {
262  | |     impl Binary
263  | |     impl Display
264  | |     impl LowerHex
...    |
267  | |     for BitArray
268  | | }
     | |_- in this macro invocation
note: inside `array::traits::<impl std::fmt::Debug for array::BitArray<u8>>::fmt` at src/array/traits.rs:257:3
    --> src/array/traits.rs:257:3
     |
257  |         Display::fmt(self, fmt)
     |         ^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `std::fmt::write` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1202:17
     = note: inside `<std::string::String as std::fmt::Write>::write_fmt` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:192:9
     = note: inside `std::fmt::format::format_inner` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:612:9
     = note: inside closure at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:34
     = note: inside `std::option::Option::<&str>::map_or_else::<std::string::String, [closure@std::fmt::format::{closure#0}], for<'r> fn(&'r str) -> <str as std::borrow::ToOwned>::Owned {<str as std::borrow::ToOwned>::to_owned}>` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1023:21
     = note: inside `std::fmt::format` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:5
note: inside `array::tests::format::render` at /home/jwiesmore/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/macros.rs:118:19
    --> src/array/tests.rs:152:16
     |
152  |         let render = format!("{:?}", BitArray::<u8, Lsb0>::ZERO);
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure at src/array/tests.rs:151:2
    --> src/array/tests.rs:151:2
     |
150  |       #[test]
     |       ------- in this procedural macro expansion
151  | /     fn render() {
152  | |         let render = format!("{:?}", BitArray::<u8, Lsb0>::ZERO);
153  | |         assert!(render.starts_with(&format!(
154  | |             "BitArray<u8, {}>",
...    |
174  | |         );
175  | |     }
     | |_____^
     = note: this error originates in the macro `easy_fmt` which comes from the expansion of the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

error: test failed, to rerun pass '--lib'
error: Recipe `miri` failed on line 92 with exit code 1

CraftSpider avatar Sep 06 '22 17:09 CraftSpider

Every now and then, Miri decides that my attempts to construct an empty range pointer are invalid. The relevant line is

help: <488660> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere

I'll double check what pointers are being created here; BitArray in particular loves to cause me trouble about this when it shouldn't ever be creating any pointers to less than a full element. Thank you for the report.

myrrlyn avatar Nov 16 '22 06:11 myrrlyn

Just tried this on macis aarch64 as I was looking into miror erros in a downstream crate. Was there any conclusion here?

Miri output:

test array::tests::format::render ... error: Undefined Behavior: trying to retag from <190198> for SharedReadOnly permission at alloc6140[0x0], but that tag does not exist in the borrow stack for this location
    --> src/ptr/single.rs:776:3
     |
776  |         (*self.ptr.to_const()).load_value().get_bit::<O>(self.bit)
     |         ^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <190198> for SharedReadOnly permission at alloc6140[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc6140[0x0..0x1]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <190198> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> src/slice.rs:1579:30
     |
1579 |         BitSpan::from_bitslice_ptr(self)
     |                                    ^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `ptr::single::BitPtr::<wyz::Const, u8>::read` at src/ptr/single.rs:776:3: 776:25
note: inside closure
    --> src/slice/iter.rs:578:39
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |                                             ^^^^^^^^^
     = note: inside `std::option::Option::<ptr::single::BitPtr<wyz::Const, u8>>::map::<bool, {closure@src/slice/iter.rs:578:25: 578:29}>` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:1072:29: 1072:33
note: inside `<slice::iter::BitValIter<'_, u8, order::Lsb0> as std::iter::Iterator>::next`
    --> src/slice/iter.rs:578:3
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `<std::iter::Map<slice::iter::BitValIter<'_, u8, order::Lsb0>, {closure@src/slice/traits.rs:384:39: 384:42}> as std::iter::Iterator>::next` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:104:9: 104:25
     = note: inside `std::fmt::DebugList::<'_, '_>::entries::<u8, std::iter::Map<slice::iter::BitValIter<'_, u8, order::Lsb0>, {closure@src/slice/traits.rs:384:39: 384:42}>>` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:694:22: 694:29
note: inside `slice::traits::<impl std::fmt::Display for slice::BitSlice<u8>>::fmt`
    --> src/slice/traits.rs:383:3
     |
383  | /         fmt.debug_list()
384  | |             .entries(self.iter().by_vals().map(|b| b as u8))
     | |____________________________________________________________^
note: inside `array::traits::<impl std::fmt::Display for array::BitArray<u8>>::fmt`
    --> src/devel.rs:21:5
     |
21   |                   core::fmt::$fmt::fmt(self.as_bitslice(), fmt)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
    ::: src/array/traits.rs:261:1
     |
261  | / easy_fmt! {
262  | |     impl Binary
263  | |     impl Display
264  | |     impl LowerHex
...    |
267  | |     for BitArray
268  | | }
     | |_- in this macro invocation
note: inside `array::traits::<impl std::fmt::Debug for array::BitArray<u8>>::fmt`
    --> src/array/traits.rs:257:3
     |
257  |         Display::fmt(self, fmt)
     |         ^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `core::fmt::rt::Argument::<'_>::fmt` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:142:9: 142:40
     = note: inside `std::fmt::write` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1120:17: 1120:40
     = note: inside `<&mut std::string::String as std::fmt::Write::write_fmt::SpecWriteFmt>::spec_write_fmt` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:211:17: 211:34
     = note: inside `<std::string::String as std::fmt::Write>::write_fmt` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:215:9: 215:34
     = note: inside `std::fmt::format::format_inner` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/fmt.rs:612:9: 612:31
     = note: inside closure at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:34: 616:52
     = note: inside `std::option::Option::<&str>::map_or_else::<std::string::String, {closure@std::fmt::format::{closure#0}}, for<'a> fn(&'a str) -> <str as std::borrow::ToOwned>::Owned {<str as std::borrow::ToOwned>::to_owned}>` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:1173:21: 1173:30
     = note: inside `std::fmt::format` at /.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:5: 616:87
note: inside `array::tests::format::render`
    --> src/array/tests.rs:152:16
     |
152  |         let render = format!("{:?}", BitArray::<u8, Lsb0>::ZERO);
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/array/tests.rs:151:13
     |
150  |     #[test]
     |     ------- in this procedural macro expansion
151  |     fn render() {
     |                ^
     = note: this error originates in the macro `easy_fmt` which comes from the expansion of the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

pcwizz avatar Dec 07 '23 17:12 pcwizz

Got some more similar but different errors running the examples.

aliasing

% cargo +nightly miri run --example aliasing
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `/Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/examples/aliasing`
error: Undefined Behavior: trying to retag from <2003> for SharedReadOnly permission at alloc4[0x0], but that tag does not exist in the borrow stack for this location
    --> /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/raw.rs:102:9
     |
102  |         &*ptr::slice_from_raw_parts(data, len)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <2003> for SharedReadOnly permission at alloc4[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc4[0x0..0x5]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <2003> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/span.rs:722:27
     |
722  |         Self::from_bitslice_ptr(bits)
     |                                 ^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `std::slice::from_raw_parts::<'_, u8>` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/raw.rs:102:9: 102:47
     = note: inside `<wyz::comu::Address<bitvec::ptr::Const, [u8]> as wyz::comu::SliceReferential<'_>>::from_raw_parts` at /Users/pcwizz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wyz-0.5.1/src/comu.rs:589:3: 589:45
note: inside `bitvec::domain::Domain::<'_, bitvec::ptr::Const, u8>::spanning`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/domain.rs:501:5
     |
501  | /                 <Address<M, [T::Unalias]> as SliceReferential>::from_raw_parts(
502  | |                     addr.cast::<T::Unalias>(),
503  | |                     elts,
504  | |                 )
     | |_________________^
note: inside `bitvec::domain::Domain::<'_, bitvec::ptr::Const, u8>::new`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/domain.rs:393:3
     |
393  |         ctor(base, elts, head, tail)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `bitvec::slice::BitSlice::<u8>::domain`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:1026:3
     |
1026 |         Domain::new(self)
     |         ^^^^^^^^^^^^^^^^^
note: inside `bitvec::vec::BitVec::<u8>::from_bitslice`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/vec.rs:128:14
     |
128  |         vec.extend(slice.domain());
     |                    ^^^^^^^^^^^^^^
note: inside `bitvec::boxed::BitBox::<u8>::from_bitslice`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/boxed.rs:89:3
     |
89   |         BitVec::from_bitslice(slice).into_boxed_bitslice()
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `main`
    --> examples/aliasing.rs:57:13
     |
57   |     let data = BitBox::from_bitslice([0u8; 5].view_bits::<LocalBits>());
     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

ipv4

% cargo +nightly miri run --example ipv4    
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `/Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/examples/ipv4`
Press <Enter> to move through the steps of the example
error: Undefined Behavior: trying to retag from <6213> for SharedReadOnly permission at alloc1395[0x0], but that tag does not exist in the borrow stack for this location
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/single.rs:776:3
     |
776  |         (*self.ptr.to_const()).load_value().get_bit::<O>(self.bit)
     |         ^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <6213> for SharedReadOnly permission at alloc1395[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc1395[0x0..0x1]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <6213> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:1579:30
     |
1579 |         BitSpan::from_bitslice_ptr(self)
     |                                    ^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `bitvec::ptr::BitPtr::<wyz::Const, u8, bitvec::order::Msb0>::read` at /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/single.rs:776:3: 776:25
note: inside closure
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice/iter.rs:578:39
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |                                             ^^^^^^^^^
     = note: inside `std::option::Option::<bitvec::ptr::BitPtr<wyz::Const, u8, bitvec::order::Msb0>>::map::<bool, {closure@<bitvec::slice::BitValIter<'_, u8, bitvec::order::Msb0> as std::iter::Iterator>::next::{closure#0}}>` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:1072:29: 1072:33
note: inside `<bitvec::slice::BitValIter<'_, u8, bitvec::order::Msb0> as std::iter::Iterator>::next`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice/iter.rs:578:3
     |
578  |         self.range.next().map(|bp| unsafe { bp.read() })
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `<std::iter::Zip<bitvec::slice::BitValIter<'_, u8, bitvec::order::Msb0>, std::ops::Range<usize>> as std::iter::adapters::zip::ZipImpl<bitvec::slice::BitValIter<'_, u8, bitvec::order::Msb0>, std::ops::Range<usize>>>::next` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs:166:21: 166:34
     = note: inside `<std::iter::Zip<bitvec::slice::BitValIter<'_, u8, bitvec::order::Msb0>, std::ops::Range<usize>> as std::iter::Iterator>::next` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs:85:9: 85:28
note: inside `<AnnotatedArray<'_> as std::fmt::Display>::fmt`
    --> examples/ipv4.rs:175:22
     |
175  |             for (bit, idx) in word.iter().by_vals().zip(bits) {
     |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside `bitvec::macros::internal::core::fmt::rt::Argument::<'_>::fmt` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:142:9: 142:40
     = note: inside `bitvec::macros::internal::core::fmt::run` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1168:5: 1168:19
     = note: inside `std::fmt::write` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1136:26: 1136:61
     = note: inside `<std::io::StdoutLock<'_> as std::io::Write>::write_fmt` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/mod.rs:1810:15: 1810:43
     = note: inside `<&std::io::Stdout as std::io::Write>::write_fmt` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/stdio.rs:727:9: 727:36
     = note: inside `<std::io::Stdout as std::io::Write>::write_fmt` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/stdio.rs:701:9: 701:33
     = note: inside `std::io::stdio::print_to::<std::io::Stdout>` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1020:21: 1020:47
     = note: inside `std::io::_print` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1097:5: 1097:37
note: inside `render`
    --> examples/ipv4.rs:149:2
     |
149  |     qprintln!("{}: {:#}", title, AnnotatedArray::new(packet, range));
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `build`
    --> examples/ipv4.rs:39:2
     |
39   |     render("Starting with a blank packet", &pkt, 0 .. 0);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `main`
    --> examples/ipv4.rs:127:8
     |
127  |     parse(build());
     |           ^^^^^^^
     = note: this error originates in the macro `println` which comes from the expansion of the macro `qprintln` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

seive

% cargo +nightly miri run --example sieve
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `/Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/examples/sieve`
BitVec   [1000000]: 125000 bytes of heap
Vec<bool>[1000000]: 1000000 bytes of heap
error: Undefined Behavior: trying to retag from <495359> for SharedReadWrite permission at alloc1239[0x0], but that tag does not exist in the borrow stack for this location
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/single.rs:1203:3
     |
1203 |         (*self.ptr.cast::<T::Access>().to_const())
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <495359> for SharedReadWrite permission at alloc1239[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc1239[0x0..0x8]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <495359> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:1584:34
     |
1584 |         BitSpan::from_bitslice_ptr_mut(self)
     |                                        ^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `bitvec::ptr::BitPtr::<wyz::comu::Frozen<bitvec::ptr::Mut>>::frozen_write_bit` at /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/single.rs:1203:3: 1203:45
note: inside `bitvec::ptr::BitPtr::<bitvec::ptr::Mut>::replace`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/single.rs:1167:3
     |
1167 |         self.freeze().frozen_write_bit(value)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `bitvec::slice::BitSlice::replace_unchecked`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:838:3
     |
838  |         self.as_mut_bitptr().add(index).replace(value)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `bitvec::slice::BitSlice::replace`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:809:12
     |
809  |         unsafe { self.replace_unchecked(index, value) }
     |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `bitvec::slice::BitSlice::set`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:754:3
     |
754  |         self.replace(index, value);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `main`
    --> examples/sieve.rs:81:2
     |
81   |     primes.set(0, false);
     |     ^^^^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

tour

% cargo +nightly miri run --example tour 
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/examples/tour`
A Msb0 BitSlice has the same left-to-right order in memory as it does semantically
error: Undefined Behavior: trying to retag from <3581> for SharedReadOnly permission at alloc1041[0x0], but that tag does not exist in the borrow stack for this location
    --> /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/raw.rs:102:9
     |
102  |         &*ptr::slice_from_raw_parts(data, len)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         trying to retag from <3581> for SharedReadOnly permission at alloc1041[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of retag at alloc1041[0x0..0x10]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3581> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/ptr/span.rs:722:27
     |
722  |         Self::from_bitslice_ptr(bits)
     |                                 ^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `std::slice::from_raw_parts::<'_, u8>` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/raw.rs:102:9: 102:47
     = note: inside `<wyz::comu::Address<bitvec::ptr::Const, [u8]> as wyz::comu::SliceReferential<'_>>::from_raw_parts` at /Users/pcwizz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wyz-0.5.1/src/comu.rs:589:3: 589:45
note: inside `bitvec::domain::Domain::<'_, bitvec::ptr::Const, u8, bitvec::order::Msb0>::partial_tail`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/domain.rs:477:4
     |
477  | /             Address::<M, [T::Unalias]>::from_raw_parts(
478  | |                 addr.cast::<T::Unalias>(),
479  | |                 elts - 1,
480  | |             )
     | |_____________^
note: inside `bitvec::domain::Domain::<'_, bitvec::ptr::Const, u8, bitvec::order::Msb0>::new`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/domain.rs:393:3
     |
393  |         ctor(base, elts, head, tail)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `bitvec::slice::BitSlice::<u8, bitvec::order::Msb0>::domain`
    --> /Users/pcwizz/work/ROS/RASN/bitvec/src/slice.rs:1026:3
     |
1026 |         Domain::new(self)
     |         ^^^^^^^^^^^^^^^^^
note: inside `main::render::<u8, bitvec::order::Msb0>`
    --> examples/tour.rs:106:4
     |
106  |             bs.domain().len(),
     |             ^^^^^^^^^^^
note: inside `main`
    --> examples/tour.rs:52:2
     |
52   |     render(bits);
     |     ^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

pcwizz avatar Dec 07 '23 17:12 pcwizz

Have people tried running this under Tree Borrows yet? I'm not sure this is generally legal under SB, but with TB's lack of provenance narrowing I think this might become legal.

CraftSpider avatar Dec 07 '23 18:12 CraftSpider

Just given the unit tests a spin with tree borrows and I get different errors:

test domain::tests::domain ... error: Undefined Behavior: write access through <732191> is forbidden
    --> /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:922:9
     |
922  |         ptr::write(dest, src);
     |         ^^^^^^^^^^^^^^^^^^^^^ write access through <732191> is forbidden
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
     = help: the accessed tag <732191> is a child of the conflicting tag <731818>
     = help: the conflicting tag <731818> has state Frozen which forbids this child write access
help: the accessed tag <732191> was created here
    --> src/access.rs:48:3
     |
48   |         self.fetch_and(!mask.into_inner(), Ordering::Relaxed)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: the conflicting tag <731818> was created here, in the initial state Frozen
    --> src/ptr/span.rs:527:3
     |
527  |         &*self.into_bitslice_ptr()
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: BACKTRACE (of the first span):
     = note: inside `std::mem::replace::<u8>` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:922:9: 922:30
     = note: inside `std::cell::Cell::<u8>::replace` at /Users/pcwizz/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cell.rs:473:9: 473:61
     = note: inside `<std::cell::Cell<u8> as radium::Radium>::fetch_and` at /Users/pcwizz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/radium-0.7.0/src/lib.rs:554:13: 554:45
note: inside `<std::cell::Cell<u8> as access::BitAccess>::clear_bits`
    --> src/access.rs:48:3
     |
48   |         self.fetch_and(!mask.into_inner(), Ordering::Relaxed)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `domain::PartialElement::<'_, wyz::Const, std::cell::Cell<u8>, order::Lsb0>::store_value_aliased`
    --> src/domain.rs:887:14
     |
887  |         let prev = this.clear_bits(self.mask);
     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `domain::tests::domain`
    --> src/domain.rs:1056:14
     |
1056 |         assert_eq!(partial.store_value_aliased(!0), 0);
     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/domain.rs:1002:13
     |
1001 |     #[test]
     |     ------- in this procedural macro expansion
1002 |     fn domain() {
     |                ^
     = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

pcwizz avatar Dec 07 '23 19:12 pcwizz