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

thread 'rustc' panicked at 'called Option::unwrap() on a None value', compiler/rustc_middle/src/ty/query/mod.rs:235:5 #79661

Closed
bjorn3 opened this issue Dec 3, 2020 · 15 comments · Fixed by #79721 or softdevteam/ykrustc#152
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Dec 3, 2020

Code

This happened while working on cg_clif.

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (f4db9ffb2 2020-12-02)
binary: rustc
commit-hash: f4db9ffb22dfcb702dbdb2e0607cb91791866b57
commit-date: 2020-12-02
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

   Compiling rustc_codegen_cranelift v0.1.0 (/home/bjorn/Documenten/cg_clif3)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/ty/query/mod.rs:235:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/library/core/src/panicking.rs:50:5
   3: rustc_middle::ty::query::try_load_from_on_disk_cache
   4: rustc_query_system::dep_graph::graph::DepGraph<K>::exec_cache_promotions
   5: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
   6: rustc_incremental::persist::save::save_in
   7: rustc_data_structures::sync::join
   8: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
   9: rustc_incremental::persist::save::save_dep_graph
  10: rustc_codegen_ssa::base::finalize_tcx
  11: rustc_codegen_ssa::base::codegen_crate
  12: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  13: rustc_interface::queries::Queries::ongoing_codegen
  14: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  15: rustc_span::with_source_map
  16: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (f4db9ffb2 2020-12-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z run_dsymutil=no -C opt-level=3 -C embed-bitcode=no -C incremental -C link-arg=-Wl,-rpath=$ORIGIN/../lib --crate-type dylib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `LLVMing`,
 right: `Codegenning`', /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/compiler/rustc_codegen_ssa/src/back/write.rs:1425:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/f4db9ffb22dfcb702dbdb2e0607cb91791866b57/library/core/src/panicking.rs:92:14
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (f4db9ffb2 2020-12-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z run_dsymutil=no -C opt-level=3 -C embed-bitcode=no -C incremental -C link-arg=-Wl,-rpath=$ORIGIN/../lib --crate-type dylib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `rustc_codegen_cranelift`

To learn more, run the command again with --verbose.
@bjorn3 bjorn3 added 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. A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. labels Dec 3, 2020
@bjorn3
Copy link
Member Author

bjorn3 commented Dec 3, 2020

Removing the incremental cache fixed the issue.

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 3, 2020

Just saw this again.

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 3, 2020

I have hit this like 10 times now.

@wesleywiser
Copy link
Member

Would you be able to push your changes to a branch or tag so we can try to repro? Thanks!

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 3, 2020

This is bjorn3/rustc_codegen_cranelift@d95d03a with the following patch:

diff --git a/src/lib.rs b/src/lib.rs
index ba9ee0d..82a88b1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -204,11 +204,7 @@ fn codegen_crate<'tcx>(
         metadata: EncodedMetadata,
         need_metadata_module: bool,
     ) -> Box<dyn Any> {
-        let res = driver::codegen_crate(tcx, metadata, need_metadata_module, self.config);
-
-        rustc_symbol_mangling::test::report_symbol_names(tcx);
-
-        res
+        driver::codegen_crate(tcx, metadata, need_metadata_module, self.config)
     }
 
     fn join_codegen(
@@ -229,8 +225,6 @@ fn link(
     ) -> Result<(), ErrorReported> {
         use rustc_codegen_ssa::back::link::link_binary;
 
-        let _timer = sess.prof.generic_activity("link_crate");
-
         sess.time("linking", || {
             let target_cpu = crate::target_triple(sess).to_string();
             link_binary::<crate::archive::ArArchiveBuilder<'_>>(

The first time I hit this I think it was with just that patch. I have been working on bytecodealliance/wasmtime#2403 though and patched cg_clif to use a local checkout. This is something like bytecodealliance/wasmtime@2fea300. I don't have any clear instructions to reproduce it, but I have seen it quite often today.

@poliorcetics
Copy link
Contributor

The line in question is currently rustc_cached_queries!(try_load_from_on_disk_cache!);, removing cache seems like the recommandable workaround for now, as you said earlier.

@jyn514
Copy link
Member

jyn514 commented Dec 3, 2020

I ran into this running x.py clippy on 0ad3dce with clippy version clippy 0.0.212 (f4db9ff 2020-12-02).

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 3, 2020

I see this on ci for my cargo-cache crate as well but I didn't manage to reproduce locally yet.

EDIT: rustc 1.50.0-nightly (6645da366 2020-12-01) seems to be the first affected nightly according to my ci-log

EDIT2: in the commit range between this one and previous nightly ( git log b7ebc6b0c..6645da366 --merges ), #74967 seems suspicious as it touches incremental compilation.

@jonas-schievink jonas-schievink added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Dec 4, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 4, 2020
@vext01
Copy link
Contributor

vext01 commented Dec 4, 2020

I'm getting this on ykrustc too. We last synced with upstream rust on December 3rd.

It only seems to happen on an incremental build (i.e. not on a fresh build). I was able to trigger the error by adding more and more dbg!("x") lines and rebuilding until it crashed.

@wesleywiser
Copy link
Member

cc @Aaron1011 It looks like we're seeing some regressions from #74967

@Aaron1011 Aaron1011 self-assigned this Dec 4, 2020
@Aaron1011
Copy link
Member

I'm not able to reproduce this locally.

@bjorn3 Could you try to write a script that reproduces this crash with rustc_codegen_cranelift?

@jyn514
Copy link
Member

jyn514 commented Dec 4, 2020

@Aaron1011 can you reproduce it using clippy? #79661 (comment)

@Aaron1011
Copy link
Member

I managed to reproduce this using cloud-hypervisor/cloud-hypervisor#2032

@Aaron1011
Copy link
Member

Aaron1011 commented Dec 4, 2020

I've fixed the issue locally, and I'm working on a PR.

@hameerabbasi hameerabbasi added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 6, 2020
@hameerabbasi
Copy link
Contributor

Labelling P-high as discussed.

@camelid camelid added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 8, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 9, 2020
…wesleywiser

Properly re-use def path hash in incremental mode

Fixes rust-lang#79661

In incremental compilation mode, we update a `DefPathHash -> DefId`
mapping every time we create a `DepNode` for a foreign `DefId`.
This mapping is written out to the on-disk incremental cache, and is
read by the next compilation session to allow us to lazily decode
`DefId`s.

When we decode a `DepNode` from the current incremental cache, we need
to ensure that any previously-recorded `DefPathHash -> DefId` mapping
gets recorded in the new mapping that we write out. However, PR rust-lang#74967
didn't do this in all cases, leading to us being unable to decode a
`DefPathHash` in certain circumstances.

This PR refactors some of the code around `DepNode` deserialization to
prevent this kind of mistake from happening again.
@bors bors closed this as completed in c294640 Dec 9, 2020
@camelid camelid removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 9, 2020
jyn514 added a commit to jyn514/example-analyzer that referenced this issue Dec 11, 2020
This avoids an incremental compilation bug fixed on nightly: rust-lang/rust#79661
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.