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 with associated constant #58435

Closed
etwyniel opened this issue Feb 13, 2019 · 7 comments
Closed

Compiler panic with associated constant #58435

etwyniel opened this issue Feb 13, 2019 · 7 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@etwyniel
Copy link

The compiler panics when I use a generic associated constant from within the impl.

I was able to reproduce it with this code:

struct S<T>(T);

impl<T> S<T> {
    const ID: fn(&S<T>) -> &S<T> = |s| s;
    pub fn id(&self) -> &Self {
        Self::ID(self)
    }
}

fn main() {
    let s = S(10u32);
    assert!(S::<u32>::ID(&s).0 == 10); // Works fine
    assert!(s.id().0 == 10); // Causes compiler to panic
}

Meta

rustc --version --verbose:

rustc 1.32.0 (9fda7c2 2019-01-16)
binary: rustc
commit-hash: 9fda7c2
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0

Backtrace:

thread 'main' panicked at 'assertion failed: !value.needs_subst()', src/librustc/traits/query/normalize_erasing_regions.rs:69:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc::traits::query::normalize_erasing_regions::<impl rustc::ty::context::TyCtxt<'cx, 'tcx, 'tcx>>::normalize_erasing_late_bound_regions
   8: rustc::ty::instance::Instance::resolve_closure
   9: rustc_mir::interpret::cast::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::cast
  10: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
  11: rustc_mir::const_eval::eval_body_using_ecx
  12: rustc_mir::const_eval::const_eval_raw_provider
  13: rustc::ty::query::__query_compute::const_eval_raw
  14: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval_raw<'tcx>>::compute
  15: rustc::dep_graph::graph::DepGraph::with_task_impl
  16: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  17: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  19: rustc::ty::query::TyCtxtAt::const_eval_raw
  20: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_eval_raw
  21: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_value_to_op
  22: rustc_mir::const_eval::const_to_op
  23: rustc_mir::transform::const_prop::ConstPropagator::eval_constant
  24: <rustc_mir::transform::const_prop::ConstPropagator<'b, 'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
  25: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  26: rustc_mir::transform::run_passes::{{closure}}
  27: rustc_mir::transform::run_passes
  28: rustc_mir::transform::optimized_mir
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::optimized_mir<'tcx>>::compute
  30: rustc::dep_graph::graph::DepGraph::with_task_impl
  31: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
  34: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir
  35: rustc_mir::monomorphize::collector::collect_items_rec
  36: rustc_mir::monomorphize::collector::collect_items_rec
  37: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  38: rustc::util::common::time
  39: rustc_mir::monomorphize::collector::collect_crate_mono_items
  40: rustc::util::common::time
  41: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  42: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
  44: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  47: rustc_codegen_ssa::base::codegen_crate
  48: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  49: rustc::util::common::time
  50: rustc_driver::driver::phase_4_codegen
  51: rustc_driver::driver::compile_input::{{closure}}
  52: rustc::ty::context::tls::enter_context
  53: <std::thread::local::LocalKey<T>>::with
  54: rustc::ty::context::TyCtxt::create_and_enter
  55: rustc_driver::driver::compile_input
  56: rustc_driver::run_compiler_with_pool
  57: <scoped_tls::ScopedKey<T>>::set
  58: rustc_driver::run_compiler
  59: rustc_driver::monitor::{{closure}}
  60: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  61: rustc_driver::run
  62: rustc_driver::main
  63: std::rt::lang_start::{{closure}}
  64: std::panicking::try::do_call
             at src/libstd/rt.rs:59
             at src/libstd/panicking.rs:310
  65: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  66: std::rt::lang_start_internal
             at src/libstd/panicking.rs:289
             at src/libstd/panic.rs:398
             at src/libstd/rt.rs:58
  67: main
  68: __libc_start_main
  69: <unknown>
query stack during panic:
#0 [const_eval_raw] const-evaluating `<S<T>>::ID`
 --> associated_generic.rs:6:9
  |
6 |         Self::ID(self)
  |         ^^^^^^^^^^^^^^
#1 [optimized_mir] processing `<S<T>>::id`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.32.0 (9fda7c223 2019-01-16) running on x86_64-unknown-linux-gnu

@jonas-schievink jonas-schievink added 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. C-bug Category: This is a bug. labels Feb 13, 2019
@estebank estebank added the A-associated-items Area: Associated items (types, constants & functions) label Feb 13, 2019
@Centril Centril added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Feb 13, 2019
@Centril
Copy link
Contributor

Centril commented Feb 13, 2019

This is broken on stable and beta but works on nightly. Reduced:

struct _S<T>(T);

impl<T> _S<T> {
    const _ID: fn(_S<T>) = |_| {};

    pub fn _id(self) {
        _S::<T>::_ID(self)
    }
}

fn _foo() {
    _S(())._id();
}

Might be worth beta-backporting whatever we did to fix it on nightly?

@hellow554
Copy link
Contributor

Bug was fixed between 01f8e25...bf669d1 (nightly-2019-01-24 and 01-25)

@pnkfelix pnkfelix added the P-high High priority label Feb 14, 2019
@pnkfelix
Copy link
Member

triage: assigning to self to attempt to identify backport.

@pnkfelix pnkfelix self-assigned this Feb 21, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2019

01f8e25...bf669d1

The bors merges in this range were:

% git log 01f8e25...bf669d1 --author bors --format=oneline

@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2019

Initial guesses as to which PR(s) in list above seem most relevant: #57606 ...

(That's assuming that the const-eval bit in the stack trace is the most relevant clue as to the cause of the ICE.) all the others don't seem to touch const-eval.

@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2019

But, wait, what am I doing here...

at this point enough time has passed that the current beta is able to handle the example without ICE'ing.

This bug does not seem worthy of attempting a backport all the way to stable.

(In other words, the time to attempt a backport would have been prior to when the beta-next was cut from the nightly, which was around a week ago.)

@pnkfelix pnkfelix closed this as completed Mar 4, 2019
@pnkfelix pnkfelix reopened this Mar 4, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2019

Oh wait, lets at least add a regression test

@pnkfelix pnkfelix added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-nominated labels Mar 4, 2019
pnkfelix added a commit to pnkfelix/rust that referenced this issue Mar 4, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 8, 2019
bors added a commit that referenced this issue Mar 9, 2019
Rollup of 24 pull requests

Successful merges:

 - #58080 (Add FreeBSD armv6 and armv7 targets)
 - #58204 (On return type `impl Trait` for block with no expr point at last semi)
 - #58269 (Add librustc and libsyntax to rust-src distribution.)
 - #58369 (Make the Entry API of HashMap<K, V> Sync and Send)
 - #58861 (Expand where negative supertrait specific error is shown)
 - #58877 (Suggest removal of `&` when borrowing macro and appropriate)
 - #58883 (Suggest appropriate code for unused field when destructuring pattern)
 - #58891 (Remove stray ` in the docs for the FromIterator implementation for Option)
 - #58893 (race condition in thread local storage example)
 - #58906 (Monomorphize generator field types for debuginfo)
 - #58911 (Regression test for #58435.)
 - #58912 (Regression test for #58813)
 - #58916 (Fix release note problems noticed after merging.)
 - #58918 (Regression test added for an async ICE.)
 - #58921 (Add an explicit test for issue #50582)
 - #58926 (Make the lifetime parameters of tcx consistent.)
 - #58931 (Elide invalid method receiver error when it contains TyErr)
 - #58940 (Remove JSBackend from config.toml)
 - #58950 (Add self to mailmap)
 - #58961 (On incorrect cfg literal/identifier, point at the right span)
 - #58963 (libstd: implement Error::source for io::Error)
 - #58970 (delay_span_bug in wfcheck's ty.lift_to_tcx unwrap)
 - #58984 (Teach `-Z treat-err-as-bug` to take a number of errors to emit)
 - #59007 (Add a test for invalid const arguments)

Failed merges:

 - #58959 (Add release notes for PR #56243)

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority 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

6 participants