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 proc-macro crate and non proc-macro crate share Cargo project #50640

Closed
SergioBenitez opened this issue May 11, 2018 · 5 comments · Fixed by #50696 or rust-lang/cargo#5520
Closed
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) 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.
Milestone

Comments

@SergioBenitez
Copy link
Contributor

This is a regression introduced in a recent nightly.

When a lib and a bin are declared in the same Cargo project, where the lib is of type proc-macro, rustc experiences an ICE with a message of thread 'main' panicked at 'librustc_metadata/creader.rs:520: proc-macro crate not dylib', librustc/session/mod.rs:1281:26. This error does not occur when the proc-macro lib and the bin are split into independent Cargo projects. Running with CARGO_INCREMENTAL=0 does not change the outcome.

Cargo.toml looks as follows:

[package]
name = "demo"
version = "0.0.1"

[lib]
name = "codegen"
proc-macro = true
path = "src/lib.rs"

[[bin]]
name = "main"
path = "src/main.rs"

[dependencies]

src/lib.rs looks as follows:

#![feature(proc_macro)]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn demo(_args: TokenStream, input: TokenStream) -> TokenStream {
    input
}

src/main.rs looks as follows:

#![feature(proc_macro)]

extern crate codegen;

use codegen::demo;

#[demo]
fn test() { }

fn main() {
    println!("Hello, world!");
}

The full error log:

❯ rustc --version --verbose
rustc 1.27.0-nightly (e5f80f2a4 2018-05-09)
binary: rustc
commit-hash: e5f80f2a4f016bf724a1cfb580619d71c8fd39ec
commit-date: 2018-05-09
host: x86_64-apple-darwin
release: 1.27.0-nightly
LLVM version: 6.0

❯ RUST_BACKTRACE=1 cargo check -v
Checking demo v0.0.1 (file:///rustc-bug)
Running rustc --crate-name main src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=411579df123c68f9 -C extra-filename=-411579df123c68f9 --out-dir /rustc-bug/target/debug/deps -C incremental=/rustc-bug/target/debug/incremental -L dependency=/rustc-bug/target/debug/deps --extern codegen=/rustc-bug/target/debug/deps/libcodegen-c52c60a16469d04d.rmeta
thread 'main' panicked at 'librustc_metadata/creader.rs:520: proc-macro crate not dylib', librustc/session/mod.rs:1281:26
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
6: std::panicking::begin_panic
7: rustc::session::opt_span_bug_fmt::{{closure}}
8: rustc::ty::context::tls::with_opt::{{closure}}
9: rustc::ty::context::tls::with_context_opt
10: rustc::ty::context::tls::with_opt
11: rustc::session::opt_span_bug_fmt
12: rustc::session::span_bug_fmt
13: rustc_metadata::creader::CrateLoader::resolve_crate
14: <rustc_metadata::creader::CrateLoader<'a> as rustc::middle::cstore::CrateLoader>::process_extern_crate
15: rustc_resolve::build_reduced_graph::<impl rustc_resolve::Resolver<'a>>::build_reduced_graph_for_item
16: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor<'a, 'b> as syntax::visit::Visitor<'a>>::visit_item
17: syntax::visit::walk_item
18: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor<'a, 'b> as syntax::visit::Visitor<'a>>::visit_item
19: syntax::ext::expand::Expansion::visit_with
20: rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::visit_expansion
21: syntax::ext::expand::MacroExpander::collect_invocations
22: syntax::ext::expand::MacroExpander::expand
23: syntax::ext::expand::MacroExpander::expand_crate
24: rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}}
25: rustc::util::common::time
26: rustc_driver::driver::phase_2_configure_and_expand
27: rustc_driver::driver::compile_input
28: rustc_driver::run_compiler_impl
29: <scoped_tls::ScopedKey>::set
30: syntax::with_globals
31: <std::panic::AssertUnwindSafe as core::ops::function::FnOnce<()>>::call_once
32: __rust_maybe_catch_panic
33: rustc_driver::run
34: rustc_driver::main
35: std::rt::lang_start::{{closure}}
36: std::panicking::try::do_call
37: __rust_maybe_catch_panic
38: std::rt::lang_start_internal
39: main
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.27.0-nightly (e5f80f2a4 2018-05-09) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile demo.

Caused by:
process didn't exit successfully: rustc --crate-name main src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=411579df123c68f9 -C extra-filename=-411579df123c68f9 --out-dir /rustc-bug/target/debug/deps -C incremental=/rustc-bug/target/debug/incremental -L dependency=/rustc-bug/target/debug/deps --extern codegen=/rustc-bug/target/debug/deps/libcodegen-c52c60a16469d04d.rmeta (exit code: 101)

@pietroalbini
Copy link
Member

A bisect points at #50345 as the cause of the regression, which is a rollup. The only thing that might make sense in there is the cargo update. cc @alexcrichton

@pietroalbini pietroalbini added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. labels May 11, 2018
@alexcrichton alexcrichton added this to the 1.27 milestone May 11, 2018
@alexcrichton
Copy link
Member

Yep looks like a Cargo regression, looking into it

@alexcrichton alexcrichton added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label May 11, 2018
alexcrichton added a commit to alexcrichton/cargo that referenced this issue May 11, 2018
The new `mode` for the library dependency is dependent on the library target
rather than the target which is the reason for the dependency on the library!

Closes rust-lang/rust#50640
@alexcrichton
Copy link
Member

I believe this should be fixed in rust-lang/cargo#5520

bors added a commit to rust-lang/cargo that referenced this issue May 11, 2018
Fix mode generated in `maybe_lib`

The new `mode` for the library dependency is dependent on the library target
rather than the target which is the reason for the dependency on the library!

Closes rust-lang/rust#50640
alexcrichton added a commit to alexcrichton/cargo that referenced this issue May 11, 2018
The new `mode` for the library dependency is dependent on the library target
rather than the target which is the reason for the dependency on the library!

Closes rust-lang/rust#50640
alexcrichton added a commit to rust-lang/cargo that referenced this issue May 12, 2018
The new `mode` for the library dependency is dependent on the library target
rather than the target which is the reason for the dependency on the library!

Closes rust-lang/rust#50640
ehuss added a commit to ehuss/rust that referenced this issue May 12, 2018
Regression fixes:
- rust-lang/cargo#5510 `cargo rustc` broken for tests in project with bins
- rust-lang/cargo#5523 (rust-lang#50640) shared proc-macro dependency built incorrectly
@ehuss ehuss mentioned this issue May 12, 2018
bors added a commit that referenced this issue May 13, 2018
[BETA] Update Cargo

Regression fixes:
- rust-lang/cargo#5510 `cargo rustc` broken for tests in project with bins
- rust-lang/cargo#5523 (#50640) shared proc-macro dependency built incorrectly
ehuss added a commit to ehuss/rust that referenced this issue May 14, 2018
Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - (rust-lang#50640) shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md
kennytm added a commit to kennytm/rust that referenced this issue May 14, 2018
Update Cargo

Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - (rust-lang#50640) shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md
ehuss added a commit to ehuss/rust that referenced this issue May 15, 2018
Unblocking PRs:
- rust-lang/cargo#5535 - Ignore <tab> in libtest output. (unblocks rust-lang#50387)
- rust-lang/cargo#5537 - Remove -Zno-trans test. (unblocks rust-lang#50615)
- rust-lang/cargo#5540 - Fix tests when CARGO_TARGET_DIR is set. (unblocks self)

Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - (rust-lang#50640) shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5527 - Point Source Replacement to the Overriding Dependencies section
- rust-lang/cargo#5533 - Detail how to run locally-built nightly cargo
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md
kennytm added a commit to kennytm/rust that referenced this issue May 15, 2018
Update Cargo

Unblocking PRs:
- rust-lang/cargo#5535 - Ignore <tab> in libtest output. (unblocks rust-lang#50387)
- rust-lang/cargo#5537 - Remove -Zno-trans test. (unblocks rust-lang#50615)
- rust-lang/cargo#5540 - Fix tests when CARGO_TARGET_DIR is set. (unblocks self)

Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - (rust-lang#50640) shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5527 - Point Source Replacement to the Overriding Dependencies section
- rust-lang/cargo#5533 - Detail how to run locally-built nightly cargo
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md
@SergioBenitez
Copy link
Contributor Author

This is still an issue in 2018-05-15 when running cargo check.

@pietroalbini pietroalbini reopened this May 16, 2018
@pietroalbini pietroalbini added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels May 16, 2018
@pietroalbini
Copy link
Member

@SergioBenitez the issue is fixed in cargo, and cargo was updated in beta. The PR updating it in nightly (#50696) is not merged yet.

ehuss added a commit to ehuss/rust that referenced this issue May 16, 2018
Unblocking PRs:
- rust-lang/cargo#5535 - Ignore <tab> in libtest output. (unblocks rust-lang#50387)
- rust-lang/cargo#5537 - Remove -Zno-trans test. (unblocks rust-lang#50615)
- rust-lang/cargo#5540 - Fix tests when CARGO_TARGET_DIR is set. (unblocks self)

Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - (rust-lang#50640) shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5527 - Point Source Replacement to the Overriding Dependencies section
- rust-lang/cargo#5533 - Detail how to run locally-built nightly cargo
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md
bors added a commit that referenced this issue May 16, 2018
Update Cargo

Unblocking PRs:
- rust-lang/cargo#5535 - Ignore tab in libtest output. (unblocks #50387)
- rust-lang/cargo#5537 - Remove -Zno-trans test. (unblocks #50615)
- rust-lang/cargo#5540 - Fix tests when CARGO_TARGET_DIR is set. (unblocks self)

Regression fixes:
- rust-lang/cargo#5503 - cargo rustc broken for tests in project with bins
- rust-lang/cargo#5520 - shared proc-macro dependency built incorrectly

Changes:
- rust-lang/cargo#5527 - Point Source Replacement to the Overriding Dependencies section
- rust-lang/cargo#5533 - Detail how to run locally-built nightly cargo
- rust-lang/cargo#5522 - Add option to set user-agent
- rust-lang/cargo#5519 - NFC: fix a couple of typos, found by codespell.
- rust-lang/cargo#5513 - Fix `panic` for binaries built during tests.
- rust-lang/cargo#5512 - simplify build_requirements
- rust-lang/cargo#5301 - Add --build-plan for 'cargo build'
- rust-lang/cargo#5460 - Be more conservative about which files are linked to the output dir.
- rust-lang/cargo#5509 - Use the new stable
- rust-lang/cargo#5507 - Does not print seconds fraction with minutes
- rust-lang/cargo#5498 - Bump to 0.29.0
- rust-lang/cargo#5497 - Mention +nightly in ARCHITECTURE.md

The PR fixes #50640.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants