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

Relax the recursive type restriction. #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aatxe
Copy link
Contributor

@aatxe aatxe commented Jan 15, 2025


## Alternatives

The only serious alternative besides doing nothing at all would be to implement equirecursive types.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more of a nit: don't we already have equirecursive types? I would think that any class-ish looking table would be one.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline: you could consider type inference as constructing equirecursive types, but this PR is about relaxing the current restrictions on recursive types, and saying we will implement such via isorecursion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some sense, type inference will sometimes construct a recursive type that you could probably consider equirecursive, e.g. t1 where t1 = { foo(self: t1) -> ... } but this is one of the things that hampers the developer experience by leading to complex types, and is not supported by any of our syntax for actually annotating types. It's strictly a representation of a cyclic type that has occurred because of inference. #5 should also hopefully help us get rid of those patterns as well.

@vegorov-rbx
Copy link
Collaborator

Relation to #2 could be noted.

@aatxe
Copy link
Contributor Author

aatxe commented Jan 15, 2025

Relation to #2 could be noted.

Honestly, did not remember that it existed, but the relation between the two is that the old one was proposing a caching strategy to allow finite expansions that would work as a mild relaxation of the already in-place restriction. This is proposing what was listed as the top alternative (infinite expansion). I don't know whether we will or won't implement a cache for that expansion (which was the top two alternatives), but frankly, I think that caching or not for this strategy is an implementation detail and not a part of the language design proposal. We probably do not want to implement caching in the type system that has an impact on the static semantics.

I'll bring over the alternatives from #2 though.

@vegorov-rbx
Copy link
Collaborator

vegorov-rbx commented Jan 16, 2025

I view it as an implementation detail for the old solver similar to how your proposal mentions by treating type aliases as proper type functions that are lazily expanded when their contents are needed in the new solver.

I don't think it's that bad to explain it, but it could have been in the PR desc as opposed to the RFC body (edit: in the previous RFC).
Didn't feel to me that described caching there was particularly arbitrary.

I'm also not saying that it has to be made that way, but it is prior art for the same problem and I would say that RFC was already accepted in spirit, but we switched gears on the implementation.
If new solver has a simpler implementation without exploding, I'm all for this RFC as well.

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

Successfully merging this pull request may close these issues.

4 participants