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

detect non-regular recursion in types and error out early #22529

Closed
pnkfelix opened this issue Feb 19, 2015 · 3 comments
Closed

detect non-regular recursion in types and error out early #22529

pnkfelix opened this issue Feb 19, 2015 · 3 comments
Labels
A-type-system Area: Type system

Comments

@pnkfelix
Copy link
Member

We don't currently support non-regular recursive types; an example of such a type is:

struct Foo<A> {
    data: Option<Foo<Vec<A>>>
}

Foo<A> is non-regular, because the recursive reference to Foo within the type is not Foo<A>, but instead is Foo<Vec<A>>.

We don't support such types today (and are unlikely to do so in the foreseeable future) because our strategy of code-generation via monomorphization breaks down for such types, which yield an infinite-sized family of instances. (We might support some cases of this in the future, if we can somehow identify some subfamily as being all representable via one piece of generated code. But that's not a question for today.)

A number of compiler passes in rustc are not really equipped to deal with such types.

We could (and should) write code to detect such types early on, (perhaps in the well-formedness checking code in wf.rs), and report an error to the user with appropriate feedback about the source of the non-regular recursion.

@pnkfelix pnkfelix added A-type-system Area: Type system I-wishlist labels Feb 19, 2015
@huonw
Copy link
Member

huonw commented Feb 19, 2015

cc #4287

@steveklabnik
Copy link
Member

We have like three or four bugs associated with this...

@pnkfelix
Copy link
Member Author

oh this is totally a dupe of #4287.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants