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

Type Checker getting confused with constraints + ICE #33904

Closed
CryZe opened this issue May 27, 2016 · 15 comments
Closed

Type Checker getting confused with constraints + ICE #33904

CryZe opened this issue May 27, 2016 · 15 comments

Comments

@CryZe
Copy link
Contributor

CryZe commented May 27, 2016

I've written the same code in 2 different crates. One compiles perfectly fine, the other doesn't. Apparently the constraints on the function merge(!!) with the constraints of the other function and the type checker is getting really confused and errors out. If you look at the code, the constrained type Q does not come in contact with convex_hull::create in any way, yet it influences it. Removing Q from the function lets convex_hull::create compile just fine.

Also the compiler is complaining about a type called convex_hull::Vector3, which doesn't exist, it's called Vec3. Vec3 is actually a reexport of Vector3 as Vec3, which then got reexported again (and I think again). So maybe somewhere the type checker got confused by that and now thinks it needs to look for a type called Vector3. Not sure if that's related to the problem at all though, just seems like maybe another small bug.

http://i.imgur.com/DdOIt9t.png

@eddyb
Copy link
Member

eddyb commented May 27, 2016

Looks like this is #30472.

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

It's not, it also gets confused if I remove the HRTB and add the lifetime
to the function's generics.

It's definitely related to the Deref and / or lifetimes though. Just requiring IntoIterator makes it work.

Also, convex_hull::create has the same signature, with the same constraints, so this isn't about the constraints themselves, as they work perfectly fine in other places. It's about this particular combination that confuses the compiler.

Am Freitag, 27. Mai 2016 schrieb Eduard-Mihai Burtescu :

Looks like this is #30472 #30472
.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#33904 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABYmbpGQXrpK79RHDJjVGNICwx67Nw5qks5qFwnngaJpZM4IoabF
.

@eddyb
Copy link
Member

eddyb commented May 27, 2016

@CryZe With associated types under HRTB, the compiler cannot tell that two identical-looking bounds are the same, or that they imply each-other. This has been a problem for as long as HRTB has existed.

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

http://puu.sh/p72qF.png

As you can see here, I just removed all HRTB and it still doesn't compile.

It still expects Q even though there's no Q on convex_hull::create, just P.

At least it correctly named convex_hull::Vec3 as na::Vector3 instead of convex_hull::Vector3 this time :D (actually nvm, na is also a renamed reexport, so it's still kind of wrong).

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

This is just getting weirder and weirder:

http://puu.sh/p7342.png

@eddyb
Copy link
Member

eddyb commented May 27, 2016

The Rust compiler never uses type parameter names from callees in error messages in callers.
It's type-checking concave_hull::create, which has a Q parameter, so that's what it will say.

@eddyb
Copy link
Member

eddyb commented May 27, 2016

@CryZe Could you reduce to one file that we can reasonably work with? (The ICE is likely #33852 AFAICT)
I don't see any reason having two crates is actually relevant here, other than potential confusion.

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

The ICE seems to be caused by the Vec not being able to type infer its type from the constraint. Explicitly giving it a type makes it work. Nvm, it's even more weird.

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

Here's the reduced code: https://is.gd/DHxfbu

ICE happens on Beta and Nightly. Type Checker problem happens on all.

pub fn problem_creator<'a, P>(_: &'a P) 
    where &'a P: IntoIterator<Item = &'a f64> 
{}

pub fn ok() {
    let points = Vec::new();
    problem_creator(&points)
}

pub fn ok2() {
    let points: Vec<f64> = Vec::new();
    problem_creator(&points)
}

pub fn ice<'a, Q>(_: &'a Q)
    where &'a Q: IntoIterator<Item = &'a f64>
{
    let points = Vec::new();
    problem_creator(&points)
}

pub fn broken_typechecking<'a, Q>(_: &'a Q)
    where &'a Q: IntoIterator<Item = &'a f64>
{
    let points: Vec<f64> = Vec::new();
    problem_creator(&points)
}

fn main() {}

@CryZe CryZe changed the title Type Checker getting confused with constraints Type Checker getting confused with constraints + ICE May 27, 2016
@eddyb
Copy link
Member

eddyb commented May 27, 2016

Ahh, I see what happens: problem_creator expects &$0: IntoIterator and the bound is actually satisfied by &Q: IntoIterator, which results in $0 == Q even though points has type Vec<f64>.
However, obligations like &$0: IntoIterator get resolved before arguments are checked, so that's how this arises.
I suspect #33852 fixes the ICE, but I'm not sure. cc @nikomatsakis @arielb1

@eddyb
Copy link
Member

eddyb commented May 27, 2016

@CryZe As a workaround, problem_creator::<Vec<_>>(&points) seems to work for me, could you try that (explicitly specifying type parameters) in your own project?

@CryZe
Copy link
Contributor Author

CryZe commented May 27, 2016

Yeah, seems to work. Thanks for your help :)

@arielb1
Copy link
Contributor

arielb1 commented May 29, 2016

@eddyb

That's the standard "inference guessing" issue (#30767).

@arielb1 arielb1 closed this as completed May 29, 2016
@eddyb
Copy link
Member

eddyb commented May 29, 2016

@arielb1 Is the ICE fixed?

@arielb1
Copy link
Contributor

arielb1 commented May 29, 2016

@eddyb

it looks like the Vec one, but that didn't reach nightly yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants