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

Project fails (or takes long time) to compile on latest stable and nightly (hang/stackoverflow) #57735

Closed
bgourlie opened this issue Jan 18, 2019 · 23 comments
Assignees
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@bgourlie
Copy link

While attempting to compile my application (or simply run cargo check), rustc will crash, with slightly different results depending on whether it's the stable or nightly branch.

OS: Windows 10 x64 version 1809 build 17763.253

stable toolchain

  • stable-x86_64-pc-windows-msvc
  • rustc 1.32.0 (9fda7c2 2019-01-16)

cargo check result: thread 'main' has overflowed its stack

Repro steps

  • Clone my project
  • cd rs-nes
  • git checkout remove-unstable-features
  • cargo check

nightly toolchain

  • nightly-x86_64-pc-windows-msvc
  • rustc 1.33.0-nightly (daa53a5 2019-01-17)

cargo check result: Process finished with exit code -1

Repro steps

  • Same as above, but on the master branch

Suspected cause

I've narrowed down the issue to a procedural macro that I've had no issues compiling in the past (on nightly). It generates a large match statement which made me think that this recent change may be related, but I have no evidence to support it other than the fact that it changes how the compiler behaves wrt large match statements.

It's also worth noting that I created the remove-unstable-features branch specifically to see if this was only an issue on nightly. It's possible that the error seen on stable is a manifestation of not using unstable features I had been relying on (box patterns, in this case).

@nagisa
Copy link
Member

nagisa commented Jan 18, 2019

I've had no issues compiling in the past (on nightly)

Is there perhaps at least a vague idea of what nightly it was that used to work well?

@bgourlie
Copy link
Author

I can confirm that cargo check succeeds on the following toolchains (apologies, I should have checked on my un-updated laptops prior to submitting this ticket!):

master branch:

  • nightly-x86_64-pc-windows-msvc (1.33.0-nightly a2b0f24 2018-12-30)
  • nightly-x86_64-apple-darwin (rustc 1.33.0 nightly c2d381d 2019-01-10)

remove-unstable-features branch

  • stable-x86_64-pc-windows-msvc (rustc 1.31.1 b6c32da 2018-12-18)
  • stable-x86_x64-apple-darwin (rustc 1.31.1 b6c32da 2018-12-18)

@nagisa nagisa added O-windows Operating system: Windows regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jan 18, 2019
@nagisa
Copy link
Member

nagisa commented Jan 18, 2019

Does not reproduce on Linux.

@bgourlie
Copy link
Author

bgourlie commented Jan 18, 2019

Updated my toolchains on OS X, was able to reproduce on stable, on nightly it succeeded but takes an incredibly long time (12 minutes, 41 seconds on 2.2ghz Intel i7)

@ExpHP
Copy link
Contributor

ExpHP commented Jan 18, 2019

Unable to reproduce. I am also on linux. (triple: x86_64-unknown-linux-gnu)

git clone https://github.com/bgourlie/rs-nes.git
cd rs-nes
git checkout 4d98499f # HEAD of remove-unstable-features at time of posting
cargo +stable check # using rustc 1.32.0 (9fda7c223 2019-01-16)

@nagisa nagisa added the O-macos Operating system: macOS label Jan 18, 2019
@bgourlie
Copy link
Author

Also unable to reproduce on Linux (WSL).

@ExpHP
Copy link
Contributor

ExpHP commented Jan 18, 2019

Okay. I can confirm that it takes a suspiciously long time to cargo check on nightly even on linux (either on rs-nes master or remove-unstable-features). It does eventually finish successfully.

I attached gdb to a running process and sampled some backtraces:

cargo check gdb backtraces (nightly rustc daa53a5, rs-nes 4d98499f (remove-unstable-features))
Thread 2 (Thread 0x7fa8a6fff700 (LWP 14924)):
#0  0x00007fa89ce685ea in <proc_macro::TokenStream as core::iter::traits::Extend<proc_macro::TokenStream>>::extend (self=0x7fa8a6fedb34, streams=...)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:179
#1  0x00007fa89ce69284 in <proc_macro2::imp::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/unstable.rs:245
#2  0x00007fa89ce6766b in <proc_macro2::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/lib.rs:170
#3  0x00007fa89ce67d9b in <proc_macro2::TokenStream as quote::ext::TokenStreamExt>::append (self=0x7fa8a6fedb30, token=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/ext.rs:41
#4  0x00007fa89ce5fcea in quote::__rt::push_comma (tokens=0x7fa8a6fedb30, span=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/lib.rs:163
#5  0x00007fa89ce47518 in rs_nes_macros::ppu_loop_impl () at rs-nes-macros/src/lib.rs:155
#6  0x00007fa89ce53fb3 in rs_nes_macros::ppu_loop (input=...) at rs-nes-macros/src/lib.rs:490
#7  0x00007fa8a872cdc8 in proc_macro::bridge::client::__run_expand2::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:409
#8  <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set::{{closure}} () at src/libproc_macro/bridge/scoped_cell.rs:78
#9  <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#10 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set () at src/libproc_macro/bridge/scoped_cell.rs:78
#11 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter::{{closure}} () at src/libproc_macro/bridge/client.rs:306
#12 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
#13 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#14 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter () at src/libproc_macro/bridge/client.rs:306
#15 proc_macro::bridge::client::__run_expand2::{{closure}} () at src/libproc_macro/bridge/client.rs:401
#16 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once ()
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:309
#17 std::panicking::try::do_call () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:297
#18 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#19 0x00007fa8a8732d75 in std::panicking::try () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:276
#20 std::panic::catch_unwind () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:388
#21 proc_macro::bridge::client::__run_expand2 () at src/libproc_macro/bridge/client.rs:400
#22 0x00007fa8abc74d1e in proc_macro::bridge::server::run_server ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#23 0x00007fa8abc384b7 in proc_macro::bridge::server::<impl proc_macro::bridge::client::Client<fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream>>::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#24 0x00007fa8abcfb4a5 in <syntax_ext::proc_macro_impl::AttrProcMacro as syntax::ext::base::AttrProcMacro>::expand ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#25 0x00007fa8a943cb84 in syntax::ext::expand::MacroExpander::expand_invoc ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#26 0x00007fa8a94364de in syntax::ext::expand::MacroExpander::expand_fragment ()
--Type <RET> for more, q to quit, c to continue without paging--
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#27 0x00007fa8a9435624 in syntax::ext::expand::MacroExpander::expand_crate ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#28 0x00007fa8ae3d86a5 in rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}} ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#29 0x00007fa8ae3cf72d in rustc::util::common::time ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#30 0x00007fa8ae436f4e in rustc_driver::driver::phase_2_configure_and_expand ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#31 0x00007fa8ae432842 in rustc_driver::driver::compile_input ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#32 0x00007fa8ae38ec21 in rustc_driver::run_compiler_with_pool ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#33 0x00007fa8ae39afc6 in <scoped_tls::ScopedKey<T>>::set ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#34 0x00007fa8ae38da6b in rustc_driver::run_compiler ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#35 0x00007fa8ae39a9bb in <scoped_tls::ScopedKey<T>>::set ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#36 0x00007fa8ae40d343 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#37 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#38 0x00007fa8ae424ec1 in <F as alloc::boxed::FnBox<A>>::call_box ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#39 0x00007fa8ae06a2ae in _$LT$alloc..boxed..Box$LT$$LP$dyn$u20$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$RP$$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd0c21f6d144d255f () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/liballoc/boxed.rs:744
#40 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:14
#41 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:81
#42 0x00007fa8adf93a9d in start_thread () from /usr/lib/libpthread.so.0
#43 0x00007fa8adeb4b23 in clone () from /usr/lib/libc.so.6

Thread 1 (Thread 0x7fa8a790e380 (LWP 14923)):
#0  0x00007fa8adf94f6d in __pthread_timedjoin_ex () from /usr/lib/libpthread.so.0
#1  0x00007fa8ae06a36d in std::sys::unix::thread::Thread::join () at src/libstd/sys/unix/thread.rs:168
#2  0x00007fa8ae40e1b3 in <std::thread::JoinHandle<T>>::join ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#3  0x00007fa8ae38ba39 in rustc_driver::run ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#4  0x00007fa8ae3998fc in rustc_driver::main ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#5  0x00005589dd3ac453 in std::rt::lang_start::{{closure}} ()
#6  0x00007fa8ae059863 in std::rt::lang_start_internal::{{closure}} () at src/libstd/rt.rs:49
#7  std::panicking::try::do_call () at src/libstd/panicking.rs:297
#8  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#9  0x00007fa8ae05a476 in std::panicking::try () at src/libstd/panicking.rs:276
#10 std::panic::catch_unwind () at src/libstd/panic.rs:388
#11 std::rt::lang_start_internal () at src/libstd/rt.rs:48
#12 0x00005589dd3ac442 in main ()

========================================================================

Thread 2 (Thread 0x7fa8a6fff700 (LWP 14924)):
#0  0x00007fa89ce685ea in <proc_macro::TokenStream as core::iter::traits::Extend<proc_macro::TokenStream>>::extend (self=0x7fa8a6fedb34, streams=...)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:179
#1  0x00007fa89ce69284 in <proc_macro2::imp::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/unstable.rs:245
#2  0x00007fa89ce6766b in <proc_macro2::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/lib.rs:170
#3  0x00007fa89ce67d9b in <proc_macro2::TokenStream as quote::ext::TokenStreamExt>::append (self=0x7fa8a6fedb30, token=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/ext.rs:41
#4  0x00007fa89ce5fcea in quote::__rt::push_comma (tokens=0x7fa8a6fedb30, span=...)
    at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/lib.rs:163
#5  0x00007fa89ce47518 in rs_nes_macros::ppu_loop_impl () at rs-nes-macros/src/lib.rs:155
#6  0x00007fa89ce53fb3 in rs_nes_macros::ppu_loop (input=...) at rs-nes-macros/src/lib.rs:490
#7  0x00007fa8a872cdc8 in proc_macro::bridge::client::__run_expand2::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:409
#8  <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set::{{closure}} () at src/libproc_macro/bridge/scoped_cell.rs:78
#9  <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#10 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set () at src/libproc_macro/bridge/scoped_cell.rs:78
#11 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter::{{closure}} () at src/libproc_macro/bridge/client.rs:306
#12 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
#13 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#14 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter () at src/libproc_macro/bridge/client.rs:306
#15 proc_macro::bridge::client::__run_expand2::{{closure}} () at src/libproc_macro/bridge/client.rs:401
#16 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once ()
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:309
#17 std::panicking::try::do_call () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:297
#18 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#19 0x00007fa8a8732d75 in std::panicking::try () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:276
#20 std::panic::catch_unwind () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:388
#21 proc_macro::bridge::client::__run_expand2 () at src/libproc_macro/bridge/client.rs:400
#22 0x00007fa8abc74d1e in proc_macro::bridge::server::run_server ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#23 0x00007fa8abc384b7 in proc_macro::bridge::server::<impl proc_macro::bridge::client::Client<fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream>>::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#24 0x00007fa8abcfb4a5 in <syntax_ext::proc_macro_impl::AttrProcMacro as syntax::ext::base::AttrProcMacro>::expand ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#25 0x00007fa8a943cb84 in syntax::ext::expand::MacroExpander::expand_invoc ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#26 0x00007fa8a94364de in syntax::ext::expand::MacroExpander::expand_fragment ()
--Type <RET> for more, q to quit, c to continue without paging--c
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#27 0x00007fa8a9435624 in syntax::ext::expand::MacroExpander::expand_crate () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#28 0x00007fa8ae3d86a5 in rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}} () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#29 0x00007fa8ae3cf72d in rustc::util::common::time () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#30 0x00007fa8ae436f4e in rustc_driver::driver::phase_2_configure_and_expand () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#31 0x00007fa8ae432842 in rustc_driver::driver::compile_input () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#32 0x00007fa8ae38ec21 in rustc_driver::run_compiler_with_pool () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#33 0x00007fa8ae39afc6 in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#34 0x00007fa8ae38da6b in rustc_driver::run_compiler () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#35 0x00007fa8ae39a9bb in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#36 0x00007fa8ae40d343 in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#37 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#38 0x00007fa8ae424ec1 in <F as alloc::boxed::FnBox<A>>::call_box () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#39 0x00007fa8ae06a2ae in _$LT$alloc..boxed..Box$LT$$LP$dyn$u20$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$RP$$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd0c21f6d144d255f () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/liballoc/boxed.rs:744
#40 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:14
#41 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:81
#42 0x00007fa8adf93a9d in start_thread () from /usr/lib/libpthread.so.0
#43 0x00007fa8adeb4b23 in clone () from /usr/lib/libc.so.6

Thread 1 (Thread 0x7fa8a790e380 (LWP 14923)):
#0  0x00007fa8adf94f6d in __pthread_timedjoin_ex () from /usr/lib/libpthread.so.0
#1  0x00007fa8ae06a36d in std::sys::unix::thread::Thread::join () at src/libstd/sys/unix/thread.rs:168
#2  0x00007fa8ae40e1b3 in <std::thread::JoinHandle<T>>::join () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#3  0x00007fa8ae38ba39 in rustc_driver::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#4  0x00007fa8ae3998fc in rustc_driver::main () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#5  0x00005589dd3ac453 in std::rt::lang_start::{{closure}} ()
#6  0x00007fa8ae059863 in std::rt::lang_start_internal::{{closure}} () at src/libstd/rt.rs:49
#7  std::panicking::try::do_call () at src/libstd/panicking.rs:297
#8  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#9  0x00007fa8ae05a476 in std::panicking::try () at src/libstd/panicking.rs:276
#10 std::panic::catch_unwind () at src/libstd/panic.rs:388
#11 std::rt::lang_start_internal () at src/libstd/rt.rs:48
#12 0x00005589dd3ac442 in main ()

===============================================

Thread 2 (Thread 0x7fa8a6fff700 (LWP 14924)):
#0  0x00007fa8ade5cc72 in __memmove_sse2_unaligned_erms () from /usr/lib/libc.so.6
#1  0x00005589dd3d5c14 in _rjem_je_large_ralloc (tsdn=<optimized out>, arena=0x0, extent=0x7fa8a4c16700, usize=<optimized out>, alignment=<optimized out>, 
    zero=<optimized out>, tcache=0x7fa8a6ffe0c0)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/large.c:299
#2  0x00005589dd3b87bb in _rjem_je_arena_ralloc (tsdn=0x7fa8a6ffdf00, arena=0x0, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, 
    alignment=0, zero=<optimized out>, tcache=0x7fa8a6ffe0c0)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/arena.c:1647
#3  0x00005589dd3af964 in iralloct (tsdn=<optimized out>, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, alignment=0, 
    tcache=0x7fa89c430140, arena=0x0, zero=<optimized out>)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h:190
#4  iralloc (tsd=<optimized out>, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, alignment=0, zero=false)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h:197
#5  realloc (ptr=0x7fa89c931340, size=4910400)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/jemalloc.c:2338
#6  0x00007fa8a95cae11 in syntax::tokenstream::TokenStream::from_streams ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#7  0x00007fa8a95cf031 in syntax::tokenstream::TokenStreamBuilder::build ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#8  0x00007fa8abcd344d in std::panicking::try::do_call ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#9  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#10 0x00007fa8abc76a39 in <proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<S>> as proc_macro::bridge::server::DispatcherTrait>::dispatch () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#11 0x00007fa8abcfc813 in <proc_macro::bridge::closure::Closure<'a, A, R> as core::convert::From<&'a mut F>>::from::call ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#12 0x00007fa8a8752d23 in <proc_macro::bridge::closure::Closure<'a, A, R>>::call () at src/libproc_macro/bridge/closure.rs:30
#13 proc_macro::bridge::client::TokenStreamBuilder::build::{{closure}} () at src/libproc_macro/bridge/client.rs:233
#14 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::with::{{closure}} () at src/libproc_macro/bridge/client.rs:317
#15 proc_macro::bridge::client::BridgeState::with::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:282
#16 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#17 proc_macro::bridge::client::BridgeState::with::{{closure}} () at src/libproc_macro/bridge/client.rs:280
#18 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
--Type <RET> for more, q to quit, c to continue without paging--c
#19 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#20 proc_macro::bridge::client::BridgeState::with () at src/libproc_macro/bridge/client.rs:279
#21 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::with () at src/libproc_macro/bridge/client.rs:310
#22 proc_macro::bridge::client::TokenStreamBuilder::build () at src/libproc_macro/bridge/client.rs:226
#23 0x00007fa89ce68bec in <proc_macro::TokenStream as core::iter::traits::FromIterator<proc_macro::TokenStream>>::from_iter (streams=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:164
#24 0x00007fa89ce62dd1 in core::iter::iterator::Iterator::collect (self=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libcore/iter/iterator.rs:1468
#25 0x00007fa89ce685ea in <proc_macro::TokenStream as core::iter::traits::Extend<proc_macro::TokenStream>>::extend (self=0x7fa8a6fedb34, streams=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:179
#26 0x00007fa89ce69284 in <proc_macro2::imp::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/unstable.rs:245
#27 0x00007fa89ce6766b in <proc_macro2::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/lib.rs:170
#28 0x00007fa89ce67d9b in <proc_macro2::TokenStream as quote::ext::TokenStreamExt>::append (self=0x7fa8a6fedb30, token=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/ext.rs:41
#29 0x00007fa89ce5fcea in quote::__rt::push_comma (tokens=0x7fa8a6fedb30, span=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/lib.rs:163
#30 0x00007fa89ce47518 in rs_nes_macros::ppu_loop_impl () at rs-nes-macros/src/lib.rs:155
#31 0x00007fa89ce53fb3 in rs_nes_macros::ppu_loop (input=...) at rs-nes-macros/src/lib.rs:490
#32 0x00007fa8a872cdc8 in proc_macro::bridge::client::__run_expand2::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:409
#33 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set::{{closure}} () at src/libproc_macro/bridge/scoped_cell.rs:78
#34 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#35 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set () at src/libproc_macro/bridge/scoped_cell.rs:78
#36 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter::{{closure}} () at src/libproc_macro/bridge/client.rs:306
#37 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
#38 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#39 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter () at src/libproc_macro/bridge/client.rs:306
#40 proc_macro::bridge::client::__run_expand2::{{closure}} () at src/libproc_macro/bridge/client.rs:401
#41 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:309
#42 std::panicking::try::do_call () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:297
#43 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#44 0x00007fa8a8732d75 in std::panicking::try () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:276
#45 std::panic::catch_unwind () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:388
#46 proc_macro::bridge::client::__run_expand2 () at src/libproc_macro/bridge/client.rs:400
#47 0x00007fa8abc74d1e in proc_macro::bridge::server::run_server () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#48 0x00007fa8abc384b7 in proc_macro::bridge::server::<impl proc_macro::bridge::client::Client<fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream>>::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#49 0x00007fa8abcfb4a5 in <syntax_ext::proc_macro_impl::AttrProcMacro as syntax::ext::base::AttrProcMacro>::expand () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#50 0x00007fa8a943cb84 in syntax::ext::expand::MacroExpander::expand_invoc () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#51 0x00007fa8a94364de in syntax::ext::expand::MacroExpander::expand_fragment () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#52 0x00007fa8a9435624 in syntax::ext::expand::MacroExpander::expand_crate () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#53 0x00007fa8ae3d86a5 in rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}} () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#54 0x00007fa8ae3cf72d in rustc::util::common::time () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#55 0x00007fa8ae436f4e in rustc_driver::driver::phase_2_configure_and_expand () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#56 0x00007fa8ae432842 in rustc_driver::driver::compile_input () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#57 0x00007fa8ae38ec21 in rustc_driver::run_compiler_with_pool () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#58 0x00007fa8ae39afc6 in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#59 0x00007fa8ae38da6b in rustc_driver::run_compiler () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#60 0x00007fa8ae39a9bb in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#61 0x00007fa8ae40d343 in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#62 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#63 0x00007fa8ae424ec1 in <F as alloc::boxed::FnBox<A>>::call_box () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#64 0x00007fa8ae06a2ae in _$LT$alloc..boxed..Box$LT$$LP$dyn$u20$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$RP$$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd0c21f6d144d255f () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/liballoc/boxed.rs:744
#65 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:14
#66 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:81
#67 0x00007fa8adf93a9d in start_thread () from /usr/lib/libpthread.so.0
#68 0x00007fa8adeb4b23 in clone () from /usr/lib/libc.so.6

Thread 1 (Thread 0x7fa8a790e380 (LWP 14923)):
#0  0x00007fa8adf94f6d in __pthread_timedjoin_ex () from /usr/lib/libpthread.so.0
#1  0x00007fa8ae06a36d in std::sys::unix::thread::Thread::join () at src/libstd/sys/unix/thread.rs:168
#2  0x00007fa8ae40e1b3 in <std::thread::JoinHandle<T>>::join () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#3  0x00007fa8ae38ba39 in rustc_driver::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#4  0x00007fa8ae3998fc in rustc_driver::main () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#5  0x00005589dd3ac453 in std::rt::lang_start::{{closure}} ()
#6  0x00007fa8ae059863 in std::rt::lang_start_internal::{{closure}} () at src/libstd/rt.rs:49
#7  std::panicking::try::do_call () at src/libstd/panicking.rs:297
#8  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#9  0x00007fa8ae05a476 in std::panicking::try () at src/libstd/panicking.rs:276
#10 std::panic::catch_unwind () at src/libstd/panic.rs:388
#11 std::rt::lang_start_internal () at src/libstd/rt.rs:48

===============================================

Thread 2 (Thread 0x7fa8a6fff700 (LWP 14924)):
#0  0x00007fa8ade5cc72 in __memmove_sse2_unaligned_erms () from /usr/lib/libc.so.6
#1  0x00005589dd3d5c14 in _rjem_je_large_ralloc (tsdn=<optimized out>, arena=0x0, extent=0x7fa8a4c16700, usize=<optimized out>, alignment=<optimized out>, 
    zero=<optimized out>, tcache=0x7fa8a6ffe0c0)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/large.c:299
#2  0x00005589dd3b87bb in _rjem_je_arena_ralloc (tsdn=0x7fa8a6ffdf00, arena=0x0, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, 
    alignment=0, zero=<optimized out>, tcache=0x7fa8a6ffe0c0)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/arena.c:1647
#3  0x00005589dd3af964 in iralloct (tsdn=<optimized out>, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, alignment=0, 
    tcache=0x7fa89c430140, arena=0x0, zero=<optimized out>)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h:190
#4  iralloc (tsd=<optimized out>, ptr=<optimized out>, oldsize=<optimized out>, size=<optimized out>, alignment=0, zero=false)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h:197
#5  realloc (ptr=0x7fa89c931340, size=4910400)
    at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/build/jemalloc-sys-52018b331c920d2b/out/jemalloc/src/jemalloc.c:2338
#6  0x00007fa8a95cae11 in syntax::tokenstream::TokenStream::from_streams ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#7  0x00007fa8a95cf031 in syntax::tokenstream::TokenStreamBuilder::build ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#8  0x00007fa8abcd344d in std::panicking::try::do_call ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#9  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#10 0x00007fa8abc76a39 in <proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<S>> as proc_macro::bridge::server::DispatcherTrait>::dispatch () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#11 0x00007fa8abcfc813 in <proc_macro::bridge::closure::Closure<'a, A, R> as core::convert::From<&'a mut F>>::from::call ()
   from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#12 0x00007fa8a8752d23 in <proc_macro::bridge::closure::Closure<'a, A, R>>::call () at src/libproc_macro/bridge/closure.rs:30
#13 proc_macro::bridge::client::TokenStreamBuilder::build::{{closure}} () at src/libproc_macro/bridge/client.rs:233
#14 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::with::{{closure}} () at src/libproc_macro/bridge/client.rs:317
#15 proc_macro::bridge::client::BridgeState::with::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:282
#16 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#17 proc_macro::bridge::client::BridgeState::with::{{closure}} () at src/libproc_macro/bridge/client.rs:280
#18 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
--Type <RET> for more, q to quit, c to continue without paging--c
#19 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#20 proc_macro::bridge::client::BridgeState::with () at src/libproc_macro/bridge/client.rs:279
#21 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::with () at src/libproc_macro/bridge/client.rs:310
#22 proc_macro::bridge::client::TokenStreamBuilder::build () at src/libproc_macro/bridge/client.rs:226
#23 0x00007fa89ce68bec in <proc_macro::TokenStream as core::iter::traits::FromIterator<proc_macro::TokenStream>>::from_iter (streams=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:164
#24 0x00007fa89ce62dd1 in core::iter::iterator::Iterator::collect (self=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libcore/iter/iterator.rs:1468
#25 0x00007fa89ce685ea in <proc_macro::TokenStream as core::iter::traits::Extend<proc_macro::TokenStream>>::extend (self=0x7fa8a6fedb34, streams=...) at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libproc_macro/lib.rs:179
#26 0x00007fa89ce69284 in <proc_macro2::imp::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/unstable.rs:245
#27 0x00007fa89ce6766b in <proc_macro2::TokenStream as core::iter::traits::Extend<proc_macro2::TokenTree>>::extend (self=0x7fa8a6fedb30, streams=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/lib.rs:170
#28 0x00007fa89ce67d9b in <proc_macro2::TokenStream as quote::ext::TokenStreamExt>::append (self=0x7fa8a6fedb30, token=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/ext.rs:41
#29 0x00007fa89ce5fcea in quote::__rt::push_comma (tokens=0x7fa8a6fedb30, span=...) at /home/lampam/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.10/src/lib.rs:163
#30 0x00007fa89ce47518 in rs_nes_macros::ppu_loop_impl () at rs-nes-macros/src/lib.rs:155
#31 0x00007fa89ce53fb3 in rs_nes_macros::ppu_loop (input=...) at rs-nes-macros/src/lib.rs:490
#32 0x00007fa8a872cdc8 in proc_macro::bridge::client::__run_expand2::{{closure}}::{{closure}} () at src/libproc_macro/bridge/client.rs:409
#33 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set::{{closure}} () at src/libproc_macro/bridge/scoped_cell.rs:78
#34 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::replace () at src/libproc_macro/bridge/scoped_cell.rs:73
#35 <proc_macro::bridge::scoped_cell::ScopedCell<T>>::set () at src/libproc_macro/bridge/scoped_cell.rs:78
#36 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter::{{closure}} () at src/libproc_macro/bridge/client.rs:306
#37 <std::thread::local::LocalKey<T>>::try_with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:299
#38 <std::thread::local::LocalKey<T>>::with () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/thread/local.rs:245
#39 proc_macro::bridge::client::<impl proc_macro::bridge::Bridge<'_>>::enter () at src/libproc_macro/bridge/client.rs:306
#40 proc_macro::bridge::client::__run_expand2::{{closure}} () at src/libproc_macro/bridge/client.rs:401
#41 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:309
#42 std::panicking::try::do_call () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:297
#43 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#44 0x00007fa8a8732d75 in std::panicking::try () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panicking.rs:276
#45 std::panic::catch_unwind () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/libstd/panic.rs:388
#46 proc_macro::bridge::client::__run_expand2 () at src/libproc_macro/bridge/client.rs:400
#47 0x00007fa8abc74d1e in proc_macro::bridge::server::run_server () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#48 0x00007fa8abc384b7 in proc_macro::bridge::server::<impl proc_macro::bridge::client::Client<fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream>>::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#49 0x00007fa8abcfb4a5 in <syntax_ext::proc_macro_impl::AttrProcMacro as syntax::ext::base::AttrProcMacro>::expand () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax_ext-065cea48e300124c.so
#50 0x00007fa8a943cb84 in syntax::ext::expand::MacroExpander::expand_invoc () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#51 0x00007fa8a94364de in syntax::ext::expand::MacroExpander::expand_fragment () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#52 0x00007fa8a9435624 in syntax::ext::expand::MacroExpander::expand_crate () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libsyntax-2e8dd76d87693318.so
#53 0x00007fa8ae3d86a5 in rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}} () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#54 0x00007fa8ae3cf72d in rustc::util::common::time () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#55 0x00007fa8ae436f4e in rustc_driver::driver::phase_2_configure_and_expand () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#56 0x00007fa8ae432842 in rustc_driver::driver::compile_input () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#57 0x00007fa8ae38ec21 in rustc_driver::run_compiler_with_pool () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#58 0x00007fa8ae39afc6 in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#59 0x00007fa8ae38da6b in rustc_driver::run_compiler () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#60 0x00007fa8ae39a9bb in <scoped_tls::ScopedKey<T>>::set () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#61 0x00007fa8ae40d343 in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#62 0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#63 0x00007fa8ae424ec1 in <F as alloc::boxed::FnBox<A>>::call_box () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#64 0x00007fa8ae06a2ae in _$LT$alloc..boxed..Box$LT$$LP$dyn$u20$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$RP$$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd0c21f6d144d255f () at /rustc/daa53a52a2667533d5fe59bfcc5b8614b79c3d31/src/liballoc/boxed.rs:744
#65 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:14
#66 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:81
#67 0x00007fa8adf93a9d in start_thread () from /usr/lib/libpthread.so.0
#68 0x00007fa8adeb4b23 in clone () from /usr/lib/libc.so.6

Thread 1 (Thread 0x7fa8a790e380 (LWP 14923)):
#0  0x00007fa8adf94f6d in __pthread_timedjoin_ex () from /usr/lib/libpthread.so.0
#1  0x00007fa8ae06a36d in std::sys::unix::thread::Thread::join () at src/libstd/sys/unix/thread.rs:168
#2  0x00007fa8ae40e1b3 in <std::thread::JoinHandle<T>>::join () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#3  0x00007fa8ae38ba39 in rustc_driver::run () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#4  0x00007fa8ae3998fc in rustc_driver::main () from /home/lampam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-c5efcb7334989aff.so
#5  0x00005589dd3ac453 in std::rt::lang_start::{{closure}} ()
#6  0x00007fa8ae059863 in std::rt::lang_start_internal::{{closure}} () at src/libstd/rt.rs:49
#7  std::panicking::try::do_call () at src/libstd/panicking.rs:297
#8  0x00007fa8ae06b4ea in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:92
#9  0x00007fa8ae05a476 in std::panicking::try () at src/libstd/panicking.rs:276
#10 std::panic::catch_unwind () at src/libstd/panic.rs:388
#11 std::rt::lang_start_internal () at src/libstd/rt.rs:48
#12 0x00005589dd3ac442 in main ()

@matthiaskrgr
Copy link
Member

When cargo checking with RUSTFLAGS="-Ztime-passes", I can see that the expand crate step takes an unusually big amount of time:

    Checking rs_nes v0.0.1 (/tmp/rs-nes/rs-nes)
  time: 0.009; rss: 54MB	parsing
  time: 0.000; rss: 54MB	attributes injection
  time: 0.000; rss: 54MB	garbage collect incremental cache directory
  time: 0.000; rss: 54MB	recursion limit
  time: 0.000; rss: 54MB	crate injection
  time: 0.000; rss: 54MB	plugin loading
  time: 0.000; rss: 54MB	plugin registration
  time: 0.000; rss: 54MB	background load prev dep-graph
  time: 0.002; rss: 55MB	pre ast expansion lint checks
    time: 176.138; rss: 100MB	expand crate
    time: 0.000; rss: 100MB	check unused macros
  time: 176.138; rss: 100MB	expansion
  time: 0.000; rss: 100MB	maybe building test harness
  time: 0.001; rss: 100MB	maybe creating a macro crate
  time: 0.007; rss: 100MB	creating allocators
  time: 0.004; rss: 100MB	AST validation
  time: 0.016; rss: 102MB	name resolution
  time: 0.003; rss: 102MB	complete gated feature checking
  time: 0.000; rss: 102MB	blocked while dep-graph loading finishes
  time: 0.020; rss: 116MB	lowering ast -> hir
  time: 0.016; rss: 116MB	early lint checks
    time: 0.008; rss: 125MB	validate hir map
  time: 0.051; rss: 125MB	indexing hir
  time: 0.000; rss: 125MB	load query result cache
  time: 0.000; rss: 125MB	looking for entry point
  time: 0.000; rss: 125MB	dep graph tcx init
  time: 0.000; rss: 125MB	looking for plugin registrar
  time: 0.000; rss: 125MB	looking for derive registrar
  time: 0.001; rss: 127MB	loop checking
  time: 0.002; rss: 127MB	attribute checking
  time: 0.004; rss: 127MB	stability checking
  time: 0.010; rss: 131MB	type collecting
  time: 0.000; rss: 131MB	outlives testing
  time: 0.000; rss: 131MB	impl wf inference
  time: 0.045; rss: 142MB	coherence checking
  time: 0.000; rss: 142MB	variance testing

@pnkfelix
Copy link
Member

triage. P-high. Assigning to self for further bisection on OS X (to hopefully confirm or reject the reporter's hypothesis regarding #57494

@pnkfelix pnkfelix added P-high High priority I-slow Issue: Problems and improvements with respect to performance of generated code. labels Jan 24, 2019
@pnkfelix pnkfelix changed the title Project fails to compile on latest stable and nightly (hang/stackoverflow) Project fails (or takes long time) to compile on latest stable and nightly (hang/stackoverflow) Jan 24, 2019
@pnkfelix pnkfelix self-assigned this Jan 24, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jan 28, 2019

On my Mac OS X laptop, the source of the slowdown appears to be tied to the expansion-time construction (or maybe compilation) of the following line:

const CYCLES_MAP: [u8; #total_cycles] = [#(#compact_cycle_number_map),*];

Or at least, when I replace that array with one that just says:

const CYCLES_MAP: [u8; #total_cycles] = [0; #total_cycles];

then the overall compilation via cargo check completes quite quickly.


eprintln! instrumentation reveals that during the expansion in question, the const array in question has 89,342 entries (i.e. total_cycles == 89342).

@pnkfelix
Copy link
Member

I am now focusing on bisection; I found that I was able to comment out most of the other code, effectively generating a much reduced test case, which I will try to extract into its own crate (or perhaps pair of source files? we'll see) in a bit.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 28, 2019

Here is a gist that captures the test case I've reduced this to for now (unfortunately gist does not allow forward-slashes in the names so I've used spaces instead of slashes as the directory separator):
https://gist.github.com/pnkfelix/06a63f45fda5066245b9b516eea68598


Regarding that reduced test case, here's what I've observed so far:

  • Regarding bisection: The time-regression appears to have been injected in between nightly-2019-01-13 and nightly-2019-01-14 (those are the tags assigned by rustup.

That is, running cargo check in demo/, with dependencies already built for both rust versions, I see this:

% rustup default nightly-2019-01-13 && touch src/lib.rs && touch ../ppu_loop/src/lib.rs
info: using existing install for 'nightly-2019-01-13-x86_64-apple-darwin'
info: default toolchain set to 'nightly-2019-01-13-x86_64-apple-darwin'

  nightly-2019-01-13-x86_64-apple-darwin unchanged - rustc 1.33.0-nightly (75a369c5b 2019-01-12)

% time cargo check
   Compiling ppu_loop v0.1.0 (/Users/fklock/Dev/Mozilla/issue57335/ppu_loop)
    Checking demo v0.1.0 (/Users/fklock/Dev/Mozilla/issue57335/demo)
expansion ppu_loop_impl total_cycles: 17000
    Finished dev [unoptimized + debuginfo] target(s) in 1.57s

real	0m1.616s
user	0m1.109s
sys	0m0.443s
% rustup default nightly-2019-01-14 && touch src/lib.rs && touch ../ppu_loop/src/lib.rs
info: using existing install for 'nightly-2019-01-14-x86_64-apple-darwin'
info: default toolchain set to 'nightly-2019-01-14-x86_64-apple-darwin'

  nightly-2019-01-14-x86_64-apple-darwin unchanged - rustc 1.33.0-nightly (2fadb0a16 2019-01-13)

% time cargo check
   Compiling ppu_loop v0.1.0 (/Users/fklock/Dev/Mozilla/issue57335/ppu_loop)
    Checking demo v0.1.0 (/Users/fklock/Dev/Mozilla/issue57335/demo)
expansion ppu_loop_impl total_cycles: 17000
    Finished dev [unoptimized + debuginfo] target(s) in 33.07s

real	0m33.115s
user	0m14.167s
sys	0m18.665s

In the reduced test case, I tried adjusting the size of the array in the generated code by changing the values of SCANLINES and CYCLES_PER_SCANLINE. (You can see that in the version I posted above, there is eprintln! instrumentation reporting that the total_cycles is 17,000.)

Here is a summary of how the cargo check time changes as total_cycles changes. (This is based on single runs, no statistical averaging or whatnot, so take it all with a grain of salt.)

total_cycles real time user time sys time
1,000 1.170s 0.907s 0.263s
2,000 1.241s 0.965s 0.264s
3,000 1.703s 1.178s 0.517s
4,000 2.347s 1.438s 0.875s
5,000 3.100s 1.757s 1.325s
6,000 3.972s 2.138s 1.819s
7,000 5.130s 2.635s 2.469s
8,000 6.414s 3.156s 3.216s
9,000 7.927s 3.773s 4.089s
10,000 9.695s 4.763s 5.032s
11,000 11.167s 5.156s 5.973s
12,000 13.142s 5.954s 7.130s
13,000 15.347s 6.862s 8.412s
14,000 17.599s 7.739s 9.718s
15,000 20.102s 8.734s 11.222s
16,000 22.727s 10.057s 12.567s
17,000 26.309s 11.313s 14.807s
18,000 28.580s 12.311s 16.065s
19,000 32.359s 13.691s 18.480s
20,000 35.701s 15.127s 20.360s

The main reason why I've included the above table (in the details block) is it looks like there may be a non-linear relationship from total_cycles to the elapsed time. each row increases the total_cycles by 1,000, but the delta for time increase starts at around 1.5 seconds but grows to 3 seconds by the end. (I also included the table because on some of my runs, the step from 16,000 to 17,000 jumped by quite a lot. But after repeated runs it appears that may have been noise.)

@pnkfelix
Copy link
Member

Between the two nightlies I referenced in the above comment, here are the PR's that were merged:

% git log 75a369c5b..2fadb0a16 --author=bors --format=oneline

Of the PR's referenced above, my spidey-sense is most-immediately firing in response to seeing #57004 "(Make TokenStream less recursive.) "

@pnkfelix
Copy link
Member

Okay further bisection indicates that the regression was injected by 2cf736f.

Spidey-sense continues to fire in response to #57004. I'm going to look into reverting that on its own and see what happens.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 29, 2019

According to an Instruments run profiling the invocation of rustc on my demo test code, the vast majority of the time is being spent here:

Some(stream2) => vec.extend(stream2.iter().cloned()),

I'm going to review #57004 and follow-on code a little, see if I can determine whether we can get rid of that eager traversal and cloning of the contents of the vector of streams.

@petrochenkov
Copy link
Contributor

cc @nnethercote

@pnkfelix
Copy link
Member

pnkfelix commented Jan 30, 2019

Okay I think I have a fix.

I made two different micro-optimizations to the code path I identified in my previous comment.

  • The first micro-optimization was to add a prepass over streams to figure out what capacity our accumulating vec is going to require, and then build the vec with that capacity.
  • The second micro-optimization (which I suspect may be the more relevant one) was to identify when the Lrc for stream2 has a single owner (i.e. a ref-count of one); if so, then we can just move the trees directly from stream2 into vec, without cloning them.

After rebuilding the compiler with those micro-optimizations, my demo code compiles much faster than before.

Here's the current diff. I'm going to try to identify which of the two micro-optimizations was the important one:

diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs
index f5d2d6f18e..db6b701b83 100644
--- a/src/libsyntax/tokenstream.rs
+++ b/src/libsyntax/tokenstream.rs
@@ -255,11 +255,19 @@ impl TokenStream {
             0 => TokenStream::empty(),
             1 => streams.pop().unwrap(),
             _ => {
-                let mut vec = vec![];
+                let tree_count = streams.iter()
+                    .map(|ts| match &ts.0 { None => 0, Some(s) => s.len() })
+                    .sum();
+                let mut vec = Vec::with_capacity(tree_count);
                 for stream in streams {
                     match stream.0 {
                         None => {},
-                        Some(stream2) => vec.extend(stream2.iter().cloned()),
+                        Some(stream2) => {
+                            match Lrc::try_unwrap(stream2) {
+                                Ok(trees) => vec.extend(trees.into_iter()),
+                                Err(stream2) => vec.extend(stream2.iter().cloned()),
+                            }
+                        }
                     }
                 }
                 TokenStream::new(vec)

@pnkfelix
Copy link
Member

pnkfelix commented Jan 30, 2019

One mystery to me is why the problem was not replicated on Linux. If I am correct that one or both of the micro-optimizations listed above fixes this issue, then we should be observing a similar execution time hit on Linux systems, I imagine...

... although ... maybe it is the with_capacity call that is fixing things on OS X, and memory allocation on Linux is simply so much better than on OS X that it is able to mask the problem there?

Update: I overlooked @ExpHP 's report that the slowdown does reproduce on Linux.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 30, 2019

Okay I have now determined that on my OS X machine, it is the with_capacity delta that makes the difference here. The attempt to avoid cloning the trees within a singly-owned vector doesn't help at all for my reduced demo.

@ExpHP
Copy link
Contributor

ExpHP commented Jan 30, 2019

Well, there were two problems here, right? One that does not replicate on Linux (crash), and one that does (super slow cargo check)

@pnkfelix
Copy link
Member

Oh, I'm sorry, I overlooked @ExpHP 's comment that they reproduced the slowdown on Linux.

@pnkfelix
Copy link
Member

cc rust-lang/rustc-perf#277

@pnkfelix pnkfelix removed O-macos Operating system: macOS O-windows Operating system: Windows labels Jan 30, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jan 31, 2019

Just to make sure I cover all the issues here, I have now replicated the stack overflow on OS X atop commit 9fda7c2

A backtrace shows that the overflow is happening during a particularly deep series of drop calls. (Chances seem high that this is related in some manner to how the token-tree/token-stream was (re)structured.)

kennytm added a commit to kennytm/rust that referenced this issue Feb 5, 2019
…h-large-tokenstream-slow, r=eddyb

proc_macro: make `TokenStream::from_streams` pre-allocate its vector.

This requires a pre-pass over the input streams. But that is cheap compared to the quadratic blowup associated with reallocating the accumulating vector on-the-fly.

Fix rust-lang#57735
nnethercote added a commit to nnethercote/rust that referenced this issue Oct 5, 2022
`TokenStreamBuilder` exists to concatenate multiple `TokenStream`s
together. This commit removes it, and moves the concatenation
functionality directly into `TokenStream`, via two new methods
`push_tree` and `push_stream`. This makes things both simpler and
faster.

`push_tree` is particularly important. `TokenStreamBuilder` only had a
single `push` method, which pushed a stream. But in practice most of the
time we push a single token tree rather than a stream, and `push_tree`
avoids the need to build a token stream with a single entry (which
requires two allocations, one for the `Lrc` and one for the `Vec`).

The main `push_tree` use arises from a change to one of the `ToInternal`
impls in `proc_macro_server.rs`. It now returns a `SmallVec` instead of
a `TokenStream`. This return value is then iterated over by
`concat_trees`, which does `push_tree` on each element. Furthermore, the
use of `SmallVec` avoids more allocations, because there is always only
one or two token trees.

Note: the removed `TokenStreamBuilder::push` method had some code to
deal with a quadratic blowup case from rust-lang#57735. This commit removes the
code. I tried and failed to reproduce the blowup from that PR, before
and after this change. Various other changes have happened to
`TokenStreamBuilder` in the meantime, so I suspect the original problem
is no longer relevant, though I don't have proof of this. Generally
speaking, repeatedly extending a `Vec` without pre-determining its
capacity is *not* quadratic. It's also incredibly common, within rustc
and many other Rust programs, so if there were performance problems
there you'd think it would show up in other places, too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

No branches or pull requests

6 participants