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

ICE on use on a macro-generated macro from an external crate/doctest #91156

Open
kepexx opened this issue Nov 23, 2021 · 2 comments
Open

ICE on use on a macro-generated macro from an external crate/doctest #91156

kepexx opened this issue Nov 23, 2021 · 2 comments
Labels
C-bug Category: This is a bug. F-adt_const_params `#![feature(adt_const_params)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kepexx
Copy link

kepexx commented Nov 23, 2021

Code

I tried to minimize the code by removing everything except the module containing the offending macro, but it didn't ICE, not sure what to do, so here is my entire code: https://github.com/oxidash/oxibase/tree/ice

ICE occurs on running doctests via cargo test (or cargo test --doc), but also works if you create a separate crate which depends on the above crate and do use oxibase::change_cc;

The specific doctests are in src/callconv/mod.rs on change_cc and select_cc

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (936f2600b 2021-11-22)
binary: rustc
commit-hash: 936f2600b6c903b04387f74ed5cbce88bb06d243
commit-date: 2021-11-22
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

Both tests fail because they can't compile the doctest, as they get an ICE:

---- src/callconv/mod.rs - callconv::change_cc (line 117) stdout ----
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/compiler/rustc_middle/src/mir/interpret/mod.rs:282:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.58.0-nightly (936f2600b 2021-11-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C embed-bitcode=no --crate-type bin

query stack during panic:
#0 [exported_symbols] exported_symbols
#1 [upstream_monomorphizations] collecting available upstream monomorphizations
end of query stack
Couldn't compile the test.
---- src/callconv/mod.rs - callconv::select_cc (line 143) stdout ----
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/compiler/rustc_middle/src/mir/interpret/mod.rs:282:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.58.0-nightly (936f2600b 2021-11-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C embed-bitcode=no --crate-type bin

query stack during panic:
#0 [exported_symbols] exported_symbols
#1 [upstream_monomorphizations] collecting available upstream monomorphizations
end of query stack
Couldn't compile the test.

failures:
    src/callconv/mod.rs - callconv::change_cc (line 117)
    src/callconv/mod.rs - callconv::select_cc (line 143)

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/compiler/rustc_middle/src/mir/interpret/mod.rs:282:35
stack backtrace:
   0: rust_begin_unwind
             at /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_bounds_check
             at /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/library/core/src/panicking.rs:75:5
   3: <rustc_middle::mir::interpret::AllocDecodingSession>::decode_alloc_id::<rustc_metadata::rmeta::decoder::DecodeContext>
   4: <rustc_middle::mir::interpret::pointer::Pointer as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
   5: <rustc_middle::ty::consts::kind::ConstKind as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
   6: <smallvec::SmallVec<[rustc_middle::ty::subst::GenericArg; 8]> as core::iter::traits::collect::Extend<rustc_middle::ty::subst::GenericArg>>::extend::<core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode::{closure#0}>, alloc::string::String>>
   7: <core::result::Result<rustc_middle::ty::subst::GenericArg, alloc::string::String> as rustc_middle::ty::context::InternIteratorElement<rustc_middle::ty::subst::GenericArg, &rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>>>::intern_with::<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode::{closure#0}>, <rustc_middle::ty::context::TyCtxt>::mk_substs<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode::{closure#0}>>::{closure#0}>
   8: <rustc_middle::arena::Arena>::alloc_from_iter::<(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel), (), core::iter::adapters::map::Map<core::ops::range::Range<usize>, <rustc_metadata::rmeta::Lazy<[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)], usize>>::decode<(&rustc_metadata::creader::CrateMetadataRef, rustc_middle::ty::context::TyCtxt)>::{closure#0}>>
   9: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::exported_symbols
  10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>>
  11: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::exported_symbols, rustc_query_impl::plumbing::QueryCtxt>
  12: rustc_codegen_ssa::back::symbol_export::upstream_monomorphizations_provider
  13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::ArenaCache<(), std::collections::hash::map::HashMap<rustc_span::def_id::DefId, std::collections::hash::map::HashMap<&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>, rustc_span::def_id::CrateNum, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>>
  14: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::upstream_monomorphizations, rustc_query_impl::plumbing::QueryCtxt>
  15: rustc_codegen_ssa::back::symbol_export::upstream_monomorphizations_for_provider
  16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, core::option::Option<&std::collections::hash::map::HashMap<&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>, rustc_span::def_id::CrateNum, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>>>
  17: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::upstream_monomorphizations_for, rustc_query_impl::plumbing::QueryCtxt>
  18: <rustc_middle::ty::instance::Instance>::upstream_monomorphization
  19: rustc_monomorphize::collector::collect_neighbours
  20: rustc_monomorphize::collector::collect_items_rec
  21: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  22: rustc_monomorphize::collector::collect_crate_mono_items
  23: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  25: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  27: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  28: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  29: <rustc_interface::queries::Queries>::ongoing_codegen
  30: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  31: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  32: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  33: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@kepexx kepexx added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 23, 2021
@jyn514 jyn514 added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Nov 23, 2021
@kepexx
Copy link
Author

kepexx commented Nov 23, 2021

I believe this has to do with the usage of adt_const_params in the crate root, as commenting out the pub mod tests seems to fix it. I'll look more into it

@steffahn
Copy link
Member

steffahn commented Aug 28, 2022

Minimized:

#![feature(adt_const_params)]

#[derive(PartialEq, Eq)]
pub struct Ptr(*const ());

pub trait Trait {
    fn get_translate<const F: Ptr>() {}
}
impl Trait for () {}

pub trait WrapperFunc<const F: Ptr> {
    type CallConv;
}

fn f() {}

pub fn foo() {
    <()>::get_translate::<{ Ptr(f as *const ()) }>();
}

/// ```
/// use my_crate; // <- name of the crate
/// ```
pub struct Documented;
cargo +nightly-2021-11-23 test --doc
   Compiling my_crate v0.1.0 (…path…)
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(adt_const_params)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: `my_crate` (lib) generated 1 warning
    Finished test [unoptimized + debuginfo] target(s) in 0.15s
   Doc-tests my_crate
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> …path…/src/lib.rs:1:12
  |
1 | #![feature(adt_const_params)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: 1 warning emitted


running 1 test
test src/lib.rs - Documented (line 23) ... FAILED

failures:

---- src/lib.rs - Documented (line 23) stdout ----
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/936f2600b6c903b04387f74ed5cbce88bb06d243/compiler/rustc_middle/src/mir/interpret/mod.rs:282:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.58.0-nightly (936f2600b 2021-11-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C embed-bitcode=no --crate-type bin

query stack during panic:
#0 [exported_symbols] exported_symbols
#1 [upstream_monomorphizations] collecting available upstream monomorphizations
end of query stack
Couldn't compile the test.

failures:
    src/lib.rs - Documented (line 23)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass '--doc'

In later versions of Rust, this kind of code, where pointers appear in const generics, is forbidden.

@rustbot label -E-needs-mcve

@rustbot rustbot removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Aug 28, 2022
@Enselic Enselic added F-adt_const_params `#![feature(adt_const_params)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-adt_const_params `#![feature(adt_const_params)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants