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: "trans_argument: [....] invalid for pair argument" #50153

Closed
elinorbgr opened this issue Apr 22, 2018 · 6 comments
Closed

ICE: "trans_argument: [....] invalid for pair argument" #50153

elinorbgr opened this issue Apr 22, 2018 · 6 comments
Labels
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.

Comments

@elinorbgr
Copy link
Contributor

elinorbgr commented Apr 22, 2018

Edit: see my first answer for a real minimal repro


```rust
extern crate wayland_server;

use wayland_server::NewResource;
use wayland_server::protocol::wl_callback;

pub fn break(callback: NewResource<wl_callback::WlCallback>) {
    callback.implement(|e, _| match e {}, None::<fn(_,_)>);
}
```

using `wayland-server = "0.20.0"` as dependency, and compiled as a lib (otherwise the dead code elimination prevents the ICE to occur)

Possibly useful information: the arguments of the first closure are:

- `e`: an empty enum (never seen this ICE on the same pattern where this argument was a non-empty enum)
- second argument of type `wayland_server::Resource<I>` with this definition:

```rust
pub struct Resource<I: Interface> {
    _i: ::std::marker::PhantomData<*const I>,
    internal: Option<Arc<ResourceInternal>>,
    ptr: *mut wl_resource,
}
```

Causes this ICE on stable, beta, and nightly:

```
error: internal compiler error: librustc_trans/mir/block.rs:638: trans_argument: OperandRef(Immediate(({ i64*, i8* }:{ i64*, i8* } undef)) @ TyLayout { ty: wayland_server::Resource<wayland_server::protocol::wl_callback::WlCallback>, details: LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 0 }, Size { raw: 8 }], memory_index: [0, 1, 2] }, abi: ScalarPair(Scalar { value: Pointer, valid_range: 1..=0 }, Scalar { value: Pointer, valid_range: 0..=18446744073709551615 }), align: Align { abi: 3, pref: 3 }, size: Size { raw: 16 } } }) invalid for pair arugment

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::ty::context::tls::with_opt::{{closure}}
   9: <std::thread::local::LocalKey<T>>::try_with
  10: <std::thread::local::LocalKey<T>>::with
  11: rustc::ty::context::tls::with
  12: rustc::ty::context::tls::with_opt
  13: rustc::session::opt_span_bug_fmt
  14: rustc::session::bug_fmt
  15: rustc_trans::mir::block::<impl rustc_trans::mir::FunctionCx<'a, 'tcx>>::trans_argument
  16: rustc_trans::mir::block::<impl rustc_trans::mir::FunctionCx<'a, 'tcx>>::trans_terminator
  17: rustc_trans::mir::trans_mir
  18: rustc_trans::base::trans_instance
  19: rustc_trans::base::compile_codegen_unit
  20: rustc::dep_graph::graph::DepGraph::with_task_impl
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::force
  22: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
  23: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
  24: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
  25: rustc_trans::base::trans_crate
  26: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  27: rustc_driver::driver::phase_4_translate_to_llvm
  28: rustc_driver::driver::compile_input::{{closure}}
  29: rustc::ty::context::TyCtxt::create_and_enter
  30: rustc_driver::driver::compile_input
  31: rustc_driver::run_compiler
```
@elinorbgr
Copy link
Contributor Author

elinorbgr commented Apr 23, 2018

I managed to make a smaller example from my bug case, should be easier to work with as it is self contained:

pub struct Resource {
    internal: Box<u32>,
    ptr: Box<u32>,
}

pub trait Implementation<Meta, Msg> {
    fn receive(&mut self, msg: Msg, meta: Meta);
}

impl<Meta, Msg, F> Implementation<Meta, Msg> for F
where
    F: FnMut(Msg, Meta) + 'static,
{
    fn receive(&mut self, msg: Msg, meta: Meta) {
        (self)(msg, meta)
    }
}

pub fn create<A, B, Impl>(i: Impl) -> Box<Implementation<A, B>>
where
    Impl: Implementation<A, B> + 'static,
{
        Box::new(i)
}

pub enum Empty {}

pub fn lol() -> Box<Implementation<Resource, Empty>> {
    create(
        |_, _| {},
    )
}

playground link

@elinorbgr
Copy link
Contributor Author

Further minimized:

pub struct Resource {
    a: u8,
    b: u8,
}

pub fn create<A, B, Impl>(i: Impl) -> Box<FnMut(A, B)>
where
    Impl: FnMut(A, B) + 'static,
{
        Box::new(i)
}

pub enum Empty {}

pub fn lol() -> Box<FnMut(Resource, Empty)> {
    create(
        |_, _| {},
    )
}

@elinorbgr
Copy link
Contributor Author

Above example triggers an ICE on both Debug and Release, on Stable, Beta and Nightly

@pietroalbini pietroalbini 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 Apr 24, 2018
@eddyb
Copy link
Member

eddyb commented Apr 26, 2018

This will hopefully go away when #49298 is fixed.

@dotdash
Copy link
Contributor

dotdash commented Jan 17, 2019

The last two examples seem to work fine on the playground, is this fixed?

@jakubadamw
Copy link
Contributor

No longer ICEs.

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. 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.
Projects
None yet
Development

No branches or pull requests

6 participants