Skip to content

-Zthreads breaks the single-threaded assumption made by the format args collector #11886

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
y21 opened this issue Nov 27, 2023 · 2 comments · Fixed by #12567
Closed

-Zthreads breaks the single-threaded assumption made by the format args collector #11886

y21 opened this issue Nov 27, 2023 · 2 comments · Fixed by #12567
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@y21
Copy link
Member

y21 commented Nov 27, 2023

Summary

With -Zthreads being a thing now, maybe we shouldn't rely on TLS anymore like we're doing right now? I can reliably hit this assertion

"incorrect assumption: `AST_FORMAT_ARGS` should only be accessed by a single thread",

This is a debug assert, so the ICE won't be reproducible with the cargo clippy that is shipped as a component.

Reproducer

// y.rs
fn main() {
    println!("1");
}
$ ./target/debug/clippy-driver y.rs -Zno-codegen -Zthreads=10

Version

commit f30a859ae32c97668a1a8473fc95b72857073e37

Error output

Backtrace

thread 'rustc' panicked at clippy_utils/src/macros.rs:391:9:
incorrect assumption: `AST_FORMAT_ARGS` should only be accessed by a single thread
stack backtrace:
 0:     0x7f6775df889c - std::backtrace_rs::backtrace::libunwind::trace::hc8ce14f1f51b19f3
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
 1:     0x7f6775df889c - std::backtrace_rs::backtrace::trace_unsynchronized::h31756ac1c596273b
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7f6775df889c - std::sys_common::backtrace::_print_fmt::h40f31fb4d7056540
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys_common/backtrace.rs:67:5
 3:     0x7f6775df889c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcd6ddd3255a8e554
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7f6775e4b8a0 - core::fmt::rt::Argument::fmt::haa38531ef8752652
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/fmt/rt.rs:142:9
 5:     0x7f6775e4b8a0 - core::fmt::write::ha0f782bd1ecfc2dc
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/fmt/mod.rs:1120:17
 6:     0x7f6775dec7bf - std::io::Write::write_fmt::h5f37f3e5a0e4b544
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/io/mod.rs:1762:15
 7:     0x7f6775df8684 - std::sys_common::backtrace::_print::h166370b298d5569f
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7f6775df8684 - std::sys_common::backtrace::print::hab8f751e46216a08
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7f6775dfb317 - std::panicking::default_hook::{{closure}}::h058a18801f9aa311
10:     0x7f6775dfb07f - std::panicking::default_hook::h21798126b0cefb30
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/panicking.rs:292:9
11:     0x7f6772ae4660 - std[ee38bba0a237925c]::panicking::update_hook::<alloc[a43fc757b277f94f]::boxed::Box<rustc_driver_impl[4cf9e24b9673574]::install_ice_hook::{closure#0}>>::{closure#0}
12:     0x7f6775dfba58 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hae78327b43bc7d35
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2021:9
13:     0x7f6775dfba58 - std::panicking::rust_panic_with_hook::h394983fd1617103f
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/panicking.rs:783:13
14:     0x7f6775dfb779 - std::panicking::begin_panic_handler::{{closure}}::hd49ee216b5583372
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/panicking.rs:649:13
15:     0x7f6775df8d66 - std::sys_common::backtrace::__rust_end_short_backtrace::h29c7582710951d8d
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys_common/backtrace.rs:170:18
16:     0x7f6775dfb512 - rust_begin_unwind
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/panicking.rs:645:5
17:     0x7f6775e47f85 - core::panicking::panic_fmt::h1ab6d174ce586fe3
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/panicking.rs:72:14
18:     0x5572633c761e - clippy_utils::macros::AST_FORMAT_ARGS::__init::h54adb8261143af00
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/panic.rs:106:9
19:     0x55726320c8d4 - clippy_utils::macros::AST_FORMAT_ARGS::__getit::{{closure}}::hb43e469d96715dbc
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/common/thread_local/fast_local.rs:99:25
20:     0x557263117b31 - std::sys::common::thread_local::lazy::LazyKeyInner<T>::initialize::h70a0e9f33a1c05f8
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/common/thread_local/mod.rs:54:25
21:     0x557263251602 - std::sys::common::thread_local::fast_local::Key<T>::try_initialize::hd222f65d0e36c777
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/common/thread_local/fast_local.rs:190:27
22:     0x557263251870 - std::sys::common::thread_local::fast_local::Key<T>::get::hb43b1876ea5aafa7
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/common/thread_local/fast_local.rs:173:25
23:     0x5572633c7665 - clippy_utils::macros::AST_FORMAT_ARGS::__getit::h80c8efd0c1c63629
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/common/thread_local/fast_local.rs:91:21
24:     0x55726332b7b4 - std::thread::local::LocalKey<T>::try_with::hda287d5dbe8b5f4d
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/thread/local.rs:269:32
25:     0x55726332a7ad - std::thread::local::LocalKey<T>::with::ha72d176466541b1f
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/thread/local.rs:246:9
26:     0x5572633c6c37 - clippy_utils::macros::find_format_args::h836040932b2da5f6
                             at /home/timo/rust-clippy/clippy_utils/src/macros.rs:419:5
27:     0x557262beecbf - <clippy_lints::format_args::FormatArgs as rustc_lint::passes::LateLintPass>::check_expr::he7f74ba4c7a752b2
                             at /home/timo/rust-clippy/clippy_lints/src/format_args.rs:190:40
28:     0x7f6772e8cf50 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_expr::{closure#0}
29:     0x7f6772e8cdd8 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_expr
30:     0x7f6772e8de6e - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_block
31:     0x7f6772e8d5a8 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_expr::{closure#0}
32:     0x7f6772e8cdd8 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_expr
33:     0x7f6772e8b7aa - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_nested_body
34:     0x7f6772e8d944 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_fn
35:     0x7f6772e8bff5 - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_item
36:     0x7f6772e8dc7a - <rustc_lint[6b16f16878f0609a]::late::LateContextAndPass<rustc_lint[6b16f16878f0609a]::late::RuntimeCombinedLateLintPass> as rustc_hir[bfecebe82f70b3af]::intravisit::Visitor>::visit_mod
37:     0x7f6774817ba7 - rustc_lint[6b16f16878f0609a]::late::check_crate::{closure#0}
38:     0x7f6772e6d842 - rayon_core[4fd33d6976072015]::join::join_context::<rayon_core[4fd33d6976072015]::join::join::call<core[8f41822517f550cc]::option::Option<rustc_data_structures[74d3a12135b02663]::marker::FromDyn<()>>, rustc_data_structures[74d3a12135b02663]::sync::parallel::enabled::join<rustc_lint[6b16f16878f0609a]::late::check_crate::{closure#0}, rustc_lint[6b16f16878f0609a]::late::check_crate::{closure#1}, (), ()>::{closure#0}::{closure#0}>::{closure#0}, rayon_core[4fd33d6976072015]::join::join::call<core[8f41822517f550cc]::option::Option<rustc_data_structures[74d3a12135b02663]::marker::FromDyn<()>>, rustc_data_structures[74d3a12135b02663]::sync::parallel::enabled::join<rustc_lint[6b16f16878f0609a]::late::check_crate::{closure#0}, rustc_lint[6b16f16878f0609a]::late::check_crate::{closure#1}, (), ()>::{closure#0}::{closure#1}>::{closure#0}, core[8f41822517f550cc]::option::Option<rustc_data_structures[74d3a12135b02663]::marker::FromDyn<()>>, core[8f41822517f550cc]::option::Option<rustc_data_structures[74d3a12135b02663]::marker::FromDyn<()>>>::{closure#0}
39:     0x7f6774817e55 - rustc_lint[6b16f16878f0609a]::late::check_crate
40:     0x7f6772e3af3a - <rayon_core[4fd33d6976072015]::job::HeapJob<<rayon_core[4fd33d6976072015]::scope::Scope>::spawn<rustc_interface[bcd40bc45d5d0754]::passes::analysis::{closure#6}::{closure#2}::{closure#0}::{closure#2}::{closure#1}::{closure#0}::{closure#3}>::{closure#0}> as rayon_core[4fd33d6976072015]::job::Job>::execute
41:     0x7f67726d9ed5 - <rayon_core[4fd33d6976072015]::registry::WorkerThread>::wait_until_cold
42:     0x7f67726d6da3 - <rayon_core[4fd33d6976072015]::registry::ThreadBuilder>::run
43:     0x7f6772ae6697 - <<crossbeam_utils[6d482fbb41000f9]::thread::ScopedThreadBuilder>::spawn<<rayon_core[4fd33d6976072015]::ThreadPoolBuilder>::build_scoped<rustc_interface[bcd40bc45d5d0754]::util::run_in_thread_pool_with_globals<rustc_interface[bcd40bc45d5d0754]::interface::run_compiler<core[8f41822517f550cc]::result::Result<(), rustc_span[74aab3a68d021777]::ErrorGuaranteed>, rustc_driver_impl[4cf9e24b9673574]::run_compiler::{closure#1}>::{closure#0}, core[8f41822517f550cc]::result::Result<(), rustc_span[74aab3a68d021777]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[bcd40bc45d5d0754]::util::run_in_thread_pool_with_globals<rustc_interface[bcd40bc45d5d0754]::interface::run_compiler<core[8f41822517f550cc]::result::Result<(), rustc_span[74aab3a68d021777]::ErrorGuaranteed>, rustc_driver_impl[4cf9e24b9673574]::run_compiler::{closure#1}>::{closure#0}, core[8f41822517f550cc]::result::Result<(), rustc_span[74aab3a68d021777]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[8f41822517f550cc]::result::Result<(), rustc_span[74aab3a68d021777]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[8f41822517f550cc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
44:     0x7f6772adf3ce - std[ee38bba0a237925c]::sys_common::backtrace::__rust_begin_short_backtrace::<alloc[a43fc757b277f94f]::boxed::Box<dyn core[8f41822517f550cc]::ops::function::FnOnce<(), Output = ()> + core[8f41822517f550cc]::marker::Send>, ()>
45:     0x7f6772ae6323 - <<std[ee38bba0a237925c]::thread::Builder>::spawn_unchecked_<alloc[a43fc757b277f94f]::boxed::Box<dyn core[8f41822517f550cc]::ops::function::FnOnce<(), Output = ()> + core[8f41822517f550cc]::marker::Send>, ()>::{closure#1} as core[8f41822517f550cc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
46:     0x7f6775e05915 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he32d1cc72bddfec8
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007:9
47:     0x7f6775e05915 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfc224f9cd2e7edd6
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007:9
48:     0x7f6775e05915 - std::sys::unix::thread::Thread::new::thread_start::h1b679b756cd6878e
                             at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/unix/thread.rs:108:17
49:     0x7f676826cb43 - start_thread
                             at ./nptl/pthread_create.c:442:8
50:     0x7f67682fea00 - clone3
                             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
51:                0x0 - <unknown>

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

@y21 y21 added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Nov 27, 2023
@flip1995
Copy link
Member

flip1995 commented Nov 27, 2023

#10275 (comment)

Damn, I kinda predicted that... But back then I didn't expect that we'll get parallel compilation this soon.

@Alexendoo I think we'll have to think about a different solution...

@Alexendoo
Copy link
Member

Ahh I thought we'd have longer since whole crate passes aren't run in parallel even with -Zthreads, however the early lint passes may have happened on a different thread when parallel is enabled

I've been thinking about how to fix it when working on the module pass stuff and have a pretty good idea of how to go about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants