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 when generating docs #46271

Closed
Michael-F-Bryan opened this issue Nov 26, 2017 · 9 comments · Fixed by #46405
Closed

ICE when generating docs #46271

Michael-F-Bryan opened this issue Nov 26, 2017 · 9 comments · Fixed by #46405
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Michael-F-Bryan
Copy link

Michael-F-Bryan commented Nov 26, 2017

On the latest nightly (e97ba83 2017-11-25) there's an ICE when generating the docs for the atty crate. Presumably somewhere along the line internal bookkeeping got confused and an invalid NodeId was generated (or a valid one was deleted), resulting in a panic during the phase 3 analysis passes.

It looks like this is a regression in the latest nightly because it was works just fine on the (5f44c653c 2017-11-24) build.

Minimal Example:

$ cargo new dummy
     Created library `dummy` project
$ cd dummy
$ cargo add atty
$ RUST_BACKTRACE=full cargo doc
    Updating registry `https:/rust-lang/crates.io-index`
   Compiling libc v0.2.33
 Documenting libc v0.2.33
   Compiling atty v0.2.3
 Documenting atty v0.2.3
error: internal compiler error: /checkout/src/librustc/hir/map/mod.rs:298: called HirMap::read() with invalid NodeId

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https:/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.23.0-nightly (e97ba8328 2017-11-25) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:501:8
stack backtrace:
   0:     0x7fd1e2817c2b - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h1ce402f4dccb5698
                               at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7fd1e280ec0e - std::sys_common::backtrace::print::h55c96f65d7235993
                               at /checkout/src/libstd/sys_common/backtrace.rs:68
                               at /checkout/src/libstd/sys_common/backtrace.rs:57
   2:     0x7fd1e2823b10 - _ZN3std9panicking12default_hook28_$u7b$$u7b$closure$u7d$$u7d$17haba1b8b7cf61bd7aE.llvm.526D1984
                               at /checkout/src/libstd/panicking.rs:381
   3:     0x7fd1e2823815 - _ZN3std9panicking12default_hook17h7be06c8634f460d7E.llvm.526D1984
                               at /checkout/src/libstd/panicking.rs:391
   4:     0x7fd1e2823feb - std::panicking::rust_panic_with_hook::h2be23432ffb4c204
                               at /checkout/src/libstd/panicking.rs:577
   5:     0x7fd1e318ab77 - std::panicking::begin_panic::h28c81c4c0cdf4c69
   6:     0x7fd1e31a2921 - rustc_errors::Handler::bug::h3b10b8fa0aba89a9
   7:     0x7fd1e47db4df - <std::thread::local::LocalKey<T>>::with::hb7233c79388bcb56
   8:     0x7fd1e4af57fe - rustc::ty::context::tls::with_opt::hcdba978ba842b0a7
   9:     0x7fd1e460a137 - _ZN5rustc7session16opt_span_bug_fmt17hb56476d414c941fdE.llvm.1FD79818
  10:     0x7fd1e460a046 - rustc::session::bug_fmt::h148122f0b4a2fc72
  11:     0x7fd1e4954b6d - rustc::hir::map::Map::read::h6c37e24df5a52b88
  12:     0x7fd1e49576ed - rustc::hir::map::Map::span::h24b98904b0fc9b3e
  13:     0x7fd1e491e423 - _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17h68ec3a1599129d45E.llvm.BAC8A759
  14:     0x7fd1e4564893 - rustc_errors::Handler::track_diagnostics::h03a8f4feb900350d
  15:     0x7fd1e4ab74af - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::h5c86d9422008a20e
  16:     0x7fd1e46db77e - rustc::ty::maps::<impl rustc::ty::maps::queries::def_span<'tcx>>::force::h43503f8edc09a3d9
  17:     0x7fd1e46dbd9d - rustc::ty::maps::<impl rustc::ty::maps::queries::def_span<'tcx>>::try_get::h008fa80f38be9cec
  18:     0x7fd1e486b56a - rustc::ty::maps::TyCtxtAt::def_span::hbcaeb771c1631aee
  19:     0x7fd1e47260c4 - rustc::ty::maps::<impl rustc::ty::maps::queries::extern_mod_stmt_cnum<'tcx>>::try_get::h27ee8706106e4024
  20:     0x7fd1e486e94a - rustc::ty::maps::TyCtxtAt::extern_mod_stmt_cnum::hb4193a83d0e4e32c
  21:     0x7fd1e4aff170 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::extern_mod_stmt_cnum::hc809b1ab1d193e3b
  22:     0x7fd1e5f0bb71 - rustc_typeck::check_unused::check_crate::h7f7b546a03efb217
  23:     0x7fd1e5ff21d6 - rustc_typeck::check_crate::h418a4ca4886371c9
  24:     0x55b06f47c42a - <std::thread::local::LocalKey<T>>::with::hdfd852279eb6b52d
                               at /checkout/src/librustc_driver/driver.rs:1041
                               at /checkout/src/librustc/ty/context.rs:1453
                               at /checkout/src/libstd/thread/local.rs:377
                               at /checkout/src/libstd/thread/local.rs:288
  25:     0x55b06f47d02d - <std::thread::local::LocalKey<T>>::with::hf52f8a939f7bc32d
                               at /checkout/src/librustc/ty/context.rs:1450
                               at /checkout/src/libstd/thread/local.rs:377
                               at /checkout/src/libstd/thread/local.rs:288
  26:     0x55b06f3603c4 - rustc::ty::context::TyCtxt::create_and_enter::he8d409a0d6f33129
  27:     0x55b06f29ac16 - rustc_driver::driver::phase_3_run_analysis_passes::h8dc82e2d661d53a4
                               at /checkout/src/librustc_driver/driver.rs:1018
  28:     0x55b06f36e732 - rustdoc::core::run_core::h6b6400baa0975073
                               at /checkout/src/librustdoc/core.rs:182
  29:     0x55b06f2a5886 - std::sys_common::backtrace::__rust_begin_short_backtrace::h48f63b8c8d11bac5
                               at /checkout/src/librustdoc/lib.rs:504
                               at /checkout/src/librustc_driver/lib.rs:1216
                               at /checkout/src/libstd/sys_common/backtrace.rs:133
  30:     0x55b06f37bc2d - _ZN3std9panicking3try7do_call17hbd51d01ae49b5078E.llvm.8062FEE3
                               at /checkout/src/libstd/thread/mod.rs:406
  31:     0x7fd1e2852cee - __rust_maybe_catch_panic
                               at /checkout/src/libpanic_unwind/lib.rs:101
  32:     0x55b06f358b63 - _ZN50_$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$8call_box17h69343f0219729beeE.llvm.1F73C0E0
                               at /checkout/src/libstd/panicking.rs:459
                               at /checkout/src/liballoc/boxed.rs:825
  33:     0x7fd1e28113c7 - std::sys_common::thread::start_thread::hebc1ffd0e5c0e31f
                               at /checkout/src/liballoc/boxed.rs:835
  34:     0x7fd1e2829998 - _ZN3std3sys4unix6thread6Thread3new12thread_start17h6af1de78c77e3921E.llvm.96D7229C
                               at /checkout/src/libstd/sys/unix/thread.rs:90
  35:     0x7fd1e25a9089 - start_thread
  36:     0x7fd1e20c947e - __clone
  37:                0x0 - <unknown>

error: Could not document `atty`.

Caused by:
  process didn't exit successfully: `rustdoc --crate-name atty /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/atty-0.2.3/src/lib.rs -o /tmp/dummy/target/doc -L dependency=/tmp/dummy/target/debug/deps --extern libc=/tmp/dummy/target/debug/deps/liblibc-637e21c9105ecc6e.rlib` (exit code: 101)

This was on an up-to-date Arch Linux machine.

$ rustc --version --verbose
rustc 1.23.0-nightly (e97ba8328 2017-11-25)
binary: rustc
commit-hash: e97ba83287a6f0f85cc9cc7a51ab309487e17038
commit-date: 2017-11-25
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0
$ cargo --version --verbose
cargo 0.24.0-nightly (abd137ad1 2017-11-12)
release: 0.24.0
commit-hash: abd137ad14a8f352b48f24b11c3995d716deb260
commit-date: 2017-11-12
@kennytm kennytm added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 26, 2017
@kennytm
Copy link
Member

kennytm commented Nov 26, 2017

For reference: 5f44c65...e97ba83

@kennytm
Copy link
Member

kennytm commented Nov 26, 2017

Simplified repro, no dependency needed:

pub fn x() {
	extern crate core;
}

@kennytm kennytm added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Nov 26, 2017
@kennytm
Copy link
Member

kennytm commented Nov 26, 2017

bisect-rust found the commit to be 5f44c65. Hold on, something's wrong.

Edit: I've inverted the failure condition when bisecting 😂

The actual regressing commit is e97ba83 #46115 @alexcrichton.

searched commits bbd7932a66b56da9a1c7d8cc30dc931922b356c0 through d4dc289f4bd5bff48b4eba393521b3eb899723a8
regression in 12; Some(Commit { sha: "e97ba83287a6f0f85cc9cc7a51ab309487e17038", date: 2017-11-25T19:00:45Z, summary: "Auto merge of #46115 - alexcrichton:add-wasm-target, r=kennytm" })

@kennytm
Copy link
Member

kennytm commented Nov 26, 2017

The issue here is likely due to the everybody-loops pass moved to a different place. Previously it was called immediately after phase 1, now it is called in the middle of phase 2. I'm now trying to see if putting it at the end of phase 2 would help. If not we'd put it back to the beginning of phase 2.

Edit: neither is working.

@est31
Copy link
Member

est31 commented Nov 28, 2017

Also happens to https:/alexcrichton/git2-rs

@Mark-Simulacrum
Copy link
Member

@rust-lang/dev-tools @GuillaumeGomez Can we prioritize fixing this? It looks like a relatively widespread problem...

@Mark-Simulacrum Mark-Simulacrum changed the title ICE when generating docs for atty ICE when generating docs Nov 29, 2017
@GuillaumeGomez
Copy link
Member

Sure. Will take a look in the next days.

@alexcrichton
Copy link
Member

Minimized:

pub fn foo() {
    extern crate std;
}

I believe I see what's going on, will try to make a fix.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Nov 30, 2017
Rustdoc has for some time now used the "everybody loops" pass in the compiler to
avoid typechecking and otherwise avoid looking at implementation details.
In rust-lang#46115 the placement of this pass was pushed back in the compiler to after
macro expansion to ensure that it works with macro-expanded code as well. This
in turn caused the regression in rust-lang#46271.

The bug here was that the resolver was producing `def_id` instances for
"possibly unused extern crates" which would then later get processed during
typeck to actually issue lint warnings. The problem was that *after* resolution
these `def_id` nodes were actually removed from the AST by the "everybody loops"
pass. This later, when we tried to take a look at `def_id`, caused the compiler
to panic.

The fix applied here is a bit of a heavy hammer which is to just, in this one
case, ignore the `extern crate` lints if the `def_id` looks "bogus" in any way
(basically if it looks like the node was removed after resolution). The real
underlying bug here is probably that the "everybody loops" AST pass is being
stressed to much beyond what it was originally intended to do, but this should
at least fix the ICE for now...

Closes rust-lang#46271
@alexcrichton
Copy link
Member

I've posted a fix for this issue at #46405

kennytm added a commit to kennytm/rust that referenced this issue Dec 1, 2017
rustc: Filter out bogus extern crate warnings

Rustdoc has for some time now used the "everybody loops" pass in the compiler to
avoid typechecking and otherwise avoid looking at implementation details.
In rust-lang#46115 the placement of this pass was pushed back in the compiler to after
macro expansion to ensure that it works with macro-expanded code as well. This
in turn caused the regression in rust-lang#46271.

The bug here was that the resolver was producing `def_id` instances for
"possibly unused extern crates" which would then later get processed during
typeck to actually issue lint warnings. The problem was that *after* resolution
these `def_id` nodes were actually removed from the AST by the "everybody loops"
pass. This later, when we tried to take a look at `def_id`, caused the compiler
to panic.

The fix applied here is a bit of a heavy hammer which is to just, in this one
case, ignore the `extern crate` lints if the `def_id` looks "bogus" in any way
(basically if it looks like the node was removed after resolution). The real
underlying bug here is probably that the "everybody loops" AST pass is being
stressed to much beyond what it was originally intended to do, but this should
at least fix the ICE for now...

Closes rust-lang#46271
@QuietMisdreavus QuietMisdreavus added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants