Skip to content

Add proper name mangling for pattern types #142401

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jun 12, 2025

requires adding demangler support first rust-lang/rustc-demangle#81

needed for #136006 (comment) as otherwise we will have symbol collisions

@rustbot
Copy link
Collaborator

rustbot commented Jun 12, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 12, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [codegen] tests/codegen/pattern_type_symbols.rs stdout ----

error: compilation failed!
status: exit status: 101
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/codegen/pattern_type_symbols.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "-Cdebug-assertions=no" "--emit" "llvm-ir" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen/pattern_type_symbols/pattern_type_symbols.ll" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Csymbol-mangling-version=v0" "-Copt-level=0" "--crate-type=lib"
stdout: none
--- stderr -------------------------------

thread 'rustc' panicked at compiler/rustc_symbol_mangling/src/lib.rs:317:5:
compute_symbol_name: `_RINvCs3QvG2ESzx2Q_20pattern_type_symbols3fooWmRm0_m3b9ac9ff_EB2_` cannot be demangled
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_symbol_mangling::symbol_name_provider
      [... omitted 3 frames ...]
   3: <rustc_middle::mir::mono::MonoItem>::symbol_name
   4: <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::partitioning::assert_symbols_are_distinct<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>>::{closure#0}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<(&rustc_middle::mir::mono::MonoItem, rustc_middle::ty::SymbolName), <alloc::vec::Vec<(&rustc_middle::mir::mono::MonoItem, rustc_middle::ty::SymbolName)>>::extend_trusted<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::partitioning::assert_symbols_are_distinct<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>>::{closure#0}>>::{closure#0}>::{closure#0}>
   5: <alloc::vec::Vec<(&rustc_middle::mir::mono::MonoItem, rustc_middle::ty::SymbolName)> as alloc::vec::spec_from_iter::SpecFromIter<(&rustc_middle::mir::mono::MonoItem, rustc_middle::ty::SymbolName), core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::partitioning::assert_symbols_are_distinct<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>>::{closure#0}>>>::from_iter
   6: rustc_monomorphize::partitioning::assert_symbols_are_distinct::<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>>
   7: <rustc_session::session::Session>::time::<(&[rustc_middle::mir::mono::CodegenUnit], ()), rustc_monomorphize::partitioning::collect_and_partition_mono_items::{closure#0}>
   8: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 3 frames ...]
   9: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
      [... omitted 3 frames ...]
  10: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  11: rustc_metadata::rmeta::encoder::encode_metadata
  12: rustc_metadata::fs::encode_and_write_metadata
  13: rustc_interface::passes::start_codegen
  14: <rustc_interface::queries::Linker>::codegen_and_build_linker
  15: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  16: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  17: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  18: <alloc::boxed::Box<dyn for<'a> core::ops::function::FnOnce<(&'a rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &'a std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena<'a>>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option<rustc_interface::queries::Linker>>> as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once
  19: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  20: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  21: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: rustc 1.89.0-nightly (84e9b789c 2025-06-12) running on aarch64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -C debug-assertions=no -C prefer-dynamic -C rpath -C debuginfo=0 -C symbol-mangling-version=v0 -C opt-level=0 --crate-type lib

query stack during panic:
#0 [symbol_name] computing the symbol for `foo::<(u32) is ValTree(Leaf(0x00000000): u32)..=ValTree(Leaf(0x3b9ac9ff): u32)>`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
#2 [exported_symbols] collecting exported symbols for crate `0`
end of query stack
------------------------------------------



// HACK: Represent as tuple until we have something better.
// HACK: constants are used in arrays, even if the types don't match.
self.push("T");
self.push("W");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the v0 mangling docs to incorporate the new manglings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants