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

Compiler panic on programs using to_string() #27

Open
jberthold opened this issue Jan 16, 2025 · 1 comment
Open

Compiler panic on programs using to_string() #27

jberthold opened this issue Jan 16, 2025 · 1 comment
Assignees

Comments

@jberthold
Copy link
Member

When extracting smir json for a program that contains a call to `to_string()`, the `printer.rs` code crashes with
thread 'rustc' panicked at compiler/rustc_middle/src/ty/predicate.rs:533:9:
`<[core::fmt::rt::Argument<'_>] as std::marker::Sized>` has escaping bound vars, so it cannot be wrapped in a dummy binder.

Programs that exhibit this are tests/integration/failing/{defined-trait,std-to-string}.rs

The backtrace is here:

$ RUST_BACKTRACE=1 deps/smir_pretty/run.sh -Z no-codegen kmir/src/tests/integration/data/run-rs/strings-chars/std-to-string.rs 

thread 'rustc' panicked at compiler/rustc_middle/src/ty/predicate.rs:533:9:
`<[core::fmt::rt::Argument<'_>] as std::marker::Sized>` has escaping bound vars, so it cannot be wrapped in a dummy binder.
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_middle::ty::predicate::Predicate as rustc_type_ir::upcast::UpcastFrom<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::TraitRef<rustc_middle::ty::context::TyCtxt>>>::upcast_from
   3: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions
   4: rustc_ty_utils::common_traits::is_item_raw
      [... omitted 2 frames ...]
   5: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 1]>>>
   6: <rustc_middle::ty::Ty>::is_sized
   7: rustc_ty_utils::layout::layout_of
      [... omitted 2 frames ...]
   8: <rustc_middle::ty::layout::LayoutCx as rustc_middle::ty::layout::LayoutOf>::spanned_layout_of
   9: core::iter::adapters::try_process::<core::iter::adapters::by_ref_sized::ByRefSized<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}::{closure#0}>>, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>, core::result::Result<core::convert::Infallible, &rustc_middle::ty::layout::LayoutError>, <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}::{closure#0}> as core::iter::traits::iterator::Iterator>::try_collect<rustc_index::vec::IndexVec<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>>>::{closure#0}, rustc_index::vec::IndexVec<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>>>
  10: core::iter::adapters::try_process::<core::iter::adapters::by_ref_sized::ByRefSized<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}>>, rustc_index::vec::IndexVec<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>>, core::result::Result<core::convert::Infallible, &rustc_middle::ty::layout::LayoutError>, <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}> as core::iter::traits::iterator::Iterator>::try_collect<rustc_index::vec::IndexVec<rustc_abi::layout::ty::VariantIdx, rustc_index::vec::IndexVec<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>>>>::{closure#0}, rustc_index::vec::IndexVec<rustc_abi::layout::ty::VariantIdx, rustc_index::vec::IndexVec<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>>>>
  11: rustc_ty_utils::layout::layout_of
      [... omitted 2 frames ...]
  12: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>>
  13: <rustc_smir::rustc_smir::context::TablesWrapper as stable_mir::compiler_interface::Context>::ty_layout
  14: <stable_mir::ty::Ty>::layout
  15: smir_pretty::printer::collect_ty
             at ./deps/smir_pretty/src/printer.rs:477:65
  16: smir_pretty::printer::collect_vec_tys::{{closure}}
             at ./deps/smir_pretty/src/printer.rs:458:35
  17: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at ./deps/smir_pretty/deps/rust/src/library/core/src/iter/traits/iterator.rs:797:29
  18: <alloc::vec::into_iter::IntoIter<T,A> as core::iter::traits::iterator::Iterator>::fold
             at ./deps/smir_pretty/deps/rust/src/library/alloc/src/vec/into_iter.rs:318:25
  19: core::iter::traits::iterator::Iterator::for_each
             at ./deps/smir_pretty/deps/rust/src/library/core/src/iter/traits/iterator.rs:800:9
  20: smir_pretty::printer::collect_vec_tys
             at ./deps/smir_pretty/src/printer.rs:458:5
  21: smir_pretty::printer::collect_ty
             at ./deps/smir_pretty/src/printer.rs:494:17
  22: <smir_pretty::printer::InternedValueCollector as stable_mir::mir::visit::MirVisitor>::visit_ty
             at ./deps/smir_pretty/src/printer.rs:559:6
  23: stable_mir::mir::visit::MirVisitor::super_mir_const
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:381:9
  24: <smir_pretty::printer::InternedValueCollector as stable_mir::mir::visit::MirVisitor>::visit_mir_const
             at ./deps/smir_pretty/src/printer.rs:555:5
  25: stable_mir::mir::visit::MirVisitor::super_const_operand
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:376:9
  26: stable_mir::mir::visit::MirVisitor::visit_const_operand
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:112:9
  27: stable_mir::mir::visit::MirVisitor::super_operand
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:359:17
  28: stable_mir::mir::visit::MirVisitor::visit_operand
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:99:9
  29: stable_mir::mir::visit::MirVisitor::super_terminator
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:247:17
  30: <smir_pretty::printer::InternedValueCollector as stable_mir::mir::visit::MirVisitor>::visit_terminator
             at ./deps/smir_pretty/src/printer.rs:525:5
  31: stable_mir::mir::visit::MirVisitor::super_basic_block
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:172:9
  32: stable_mir::mir::visit::MirVisitor::visit_basic_block
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:48:9
  33: stable_mir::mir::visit::MirVisitor::super_body
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:146:13
  34: stable_mir::mir::visit::MirVisitor::visit_body
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/mir/visit.rs:44:9
  35: smir_pretty::printer::collect_interned_values
             at ./deps/smir_pretty/src/printer.rs:578:12
  36: smir_pretty::printer::emit_smir_internal
             at ./deps/smir_pretty/src/printer.rs:702:50
  37: smir_pretty::printer::emit_smir
             at ./deps/smir_pretty/src/printer.rs:748:9
  38: <smir_pretty::driver::StableMirCallbacks as rustc_driver_impl::Callbacks>::after_analysis::{{closure}}
             at ./deps/smir_pretty/src/driver.rs:41:45
  39: rustc_smir::rustc_internal::init::{{closure}}
             at ./deps/smir_pretty/deps/rust/src/compiler/rustc_smir/src/rustc_internal/mod.rs:196:33
  40: scoped_tls::ScopedKey<T>::set
             at /home/jost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9
  41: rustc_smir::rustc_internal::init
             at ./deps/smir_pretty/deps/rust/src/compiler/rustc_smir/src/rustc_internal/mod.rs:196:5
  42: rustc_smir::rustc_internal::run::{{closure}}
             at ./deps/smir_pretty/deps/rust/src/compiler/rustc_smir/src/rustc_internal/mod.rs:227:53
  43: stable_mir::compiler_interface::run::{{closure}}
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/compiler_interface.rs:265:40
  44: scoped_tls::ScopedKey<T>::set
             at /home/jost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9
  45: stable_mir::compiler_interface::run
             at ./deps/smir_pretty/deps/rust/src/compiler/stable_mir/src/compiler_interface.rs:265:9
  46: rustc_smir::rustc_internal::run
             at ./deps/smir_pretty/deps/rust/src/compiler/rustc_smir/src/rustc_internal/mod.rs:227:5
  47: <smir_pretty::driver::StableMirCallbacks as rustc_driver_impl::Callbacks>::after_analysis
             at ./deps/smir_pretty/src/driver.rs:41:17
  48: <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}>
  49: <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, &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}
  50: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  51: <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}, ()>
  52: 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}>

@jberthold
Copy link
Member Author

Also see Stephen's comment about this: #19 (comment)

@dkcumming dkcumming self-assigned this Jan 17, 2025
@dkcumming dkcumming linked a pull request Jan 21, 2025 that will close this issue
dkcumming added a commit that referenced this issue Jan 21, 2025
Creating the layout for a `Binder<DUMMY>` is creating panics, see
#27 for
details. This PR does not solve the problem but side steps it. There may
be other times that this will be needed unless we find a fix to get the
`Layout` without triggering the error.

---------

Co-authored-by: Jost Berthold <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants