-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
rustc stack overflow when using polymorphically recursive type #7587
Comments
The issue is with
It shouldn't be surprising that this, however, doesn't cause the problem:
|
i guess @nikomatsakis is most likely to know how to deal with this |
This is interesting. I can't decide whether such a type ought to be legal or not. I can't think of any principled reason for it to be illegal precisely, though it's not quite clear to me what such a type is good for. In any case, handling this case does significantly complicate type contents (and perhaps a few other similar algorithms, though most are robust to such types). As @bblum points out, the current design is "inductive" and assumes we can fully expand out all the types. One alternate design that comes to mind would be to modify type contents so that it computes "type content equations" rather than precise bit sets. These equations could then be applied to a specific set of type parameters. So, in other words, for something like However, I should go re-read the various literature on other algorithms that operate over infinitely sized types and see whether there is another approach. This seems to be highly related to such algorithms as well as induction vs co-induction and maybe there is another solution to be had. |
Actually using such a type won't work well, since polymorphic recursion doesn't work in rust. (Because we monomorphize.) |
�I went ahead and looked up the references I could remember and skimmed them over, so i figured I might as well attach them here:
Am I convinced by these examples? Well, no, at least, not the one's I've actually read and digested. |
actually this is a dupe of #4363. |
Compiling the following file:
Results in rustc running for a while and eventually aborting:
Using gdb, the cause of this appears to be an infinite recursion resulting in stack overflow. Setting RUST_MAX_STACK=48000 to limit the size of the backtrace, and omitting a bunch of lines in the middle, we get:
The text was updated successfully, but these errors were encountered: