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

Normalize away annotated types #178

Closed
wants to merge 1 commit into from

Conversation

gomoripeti
Copy link
Collaborator

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! Needs to be investigated.

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!
Copy link
Collaborator

@zuiderkwast zuiderkwast left a 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(),
Copy link
Collaborator

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().
Copy link
Collaborator

Choose a reason for hiding this comment

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

?TYPE_MOD here?

Copy link
Collaborator Author

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)

@zuiderkwast
Copy link
Collaborator

gradualizer_tests: type_check_dir_test...*timed out*

Perhaps there is another infinite loop?

@zuiderkwast
Copy link
Collaborator

zuiderkwast commented Apr 5, 2019

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.

@gomoripeti gomoripeti changed the title Normalize away type annotations Normalize away annotated types Apr 5, 2019
@gomoripeti
Copy link
Collaborator Author

I tried hard to get the title right but in that late hour I picked the wrong choice :)

@gomoripeti
Copy link
Collaborator Author

type_check_dir_test runs all the should_pass testcases, also the one that is a negative example. So (I really hope) there is just one infinite loop.

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.

Copy link
Owner

@josefs josefs left a 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_types so that they make sense, otherwise it's going to be very confusing for programmers.

@Zalastax
Copy link
Collaborator

Zalastax commented Apr 5, 2019

Some notes:

If T is a type definition Name :: Type, where Name is a variable and Type is a type, then Rep(T) = {ann_type,LINE,[Rep(Name),Rep(Type)]} (from absform).

----------------------------------------

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:

  -spec id(X) -> X when X :: tuple().

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.

Note

The 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:

  -spec id(tuple()) -> tuple().

The latter specification says that the function takes some tuple and returns some tuple. The specification with the X type variable specifies that the function takes a tuple and returns the same tuple.

However, it is up to the tools that process the specifications to choose whether to take this extra information into account or not.
(from typespec).

----------------------------------------

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?

@gomoripeti
Copy link
Collaborator Author

@Zalastax I think there are two things here: type variables in general and annotated types specifically.

Re: annotated types let's discuss in #180

@zuiderkwast
Copy link
Collaborator

Closing this in favor of #228, which is basically the same change.

@zuiderkwast zuiderkwast closed this Jan 8, 2020
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.

4 participants