-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Infinite loop/stack overflow in rustc (dropck) on non-regular data type #22443
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
The bug seems to be caused by the recursive datatype: Deep(Digit<T>, Box<FingerTree<Node<T>>>, Digit<T>) If I remove the Boxed thing, it compiles and runs. |
Reduced test cases: struct Digit<T> {
elem: T,
}
enum Node<T> {}
enum FingerTree<T> {
Single(T),
Deep(
- Digit<T>,
Box<FingerTree<Node<T>>>,
+ Digit<T>,
)
}
fn main() {
let ft = FingerTree::Single(1);
} The one with
|
Note that enum Tree<T> {
Single(T),
Deep(Box<Tree<Node<T>>>)
} and variations thereof, is a non-regular data type (see also polymorphic recursion). Rust doesn't handle such types very well, because it implements type-parametric code via monomorphization, but you need infinite codegen to monomorphize non-regular data types in general. I should (and will) put a recursion counter into dropck so that we at least do not infinite loop in such cases. |
Thanks for the update. Yes, the restriction makes sense. I'll try and implement the algorithm using some runtime typecast "Any" magic. |
(this could be considered part of #22321, though really it probably should be given slightly higher priority given the undesirability of infinite looping here.) |
@miv-ableton by the way, you probably do not need to drop all the way down to working in terms of |
Check for unbounded recursion during dropck. Such recursion can be introduced by the erroneous use of non-regular types (aka types employing polymorphic recursion), which Rust does not support. Fix rust-lang#22443
Check for unbounded recursion during dropck. Such recursion can be introduced by the erroneous use of non-regular types (aka types employing polymorphic recursion), which Rust does not support. Fix rust-lang#22443
The compiler goes into an infinite loop compiling this code (an incomplete finger tree implementation):
Tested with latest nightly. I can also cause this to happen by pasting this into the box on the rust-lang homepage.
The text was updated successfully, but these errors were encountered: