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

[rustc panic:ed] associated constant #48081

Closed
niklasad1 opened this issue Feb 8, 2018 · 4 comments · Fixed by #46882
Closed

[rustc panic:ed] associated constant #48081

niklasad1 opened this issue Feb 8, 2018 · 4 comments · Fixed by #46882
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@niklasad1
Copy link

Summary

I tried the following snippet:

                self.dest.map_or_else(
                    || {
                        debug!("Called write_block() with no data");
                        false
                    },
                    |dest| {
                        let index = self.write_index.get();
                        let more = index + AES128::BLOCK_SIZE <= self.stop_index.get();
                        if !more {
                            return false;
                        }
                        let regs: &mut AesRegisters = unsafe { mem::transmute(self.registers) };
                        for i in 0..4 {
                            let mut v = dest[index + (i * 4) + 0] as usize;
                            v |= (dest[index + (i * 4) + 1] as usize) << 8;
                            v |= (dest[index + (i * 4) + 2] as usize) << 16;
                            v |= (dest[index + (i * 4) + 3] as usize) << 24;
                            regs.idata.set(v as u32);
                        }
                        self.write_index.set(index + AES128::BLOCK_SIZE);

                        let more =
                            self.write_index.get() + AES128::BLOCK_SIZE <= self.stop_index.get();
                        more
                    },
                )

Expected

Not a compiler crash

Outcome

error[E0283]: type annotations required: cannot resolve `_: kernel::hil::symmetric_encryption::AES128<'_>`
   --> /home/niklasad1/tock/chips/sam4l/src/aes.rs:211:44
    |
211 |                         let more = index + AES128::BLOCK_SIZE <= self.stop_index.get();
    |                                            ^^^^^^^^^^^^^^^^^^
    |
    = note: required by `kernel::hil::symmetric_encryption::AES128::BLOCK_SIZE`

error: internal compiler error: /checkout/src/librustc/traits/trans/mod.rs:62: Encountered ambiguity selecting `Binder(<[type error] as kernel::hil::symmetric_encryption::AES128>)` during trans, presuming due to overflow

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.24.0-nightly (8e7a609e6 2018-01-04) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:504:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Backtrace

stack backtrace:
   0:     0x7fa41ef5bbfb - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h91d1666c6327d52b
                               at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7fa41ef6a7be - std::sys_common::backtrace::print::h66e8f3310af6a54c
                               at /checkout/src/libstd/sys_common/backtrace.rs:68
                               at /checkout/src/libstd/sys_common/backtrace.rs:57
   2:     0x7fa41ef47680 - std::panicking::default_hook::{{closure}}::h7a402dd600c5b3cc
                               at /checkout/src/libstd/panicking.rs:381
   3:     0x7fa41ef47143 - std::panicking::default_hook::hc7cfa94336f822ac
                               at /checkout/src/libstd/panicking.rs:391
   4:     0x7fa41ef47acb - std::panicking::rust_panic_with_hook::h7bb2af2582fdefca
                               at /checkout/src/libstd/panicking.rs:577
   5:     0x7fa4198f0d47 - std::panicking::begin_panic::h050149da9cc7f772
   6:     0x7fa41990b681 - rustc_errors::Handler::bug::hfa625afa9f723db3
   7:     0x7fa41acd9eff - <std::thread::local::LocalKey<T>>::with::h543ce26cfb6f50bf
   8:     0x7fa41b0c864e - rustc::ty::context::tls::with_opt::h6878b003f8522a9e
   9:     0x7fa41ac0abd7 - rustc::session::opt_span_bug_fmt::hc8994976b9fd9c44
  10:     0x7fa41ac0aae6 - rustc::session::bug_fmt::ha9ee1b22a61f2e60
  11:     0x7fa41ace3ff4 - <std::thread::local::LocalKey<T>>::with::hc56362f2e196171c
  12:     0x7fa41aacf9f8 - rustc::ty::context::GlobalCtxt::enter_local::ha46ec5fc488a532a
  13:     0x7fa41b0711d7 - rustc::traits::trans::trans_fulfill_obligation::h36d04a4b73b138da
  14:     0x7fa41af73551 - rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::compute_result::h3a5709afd05411f6
  15:     0x7fa41aeaa80b - rustc::dep_graph::graph::DepGraph::with_task_impl::h3594064c92f10ee3
  16:     0x7fa41ab94e1f - rustc_errors::Handler::track_diagnostics::h212e44cb9f6613a7
  17:     0x7fa41aab7a40 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::hdb86a4c730046d0c
  18:     0x7fa41af735f4 - rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::force::h280621a9d1094134
  19:     0x7fa41af74178 - rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::try_get::h36d73c6793bed8fd
  20:     0x7fa41ad78d88 - rustc::ty::maps::TyCtxtAt::trans_fulfill_obligation::h3b01c51eba8ba696
  21:     0x7fa41af1456f - rustc::ty::instance::Instance::resolve::ha42785737c9d07b1
  22:     0x7fa41b8a0bf5 - rustc_const_eval::eval::lookup_const_by_id::h235481ee0dad229a
  23:     0x7fa41be46fae - rustc_mir::interpret::const_eval::const_eval_provider::he61ff6eb78749b4c
  24:     0x7fa41af52911 - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::compute_result::hd372dc799ddc81ba
  25:     0x7fa41aebdedb - rustc::dep_graph::graph::DepGraph::with_task_impl::h7d18d69d2b29c6ea
  26:     0x7fa41abaf2cf - rustc_errors::Handler::track_diagnostics::ha705e0db47c7e786
  27:     0x7fa41aabe750 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::hf369de754f658497
  28:     0x7fa41af529ab - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force::hfe662e34cd1da2c1
  29:     0x7fa41af534c5 - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get::h6b701d0550a2baf8
  30:     0x7fa41ad77858 - rustc::ty::maps::TyCtxtAt::const_eval::h55d029a49f1964dd
  31:     0x7fa41b8a209b - rustc_const_eval::eval::eval_const_expr_partial::hba9bae625532d936
  32:     0x7fa41b8a0c9b - rustc_const_eval::eval::ConstContext::eval::h88555953a4be0435
  33:     0x7fa41be4725d - rustc_mir::interpret::const_eval::const_eval_provider::he61ff6eb78749b4c
  34:     0x7fa41af52911 - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::compute_result::hd372dc799ddc81ba
  35:     0x7fa41aebdedb - rustc::dep_graph::graph::DepGraph::with_task_impl::h7d18d69d2b29c6ea
  36:     0x7fa41abaf2cf - rustc_errors::Handler::track_diagnostics::ha705e0db47c7e786
  37:     0x7fa41aabe750 - rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check::hf369de754f658497
  38:     0x7fa41af529ab - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force::hfe662e34cd1da2c1
  39:     0x7fa41af534c5 - rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get::h6b701d0550a2baf8
  40:     0x7fa41ad77858 - rustc::ty::maps::TyCtxtAt::const_eval::h55d029a49f1964dd
  41:     0x7fa41af016f2 - <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const::h367c7dcc2822faf4
  42:     0x7fa41ac35469 - rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with::hbbcbd16bc6f9410d
  43:     0x7fa41af00d79 - <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty::he448e45aef860a24
  44:     0x7fa41d55af9f - rustc::traits::project::normalize::h1a189fdb64aef9cc
  45:     0x7fa41d468e2c - rustc::infer::InferCtxt::partially_normalize_associated_types_in::h66d802a5e340389e
  46:     0x7fa41d4b8f5a - <std::thread::local::LocalKey<T>>::with::h15b2117ec1c7d041
  47:     0x7fa41d45df74 - rustc::infer::InferCtxtBuilder::enter::hd970daac5fcaeb5c
  48:     0x7fa41d4d633c - rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor::check_item_type::h7c821f3c0df87f83
  49:     0x7fa41d4d7fec - <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'v>>::visit_item::h9ec08c5b3cd06f28
  50:     0x7fa41d5aa6bc - rustc::hir::Crate::visit_all_item_likes::h2ee6e7a157d04a3b
  51:     0x7fa41d5327e7 - rustc::session::Session::track_errors::h1f6a33d2e50a3c3c
  52:     0x7fa41d5803b5 - rustc_typeck::check_crate::hb09122b4ee79ea95
  53:     0x7fa41f389717 - <std::thread::local::LocalKey<T>>::with::hc6fb6087df81e9d2
  54:     0x7fa41f3871d6 - <std::thread::local::LocalKey<T>>::with::h836036c2a71f0071
  55:     0x7fa41f3de607 - rustc::ty::context::TyCtxt::create_and_enter::hb73d12258cf88a3c
  56:     0x7fa41f33ef3a - rustc_driver::driver::compile_input::h9deb377f84422e28
  57:     0x7fa41f3b4500 - rustc_driver::run_compiler::h7957e266f41bd133
  58:     0x7fa41f2f9af1 - std::sys_common::backtrace::__rust_begin_short_backtrace::hca871f110f764e5c
  59:     0x7fa41ef933ae - __rust_maybe_catch_panic
                               at /checkout/src/libpanic_unwind/lib.rs:101
  60:     0x7fa41f2d8972 - <F as alloc::boxed::FnBox<A>>::call_box::h21ccf4de9d93f71f
  61:     0x7fa41ef6d087 - std::sys_common::thread::start_thread::h95c8df0df264c758
                               at /checkout/src/liballoc/boxed.rs:827
                               at /checkout/src/libstd/sys_common/thread.rs:24
  62:     0x7fa41ef71498 - std::sys::unix::thread::Thread::new::thread_start::hc1ac9245a2c79957
                               at /checkout/src/libstd/sys/unix/thread.rs:90
  63:     0x7fa418e357fb - start_thread
  64:     0x7fa41ec31b5e - clone
  65:                0x0 - <unknown>

Thanks

@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 8, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2018

From just that snippet this is very hard to reproduce. Do you have a repository where I can try that out?

@eddyb
Copy link
Member

eddyb commented Feb 9, 2018

@oli-obk Looks like AES128 is a trait, so this is about a post-error ICE when using Trait::CONST when it's ambiguous and T::CONST (or <T as Trait>::CONST) should be used instead.

@niklasad1
Copy link
Author

@eddyb that is correct, it seem not be sufficient with only one error it seems like there must a dependency or a cycle to trigger this.

@oli-obk
You can get the commit here but you might need a couple of dependencies installed in order compile it

If it doesn't work please check Getting_Started.md

Then just in the root folder:

$ make allboards

@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2018

I can confirm that #46882 fixes this issue (maybe even a newer nightly (than 5th January) fixes it and it's not #46882, but after that PR it's definitely fixed):

error[E0283]: type annotations required: cannot resolve `_: kernel::hil::symmetric_encryption::AES128<'_>`
   --> src/aes.rs:162:22
    |
162 |             sublen % AES128::BLOCK_SIZE == 0 && {
    |                      ^^^^^^^^^^^^^^^^^^
    |
    = note: required by `kernel::hil::symmetric_encryption::AES128::BLOCK_SIZE`

error: aborting due to previous error

bors added a commit that referenced this issue Mar 7, 2018
Replace all const evaluation with miri

* error reporting in constants prints a stacktrace through all called const fns
* Trivial constant propagation and folding in MIR (always active, irrelevant of the optimization level)
* can now use floating constants in patterns (previously only floating point literals were allowed)
    * the future compat lint is still produced for both cases
* can index into constant arrays during const eval (previously feature gated)
* can create a constant union value with field `a` and read from field `b`
* can dereference references into constants
* can create references inside constants (`const X: &u32 = &22`)
* Tuple struct constructors can be used in constants
* regression in const eval errors spans (some of these need improvements in mir debug info)
* can cast floats to ints and vice versa (in constants, and even nan/inf constants)
* Mir dump prints false/true instead of 0u8/1u8
* `1i8 >> [8][0]` does not lint about exceeding bitshifts anymore.
    * Needs const propagation across projections
* `foo[I]` produces a const eval lint if `foo: [T; N]` and `N < I`
    * Essentially all builtin panics produce lints if they can be statically proven to trigger at runtime. This is on a best effort basis, so there might be some complex cases that don't trigger. (The runtime panic stays there, irrelevant of whether the lint is produced or not)
* can use `union`s to implement `transmute` for `Copy` types in constants without a feature gate. With all the greatness and nasal demons that come with this.
* can convert integers to `&'static T` in constants (useful for embedded)

fixes #34997 (stack overflow with many constants)
fixes #25574 (deref byte strings in patterns)
fixes #27918 (broken mir ICE)
fixes #46114 (ICE on struct constructors in patterns)
fixes #37448 (`SomeStruct { foo } as SomeStruct`)
fixes #43754 (`return` in const fn)
fixes #41898 (tuple struct constructors)
fixes #31364 (infinite recursion with const fn, fixed by miri's recursion limit)
closes #29947 (const indexing stabilization)
fixes #45044 (pattern matching repeat expressions)
fixes #47971 (ICE on const fn + references)
fixes #48081 (ICE on cyclic assoc const error)
fixes #48746 (nonhelpful error message with unions)

r? @eddyb

even though 1k loc are added in tests, this PR reduces the loc in this repository by 700
bors added a commit that referenced this issue Mar 8, 2018
Replace all const evaluation with miri

* error reporting in constants prints a stacktrace through all called const fns
* Trivial constant propagation and folding in MIR (always active, irrelevant of the optimization level)
* can now use floating constants in patterns (previously only floating point literals were allowed)
    * the future compat lint is still produced for both cases
* can index into constant arrays during const eval (previously feature gated)
* can create a constant union value with field `a` and read from field `b`
* can dereference references into constants
* can create references inside constants (`const X: &u32 = &22`)
* Tuple struct constructors can be used in constants
* regression in const eval errors spans (some of these need improvements in mir debug info)
* can cast floats to ints and vice versa (in constants, and even nan/inf constants)
* Mir dump prints false/true instead of 0u8/1u8
* `1i8 >> [8][0]` does not lint about exceeding bitshifts anymore.
    * Needs const propagation across projections
* `foo[I]` produces a const eval lint if `foo: [T; N]` and `N < I`
    * Essentially all builtin panics produce lints if they can be statically proven to trigger at runtime. This is on a best effort basis, so there might be some complex cases that don't trigger. (The runtime panic stays there, irrelevant of whether the lint is produced or not)
* can use `union`s to implement `transmute` for `Copy` types in constants without a feature gate. With all the greatness and nasal demons that come with this.
* can convert integers to `&'static T` in constants (useful for embedded)

fixes #34997 (stack overflow with many constants)
fixes #25574 (deref byte strings in patterns)
fixes #27918 (broken mir ICE)
fixes #46114 (ICE on struct constructors in patterns)
fixes #37448 (`SomeStruct { foo } as SomeStruct`)
fixes #43754 (`return` in const fn)
fixes #41898 (tuple struct constructors)
fixes #31364 (infinite recursion with const fn, fixed by miri's recursion limit)
closes #29947 (const indexing stabilization)
fixes #45044 (pattern matching repeat expressions)
fixes #47971 (ICE on const fn + references)
fixes #48081 (ICE on cyclic assoc const error)
fixes #48746 (nonhelpful error message with unions)

r? @eddyb

even though 1k loc are added in tests, this PR reduces the loc in this repository by 700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants