Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upBogus error in beta and nightly: recursive type has infinite size #31299
Comments
This comment has been minimized.
This comment has been minimized.
|
Same error if I change the pointer to a Box. |
This comment has been minimized.
This comment has been minimized.
|
cc @nikomatsakis since I think he touched that code last |
This comment has been minimized.
This comment has been minimized.
|
Mini (no trait Front { type Back; }
impl<T> Front for T { type Back = T; }
struct PtrBack<T: Front>(*mut T::Back);
struct M(PtrBack<M>);
fn main() {
println!("{}", std::mem::size_of::<M>());
} |
This comment has been minimized.
This comment has been minimized.
|
This is fallout from inductiveness In the OC, the problem is that:
This could potentially be fixed by lazy normalization. A harder case is: trait Front { type Back; }
impl<T> Front for T { type Back = *mut T; /* note *mut is here */ }
struct PtrBack<T: Front>(T::Back);
struct M(PtrBack<M>);
fn main() {
println!("{}", std::mem::size_of::<M>());
}The cycle is similar:
However, not even lazy normalization can save us here. I admit the infinite type detection here is just plain wrong. |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 those sequences are kinda hard to understand. However, I'm not sure why |
This comment has been minimized.
This comment has been minimized.
|
@Aatch the message is basically a special-cased variant targeting the case where computing whether This is pretty related to how we can formalize auto traits. I'd been debating about a formalization that basically inserted one (automatically generated) impl for each auto trait, but those impls worked the same way as all other impls (this is not how it works today, but how it works today is unsound). However, I realized that this could fail, and my example was exactly the one that @jorendorff gives here -- one where the recursion arises through a projection. In the Obligation Forest PR, I considered whether to make So it may be that the correct fix is to have auto traits have a more complex, co-inductive proving semantics and -- since |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis so to be clear, the error message is wrong here, the problem is that we have " |
This comment has been minimized.
This comment has been minimized.
|
@Aatch I agree the message is wrong, I didn't consider this case when phrasing it -- but I think ideally we wouldn't be reporting an error here at all. I guess the question is if there is a way to achieve that. |
This comment has been minimized.
This comment has been minimized.
|
auto trait = OIBIT right?
What's the difference between that and what we have today? That auto traits are coinductive? If we forbid coinductive traits from having supertraits and associated types/constants we should be fine, as they can only be inputs of trait selection and not outputs. |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
P-high
and removed
I-nominated
labels
Feb 4, 2016
This comment has been minimized.
This comment has been minimized.
|
It's not clear what the best fix here is. One option is to change how we process the |
nikomatsakis
self-assigned this
Feb 4, 2016
nikomatsakis
referenced this issue
Feb 11, 2016
Merged
Add a per-tree cache into the obligation forest #31349
This comment has been minimized.
This comment has been minimized.
|
I think that for now the best thing here is to fix the error message, leaving ourselves the freedom to make this legal again in the future if we decide it won't undermine the type system. :) |
This comment has been minimized.
This comment has been minimized.
|
@areilb1 Would you mind explaining your I'm trying to understand what's causing the loop. It seemed to me like it might be
But that can't be right, because @nikomatsakis While we're here - I have feels about the wording "has infinite size" in error messages. It feels like it's attributing a deeply ridiculous intent to me, the user. Instead of saying "you did a typo" rustc is saying "oh, you want an infinitely large struct, I'm sorry, I can't do that". It must think I'm some kind of genius-level doofus. The message would be a little insulting, if the compiler were constructed by actual people who are actually smarter than me... waaaait a minute... |
This comment has been minimized.
This comment has been minimized.
|
@jorendorff so the message you get about "infinite size" there is actually wrong, it's actually the issue that we have the requirement As for the general problem of "infinite size" in errors, I see your point, but the error has to explain why it's incorrect somehow. I mean, what would an alternative error message look like? "You appear to have made a mistake, trying adding indirection in this type"? What mistake? What's the issue? Why would adding indirection help? |
This comment has been minimized.
This comment has been minimized.
The expectation was that you encounter this error when you try to make a recursive type (say a tree or something) without using a I think that's a general problem with error messages. When code with a typo attempts to do something silly, you will get an error message about the silly thing. There's a bug here that we report this error message with no infinite-sized type in sight. @nikomatsakis is working on fixing this (I think). Its just a recursive trait evaluation error. |
This comment has been minimized.
This comment has been minimized.
|
Sorry I mentioned it. Filed #31683 for the pet peeve. |
nikomatsakis
added
regression-from-stable-to-nightly
and removed
regression-from-stable-to-beta
labels
Feb 25, 2016
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Apr 8, 2016
nikomatsakis
assigned
arielb1
and unassigned
nikomatsakis
May 6, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This is now fixed (just verified) by #33138. Closing. |
jorendorff commentedJan 30, 2016
This program prints
8in Stable (1.5.0), but in Beta and Nightly compilation fails with:From 8 bytes to infinity would seem to be a serious memory usage regression.