Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running tests under miri fails #26

Closed
matklad opened this issue Apr 16, 2019 · 6 comments
Closed

running tests under miri fails #26

matklad opened this issue Apr 16, 2019 · 6 comments

Comments

@matklad
Copy link

matklad commented Apr 16, 2019

Hi! I've tried running the test suite with miri and got the following result:

running 62 tests
error[E0080]: constant evaluation error: stopping looking for borrow being accessed (Alias(None)) because of barrier (88940)
    --> /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:5108:5
     |
5108 |     Repr { raw: FatPtr { data, len } }.rust_mut
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stopping looking for borrow being accessed (Alias(None)) because of barrier (88940)
     |
error[E0080]: constant evaluation error: stopping looking for borrow being accessed (Alias(None)) because of barrier (38549)
    --> /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:5108:5
     |
5108 |     Repr { raw: FatPtr { data, len } }.rust_mut
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stopping looking for borrow being accessed (Alias(None)) because of barrier (38549)
     |
     = note: inside call to `std::slice::from_raw_parts_mut::<test::Node>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/vec.rs:1712:13
     = note: inside call to `<std::vec::Vec<test::Node> as std::ops::DerefMut>::deref_mut` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/vec.rs:1026:23
note: inside call to `std::vec::Vec::<test::Node>::push` at src/lib.rs:169:13
    --> src/lib.rs:169:13
     |
169  |             chunks.current.push(value);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `Arena::<test::Node>::alloc_fast_path` at src/lib.rs:161:9
    --> src/lib.rs:161:9
     |
161  |         self.alloc_fast_path(value)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `Arena::<test::Node>::alloc` at src/test.rs:24:16
    --> src/test.rs:24:16
     |
24   |         node = arena.alloc(Node(Some(node), 2, DropTracker(&drop_counter)));
     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `test::arena_as_intended` at src/test.rs:16:1
    --> src/test.rs:16:1
     |
16   | / fn arena_as_intended() {
17   | |     let drop_counter = Cell::new(0);
18   | |     {
19   | |         let arena = Arena::with_capacity(2);
...    |
60   | |     assert_eq!(drop_counter.get(), 7);
61   | | }
     | |_^
     = note: inside call to closure at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
     = note: inside call to `<[closure@src/test.rs:16:1: 61:2] as std::ops::FnOnce<()>>::call_once - shim` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
     = note: inside call to `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1522:5
     = note: inside call to `test::test::__rust_begin_short_backtrace::<fn()>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1513:30
     = note: inside call to closure at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
     = note: inside call to `<[closure@DefId(9/1:109 ~ test[6977]::run_test[0]::{{closure}}[3]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
     = note: inside call to `<[closure@DefId(9/1:109 ~ test[6977]::run_test[0]::{{closure}}[3]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/boxed.rs:704:9
     = note: inside call to `<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send> as std::ops::FnOnce<()>>::call_once` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:309:9
     = note: inside call to `<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>> as std::ops::FnOnce<()>>::call_once` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:293:40
     = note: inside call to `std::panicking::try::do_call::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>, ()>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:289:5
     = note: inside call to `std::panicking::try::<(), std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:388:9
     = note: inside call to `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>, ()>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1468:26
     = note: inside call to closure at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1490:13
     = note: inside call to `test::test::run_test::run_test_inner` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1509:28
     = note: inside call to `test::test::run_test` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:1167:13
     = note: inside call to `test::test::run_tests::<[closure@DefId(9/1:80 ~ test[6977]::run_tests_console[0]::{{closure}}[2]) 0:&mut test::test::ConsoleTestState, 1:&mut std::boxed::Box<dyn test::test::formatters::OutputFormatter>]>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:972:5
     = note: inside call to `test::test::run_tests_console` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:293:15
     = note: inside call to `test::test::test_main` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:327:5
     = note: inside call to `test::test::test_main_static`
     = note: inside call to `main` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:64:34
     = note: inside call to closure at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:53
     = note: inside call to closure at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:293:40
     = note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1833 ~ std[c18b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:289:5
     = note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1833 ~ std[c18b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:388:9
     = note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1833 ~ std[c18b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:25
     = note: inside call to `std::rt::lang_start_internal` at /home/matklad/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:64:5
     = note: inside call to `std::rt::lang_start::<()>`

@RalfJung says that this error means that code invokes UB ^^

EDIT: pasted the wrgon detail initially, updated

@RalfJung
Copy link
Contributor

that this error means that code invokes UB ^^

Well, that or the model isn't what we think it should be.

@RalfJung
Copy link
Contributor

RalfJung commented Apr 18, 2019

I looked into this. The problem is as follows:

  • The first arena.alloc returns a shared reference into one of the Vec<T> that hold the actual data.
  • The second arena.alloc pushes to that same Vec after ensuring that there is enough capacity.
  • As part of Vec::push, a mutable reference to all elements in the Vec (as a slice) gets created. This mutable reference aliases with the shared reference that was handed out by the first arena.alloc -> UB.

The mutable reference gets created by self.as_mut_ptr(), which implicitly is self.deref_mut().as_mut_ptr(), and the deref_mut() creates and returns said reference. The irony is that it gets turned into a raw pointer immediately, but at that point the damage is already done.

This crate here cannot really do anything about that. If this is a pattern that Vec wishes to support, it's push implementation has to be adjusted accordingly.

@RalfJung
Copy link
Contributor

Reported upstream as rust-lang/rust#60847

@RalfJung
Copy link
Contributor

This should be fixed by rust-lang/rust#61114.

@matklad
Copy link
Author

matklad commented Aug 15, 2019

confirm that this is not the issue anymore!

@matklad matklad closed this as completed Aug 15, 2019
@RalfJung
Copy link
Contributor

We also have Miri on CI now for this project: #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants