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

Require all functions in src/typechecker.erl to have specs #499

Merged
merged 29 commits into from
Dec 30, 2022

Conversation

erszcz
Copy link
Collaborator

@erszcz erszcz commented Dec 17, 2022

This significantly raises the bar on self-check consistency by requiring ALL functions in the type checker to have specs. It uncovered a number of consistency issues, but most of them could be solved. Most importantly, though, it documents the interfaces between various parts of the type checker and eases discoverability.

Done in this PR:

  • enabled warn_missing_spec_all in src/typechecker.erl
  • added all missing specs
  • added some tuple union and record union tests
  • removed dead record handling code for which no examples could be found (cross-checked with Cover)
  • fixed Cover Make rule
  • renamed constraints:constraints() to constraints:t() for brevity
  • reduced the number of self-check error lines back to below 100

This PR is also a good example of dog-fooding.

…return_type_should_pass.erl

Based on `import_beam_files/2` calling itself:

    -spec import_beam_files([file:filename() | binary()], state()) -> {ok, state()} | gradualizer_file_utils:parsed_file_error().
    import_beam_files([File | Files], State) ->
        case gradualizer_file_utils:get_forms_from_beam(File) of
            {ok, Forms} ->
                {attribute, _, module, Module} = lists:keyfind(module, 3, Forms),
                import_beam_files(Files, import_absform(Module, Forms, State));
            Error = {Status, _} when (Status /= ok) ->
                Error
        end;
    import_beam_files([], St) ->
        {ok, St}.
This raises hits on line 1245 of Cover output from 0 to 1:

1233		-spec expect_tuple_union(Tys, [Tys], constraints:t(), any | no_any, non_neg_integer(), env()) -> R when
1234		      Tys :: [type()],
1235		      R :: {[Tys], constraints:t()}.
1236		expect_tuple_union([Ty|Tys], AccTy, AccCs, Any, N, Env) ->
1237	27	    case expect_tuple_type(Ty, N, Env) of
1238		        {type_error, _} ->
1239	9	            expect_tuple_union(Tys, AccTy, AccCs, Any, N, Env);
1240		        any ->
1241	1	            expect_tuple_union(Tys, AccTy, AccCs, any, N, Env);
1242		        {elem_ty, TTy, Cs} ->
1243	16	            expect_tuple_union(Tys, [TTy | AccTy], constraints:combine(Cs, AccCs), Any, N, Env);
1244		        {elem_tys, TTys, Cs} ->
1245	1	            expect_tuple_union(Tys, TTys ++ AccTy, constraints:combine(Cs, AccCs), Any, N, Env)
1246		    end;
1247		expect_tuple_union([], AccTy, AccCs, any, N, _Env) ->
1248	1	    {[ lists:duplicate(N, type(any)) | AccTy], AccCs};
1249		expect_tuple_union([], AccTy, AccCs, _NoAny, _N, _Env) ->
1250	12	    {AccTy, AccCs}.
@erszcz erszcz force-pushed the raise-errors-on-missing-specs branch from 0ad0bbb to 43e5295 Compare December 28, 2022 16:13
@erszcz erszcz changed the title Raise compile errors on missing specs in src/typechecker.erl Require all functions in src/typechecker.erl to have specs Dec 28, 2022
@erszcz erszcz marked this pull request as ready for review December 28, 2022 16:25
@erszcz
Copy link
Collaborator Author

erszcz commented Dec 30, 2022

This fixes quite a few self-check errors, so I'm merging it, but I'm still happy with any reviews to come.

@erszcz erszcz merged commit 625bfaa into josefs:master Dec 30, 2022
@erszcz erszcz deleted the raise-errors-on-missing-specs branch December 30, 2022 14:25
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.

None yet

1 participant