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

ICE in library/test/src/lib.rs:356 on Nightly when running doc-tests, where the first doc-test is executed twice in a row. #81852

Closed
yoanlcq opened this issue Feb 7, 2021 · 5 comments · Fixed by #82274
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@yoanlcq
Copy link

yoanlcq commented Feb 7, 2021

Hi,

When running doc-tests with the latest Nightly on my crate, I get an ICE after the first doc-test is executed twice in a row.
The issue does not occur on Stable.
The issue seems to be caused when multiple threads are used for doc-tests.

The ICE is caused by unwrap() in /library/test/src/lib.rs:356.

The issue occured on the x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu targets. Curiously, there are multiple targets on which it does not occur (according to Travic CI builds).
The Travis CI build status is available here : https://travis-ci.com/github/yoanlcq/vek/builds/216330500.

Steps to reproduce

  1. Clone the repo for the vek crate;
  2. Checkout commit a18c2dc5af092caba2daae232d168f1c75c5d039;
  3. Run either cargo test --doc or cargo test --doc -- --test-threads 2.

The actual number of threads does not seem to matter as long as there is more than one.
In my case, specifying -- --test-threads 2 was not necessary, since I think the number of threads is determined automatically in this case.

Code

// No code in particular. The doc-test refers to a line where a macro is expanded.
//
//
// That being said, the line in the compiler's source where the crash occured is : 
let running_test = running_tests.remove(&completed_test.desc).unwrap(); // <--- Unwraps on None

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly
LLVM version: 11.0.1

Error output

    Finished test [unoptimized + debuginfo] target(s) in 0.03s
   Doc-tests vek

running 1283 tests
test src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4154) ... ok
test src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4154) ... ok
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', library\test\src\lib.rs:356:75
stack backtrace:
   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede23 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11fbc - core::panicking::panic::h3a7a516f2be28c18
  12:     0x7fffbac0cffb - test::test_main_static_abort::h4318bb20d9dc449a
  13:     0x7fffbabf7b72 - test::console::run_tests_console::h6776da77c8860d5d
  14:     0x7fffbac06e77 - test::test_main::h7d9e75411069f83b
  15:     0x7ff6d9c9e2c6 - <unknown>
  16:     0x7ff6d9bb5f77 - <unknown>
  17:     0x7ff6d9d93220 - <unknown>
  18:     0x7ff6d9bc3e0b - <unknown>
  19:     0x7ff6d9d2e69d - <unknown>
  20:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  21:     0x7ff8004a7034 - BaseThreadInitThunk
  22:     0x7ff80095d0d1 - RtlUserThreadStart

error: internal compiler error: unexpected panic

error: Unrecognized option: 'test-args'

thread 'src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4156)' panicked at 'called `Result::unwrap()` on an `Err` value: "SendError(..)"', library\test\src\lib.rs:592:30
stack backtrace:
   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede51 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11d03 - core::result::unwrap_failed::h8a30362b6787a796
  12:     0x7fffbac17ab2 - test::run_test::h5515debdb9b010cd
  13:     0x7fffbabe15c6 - <unknown>
  14:     0x7fffbabe8cb4 - <unknown>
  15:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  16:     0x7ff8004a7034 - BaseThreadInitThunk
  17:     0x7ff80095d0d1 - RtlUserThreadStart

error: internal compiler error: unexpected panic

error: Unrecognized option: 'test-args'

error: test failed, to rerun pass '--doc'
Backtrace

   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede51 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11d03 - core::result::unwrap_failed::h8a30362b6787a796
  12:     0x7fffbac17ab2 - test::run_test::h5515debdb9b010cd
  13:     0x7fffbabe15c6 - <unknown>
  14:     0x7fffbabe8cb4 - <unknown>
  15:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  16:     0x7ff8004a7034 - BaseThreadInitThunk
  17:     0x7ff80095d0d1 - RtlUserThreadStart

@yoanlcq yoanlcq added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 7, 2021
@jonas-schievink jonas-schievink added A-libtest Area: #[test] related I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Feb 7, 2021
@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 7, 2021
@tspiteri
Copy link
Contributor

This is now a regression from stable to beta.

@jyn514 jyn514 added regression-from-stable-to-beta Performance or correctness regression from stable to beta. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc T-libs Relevant to the library team, which will review and decide on the PR/issue. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Feb 18, 2021
@hkmatsumoto
Copy link
Member

hkmatsumoto commented Feb 18, 2021

Bisection says the regression happened in 1483e67.
@rustbot label -E-needs-bisection

@rustbot rustbot removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Feb 18, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 18, 2021

cc @andersk, do you have time to take a look?

@jyn514 jyn514 removed the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Feb 18, 2021
@andersk
Copy link
Contributor

andersk commented Feb 18, 2021

It seems like the underlying problem is that it’s possible for different tests to collide to the same TestDesc when macros are involved. Minimal example:

struct S;
trait A {}
trait B {}

macro_rules! whoops {
    () => {
        /// ```
        /// assert_eq!(1, 1);
        /// ```
        impl A for S {}

        /// ```
        /// assert_eq!(1, 1);
        /// ```
        impl B for S {}
    };
}

whoops!();

Before #81367, this produced

running 2 tests
test src/lib.rs - S (line 19) ... ok
test src/lib.rs - S (line 19) ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s

and now it panics.

We should fix the underlying problem, but a simple band-aid for beta would be to turn the unwrap into an if let. The only side effect would be that we don’t get the benefits of #81367 in the presence of these collisions.

@andersk
Copy link
Contributor

andersk commented Feb 18, 2021

I’ve submitted that workaround as #82274.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 19, 2021
libtest: Fix unwrap panic on duplicate TestDesc

It is possible for different tests to collide to the same `TestDesc` when macros are involved. That is a bug, but it didn’t cause a panic until rust-lang#81367. For now, change the code to ignore this problem.

Fixes rust-lang#81852.

This will need to be applied to `beta` too.
@bors bors closed this as completed in 1605af0 Feb 19, 2021
@jyn514 jyn514 removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 28, 2021
cuviper pushed a commit to cuviper/rust that referenced this issue Mar 10, 2021
It is possible for different tests to collide to the same TestDesc
when macros are involved.  That is a bug, but it didn’t cause a panic
until rust-lang#81367.  For now, change the code to ignore this problem.

Fixes rust-lang#81852.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
(cherry picked from commit 1605af0)
bors pushed a commit to rust-lang-ci/rust that referenced this issue Apr 12, 2021
This more robustly avoids problems with duplicate TestDesc.  See rust-lang#81852
and rust-lang#82274.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 12, 2021
libtest: Index tests by a unique TestId

This more robustly avoids problems with duplicate `TestDesc`. See rust-lang#81852 and rust-lang#82274.

Cc `@Mark-Simulacrum.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants