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

Restrict usages of type variables in non-generalized contexts #7454

Merged
merged 11 commits into from
Jan 20, 2025

Conversation

ayazhafiz
Copy link
Member

Type variables can only be used on functions (and in number literals as
a carve-out for now). In all other cases, a type variable takes on a
single, concrete type based on later usages. This check emits errors
when this is violated.

The implementation is to check the rank of a variable after it could be
generalized. If the variable is not generalized but annotated as a type
variable, emit an error.

Needs #7450

These are inferred vars, not rigids.
Remove branches on determining how let-bindings are introduced to the
scope. This is maybe a little more inefficient, but I think it is a huge
simplification.

One additional change this required was changing how fx suffixes are
checked. The current implementation would add additional constraints for
patterns in let bindings conditionally. However, this is unnecessary. I
believe it is sufficient to check the fx suffix by running the checks on
all introduced symbols after the type is well known (i.e. the body is
checked).
This is actually correct - the rigid approach is not. Lambda set
variables should be inferred in-scope.
I don't think this assert is actually accurate.
Type variables can only be used on functions (and in number literals as
a carve-out for now). In all other cases, a type variable takes on a
single, concrete type based on later usages. This check emits errors
when this is violated.

The implementation is to check the rank of a variable after it could be
generalized. If the variable is not generalized but annotated as a type
variable, emit an error.
@ayazhafiz ayazhafiz force-pushed the ayaz/bugfix-ts branch 2 times, most recently from 8bddbe6 to be99b82 Compare January 6, 2025 04:54
Base automatically changed from ayaz/bugfix-ts to main January 8, 2025 05:28
@lukewilliamboswell
Copy link
Collaborator

@ayazhafiz

#7450 - has merged now.

@ayazhafiz ayazhafiz force-pushed the ayaz/error-on-invalid-generalized-types branch 2 times, most recently from e5d0b77 to 859ae04 Compare January 11, 2025 01:49
@ayazhafiz ayazhafiz force-pushed the ayaz/error-on-invalid-generalized-types branch from 859ae04 to 89700b4 Compare January 11, 2025 01:49
Copy link
Collaborator

@smores56 smores56 left a comment

Choose a reason for hiding this comment

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

Great change for Roc! Things look good besides these comments and the failing tests. Let me know if you're busy, I can try to resolve stuff for you

crates/reporting/src/error/type.rs Show resolved Hide resolved
crates/compiler/types/src/subs.rs Outdated Show resolved Hide resolved
crates/compiler/solve/src/solve.rs Show resolved Hide resolved
@ayazhafiz
Copy link
Member Author

ayazhafiz commented Jan 19, 2025 via email

@smores56 smores56 enabled auto-merge January 19, 2025 23:34
smores56
smores56 previously approved these changes Jan 19, 2025
Copy link
Collaborator

@smores56 smores56 left a comment

Choose a reason for hiding this comment

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

Fixed the comments and the failing tests, should be good to go.

@lukewilliamboswell lukewilliamboswell merged commit c8467b1 into main Jan 20, 2025
16 of 19 checks passed
@lukewilliamboswell lukewilliamboswell deleted the ayaz/error-on-invalid-generalized-types branch January 20, 2025 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants