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

Partial type hint breakage #12909

Closed
sfackler opened this issue Mar 15, 2014 · 7 comments · Fixed by #18036
Closed

Partial type hint breakage #12909

sfackler opened this issue Mar 15, 2014 · 7 comments · Fixed by #18036
Labels
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) ❄️

Comments

@sfackler
Copy link
Member

This is a minimal reproduction of something I saw when updating some of my projects to use Vec.

use std::vec_ng::Vec;

fn main() {
    let s = [1i, 2, 3];
    let v: Vec<_> = s.iter().collect();
}
test.rs:5:21: 5:39 error: cannot determine a type for this bounded type parameter: unconstrained type
test.rs:5     let v: Vec<_> = s.iter().collect();
                              ^~~~~~~~~~~~~~~~~~

This manifested in other ways in larger programs, ICEing in one case:

 ❯ env RUST_LOG=std::rt::backtrace make                                                                                          [rust-postgres/master *$=]
rustc -O --cfg ndebug -L submodules/rust-openssl/build/ -L submodules/rust-openssl/build/ -L submodules/rust-phf/build/ -L submodules/rust-phf/build/ -L submodules/rust-phf/build/ --dep-info build/postgres.d \
    --out-dir build src/lib.rs
src/lib.rs:612:17: 612:42 error: the type of this value must be known in this context
src/lib.rs:612                 PgUnknownType { oid, .. } =>
                               ^~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:622:19: 622:26 error: the type of this value must be known in this context
src/lib.rs:622             match desc.ty {
                                 ^~~~~~~
error: internal compiler error: no type for node 74135: local oid (id=74135) in fcx 0x7f639ffba890
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_LOG=std::rt::backtrace` for a backtrace
task 'rustc' failed at '~Any', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:123
stack backtrace:
   1:     0x7f63a9db6740 - rt::backtrace::imp::write::h584392c0aaf88f8agYb::v0.10.pre
   2:     0x7f63a9d1b370 - rt::unwind::begin_unwind_inner::h39118a123ff832cbUzb::v0.10.pre
   3:     0x7f63a80eac40 - <unknown>
   4:     0x7f63a80eb820 - diagnostic::Handler::bug::h3def07bec623c5d9q3b::v0.10.pre
   5:     0x7f63a5aa8580 - driver::session::Session_::bug::hc25e766e0c47b22fxyc::v0.10.pre
   6:     0x7f63a5cc2f70 - middle::typeck::check::FnCtxt::node_ty::h3bb3bf7881b4ddbc4W6::v0.10.pre
   7:     0x7f63a5ce35e0 - <unknown>
   8:     0x7f63a5cea980 - <unknown>
   9:     0x7f63a5cea980 - <unknown>
  10:     0x7f63a5cea3e0 - <unknown>
  11:     0x7f63a5ce8af0 - <unknown>
  12:     0x7f63a5cea220 - <unknown>
  13:     0x7f63a5ce8af0 - <unknown>
  14:     0x7f63a5ce8af0 - <unknown>
  15:     0x7f63a5cea220 - <unknown>
  16:     0x7f63a5ce8af0 - <unknown>
  17:     0x7f63a5ce8af0 - <unknown>
  18:     0x7f63a5ce8800 - <unknown>
  19:     0x7f63a5cea700 - <unknown>
  20:     0x7f63a5ced8b0 - middle::typeck::check::writeback::resolve_type_vars_in_fn::h60db597186ed5046Vs1::v0.10.pre
  21:     0x7f63a5d38ac0 - <unknown>
  22:     0x7f63a5d424e0 - <unknown>
  23:     0x7f63a5d33c20 - middle::typeck::check::check_item::h2dd1675c2d31364e1T5::v0.10.pre
  24:     0x7f63a5d38910 - middle::typeck::check::check_item_types::ha39a6b2247f5d06aaA5::v0.10.pre
  25:     0x7f63a5e32b70 - <unknown>
  26:     0x7f63a5e31870 - middle::typeck::check_crate::h1776a18a6977a78cZvr::v0.10.pre
  27:     0x7f63a6187f70 - driver::driver::phase_3_run_analysis_passes::hef56a7cb46a523e2WOa::v0.10.pre
  28:     0x7f63a618eb80 - driver::driver::compile_input::h692b87098ca31f542bb::v0.10.pre
  29:     0x7f63a61b2630 - run_compiler::h5fa6736bc743af23tNi::v0.10.pre
  30:     0x7f63a61c5380 - <unknown>
  31:     0x7f63a61c3cb0 - <unknown>
  32:     0x7f63a61bf6e0 - <unknown>
  33:     0x7f63a551d8c0 - <unknown>
  34:     0x7f63a9db0080 - <unknown>
  35:     0x7f63a9dbd1a0 - rust_try
  36:     0x7f63a9dafec0 - rt::task::Task::run::h413709669c303bc5s58::v0.10.pre
  37:     0x7f63a551d660 - <unknown>
  38:     0x7f63a9db37b0 - <unknown>
  39:     0x7f63a4a2afe0 - start_thread
  40:     0x7f63a522ace9 - clone
  41:                0x0 - <unknown>

This can be reproduced by taking sfackler/rust-postgres@c5abe8c and changing lines 592 and 598 of src/lib.rs to use partial type hints.

cc @Kimundi

@huonw
Copy link
Member

huonw commented Mar 15, 2014

Maybe partial type hints need feature gating.

@Kimundi
Copy link
Member

Kimundi commented Mar 15, 2014

I knew that feature was too easy to implement... Lets see if I can find the cause.

@Kimundi
Copy link
Member

Kimundi commented Mar 15, 2014

Well, I'm not sure how to fix this. This inference error implies to me that partial type hints actually don't work at all for the Vec<_> = .collect() case right now, and the existing tests didn't catch it because they inferred right from both sides.

According to @eddyb this is because the T in Vec<T> and FromIterator<T> don't have any direct constrain to be identical. (Which would be possible with HKT though)

While there is a impl<T> FromIterator<T> for Vec<T>, this link is apparently not currently considered, leading to the inference failure here.

cc @nikomatsakis

@sfackler
Copy link
Member Author

@alexcrichton Any idea why there are so many <unknown> stacks in the backtrace? Does a non--g build not contain enough debug info for libbacktrace to work off of?

@sfackler sfackler added the I-ICE label Mar 15, 2014
@thestinger
Copy link
Contributor

I expect that there would be other ways of hitting these same inference bugs.

@japaric
Copy link
Member

japaric commented Oct 14, 2014

This snippet is working on 0.12 and master:

use std::collections::HashMap;

fn main() {
    let s = [(1i, 1u), (2, 2), (3, 3)];
    let v: Vec<_> = s.iter().collect();
    let m: HashMap<_, _> = s.iter().map(|&x| x).collect();
}

I'm sure one of @nikomatsakis' PR that got merged in the last two months fixed inference from partial hints. Not sure which one though.

I think this should be closed. (Unless someone got another test case that fails to infer from partial hints)

@sfackler sfackler added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 14, 2014
@nikomatsakis
Copy link
Contributor

💃 I've been meaning to look into why this doesn't work. Happy to not have to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants