Skip to content

ICE on stable: Proc macro attribute usage with lazy_static #58165

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

Closed
RustyYato opened this issue Feb 4, 2019 · 10 comments
Closed

ICE on stable: Proc macro attribute usage with lazy_static #58165

RustyYato opened this issue Feb 4, 2019 · 10 comments
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RustyYato
Copy link
Contributor

Code:
Main crate:

use lazy_static::lazy_static;

#[telem_start::start]
fn main() {
    
}

Proc Macro Crate (telem_start)

extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;

use syn::Item;
use syn::spanned::Spanned;

#[proc_macro_attribute]
pub fn start(attr: TokenStream, item: TokenStream) -> TokenStream {
    let item: Item = syn::parse(item).unwrap();
    
    let mut start_fn = if let Item::Fn(item) = item {
        item
    } else {
        panic!()
    };

    let mut block = start_fn.block;

    let stmt: syn::Stmt = syn::parse((quote! {
        lazy_static! { static ref __telem_core__start_time: std::time::Instant = { std::time::Instant::now() }; }
    }).into()).unwrap();

    block.stmts = std::iter::once(stmt).chain(block.stmts).collect();
    start_fn.block = block;

    (quote! {
        #start_fn
    }).into()
}

Backtrace

error: internal compiler error: src\librustc\dep_graph\graph.rs:610: DepNode Hir(d73c6af366f2c00f-293f1afd29c872f8) should have been pre-allocated but wasn't.

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:588:9
stack backtrace:
   0: std::sys_common::alloc::realloc_fallback
   1: std::panicking::take_hook
   2: std::panicking::take_hook
   3: rustc::ty::trait_def::TraitDef::ancestors
   4: std::panicking::rust_panic_with_hook
   5: <rustc_errors::emitter::ColorConfig as core::fmt::Debug>::fmt
   6: rustc_errors::Handler::bug
   7: rustc::util::bug::bug_fmt
   8: rustc::ty::context::<impl rustc::infer::canonical::Canonical<'gcx, rustc::ty::context::UserTypeAnnotation<'gcx>>>::is_identity
   9: rustc::ty::context::<impl rustc::infer::canonical::Canonical<'gcx, rustc::ty::context::UserTypeAnnotation<'gcx>>>::is_identity
  10: rustc::ty::context::<impl rustc::infer::canonical::Canonical<'gcx, rustc::ty::context::UserTypeAnnotation<'gcx>>>::is_identity
  11: rustc::util::bug::bug_fmt
  12: rustc::util::bug::bug_fmt
  13: rustc::dep_graph::graph::DepGraph::try_mark_green
  14: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  15: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  16: <rustc_typeck::variance::terms::InferredIndex as core::fmt::Debug>::fmt
  17: rustc_typeck::check_crate
  18: <rustc_driver::profile::trace::Query as core::fmt::Debug>::fmt
  19: rustc_driver::target_features::add_configuration
  20: rustc_driver::driver::compile_input
  21: rustc_driver::run_compiler
  22: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  23: rustc_driver::run_compiler
  24: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  25: <rustc_driver::profile::trace::Query as core::fmt::Debug>::fmt
  26: _rust_maybe_catch_panic
  27: <humantime::date::Error as std::error::Error>::cause
  28: std::sys::windows::thread::Thread::new
  29: BaseThreadInitThunk
  30: RtlUserThreadStart
query stack during panic:
end of query stack
error: aborting due to previous error
@RustyYato
Copy link
Contributor Author

Note:

If I change

use lazy_static::lazy_static;

to

#[macro_use]
extern crate lazy_static;

It compiles fine

@jonas-schievink jonas-schievink 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. C-bug Category: This is a bug. labels Feb 4, 2019
@RustyYato
Copy link
Contributor Author

After doing a clean build, I am no longer able to reproduce the ICE

@jonas-schievink
Copy link
Contributor

Sounds like an incr. comp. issue anyhow

@jonas-schievink jonas-schievink added the A-incr-comp Area: Incremental compilation label Feb 4, 2019
@RustyYato
Copy link
Contributor Author

Ok, I want to give what information I was able to find

@jonas-schievink
Copy link
Contributor

Yeah, these issues are just really hard to track down. If you find a way to reproduce this, please post it here.

@RustyYato
Copy link
Contributor Author

Ok

@hellow554
Copy link
Contributor

hellow554 commented Feb 5, 2019

@KrishnaSannasi can you try renaming a variable between two builds? I had a similar issue with the same error message: #57692

You may want to verify, that it worked with nightly-2019-01-20 -ish

@RustyYato
Copy link
Contributor Author

RustyYato commented Feb 5, 2019

I am no longer able to reproduce the issue after a clean build, so I don't know. Although, if a clean build did fix the issue, then it may be related to incremental compilation.


also changing use lazy_static::lazy_static to #[macro_use] extern crate lazy_static; did get rid of the ICE, and this seems similar to changing names, at least on the surface.

@Centril Centril added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 11, 2019
@jonas-schievink
Copy link
Contributor

I just hit this, also using a proc macro with lazy_static. I moved my incremental dir, which stopped the ICE. Unfortunately moving it back for some reason no longer reproduces the problem.

@jonas-schievink jonas-schievink removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 25, 2019
@jonas-schievink
Copy link
Contributor

Ah, it can be reproduced by renaming a variable, but not on the most up-to-date nightly, like @hellow554 said. Closing as a dupe of #57692 then.

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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants