Skip to content

Commit

Permalink
Merge pull request #461 from erszcz/function-intersections
Browse files Browse the repository at this point in the history
Function intersections
  • Loading branch information
erszcz authored Oct 27, 2022
2 parents 8abd8e0 + 6a9e54e commit 01ea62e
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 191 deletions.
4 changes: 4 additions & 0 deletions priv/prelude/lists.specs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
-spec foldl(fun((T, Acc) -> Acc), Acc, [T]) -> Acc.
-spec foldr(fun((T, Acc) -> Acc), Acc, [T]) -> Acc.

%% Preserve the (non)empty property of the input list.
-spec map(fun((A) -> B), [A, ...]) -> [B, ...];
(fun((A) -> B), [A]) -> [B].

%% -spec mapfoldl(Fun, Acc0, List1) -> {List2, Acc1} when
%% Fun :: fun((A, AccIn) -> {B, AccOut}),
%% Acc0 :: term(),
Expand Down
2 changes: 1 addition & 1 deletion src/absform.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ normalize_record_field({typed_record_field,
-spec normalize_function_type_list(FunTypeList) -> FunTypeList when
FunTypeList :: gradualizer_type:af_function_type_list().
normalize_function_type_list(FunTypeList) ->
?assert_type(lists:map(fun normalize_function_type/1, FunTypeList), [B, ...]).
lists:map(fun normalize_function_type/1, FunTypeList).

-spec normalize_function_type(BoundedFun | Fun) -> BoundedFun when
BoundedFun :: gradualizer_type:af_constrained_function_type(),
Expand Down
3 changes: 2 additions & 1 deletion src/gradualizer_fmt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ format_type_error({argument_length_mismatch, Anno, LenTy, LenArgs}, Opts) ->
format_location(Anno, verbose, Opts),
LenTy,
LenArgs]);
format_type_error({type_error, unreachable_clause, Anno}, Opts) ->
format_type_error({type_error, unreachable_clauses, Clauses}, Opts) ->
Anno = element(2, hd(Clauses)),
io_lib:format(
"~sThe clause~s cannot be reached~n",
[format_location(Anno, brief, Opts),
Expand Down
17 changes: 17 additions & 0 deletions src/gradualizer_tracer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ start() ->
%dbg:tpl(typechecker, refine_vars_by_mismatching_clause, x),
%dbg:tpl(typechecker, check_arg_exhaustiveness, x),

%dbg:tpl(typechecker, check_arg_exhaustiveness, x),
%dbg:tpl(typechecker, exhaustiveness_checking, x),
%dbg:tpl(typechecker, all_refinable, x),
%dbg:tpl(typechecker, no_clause_has_guards, x),
%dbg:tpl(typechecker, some_type_not_none, x),

%dbg:tpl(typechecker, check_clause, x),
%dbg:tpl(typechecker, check_clause, x),
%dbg:tpl(typechecker, add_types_pats, x),
Expand Down Expand Up @@ -139,6 +145,17 @@ start() ->
%dbg:tpl(typechecker, normalize, x),
%dbg:tpl(typechecker, do_add_types_pats, x),

%dbg:tpl(typechecker, check_clauses_intersection, []),
%dbg:tpl(typechecker, check_reachable_clauses, x),
%dbg:tpl(typechecker, check_clause, x),
%dbg:tpl(typechecker, check_arg_exhaustiveness, x),
%dbg:tpl(typechecker, check_clauses_intersection_throw_if_seen, x),
%dbg:tpl(typechecker, refine_clause_arg_tys, x),
%dbg:tpl(typechecker, refine_mismatch_using_guards, x),
%dbg:tpl(typechecker, are_patterns_matching_all_input, x),
%dbg:tpl(typechecker, check_guard_call, x),
%dbg:tpl(typechecker, type_diff, x),

%dbg:tpl(?MODULE, debug, x),
%dbg:tpl(erlang, throw, x),

Expand Down
6 changes: 4 additions & 2 deletions src/gradualizer_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
%% Export the additional types that gradualizer uses
-export_type([abstract_pattern/0,
af_assoc_type/0,
af_binary_op/1,
af_constrained_function_type/0,
af_constraint/0,
af_fun_type/0,
af_function_type_list/0,
af_record_field/1,
af_string/0,
af_unary_op/1,
binary_op/0,
gr_type_var/0,
unary_op/0]).
Expand Down Expand Up @@ -213,6 +215,7 @@
| af_bitstring_type()
| af_empty_list_type()
| af_fun_type()
| af_constrained_function_type()
| af_integer_range_type()
| af_map_type()
| af_predefined_type()
Expand All @@ -237,8 +240,7 @@
-type af_fun_type() :: {'type', anno(), 'fun', []}
| {'type', anno(), 'fun', [{'type', anno(), 'any'} |
abstract_type()]}
| af_function_type()
| af_constrained_function_type().
| af_function_type().

-type af_integer_range_type() ::
{'type', anno(), 'range', [af_singleton_integer_type()]}.
Expand Down
Loading

0 comments on commit 01ea62e

Please sign in to comment.