-
Notifications
You must be signed in to change notification settings - Fork 35
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
Normalize away annotated types #178
Conversation
This small change triggers a new "infinite loop" while self-gradualizing possibly again in GLB. A somewhat minimal extract of `typechecker:type_check_comprehension_on` which triggers the behaviour is put into `should_pass/glb_ann_types.erl`. Should not be merged!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Now that ann_type
is not present in normalized types, perhaps some clauses for ann_type
in functions expecting normalized types can be removed?
It would be nice of course to isolate the problem and make a stand-alone test case with the required type definitions defined within the module. If that's hard, then this is fine.
%%-define(TYPE_MOD, gradualizer_type). | ||
|
||
-spec type_check_comprehension_in( | ||
Expr :: erl_parse:abstract_expr(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?TYPE_MOD
here?
|
||
-compile(export_all). | ||
|
||
-type type() :: erl_parse:abstract_type(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?TYPE_MOD
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. (but this whole testcase is just temporary to help track down the issue)
Perhaps there is another infinite loop? |
Btw, I think the title is slightly confusing. I'm not 100% sure about the terminology, but my intuition says that type annotations is stuff annotated with types, while annotated types is types annotated with stuff. |
I tried hard to get the title right but in that late hour I picked the wrong choice :) |
When I hit this issue I didnt want to go any further before it is addressed (removing ann_type's from everywhere else). This issue is most probably not related to ann_type but until now Gradualizer would error out before reaching the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being blunt, I think this is the wrong way forward. We should be checking the ann_type
s so that they make sense, otherwise it's going to be very confusing for programmers.
Some notes: If
Type variables can be used in specifications to specify relations for the input and output arguments of a function. For example, the following specification defines the type of a polymorphic identity function: -spec id(X) -> X. Notice that the above specification does not restrict the input and output type in any way. These types can be constrained by guard-like subtype constraints and provide bounded quantification:
Currently, the :: constraint (read as «is a subtype of») is the only guard constraint that can be used in the when part of a -spec attribute. NoteThe above function specification uses multiple occurrences of the same type variable. That provides more type information than the following function specification, where the type variables are missing:
The latter specification says that the function takes some tuple and returns some tuple. The specification with the However, it is up to the tools that process the specifications to choose whether to take this extra information into account or not.
Do we want to take that extra information into account? I suspect that no tool takes advantage of the extra information and that most specs that reuse the same variable does so accidentally. I would opt for ignoring it and lobby for OTP to replace that note to instead say that it doesn't have to return the same thing. @josefs was this what you meant with checking so they make sense? What do we loose by normalizing? |
Closing this in favor of #228, which is basically the same change. |
This small change triggers a new "infinite loop" while self-gradualizing
possibly again in GLB. A somewhat minimal extract of
typechecker:type_check_comprehension_on
which triggers the behaviouris put into
should_pass/glb_ann_types.erl
.Should not be merged! Needs to be investigated.