-
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
Enable Dialyzer and ETC cross checks #429
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4839d9
Add dialyze-tests make rule
erszcz ac1cd06
Ignore *.erltypes
erszcz 03cb63e
Avoid module name clashes in tests
erszcz 748cbf8
Add a remark about some refinements in Dialyzer
erszcz 82e3ea9
Add a script to check for name clashes in test module file names
erszcz 20fd644
Export f/1 and nospec_update_bug/1 to fix Dialyzer warnings
erszcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
deps | ||
*.o | ||
*.beam | ||
*.erltypes | ||
*.plt | ||
/.dialyzer_plt | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
#set -x | ||
|
||
if [ x$(uname) == x"Darwin" ]; then | ||
BASENAME=basename | ||
else | ||
BASENAME="basename -a" | ||
fi | ||
|
||
UNIQ=$(find test/should_pass test/should_fail test/known_problems/*/ -name \*.erl \ | ||
| xargs $BASENAME \ | ||
| sort \ | ||
| uniq -c \ | ||
| sort -n \ | ||
| tail -1) | ||
|
||
COUNT=$(echo $UNIQ | awk '{print $1}') | ||
|
||
if [ "$COUNT" == 1 ]; then | ||
exit 0 | ||
else | ||
echo "Name clash in tests:" | ||
find test -name $(echo $UNIQ | awk '{print $2}') | ||
exit 1 | ||
fi |
2 changes: 1 addition & 1 deletion
2
...known_problems/should_fail/guard_fail.erl → ...roblems/should_fail/guard_should_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(guard_fail). | ||
-module(guard_should_fail). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...hould_fail/intersection_with_any_fail.erl → ...ail/intersection_with_any_should_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lems/should_fail/rigid_type_variables.erl → ...should_fail/rigid_type_variables_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(rigid_type_variables). | ||
-module(rigid_type_variables_fail). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...lems/should_pass/rigid_type_variables.erl → ...should_pass/rigid_type_variables_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(rigid_type_variables). | ||
-module(rigid_type_variables_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
3 changes: 2 additions & 1 deletion
3
test/should_fail/arith_op.erl → test/should_fail/arith_op_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(bc). | ||
-module(bc_fail). | ||
-export([f/0, non_bin_expr/0, integer_signed_wrong/1]). | ||
|
||
-spec f() -> binary(). | ||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/catch_expr.erl → test/should_fail/catch_expr_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(catch_expr). | ||
-module(catch_expr_fail). | ||
|
||
-export([foo/1]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/covariant_map_keys.erl → test/should_fail/covariant_map_keys_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/should_fail/intersection_with_any.erl → ...hould_fail/intersection_with_any_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/should_fail/list_infer.erl → test/should_fail/list_infer_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(list_infer). | ||
-module(list_infer_fail). | ||
|
||
-gradualizer(infer). | ||
-export([f/0]). | ||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/messaging.erl → test/should_fail/messaging_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(messaging). | ||
-module(messaging_fail). | ||
|
||
-export([server1/0, server2/0, server3/0, server4/0]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/named_fun.erl → test/should_fail/named_fun_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(named_fun). | ||
-module(named_fun_fail). | ||
|
||
-export([bar/0, baz/1]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/named_fun_infer.erl → test/should_fail/named_fun_infer_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(named_fun_infer). | ||
-module(named_fun_infer_fail). | ||
|
||
-gradualizer(infer). | ||
-export([bar/0, sum/1]). | ||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/operator_pattern.erl → test/should_fail/operator_pattern_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/should_fail/record_wildcard.erl → test/should_fail/record_wildcard_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(record_wildcard). | ||
-module(record_wildcard_fail). | ||
|
||
-export([f/0, g/0]). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(send). | ||
-module(send_fail). | ||
|
||
-export([foo/2, bar/2]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_fail/shortcut_ops.erl → test/should_fail/shortcut_ops_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(shortcut_ops). | ||
-module(shortcut_ops_fail). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
-module(tuple_union_fail). | ||
|
||
-export([f/0]). | ||
-export([tuple_union/0]). | ||
|
||
-spec f() -> {integer()} | {boolean()}. | ||
f() -> | ||
{apa}. | ||
|
||
-spec tuple_union() -> {undefined, binary()} | {integer(), undefined}. | ||
tuple_union() -> | ||
{undefined, undefined}. |
2 changes: 1 addition & 1 deletion
2
test/should_fail/type_refinement.erl → test/should_fail/type_refinement_fail.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(bc). | ||
-module(bc_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/catch_expr.erl → test/should_pass/catch_expr_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(catch_expr). | ||
-module(catch_expr_pass). | ||
|
||
-export([foo/1]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/covariant_map_keys.erl → test/should_pass/covariant_map_keys_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(covariant_map_keys). | ||
-module(covariant_map_keys_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/intersection.erl → test/should_pass/intersection_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(intersection). | ||
-module(intersection_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/intersection_with_any.erl → ...hould_pass/intersection_with_any_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(intersection_with_any). | ||
-module(intersection_with_any_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/list_infer.erl → test/should_pass/list_infer_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(list_infer). | ||
-module(list_infer_pass). | ||
|
||
-gradualizer(infer). | ||
-export([f/0]). | ||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/messaging.erl → test/should_pass/messaging_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/should_pass/named_fun_infer.erl → test/should_pass/named_fun_infer_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(named_fun_infer). | ||
-module(named_fun_infer_pass). | ||
|
||
-gradualizer(infer). | ||
-export([atom_sum/1]). | ||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/named_fun.erl → test/should_pass/named_fun_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(named_fun). | ||
-module(named_fun_pass). | ||
|
||
-export([fac/1, sum/1]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/operator_pattern.erl → test/should_pass/operator_pattern_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(operator_pattern). | ||
-module(operator_pattern_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/record_wildcard.erl → test/should_pass/record_wildcard_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(record_wildcard). | ||
-module(record_wildcard_pass). | ||
|
||
-export([f/0, g/0, h/1]). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(send). | ||
-module(send_pass). | ||
|
||
-export([foo/2, bar/2]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/shortcut_ops.erl → test/should_pass/shortcut_ops_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(shortcut_ops). | ||
-module(shortcut_ops_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/tuple_union.erl → test/should_pass/tuple_union_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(tuple_union). | ||
-module(tuple_union_pass). | ||
|
||
-export([f/0]). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
test/should_pass/type_refinement.erl → test/should_pass/type_refinement_pass.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(type_refinement). | ||
-module(type_refinement_pass). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we run this in CI to maintain expected results? I.e. to prevent name clashes from being introduced again.
Are there any dialyzer errors in the tests?
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.
Hmm, we probably could, but the errors do not overlap completely, so we would need to come up with some should-pass/should-fail/known-problems mapping mechanism. I don't think we can run it just to detect name clashes, we would also have to check the error code and determine which is returned why.
Below is an interesting case:
Gradualizer/test/should_pass/andalso_any.erl
Lines 5 to 10 in 51a8029
Dialyzer reports:
Whereas Gradualizer is fine with it, because
any()
is compatible with every other type. AFAIU a full-blown gradual typing system according to Siek and Taha would inject a dynamic check in such a place.Dialyzer infers the type of an integer literal, but it couldn't do so if the value was not a literal.
Gradualizer just believes the spec, even with
--infer
, and checks against it, so it assumes everything is fine.I imagine there are more cases like this, but haven't analysed all of them yet. The current summary is available at https://gist.github.com/erszcz/4d43a77464c87a514e71eecf2811af63#file-check-2022-07-13_170833-tsv.
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.
Interesting. Yes, dializer does a full inference, while gradualizer is silent on purpose in this case.
Regarding Siek & Taha: Since Erlang/BEAM is a dynamic language, there are already runtime checks for everything anyway. The runtime catches it and raises an exception such as badarg. The paper speaks about the case where a dynamic type is added to a statically language without runtime type checks. This is my interpretation anyway.
Could we check for unique module filenames in another way then? Just some simple shell script?
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.
I agree. However, I think the mentioned example shows unsoundness of the type system. Let's consider this (and the following) paragraph from https://papl.cs.brown.edu/2014/safety-soundness.html#%28part._type-soundness%29:
In our case the type checker will pretend that
f1() -> boolean()
, but in fact it turns out to bef1() -> integer()
upon evaluation.I think we can use some
find | sort | uniq
magic to do it. I'll come up with something tomorrow.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.
Are you saying Gradualizer (or any sound gradual type system) should insert an assertion to make sure
g1()
in your example above returns a boolean? This is to ensure we get a runtime type error rather than a value of the wrong type...? So f1 above is translated into something like this:This is interesting. I didn't think about it in this way before.
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.
I think this is explained in a simple way in the introduction of Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and Parametricity: Together Again for the First
Time. Proc. ACM Program. Lang. 4, POPL, Article 46 (January 2020), 32 pages. https://doi.org/10.1145/3371114
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.
I think so. The fragment you quote is aligned with what I remembered from the paper 👍
Yes, more or less. Their paper didn't cover Erlang, obviously, and the semantics of the language start to matter at this point. I'd type the Erlang
andalso
asandalso(boolean(), any()) -> any()
based on the below:So I think the inserted assertion, due to the spec we declare for
f1
, should enclose the application ofandalso
:However, I don't think we can consider this a goal for Gradualizer given it's not part of a compiler. Perhaps one day it could rewrite
.beam
files... but that's a far fetched goal. I think there are more tangible and important milestones before that.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.
@josefs What do you think about our conclusions above? The example functions
f1
andg1
...True, but without this I don't believe we have soundness and the types can't really be trusted. I always regarded gradualizer an experiment. The next experiment could be "Gradual Erlang", a language which looks like Erlang and compiles to Erlang with assertions inserted....
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.
Interesting comment that
A andalso B
actually is syntactic sugar forcase A of true -> B ...
- erlang/otp#5456 (comment).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.
As you noted @zuiderkwast, inserting checks when the typechecker coerces to/from
any()
is referred to as "sound gradual typing" in the literature. My intention with Gradualizer was to refrain from doing it, simply because I thought that it would be too much work. Adding coercions has the advantage that runtime type errors would be reported earlier and in places that are often easier to understand.In some implementations is required to insert these coercions because not doing so would lead to a crash/segfault/undefined behaviour. But since we're relying on executing things on top of BEAM we don't have such problems.
There are quite a few papers on measuring the cost of these coercions and there are example programs for which they are quite expensive. Those examples typically involve having
any()
embedded in some structure so that the coercions have to traverse the structure.I don't have anything in principle against adding these kinds of coercions. But from an efficiency point of view it might be preferrable to have this not be the default behaviour and have a flag that enables it.