Skip to content

ICE in region_inference/mod.rs #21750

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

Closed
apasel422 opened this issue Jan 29, 2015 · 10 comments · Fixed by #22785
Closed

ICE in region_inference/mod.rs #21750

apasel422 opened this issue Jan 29, 2015 · 10 comments · Fixed by #22785
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@apasel422
Copy link
Contributor

Attempting to compile https://github.com/reem/rust-traverse with cargo 0.0.1-pre-nightly (453ae9f 2015-01-29 00:56:56 +0000) and rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000) yields the following ICE:

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/middle/infer/region_inference/mod.rs:1015

stack backtrace:
   1:     0x7f8da355a880 - sys::backtrace::write::h471f2f26c91df096Q8t
   2:     0x7f8da357df80 - failure::on_fail::h389257f46ebc50afikB
   3:     0x7f8da34ea220 - rt::unwind::begin_unwind_inner::haa1ac937607e9179jZA
   4:     0x7f8da34ead50 - rt::unwind::begin_unwind_fmt::ha84452bff441c4ffPXA
   5:     0x7f8da357dde0 - rust_begin_unwind
   6:     0x7f8da35c6ef0 - panicking::panic_fmt::ha791a233597f33dbBRv
   7:     0x7f8da35cf5c0 - panicking::panic_bounds_check::h7964adf489703576CQv
   8:     0x7f8da16d6ce0 - middle::infer::region_inference::RegionVarBindings<'a, 'tcx>::infer_variable_values::hdb795f883c676391mJw
   9:     0x7f8da16d6970 - middle::infer::region_inference::RegionVarBindings<'a, 'tcx>::resolve_regions::h2570f98c1810a795Ymw
  10:     0x7f8da16fc020 - middle::infer::InferCtxt<'a, 'tcx>::resolve_regions_and_report_errors::ha6a986062307cc873YA
  11:     0x7f8da2cc9b70 - check::compare_method::compare_impl_method::h33ae495a649fd66cIgk
  12:     0x7f8da2cd21a0 - check::check_item::hf11061a9881d4ad88ll
  13:     0x7f8da2cd87f0 - visit::walk_item::h17525548578187088888
  14:     0x7f8da2cd87f0 - visit::walk_item::h17525548578187088888
  15:     0x7f8da2da1ee0 - check_crate::closure.32081
  16:     0x7f8da2d9c9c0 - check_crate::he229bdeb8fdc745cDNy
  17:     0x7f8da3ae5d80 - driver::phase_3_run_analysis_passes::h2272be7454e1eb80NFa
  18:     0x7f8da3acd130 - driver::compile_input::hb694f278d4428f99Bba
  19:     0x7f8da3b91940 - run_compiler::hc3e25a8f6c4a1b50n9b
  20:     0x7f8da3b90050 - thunk::F.Invoke<A, R>::invoke::h8035325489603501466
  21:     0x7f8da3b8efb0 - rt::unwind::try::try_fn::h9312387582241745294
  22:     0x7f8da35e9320 - rust_try_inner
  23:     0x7f8da35e9310 - rust_try
  24:     0x7f8da3b8f260 - thunk::F.Invoke<A, R>::invoke::h8464768559817507673
  25:     0x7f8da356a770 - sys::thread::thread_start::he52b8673a3629881W3w
  26:     0x7f8d9d767fe0 - start_thread
  27:     0x7f8da316c859 - __clone
  28:                0x0 - <unknown>
@renato-zannon
Copy link
Contributor

Reduced test case:

pub trait Arg<A> { }

pub trait Traversal {
    type Item;
    fn foreach<F: Arg<Self::Item>>(F);
}

impl<'a> Traversal for i32 {
    type Item = &'a i32;
    fn foreach<F: Arg<&'a i32>>(f: F) { }
}

fn main() {}

Still ICEs with rustc 1.0.0-dev (3d6f5100a 2015-01-29 11:28:30 +0000)

The ICE goes away if the Item on the impl is changed to a bare i32 instead of a reference.

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 29, 2015
@msiemens
Copy link
Contributor

Slightly different test case:

pub trait Traversal {
    type Item;

    fn foreach<F>(self, F) where F: FnMut(Self::Item);
}

impl<'a, T> Traversal for &'a [T] {
    type Item = &'a T;

    fn foreach<F>(self, mut f: F) where F: FnMut(&'a T) {
        //
    }
}

EDIT: Nevermind, it's the same but uses a closure instead of the more general Arg<A>.

@renato-zannon
Copy link
Contributor

I have bisected this issue to c61d788 (from #21019)

@edwardw
Copy link
Contributor

edwardw commented Feb 1, 2015

A workaround would be simply:

impl<'a> Traversal for i32 {
    ...
    fn foreach<F>(f: F) { }
}

@renato-zannon
Copy link
Contributor

@edwardw This doesn't help much if you need to call methods that are on the Arg trait (which was FnMut on the original code).

@nikomatsakis
Copy link
Contributor

cc me

@nikomatsakis nikomatsakis added the A-associated-items Area: Associated items (types, constants & functions) label Feb 4, 2015
@Gankra
Copy link
Contributor

Gankra commented Feb 4, 2015

This is blocking collect-rs from compiling.

@edwardw
Copy link
Contributor

edwardw commented Feb 5, 2015

This is interesting. The culprit is compare_method.rs#L251-L264: it registers obligations from implementation's methods into an hybrid parameter environment which has trait's methods in it. In the example given in this issue, when the associate type is projected out, the implementation's method acquires an extra lifetime variable. The trait's method doesn't have it so the lifetime resolution fails in an ICE later on.

I'm not sure how to fix that though.

@edwardw
Copy link
Contributor

edwardw commented Feb 11, 2015

This compiles so at first glance it looks like a viable workaround:

impl<'a> Traversal for i32 {
    type Item = &'a i32;
    fn foreach<F: Arg<<Self as Traversal>::Item>>(f: F) { }
}

But if one tries to really use f as an Arg, compiler panics on an assertion failure:

pub trait Arg<A> {
    fn arg(&self);
}

pub trait Traversal {
    type Item;
    fn foreach<F: Arg<Self::Item>>(F);
}

impl<'a> Traversal for i32 {
    type Item = &'a i32;
    fn foreach<F: Arg<<Self as Traversal>::Item>>(f: F) {
        f.arg();
    }
}

edwardw added a commit to edwardw/rust that referenced this issue Feb 22, 2015
Otherwise, the substitution is carried out from outside perspective,
which would be against the very purpose of `ParameterEnvironment`.

Closes rust-lang#21750
Closes rust-lang#22077
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 25, 2015
…ion-with-regions, r=pnkfelix

 Two changes:

1. Make traits with assoc types invariant w/r/t their inputs.
2. Fully normalize parameter environments, including any region variables (which were being overlooked).

The former supports the latter, but also just seems like a reasonably good idea.

Fixes rust-lang#21750

cc @edwardw
r? @pnkfelix
@leahcornelius
Copy link

leahcornelius commented Mar 28, 2020

Getting this with some hashing code.

fn hash_item(&self) -> String {
        println!("Start hash");
        let bytes = self.bytes();
        println!("BYTES: {:?}", bytes);
        let lyra2res = sum(bytes.clone());
        println!(
            "lyra2 finished: {}",
            bs58::encode(lyra2res.clone()).into_string()
        );
        let mut sk: u64 = 0;
        for byte in bytes.iter() {
            sk += *byte as u64;
        }

        let password = lyra2res;
        let salt = sk.to_string();
        let config = Config {
            variant: Variant::Argon2id,
            version: Version::Version13,
            mem_cost: 65536,
            time_cost: 5,
            lanes: 4,
            thread_mode: ThreadMode::Parallel,
            secret: &[],
            ad: &[],
            hash_length: 32,
        };
        println!("Starting argon");
        let hash: String = bs58::encode(
            argon2::hash_encoded(&password, salt.as_bytes(), &config)
                .unwrap_or("".to_string())
                .as_bytes(),
        )
        .into_string();
        return hash;
    }

will output something along the lines of:
Start hash
BYTES: [69, 84, 87, 87, 100, 57, 118, 102, 80, 97, 122, 56, 100, 116, 80, 82, 74, 78, 104, 116, 109, 51, 88, 54, 56, 98, 56, 97, 66, 119, 105, 116, 90, 114, 50, 83, 107, 99, 51, 52, 89, 121, 121, 112, 86, 116, 57, 66, 120, 87, 86, 112, 88, 55, 66, 49, 76, 90, 86, 48, 49, 53, 56, 53, 52, 48, 56, 56, 49, 53, 54, 48, 51]
lyra2 finished: CfV9jehQVXsVnx6Vrg5f9VgHVkWeatbrFGxKVz2knfEc
Starting argon

thread 'certificate::tests::check_cert_diff' panicked at 'index out of bounds: the len is 0 but the index is 31', /rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa/src/libcore/slice/mod.rs:2842:10

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) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
8 participants