aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialyzer')
-rw-r--r--lib/dialyzer/src/dialyzer_analysis_callgraph.erl59
-rw-r--r--lib/dialyzer/src/dialyzer_behaviours.erl12
-rw-r--r--lib/dialyzer/src/dialyzer_callgraph.erl44
-rw-r--r--lib/dialyzer/src/dialyzer_codeserver.erl17
-rw-r--r--lib/dialyzer/src/dialyzer_dataflow.erl66
-rw-r--r--lib/dialyzer/src/dialyzer_gui.erl10
-rw-r--r--lib/dialyzer/src/dialyzer_gui_wx.erl10
-rw-r--r--lib/dialyzer/src/dialyzer_plt.erl37
-rw-r--r--lib/dialyzer/src/dialyzer_races.erl21
-rw-r--r--lib/dialyzer/src/dialyzer_succ_typings.erl34
-rw-r--r--lib/dialyzer/src/dialyzer_typesig.erl153
-rw-r--r--lib/dialyzer/test/Makefile2
-rw-r--r--lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour16
-rw-r--r--lib/dialyzer/test/behaviour_SUITE_data/src/custom_sup.erl37
-rw-r--r--lib/dialyzer/test/behaviour_SUITE_data/src/sample_behaviour/sample_callback_wrong.erl3
-rw-r--r--lib/dialyzer/test/dialyzer_common.erl11
-rw-r--r--lib/dialyzer/test/opaque_SUITE_data/results/multiple_wrong_opaques2
-rw-r--r--lib/dialyzer/test/opaque_SUITE_data/src/multiple_wrong_opaques.erl8
-rw-r--r--lib/dialyzer/test/options1_SUITE_data/results/compiler1
-rw-r--r--lib/dialyzer/test/r9c_SUITE_data/results/inets1
-rw-r--r--lib/dialyzer/test/small_SUITE_data/results/cerl_hipeify2
-rw-r--r--lib/dialyzer/test/small_SUITE_data/results/inf_loop22
-rw-r--r--lib/dialyzer/test/small_SUITE_data/results/no_local_return3
-rw-r--r--lib/dialyzer/test/small_SUITE_data/src/no_local_return.erl12
-rw-r--r--lib/dialyzer/test/small_SUITE_data/src/on_load.erl11
25 files changed, 333 insertions, 241 deletions
diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
index 458f3a4c81..5be870d78f 100644
--- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
+++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
@@ -170,33 +170,32 @@ analysis_start(Parent, Analysis) ->
rcv_and_send_ext_types(Parent),
NonExports = sets:subtract(sets:from_list(AllNodes), Exports),
NonExportsList = sets:to_list(NonExports),
- Plt3 = dialyzer_plt:delete_list(State3#analysis_state.plt, NonExportsList),
- Plt4 = dialyzer_plt:delete_contract_list(Plt3, NonExportsList),
+ Plt2 = dialyzer_plt:delete_list(State3#analysis_state.plt, NonExportsList),
send_codeserver_plt(Parent, CServer, State3#analysis_state.plt),
- send_analysis_done(Parent, Plt4, State3#analysis_state.doc_plt).
+ send_analysis_done(Parent, Plt2, State3#analysis_state.doc_plt).
analyze_callgraph(Callgraph, State) ->
Codeserver = State#analysis_state.codeserver,
- Plt = dialyzer_plt:insert_callbacks(State#analysis_state.plt, Codeserver),
Parent = State#analysis_state.parent,
- case State#analysis_state.analysis_type of
- plt_build ->
- Callgraph1 = dialyzer_callgraph:finalize(Callgraph),
- NewPlt = dialyzer_succ_typings:analyze_callgraph(Callgraph1, Plt,
- Codeserver, Parent),
- dialyzer_callgraph:delete(Callgraph1),
- State#analysis_state{plt = NewPlt};
- succ_typings ->
- NoWarn = State#analysis_state.no_warn_unused,
- DocPlt = State#analysis_state.doc_plt,
- Callgraph1 = dialyzer_callgraph:finalize(Callgraph),
- {Warnings, NewPlt, NewDocPlt} =
- dialyzer_succ_typings:get_warnings(Callgraph1, Plt, DocPlt,
- Codeserver, NoWarn, Parent),
- dialyzer_callgraph:delete(Callgraph1),
- send_warnings(State#analysis_state.parent, Warnings),
- State#analysis_state{plt = NewPlt, doc_plt = NewDocPlt}
- end.
+ DocPlt = State#analysis_state.doc_plt,
+ Plt = dialyzer_plt:insert_callbacks(State#analysis_state.plt, Codeserver),
+ Callgraph1 = dialyzer_callgraph:finalize(Callgraph),
+ {NewPlt, NewDocPlt} =
+ case State#analysis_state.analysis_type of
+ plt_build ->
+ {dialyzer_succ_typings:analyze_callgraph(Callgraph1, Plt,
+ Codeserver, Parent),
+ DocPlt};
+ succ_typings ->
+ NoWarn = State#analysis_state.no_warn_unused,
+ {Warnings, NewPlt0, NewDocPlt0} =
+ dialyzer_succ_typings:get_warnings(Callgraph1, Plt, DocPlt,
+ Codeserver, NoWarn, Parent),
+ send_warnings(State#analysis_state.parent, Warnings),
+ {NewPlt0, NewDocPlt0}
+ end,
+ dialyzer_callgraph:delete(Callgraph1),
+ State#analysis_state{plt = NewPlt, doc_plt = NewDocPlt}.
%%--------------------------------------------------------------------
%% Build the callgraph and fill the codeserver.
@@ -282,10 +281,10 @@ cleanup_callgraph(#analysis_state{plt = InitPlt, parent = Parent,
if ExtCalls1 =:= [] -> {[], []};
true ->
ModuleSet = sets:from_list(Modules),
- lists:partition(fun({_From, {M, _F, _A}}) ->
- sets:is_element(M, ModuleSet) orelse
- dialyzer_plt:contains_module(InitPlt, M)
- end, ExtCalls1)
+ PltModuleSet = dialyzer_plt:all_modules(InitPlt),
+ AllModules = sets:union(ModuleSet, PltModuleSet),
+ Pred = fun({_From, {M, _F, _A}}) -> sets:is_element(M, AllModules) end,
+ lists:partition(Pred, ExtCalls1)
end,
NonLocalCalls = dialyzer_callgraph:non_local_calls(Callgraph1),
BadCalls2 = [Call || Call = {_From, To} <- NonLocalCalls,
@@ -366,9 +365,11 @@ abs_get_nowarn(Abs, M) ->
false ->
[{M, F, A} || {function, _, F, A, _} <- Abs]; % all functions
true ->
- [{M, F, A} ||
- {nowarn_unused_function, FAs} <- Opts,
- {F, A} <- lists:flatten([FAs])]
+ OnLoad =
+ lists:flatten([{M, F, A} || {attribute, _, on_load, {F, A}} <- Abs]),
+ OnLoad ++ [{M, F, A} ||
+ {nowarn_unused_function, FAs} <- Opts,
+ {F, A} <- lists:flatten([FAs])]
end.
get_exported_types_from_core(Core) ->
diff --git a/lib/dialyzer/src/dialyzer_behaviours.erl b/lib/dialyzer/src/dialyzer_behaviours.erl
index e89c08df7d..fdaa8b663c 100644
--- a/lib/dialyzer/src/dialyzer_behaviours.erl
+++ b/lib/dialyzer/src/dialyzer_behaviours.erl
@@ -72,9 +72,11 @@ check_callbacks(Module, Attrs, Plt, Codeserver) ->
%%--------------------------------------------------------------------
get_behaviours(Attrs) ->
- BehaviourListsAndLine = [{cerl:concrete(L2), hd(cerl:get_ann(L2))} ||
- {L1, L2} <- Attrs, cerl:is_literal(L1),
- cerl:is_literal(L2), cerl:concrete(L1) =:= 'behaviour'],
+ BehaviourListsAndLine =
+ [{cerl:concrete(L2), hd(cerl:get_ann(L2))} ||
+ {L1, L2} <- Attrs, cerl:is_literal(L1),
+ cerl:is_literal(L2), cerl:concrete(L1) =:= 'behaviour' orelse
+ cerl:concrete(L1) =:= 'behavior'],
Behaviours = lists:append([Behs || {Behs,_} <- BehaviourListsAndLine]),
BehLines = [{B,L} || {L1,L} <- BehaviourListsAndLine, B <- L1],
{Behaviours, BehLines}.
@@ -239,12 +241,12 @@ translatable_behaviours(Tree) ->
get_behaviour_apis(Behaviours) ->
get_behaviour_apis(Behaviours, []).
--spec translate_behaviour_api_call(dialyzer_races:mfa_or_funlbl(),
+-spec translate_behaviour_api_call(dialyzer_callgraph:mfa_or_funlbl(),
[erl_types:erl_type()],
[dialyzer_races:core_vars()],
module(),
behaviour_api_dict()) ->
- {dialyzer_races:mfa_or_funlbl(),
+ {dialyzer_callgraph:mfa_or_funlbl(),
[erl_types:erl_type()],
[dialyzer_races:core_vars()]}
| 'plain_call'.
diff --git a/lib/dialyzer/src/dialyzer_callgraph.erl b/lib/dialyzer/src/dialyzer_callgraph.erl
index d3de5aaf45..4767c02f77 100644
--- a/lib/dialyzer/src/dialyzer_callgraph.erl
+++ b/lib/dialyzer/src/dialyzer_callgraph.erl
@@ -59,7 +59,7 @@
put_named_tables/2, put_public_tables/2, put_behaviour_api_calls/2,
get_behaviour_api_calls/1]).
--export_type([callgraph/0]).
+-export_type([callgraph/0, mfa_or_funlbl/0]).
-include("dialyzer.hrl").
@@ -177,14 +177,14 @@ is_escaping(Label, #callgraph{esc = Esc}) when is_integer(Label) ->
add_edges([], CG) ->
CG;
-add_edges(Edges, #callgraph{digraph = Callgraph} = CG) ->
- CG#callgraph{digraph = digraph_add_edges(Edges, Callgraph)}.
+add_edges(Edges, #callgraph{digraph = Digraph} = CG) ->
+ CG#callgraph{digraph = digraph_add_edges(Edges, Digraph)}.
-spec add_edges([callgraph_edge()], [mfa_or_funlbl()], callgraph()) -> callgraph().
add_edges(Edges, MFAs, #callgraph{digraph = DG} = CG) ->
- DG1 = digraph_confirm_vertices(MFAs, DG),
- add_edges(Edges, CG#callgraph{digraph = DG1}).
+ DG = digraph_confirm_vertices(MFAs, DG),
+ add_edges(Edges, CG).
-spec take_scc(callgraph()) -> 'none' | {'ok', scc(), callgraph()}.
@@ -196,8 +196,8 @@ take_scc(#callgraph{postorder = []}) ->
-spec remove_external(callgraph()) -> {callgraph(), [tuple()]}.
remove_external(#callgraph{digraph = DG} = CG) ->
- {NewDG, External} = digraph_remove_external(DG),
- {CG#callgraph{digraph = NewDG}, External}.
+ {DG, External} = digraph_remove_external(DG),
+ {CG, External}.
-spec non_local_calls(callgraph()) -> mfa_calls().
@@ -241,30 +241,30 @@ modules(#callgraph{digraph = DG}) ->
-spec module_postorder(callgraph()) -> [[module()]].
module_postorder(#callgraph{digraph = DG}) ->
+ {MDG, _Nodes} = get_module_digraph_and_nodes(DG),
+ MDG1 = digraph_utils:condensation(MDG),
+ PostOrder = digraph_utils:postorder(MDG1),
+ PostOrder1 = sort_sccs_internally(PostOrder, MDG),
+ digraph:delete(MDG1),
+ digraph_delete(MDG),
+ PostOrder1.
+
+get_module_digraph_and_nodes(DG) ->
Edges = digraph_edges(DG),
Nodes = ordsets:from_list([M || {M,_F,_A} <- digraph_vertices(DG)]),
MDG = digraph:new(),
- MDG1 = digraph_confirm_vertices(Nodes, MDG),
- MDG2 = create_module_digraph(Edges, MDG1),
- MDG3 = digraph_utils:condensation(MDG2),
- PostOrder = digraph_utils:postorder(MDG3),
- PostOrder1 = sort_sccs_internally(PostOrder, MDG2),
- digraph:delete(MDG2),
- digraph_delete(MDG3),
- PostOrder1.
+ MDG = digraph_confirm_vertices(Nodes, MDG),
+ MDG = create_module_digraph(Edges, MDG),
+ {MDG, Nodes}.
%% The module deps of a module are modules that depend on the module
-spec module_deps(callgraph()) -> dict().
module_deps(#callgraph{digraph = DG}) ->
- Edges = digraph_edges(DG),
- Nodes = ordsets:from_list([M || {M,_F,_A} <- digraph_vertices(DG)]),
- MDG = digraph:new(),
- MDG1 = digraph_confirm_vertices(Nodes, MDG),
- MDG2 = create_module_digraph(Edges, MDG1),
- Deps = [{N, ordsets:from_list(digraph:in_neighbours(MDG2, N))}
+ {MDG, Nodes} = get_module_digraph_and_nodes(DG),
+ Deps = [{N, ordsets:from_list(digraph:in_neighbours(MDG, N))}
|| N <- Nodes],
- digraph_delete(MDG2),
+ digraph_delete(MDG),
dict:from_list(Deps).
-spec strip_module_deps(dict(), set()) -> dict().
diff --git a/lib/dialyzer/src/dialyzer_codeserver.erl b/lib/dialyzer/src/dialyzer_codeserver.erl
index 13ca65e4dd..f1e87affbd 100644
--- a/lib/dialyzer/src/dialyzer_codeserver.erl
+++ b/lib/dialyzer/src/dialyzer_codeserver.erl
@@ -292,15 +292,11 @@ table__loop(Cached, Map) ->
{NewCached, Ans} =
case Cached of
{M, Tree} ->
- [Val] = [VarFun || {Var, _Fun} = VarFun <- cerl:module_defs(Tree),
- cerl:fname_id(Var) =:= F,
- cerl:fname_arity(Var) =:= A],
+ Val = find_fun(F, A, Tree),
{Cached, Val};
_ ->
Tree = fetch_and_expand(M, Map),
- [Val] = [VarFun || {Var, _Fun} = VarFun <- cerl:module_defs(Tree),
- cerl:fname_id(Var) =:= F,
- cerl:fname_arity(Var) =:= A],
+ Val = find_fun(F, A, Tree),
{{M, Tree}, Val}
end,
Pid ! {self(), MFA, Ans},
@@ -329,3 +325,12 @@ fetch_and_expand(Mod, Map) ->
Msg = "found no module named '" ++ S ++ "' in the analyzed files",
exit({error, Msg})
end.
+
+find_fun(F, A, Tree) ->
+ Pred =
+ fun({Var, _Fun}) ->
+ (cerl:fname_id(Var) =/= F) orelse
+ (cerl:fname_arity(Var) =/= A)
+ end,
+ [Val|_] = lists:dropwhile(Pred, cerl:module_defs(Tree)),
+ Val.
diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl
index 6008dba080..aba13278ff 100644
--- a/lib/dialyzer/src/dialyzer_dataflow.erl
+++ b/lib/dialyzer/src/dialyzer_dataflow.erl
@@ -67,7 +67,6 @@
%%-define(DEBUG, true).
%%-define(DEBUG_PP, true).
-%%-define(DEBUG_TIME, true).
%%-define(DOT, true).
-ifdef(DEBUG).
@@ -77,9 +76,6 @@
-define(debug(S_, L_), ok).
-endif.
-%%-define(debug1(S_, L_), io:format(S_, L_)).
-%%-define(debug1(S_, L_), ok).
-
%%--------------------------------------------------------------------
-define(no_arg, no_arg).
@@ -276,6 +272,7 @@ analyze_module(Tree, Plt, Callgraph, Records, GetWarnings) ->
debug_pp(Tree, false),
Module = cerl:atom_val(cerl:module_name(Tree)),
RaceDetection = dialyzer_callgraph:get_race_detection(Callgraph),
+ RaceCode = dialyzer_callgraph:get_race_code(Callgraph),
BehaviourTranslations =
case RaceDetection of
true -> dialyzer_behaviours:translatable_behaviours(Tree);
@@ -286,9 +283,6 @@ analyze_module(Tree, Plt, Callgraph, Records, GetWarnings) ->
TopFun, Plt, Module, Records, BehaviourTranslations),
State1 = state__race_analysis(not GetWarnings, State),
State2 = analyze_loop(State1),
- RaceCode = dialyzer_callgraph:get_race_code(Callgraph),
- Callgraph1 = State2#state.callgraph,
- RaceCode1 = dialyzer_callgraph:get_race_code(Callgraph1),
case GetWarnings of
true ->
State3 = state__set_warning_mode(State2),
@@ -313,6 +307,8 @@ analyze_module(Tree, Plt, Callgraph, Records, GetWarnings) ->
St#state{callgraph = Callgraph3}
end;
false ->
+ Callgraph1 = State2#state.callgraph,
+ RaceCode1 = dialyzer_callgraph:get_race_code(Callgraph1),
state__restore_race_code(
dict:merge(fun (_K, V1, _V2) -> V1 end,
RaceCode, RaceCode1), State2)
@@ -320,27 +316,26 @@ analyze_module(Tree, Plt, Callgraph, Records, GetWarnings) ->
analyze_loop(#state{callgraph = Callgraph, races = Races} = State) ->
case state__get_work(State) of
- none -> state__clean_not_called(State);
- {Fun, NewState} ->
- ArgTypes = state__get_args(Fun, NewState),
- case any_none(ArgTypes) of
+ none -> State;
+ {Fun, NewState1} ->
+ {ArgTypes, IsCalled} = state__get_args_and_status(Fun, NewState1),
+ case not IsCalled of
true ->
- ?debug("Not handling1 ~w: ~s\n",
+ ?debug("Not handling (not called) ~w: ~s\n",
[state__lookup_name(get_label(Fun), State),
t_to_string(t_product(ArgTypes))]),
- analyze_loop(NewState);
+ analyze_loop(NewState1);
false ->
- case state__fun_env(Fun, NewState) of
+ case state__fun_env(Fun, NewState1) of
none ->
- ?debug("Not handling2 ~w: ~s\n",
+ ?debug("Not handling (no env) ~w: ~s\n",
[state__lookup_name(get_label(Fun), State),
t_to_string(t_product(ArgTypes))]),
- analyze_loop(NewState);
+ analyze_loop(NewState1);
Map ->
?debug("Handling fun ~p: ~s\n",
[state__lookup_name(get_label(Fun), State),
- t_to_string(state__fun_type(Fun, NewState))]),
- NewState1 = state__mark_fun_as_handled(NewState, Fun),
+ t_to_string(state__fun_type(Fun, NewState1))]),
Vars = cerl:fun_vars(Fun),
Map1 = enter_type_lists(Vars, ArgTypes, Map),
Body = cerl:fun_body(Fun),
@@ -2892,28 +2887,22 @@ state__new(Callgraph, Tree, Plt, Module, Records, BehaviourTranslations) ->
TreeMap = build_tree_map(Tree),
Funs = dict:fetch_keys(TreeMap),
FunTab = init_fun_tab(Funs, dict:new(), TreeMap, Callgraph, Plt, Opaques),
- Work = init_work([get_label(Tree)]),
- Env = dict:store(top, map__new(), dict:new()),
+ ExportedFuns =
+ [Fun || Fun <- Funs--[top], dialyzer_callgraph:is_escaping(Fun, Callgraph)],
+ Work = init_work(ExportedFuns),
+ Env = lists:foldl(fun(Fun, Env) -> dict:store(Fun, map__new(), Env) end,
+ dict:new(), Funs),
#state{callgraph = Callgraph, envs = Env, fun_tab = FunTab, opaques = Opaques,
plt = Plt, races = dialyzer_races:new(), records = Records,
warning_mode = false, warnings = [], work = Work, tree_map = TreeMap,
module = Module, behaviour_api_dict = BehaviourTranslations}.
-state__mark_fun_as_handled(#state{fun_tab = FunTab} = State, Fun0) ->
- Fun = get_label(Fun0),
- case dict:find(Fun, FunTab) of
- {ok, {not_handled, Entry}} ->
- State#state{fun_tab = dict:store(Fun, Entry, FunTab)};
- {ok, {_, _}} ->
- State
- end.
-
state__warning_mode(#state{warning_mode = WM}) ->
WM.
state__set_warning_mode(#state{tree_map = TreeMap, fun_tab = FunTab,
races = Races} = State) ->
- ?debug("Starting warning pass\n", []),
+ ?debug("==========\nStarting warning pass\n==========\n", []),
Funs = dict:fetch_keys(TreeMap),
State#state{work = init_work([top|Funs--[top]]),
fun_tab = FunTab, warning_mode = true,
@@ -2985,7 +2974,7 @@ state__get_warnings(#state{tree_map = TreeMap, fun_tab = FunTab,
{NotCalled, Ret} =
case dict:fetch(get_label(Fun), FunTab) of
{not_handled, {_Args0, Ret0}} -> {true, Ret0};
- {Args0, Ret0} -> {any_none(Args0), Ret0}
+ {_Args0, Ret0} -> {false, Ret0}
end,
case NotCalled of
true ->
@@ -3079,11 +3068,11 @@ state__lookup_record(Tag, Arity, #state{records = Records}) ->
error
end.
-state__get_args(Tree, #state{fun_tab = FunTab}) ->
+state__get_args_and_status(Tree, #state{fun_tab = FunTab}) ->
Fun = get_label(Tree),
case dict:find(Fun, FunTab) of
- {ok, {not_handled, {ArgTypes, _}}} -> ArgTypes;
- {ok, {ArgTypes, _}} -> ArgTypes
+ {ok, {not_handled, {ArgTypes, _}}} -> {ArgTypes, false};
+ {ok, {ArgTypes, _}} -> {ArgTypes, true}
end.
build_tree_map(Tree) ->
@@ -3099,7 +3088,7 @@ build_tree_map(Tree) ->
cerl_trees:fold(Fun, dict:new(), Tree).
init_fun_tab([top|Left], Dict, TreeMap, Callgraph, Plt, Opaques) ->
- NewDict = dict:store(top, {not_handled, {[], t_none()}}, Dict),
+ NewDict = dict:store(top, {[], t_none()}, Dict),
init_fun_tab(Left, NewDict, TreeMap, Callgraph, Plt, Opaques);
init_fun_tab([Fun|Left], Dict, TreeMap, Callgraph, Plt, Opaques) ->
Arity = cerl:fun_arity(dict:fetch(Fun, TreeMap)),
@@ -3115,9 +3104,9 @@ init_fun_tab([Fun|Left], Dict, TreeMap, Callgraph, Plt, Opaques) ->
false -> {Args, t_unit()}
end
end;
- false -> {lists:duplicate(Arity, t_none()), t_unit()}
+ false -> {not_handled, {lists:duplicate(Arity, t_none()), t_unit()}}
end,
- NewDict = dict:store(Fun, {not_handled, FunEntry}, Dict),
+ NewDict = dict:store(Fun, FunEntry, Dict),
init_fun_tab(Left, NewDict, TreeMap, Callgraph, Plt, Opaques);
init_fun_tab([], Dict, _TreeMap, _Callgraph, _Plt, _Opaques) ->
Dict.
@@ -3141,7 +3130,8 @@ state__clean_not_called(#state{fun_tab = FunTab} = State) ->
end, FunTab),
State#state{fun_tab = NewFunTab}.
-state__all_fun_types(#state{fun_tab = FunTab}) ->
+state__all_fun_types(State) ->
+ #state{fun_tab = FunTab} = state__clean_not_called(State),
Tab1 = dict:erase(top, FunTab),
dict:map(fun(_Fun, {Args, Ret}) -> t_fun(Args, Ret)end, Tab1).
diff --git a/lib/dialyzer/src/dialyzer_gui.erl b/lib/dialyzer/src/dialyzer_gui.erl
index f60194e01f..bac659548f 100644
--- a/lib/dialyzer/src/dialyzer_gui.erl
+++ b/lib/dialyzer/src/dialyzer_gui.erl
@@ -511,6 +511,16 @@ gui_loop(#gui_state{add_all = AddAll, add_file = AddFile, add_rec = AddRec,
[ExtCalls]),
free_editor(State, "Analysis done", Msg),
gui_loop(State);
+ {BackendPid, ext_types, ExtTypes} ->
+ Map = fun({M,F,A}) -> io_lib:format("~p:~p/~p",[M,F,A]) end,
+ ExtTypeString = string:join(lists:map(Map, ExtTypes), "\n"),
+ Msg = io_lib:format("The following remote types are being used "
+ "but information about them is not available.\n"
+ "The analysis might get more precise by including "
+ "the modules containing these types and making sure "
+ "that they are exported:\n~s\n", [ExtTypeString]),
+ free_editor(State, "Analysis done", Msg),
+ gui_loop(State);
{BackendPid, log, LogMsg} ->
update_editor(Log, LogMsg),
gui_loop(State);
diff --git a/lib/dialyzer/src/dialyzer_gui_wx.erl b/lib/dialyzer/src/dialyzer_gui_wx.erl
index e711c15ea7..9ff32bd8b1 100644
--- a/lib/dialyzer/src/dialyzer_gui_wx.erl
+++ b/lib/dialyzer/src/dialyzer_gui_wx.erl
@@ -503,6 +503,16 @@ gui_loop(#gui_state{backend_pid = BackendPid, doc_plt = DocPlt,
[ExtCalls]),
free_editor(State,"Analysis Done", Msg),
gui_loop(State);
+ {BackendPid, ext_types, ExtTypes} ->
+ Map = fun({M,F,A}) -> io_lib:format("~p:~p/~p",[M,F,A]) end,
+ ExtTypeString = string:join(lists:map(Map, ExtTypes), "\n"),
+ Msg = io_lib:format("The following remote types are being used "
+ "but information about them is not available.\n"
+ "The analysis might get more precise by including "
+ "the modules containing these types and making sure "
+ "that they are exported:\n~s\n", [ExtTypeString]),
+ free_editor(State, "Analysis done", Msg),
+ gui_loop(State);
{BackendPid, log, LogMsg} ->
update_editor(Log, LogMsg),
gui_loop(State);
diff --git a/lib/dialyzer/src/dialyzer_plt.erl b/lib/dialyzer/src/dialyzer_plt.erl
index 206c43e4e2..74892d1668 100644
--- a/lib/dialyzer/src/dialyzer_plt.erl
+++ b/lib/dialyzer/src/dialyzer_plt.erl
@@ -31,8 +31,7 @@
-export([check_plt/3,
compute_md5_from_files/1,
contains_mfa/2,
- contains_module/2,
- delete_contract_list/2,
+ all_modules/1,
delete_list/2,
delete_module/2,
included_files/1,
@@ -153,10 +152,8 @@ lookup_contract(#plt{contracts = Contracts},
{M, F, _} = MFA) when is_atom(M), is_atom(F) ->
table_lookup(Contracts, MFA).
--spec lookup_callbacks(plt(), module()) -> [{mfa(),
- {{Filename::string(),
- Line::pos_integer()},
- #contract{}}}].
+-spec lookup_callbacks(plt(), module()) ->
+ [{mfa(), {{Filename::string(), Line::pos_integer()}, #contract{}}}].
lookup_callbacks(#plt{callbacks = Callbacks}, Mod) when is_atom(Mod) ->
FunModFilter =
@@ -166,18 +163,6 @@ lookup_callbacks(#plt{callbacks = Callbacks}, Mod) when is_atom(Mod) ->
ModCallbacks = dict:filter(FunModFilter, Callbacks),
dict:to_list(ModCallbacks).
--spec delete_contract_list(plt(), [mfa()]) -> plt().
-
-delete_contract_list(#plt{contracts = Contracts,
- callbacks = Callbacks} = PLT, List) ->
- PLT#plt{contracts = table_delete_list(Contracts, List),
- callbacks = table_delete_list(Callbacks, List)}.
-
-%% -spec insert(plt(), mfa() | integer(), {_, _}) -> plt().
-%%
-%% insert(#plt{info = Info} = PLT, Id, Types) ->
-%% PLT#plt{info = table_insert(Info, Id, Types)}.
-
-type ret_args_types() :: {erl_types:erl_type(), [erl_types:erl_type()]}.
-spec insert_list(plt(), [{mfa() | integer(), ret_args_types()}]) -> plt().
@@ -220,10 +205,10 @@ get_exported_types(#plt{exported_types = ExpTypes}) ->
lookup_module(#plt{info = Info}, M) when is_atom(M) ->
table_lookup_module(Info, M).
--spec contains_module(plt(), atom()) -> boolean().
+-spec all_modules(plt()) -> set().
-contains_module(#plt{info = Info, contracts = Cs}, M) when is_atom(M) ->
- table_contains_module(Info, M) orelse table_contains_module(Cs, M).
+all_modules(#plt{info = Info, contracts = Cs}) ->
+ sets:union(table_all_modules(Info), table_all_modules(Cs)).
-spec contains_mfa(plt(), mfa()) -> boolean().
@@ -623,10 +608,12 @@ table_lookup_module(Plt, Mod) ->
false -> {value, List}
end.
-table_contains_module(Plt, Mod) ->
- dict:fold(fun({M, _F, _A}, _Val, _Acc) when M =:= Mod -> true;
- (_, _, Acc) -> Acc
- end, false, Plt).
+table_all_modules(Plt) ->
+ Fold =
+ fun({M, _F, _A}, _Val, Acc) -> sets:add_element(M, Acc);
+ (_, _, Acc) -> Acc
+ end,
+ dict:fold(Fold, sets:new(), Plt).
table_merge([H|T]) ->
table_merge(T, H).
diff --git a/lib/dialyzer/src/dialyzer_races.erl b/lib/dialyzer/src/dialyzer_races.erl
index ee9d5e88a3..b9594f5301 100644
--- a/lib/dialyzer/src/dialyzer_races.erl
+++ b/lib/dialyzer/src/dialyzer_races.erl
@@ -39,7 +39,7 @@
let_tag_new/2, new/0, put_curr_fun/3, put_fun_args/2,
put_race_analysis/2, put_race_list/3]).
--export_type([races/0, mfa_or_funlbl/0, core_vars/0]).
+-export_type([races/0, core_vars/0]).
-include("dialyzer.hrl").
@@ -66,8 +66,6 @@
%%%
%%% ===========================================================================
--type mfa_or_funlbl() :: label() | mfa().
-
-type label_type() :: label() | [label()] | {label()} | ?no_label.
-type args() :: [label_type() | [string()]].
-type core_vars() :: cerl:cerl() | ?no_arg | ?bypassed.
@@ -94,7 +92,7 @@
guard :: cerl:cerl()}).
-record(end_case, {clauses :: [#end_clause{}]}).
-record(curr_fun, {status :: 'in' | 'out',
- mfa :: mfa_or_funlbl(),
+ mfa :: dialyzer_callgraph:mfa_or_funlbl(),
label :: label(),
def_vars :: [core_vars()],
arg_types :: [erl_types:erl_type()],
@@ -107,8 +105,8 @@
state :: _, %% XXX: recursive
file_line :: file_line(),
var_map :: dict()}).
--record(fun_call, {caller :: mfa_or_funlbl(),
- callee :: mfa_or_funlbl(),
+-record(fun_call, {caller :: dialyzer_callgraph:mfa_or_funlbl(),
+ callee :: dialyzer_callgraph:mfa_or_funlbl(),
arg_types :: [erl_types:erl_type()],
vars :: [core_vars()]}).
-record(let_tag, {var :: var_to_map1(),
@@ -130,10 +128,10 @@
vars :: [core_vars()],
file_line :: file_line(),
index :: non_neg_integer(),
- fun_mfa :: mfa_or_funlbl(),
+ fun_mfa :: dialyzer_callgraph:mfa_or_funlbl(),
fun_label :: label()}).
--record(races, {curr_fun :: mfa_or_funlbl(),
+-record(races, {curr_fun :: dialyzer_callgraph:mfa_or_funlbl(),
curr_fun_label :: label(),
curr_fun_args = 'empty' :: core_args(),
new_table = 'no_t' :: table(),
@@ -158,7 +156,8 @@
%%%
%%% ===========================================================================
--spec store_race_call(mfa_or_funlbl(), [erl_types:erl_type()], [core_vars()],
+-spec store_race_call(dialyzer_callgraph:mfa_or_funlbl(),
+ [erl_types:erl_type()], [core_vars()],
file_line(), dialyzer_dataflow:state()) ->
dialyzer_dataflow:state().
@@ -2405,7 +2404,7 @@ end_case_new(Clauses) ->
end_clause_new(Arg, Pats, Guard) ->
#end_clause{arg = Arg, pats = Pats, guard = Guard}.
--spec get_curr_fun(races()) -> mfa_or_funlbl().
+-spec get_curr_fun(races()) -> dialyzer_callgraph:mfa_or_funlbl().
get_curr_fun(#races{curr_fun = CurrFun}) ->
CurrFun.
@@ -2444,7 +2443,7 @@ let_tag_new(Var, Arg) ->
new() -> #races{}.
--spec put_curr_fun(mfa_or_funlbl(), label(), races()) ->
+-spec put_curr_fun(dialyzer_callgraph:mfa_or_funlbl(), label(), races()) ->
races().
put_curr_fun(CurrFun, CurrFunLabel, Races) ->
diff --git a/lib/dialyzer/src/dialyzer_succ_typings.erl b/lib/dialyzer/src/dialyzer_succ_typings.erl
index 4d86bb34a7..de4c8a32a3 100644
--- a/lib/dialyzer/src/dialyzer_succ_typings.erl
+++ b/lib/dialyzer/src/dialyzer_succ_typings.erl
@@ -204,7 +204,7 @@ refine_one_module(M, State) ->
#st{callgraph = Callgraph, codeserver = CodeServer, plt = PLT} = State,
ModCode = dialyzer_codeserver:lookup_mod_code(M, CodeServer),
AllFuns = collect_fun_info([ModCode]),
- FunTypes = get_fun_types_from_plt(AllFuns, State),
+ FunTypes = get_fun_types_from_plt(AllFuns, Callgraph, PLT),
Records = dialyzer_codeserver:lookup_mod_records(M, CodeServer),
{NewFunTypes, RaceCode, PublicTables, NamedTables} =
dialyzer_dataflow:get_fun_types(ModCode, PLT, Callgraph, Records),
@@ -321,7 +321,9 @@ find_succ_typings(#st{callgraph = Callgraph, parent = Parent} = State,
end
end.
-analyze_scc(SCC, #st{codeserver = Codeserver} = State) ->
+analyze_scc(SCC, #st{codeserver = Codeserver,
+ callgraph = Callgraph,
+ plt = Plt} = State) ->
SCC_Info = [{MFA,
dialyzer_codeserver:lookup_mfa_code(MFA, Codeserver),
dialyzer_codeserver:lookup_mod_records(M, Codeserver)}
@@ -330,23 +332,19 @@ analyze_scc(SCC, #st{codeserver = Codeserver} = State) ->
|| {_, _, _} = MFA <- SCC],
Contracts2 = [{MFA, Contract} || {MFA, {ok, Contract}} <- Contracts1],
Contracts3 = orddict:from_list(Contracts2),
+ NextLabel = dialyzer_codeserver:get_next_core_label(Codeserver),
{SuccTypes, PltContracts, NotFixpoint} =
- find_succ_types_for_scc(SCC_Info, Contracts3, State),
+ find_succ_types_for_scc(SCC_Info, Contracts3, NextLabel, Callgraph, Plt),
State1 = insert_into_plt(SuccTypes, State),
ContrPlt = dialyzer_plt:insert_contract_list(State1#st.plt, PltContracts),
{State1#st{plt = ContrPlt}, NotFixpoint}.
-find_succ_types_for_scc(SCC_Info, Contracts,
- #st{codeserver = Codeserver,
- callgraph = Callgraph, plt = Plt} = State) ->
+find_succ_types_for_scc(SCC_Info, Contracts, NextLabel, Callgraph, Plt) ->
%% Assume that the PLT contains the current propagated types
AllFuns = collect_fun_info([Fun || {_MFA, {_Var, Fun}, _Rec} <- SCC_Info]),
- PropTypes = get_fun_types_from_plt(AllFuns, State),
- MFAs = [MFA || {MFA, {_Var, _Fun}, _Rec} <- SCC_Info],
- NextLabel = dialyzer_codeserver:get_next_core_label(Codeserver),
- Plt1 = dialyzer_plt:delete_contract_list(Plt, MFAs),
+ PropTypes = get_fun_types_from_plt(AllFuns, Callgraph, Plt),
FunTypes = dialyzer_typesig:analyze_scc(SCC_Info, NextLabel,
- Callgraph, Plt1, PropTypes),
+ Callgraph, Plt, PropTypes),
AllFunSet = sets:from_list([X || {X, _} <- AllFuns]),
FilteredFunTypes = dict:filter(fun(X, _) ->
sets:is_element(X, AllFunSet)
@@ -372,13 +370,13 @@ find_succ_types_for_scc(SCC_Info, Contracts,
ordsets:from_list([Fun || {Fun, _Arity} <- AllFuns])}
end.
-get_fun_types_from_plt(FunList, State) ->
- get_fun_types_from_plt(FunList, State, dict:new()).
+get_fun_types_from_plt(FunList, Callgraph, Plt) ->
+ get_fun_types_from_plt(FunList, Callgraph, Plt, dict:new()).
-get_fun_types_from_plt([{FunLabel, Arity}|Left], State, Map) ->
- Type = lookup_fun_type(FunLabel, Arity, State),
- get_fun_types_from_plt(Left, State, dict:store(FunLabel, Type, Map));
-get_fun_types_from_plt([], _State, Map) ->
+get_fun_types_from_plt([{FunLabel, Arity}|Left], Callgraph, Plt, Map) ->
+ Type = lookup_fun_type(FunLabel, Arity, Callgraph, Plt),
+ get_fun_types_from_plt(Left, Callgraph, Plt, dict:store(FunLabel, Type, Map));
+get_fun_types_from_plt([], _Callgraph, _Plt, Map) ->
Map.
collect_fun_info(Trees) ->
@@ -396,7 +394,7 @@ collect_fun_info([Tree|Trees], List) ->
collect_fun_info([], List) ->
List.
-lookup_fun_type(Label, Arity, #st{callgraph = Callgraph, plt = Plt}) ->
+lookup_fun_type(Label, Arity, Callgraph, Plt) ->
ID = lookup_name(Label, Callgraph),
case dialyzer_plt:lookup(Plt, ID) of
none -> erl_types:t_fun(Arity, erl_types:t_any());
diff --git a/lib/dialyzer/src/dialyzer_typesig.erl b/lib/dialyzer/src/dialyzer_typesig.erl
index 4268814859..04ff8e4941 100644
--- a/lib/dialyzer/src/dialyzer_typesig.erl
+++ b/lib/dialyzer/src/dialyzer_typesig.erl
@@ -91,22 +91,24 @@
-type typesig_scc() :: [{mfa(), {cerl:c_var(), cerl:c_fun()}, dict()}].
-type typesig_funmap() :: [{type_var(), type_var()}]. %% Orddict
--record(state, {callgraph :: dialyzer_callgraph:callgraph(),
- cs = [] :: [constr()],
- cmap = dict:new() :: dict(),
- fun_map = [] :: typesig_funmap(),
- fun_arities = dict:new() :: dict(),
- in_match = false :: boolean(),
- in_guard = false :: boolean(),
- module :: module(),
- name_map = dict:new() :: dict(),
- next_label :: label(),
- non_self_recs = [] :: [label()],
- plt :: dialyzer_plt:plt(),
- prop_types = dict:new() :: dict(),
- records = dict:new() :: dict(),
- opaques = [] :: [erl_types:erl_type()],
- scc = [] :: [type_var()]}).
+-record(state, {callgraph :: dialyzer_callgraph:callgraph(),
+ cs = [] :: [constr()],
+ cmap = dict:new() :: dict(),
+ fun_map = [] :: typesig_funmap(),
+ fun_arities = dict:new() :: dict(),
+ in_match = false :: boolean(),
+ in_guard = false :: boolean(),
+ module :: module(),
+ name_map = dict:new() :: dict(),
+ next_label :: label(),
+ self_recs :: [label()],
+ plt :: dialyzer_plt:plt(),
+ prop_types = dict:new() :: dict(),
+ records = dict:new() :: dict(),
+ opaques = [] :: [erl_types:erl_type()],
+ scc = [] :: [type_var()],
+ mfas = [] :: [dialyzer_callgraph:mfa_or_funlbl()]
+ }).
%%-----------------------------------------------------------------------------
@@ -448,7 +450,8 @@ traverse(Tree, DefinedVars, State) ->
%% Check if a record is constructed.
_ ->
Arity = length(Fields),
- case state__lookup_record(State2, cerl:atom_val(Tag), Arity) of
+ Records = State2#state.records,
+ case lookup_record(Records, cerl:atom_val(Tag), Arity) of
error -> {State2, TupleType};
{ok, RecType} ->
State3 = state__store_conj(TupleType, sub, RecType, State2),
@@ -646,8 +649,14 @@ get_plt_constr(MFA, Dst, ArgVars, State) ->
PltRes = dialyzer_plt:lookup(Plt, MFA),
Opaques = State#state.opaques,
Module = State#state.module,
+ SCCMFAs = State#state.mfas,
{FunModule, _, _} = MFA,
- case dialyzer_plt:lookup_contract(Plt, MFA) of
+ Contract =
+ case lists:member(MFA, SCCMFAs) of
+ true -> none;
+ false -> dialyzer_plt:lookup_contract(Plt, MFA)
+ end,
+ case Contract of
none ->
case PltRes of
none -> State;
@@ -1246,6 +1255,8 @@ get_bif_constr({erlang, is_record, 2}, Dst, [Var, Tag] = Args, _State) ->
mk_constraint(Var, sub, ArgV)]);
get_bif_constr({erlang, is_record, 3}, Dst, [Var, Tag, Arity] = Args, State) ->
%% TODO: Revise this to make it precise for Tag and Arity.
+ Records = State#state.records,
+ AllOpaques = State#state.opaques,
ArgFun =
fun(Map) ->
case t_is_atom(true, lookup_type(Dst, Map)) of
@@ -1262,10 +1273,8 @@ get_bif_constr({erlang, is_record, 3}, Dst, [Var, Tag, Arity] = Args, State) ->
GenRecord = t_tuple([TagType|AnyElems]),
case t_atom_vals(TagType) of
[TagVal] ->
- case state__lookup_record(State, TagVal,
- ArityVal - 1) of
+ case lookup_record(Records, TagVal, ArityVal - 1) of
{ok, Type} ->
- AllOpaques = State#state.opaques,
case t_opaque_match_record(Type, AllOpaques) of
[Opaque] -> Opaque;
_ -> Type
@@ -1287,7 +1296,7 @@ get_bif_constr({erlang, is_record, 3}, Dst, [Var, Tag, Arity] = Args, State) ->
DstFun = fun(Map) ->
[TmpVar, TmpTag, TmpArity] = TmpArgTypes = lookup_type_list(Args, Map),
TmpArgTypes2 =
- case lists:member(TmpVar, State#state.opaques) of
+ case lists:member(TmpVar, AllOpaques) of
true ->
case t_is_integer(TmpArity) of
true ->
@@ -1297,7 +1306,8 @@ get_bif_constr({erlang, is_record, 3}, Dst, [Var, Tag, Arity] = Args, State) ->
true ->
case t_atom_vals(TmpTag) of
[TmpTagVal] ->
- case state__lookup_record(State, TmpTagVal, TmpArityVal - 1) of
+ case lookup_record(Records, TmpTagVal,
+ TmpArityVal - 1) of
{ok, TmpType} ->
case t_is_none(t_inf(TmpType, TmpVar, opaque)) of
true -> TmpArgTypes;
@@ -1526,9 +1536,10 @@ get_bif_constr({erlang, element, 2} = _BIF, Dst, Args,
case t_is_none(GenType) of
true -> ?debug("Bif: ~w failed\n", [_BIF]), throw(error);
false ->
+ Opaques = State#state.opaques,
Fun = fun(Map) ->
[I, T] = ATs = lookup_type_list(Args, Map),
- ATs2 = case lists:member(T, State#state.opaques) of
+ ATs2 = case lists:member(T, Opaques) of
true -> [I, erl_types:t_opaque_structure(T)];
false -> ATs
end,
@@ -1546,7 +1557,7 @@ get_bif_constr({erlang, element, 2} = _BIF, Dst, Args,
end;
get_bif_constr({M, F, A} = _BIF, Dst, Args, State) ->
GenType = erl_bif_types:type(M, F, A),
- Opaques = State#state.opaques,
+ Opaques = State#state.opaques,
case t_is_none(GenType) of
true -> ?debug("Bif: ~w failed\n", [_BIF]), throw(error);
false ->
@@ -1612,11 +1623,12 @@ get_bif_test_constr(Dst, Arg, Type, State) ->
end
end,
ArgV = ?mk_fun_var(ArgFun, [Dst]),
+ Opaques = State#state.opaques,
DstFun = fun(Map) ->
ArgType = lookup_type(Arg, Map),
case t_is_none(t_inf(ArgType, Type)) of
true ->
- case lists:member(ArgType, State#state.opaques) of
+ case lists:member(ArgType, Opaques) of
true ->
OpaqueStruct = erl_types:t_opaque_structure(ArgType),
case t_is_none(t_inf(OpaqueStruct, Type)) of
@@ -1743,33 +1755,29 @@ solve_ref_or_list(#constraint_ref{id = Id, deps = Deps},
true -> solve_self_recursive(Cs, Map, MapDict, Id, t_none(), State);
false -> solve_ref_or_list(Cs, Map, MapDict, State)
end,
- case Res of
- {error, NewMapDict} ->
- ?debug("Error solving for function ~p\n", [debug_lookup_name(Id)]),
- Arity = state__fun_arity(Id, State),
- FunType =
- case state__prop_domain(t_var_name(Id), State) of
- error -> t_fun(Arity, t_none());
- {ok, Dom} -> t_fun(Dom, t_none())
- end,
- NewMap1 = enter_type(Id, FunType, Map),
- NewMap2 =
- case state__get_rec_var(Id, State) of
- {ok, Var} -> enter_type(Var, FunType, NewMap1);
- error -> NewMap1
- end,
- {ok, dict:store(Id, NewMap2, NewMapDict), NewMap2};
- {ok, NewMapDict, NewMap} ->
- ?debug("Done solving fun: ~p\n", [debug_lookup_name(Id)]),
- FunType = lookup_type(Id, NewMap),
- NewMap1 = enter_type(Id, FunType, Map),
- NewMap2 =
- case state__get_rec_var(Id, State) of
- {ok, Var} -> enter_type(Var, FunType, NewMap1);
- error -> NewMap1
- end,
- {ok, dict:store(Id, NewMap2, NewMapDict), NewMap2}
- end
+ {NewMapDict, FunType} =
+ case Res of
+ {error, NewMapDict0} ->
+ ?debug("Error solving for function ~p\n", [debug_lookup_name(Id)]),
+ Arity = state__fun_arity(Id, State),
+ FunType0 =
+ case state__prop_domain(t_var_name(Id), State) of
+ error -> t_fun(Arity, t_none());
+ {ok, Dom} -> t_fun(Dom, t_none())
+ end,
+ {NewMapDict0, FunType0};
+ {ok, NewMapDict0, NewMap} ->
+ ?debug("Done solving fun: ~p\n", [debug_lookup_name(Id)]),
+ FunType0 = lookup_type(Id, NewMap),
+ {NewMapDict0, FunType0}
+ end,
+ NewMap1 = enter_type(Id, FunType, Map),
+ NewMap2 =
+ case state__get_rec_var(Id, State) of
+ {ok, Var} -> enter_type(Var, FunType, NewMap1);
+ error -> NewMap1
+ end,
+ {ok, dict:store(Id, NewMap2, NewMapDict), NewMap2}
end;
solve_ref_or_list(#constraint_list{type=Type, list = Cs, deps = Deps, id = Id},
Map, MapDict, State) ->
@@ -2078,10 +2086,15 @@ mk_var_no_lit_list(List) ->
%% ============================================================================
new_state(SCC0, NextLabel, CallGraph, Plt, PropTypes) ->
- NameMap = dict:from_list([{MFA, Var} || {MFA, {Var, _Fun}, _Rec} <- SCC0]),
+ List = [{MFA, Var} || {MFA, {Var, _Fun}, _Rec} <- SCC0],
+ NameMap = dict:from_list(List),
+ MFAs = [MFA || {MFA, _Var} <- List],
SCC = [mk_var(Fun) || {_MFA, {_Var, Fun}, _Rec} <- SCC0],
+ SelfRecs = [F || F <- SCC,
+ dialyzer_callgraph:is_self_rec(t_var_name(F), CallGraph)],
#state{callgraph = CallGraph, name_map = NameMap, next_label = NextLabel,
- prop_types = PropTypes, plt = Plt, scc = ordsets:from_list(SCC)}.
+ prop_types = PropTypes, plt = Plt, scc = ordsets:from_list(SCC),
+ mfas = MFAs, self_recs = ordsets:from_list(SelfRecs)}.
state__set_rec_dict(State, RecDict) ->
State#state{records = RecDict}.
@@ -2091,15 +2104,6 @@ state__set_opaques(#state{records = RecDict} = State, {M, _F, _A}) ->
erl_types:module_builtin_opaques(M) ++ t_opaque_from_records(RecDict),
State#state{opaques = Opaques, module = M}.
-state__lookup_record(#state{records = Records}, Tag, Arity) ->
- case erl_types:lookup_record(Tag, Arity, Records) of
- {ok, Fields} ->
- {ok, t_tuple([t_from_term(Tag)|
- [FieldType || {_FieldName, FieldType} <- Fields]])};
- error ->
- error
- end.
-
state__set_in_match(State, Bool) ->
State#state{in_match = Bool}.
@@ -2268,14 +2272,12 @@ state__get_cs(Var, #state{cmap = Dict}) ->
%% The functions here will not be treated as self recursive.
%% These functions will need to be handled as such manually.
-state__mark_as_non_self_rec(SCC, #state{non_self_recs = NS} = State) ->
- State#state{non_self_recs = ordsets:union(NS, ordsets:from_list(SCC))}.
+state__mark_as_non_self_rec(SCC, #state{self_recs = SelfRecs} = State) ->
+ %% TODO: Check if the result is always empty and just set it to [] if so.
+ State#state{self_recs = ordsets:subtract(SelfRecs, ordsets:from_list(SCC))}.
-state__is_self_rec(Fun, #state{callgraph = CallGraph, non_self_recs = NS}) ->
- case ordsets:is_element(Fun, NS) of
- true -> false;
- false -> dialyzer_callgraph:is_self_rec(t_var_name(Fun), CallGraph)
- end.
+state__is_self_rec(Fun, #state{self_recs = SelfRecs}) ->
+ ordsets:is_element(Fun, SelfRecs).
state__store_funs(Vars0, Funs0, #state{fun_map = Map} = State) ->
debug_make_name_map(Vars0, Funs0),
@@ -2689,6 +2691,15 @@ find_constraint(Tuple, [#constraint_list{list = List}|Cs]) ->
find_constraint(Tuple, [_|Cs]) ->
find_constraint(Tuple, Cs).
+lookup_record(Records, Tag, Arity) ->
+ case erl_types:lookup_record(Tag, Arity, Records) of
+ {ok, Fields} ->
+ {ok, t_tuple([t_from_term(Tag)|
+ [FieldType || {_FieldName, FieldType} <- Fields]])};
+ error ->
+ error
+ end.
+
%% ============================================================================
%%
%% Pretty printer and debug facilities.
diff --git a/lib/dialyzer/test/Makefile b/lib/dialyzer/test/Makefile
index 47deb17f1d..6a1abce943 100644
--- a/lib/dialyzer/test/Makefile
+++ b/lib/dialyzer/test/Makefile
@@ -30,5 +30,5 @@ release_tests_spec:
$(INSTALL_DATA) $(AUXILIARY_FILES) $(RELSYSDIR)
@tar cf - *_SUITE_data | (cd $(RELSYSDIR); tar xf -)
cd $(RELSYSDIR);\
- erl -make;\
+ erlc dialyzer_common.erl file_utils.erl;\
erl -noshell -run dialyzer_common create_all_suites -s erlang halt
diff --git a/lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour b/lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour
index a38e662ccf..8cecabccaa 100644
--- a/lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour
+++ b/lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour
@@ -1,9 +1,9 @@
-sample_callback_wrong.erl:15: The inferred return type of sample_callback_2/0 (42) has nothing in common with atom(), which is the expected return type for the callback of sample_behaviour behaviour
-sample_callback_wrong.erl:16: The inferred return type of sample_callback_3/0 ('fair') has nothing in common with 'fail' | {'ok',1..255}, which is the expected return type for the callback of sample_behaviour behaviour
-sample_callback_wrong.erl:17: The inferred return type of sample_callback_4/1 ('fail') has nothing in common with 'ok', which is the expected return type for the callback of sample_behaviour behaviour
-sample_callback_wrong.erl:19: The inferred return type of sample_callback_5/1 (string()) has nothing in common with 'fail' | 'ok', which is the expected return type for the callback of sample_behaviour behaviour
-sample_callback_wrong.erl:19: The inferred type for the 1st argument of sample_callback_5/1 (atom()) is not a supertype of 1..255, which is expected type for this argument in the callback of the sample_behaviour behaviour
-sample_callback_wrong.erl:21: The inferred return type of sample_callback_6/3 ({'okk',number()}) has nothing in common with 'fail' | {'ok',1..255}, which is the expected return type for the callback of sample_behaviour behaviour
-sample_callback_wrong.erl:21: The inferred type for the 3rd argument of sample_callback_6/3 (atom()) is not a supertype of string(), which is expected type for this argument in the callback of the sample_behaviour behaviour
-sample_callback_wrong.erl:3: Undefined callback function sample_callback_1/0 (behaviour 'sample_behaviour')
+sample_callback_wrong.erl:16: The inferred return type of sample_callback_2/0 (42) has nothing in common with atom(), which is the expected return type for the callback of sample_behaviour behaviour
+sample_callback_wrong.erl:17: The inferred return type of sample_callback_3/0 ('fair') has nothing in common with 'fail' | {'ok',1..255}, which is the expected return type for the callback of sample_behaviour behaviour
+sample_callback_wrong.erl:18: The inferred return type of sample_callback_4/1 ('fail') has nothing in common with 'ok', which is the expected return type for the callback of sample_behaviour behaviour
+sample_callback_wrong.erl:20: The inferred return type of sample_callback_5/1 (string()) has nothing in common with 'fail' | 'ok', which is the expected return type for the callback of sample_behaviour behaviour
+sample_callback_wrong.erl:20: The inferred type for the 1st argument of sample_callback_5/1 (atom()) is not a supertype of 1..255, which is expected type for this argument in the callback of the sample_behaviour behaviour
+sample_callback_wrong.erl:22: The inferred return type of sample_callback_6/3 ({'okk',number()}) has nothing in common with 'fail' | {'ok',1..255}, which is the expected return type for the callback of sample_behaviour behaviour
+sample_callback_wrong.erl:22: The inferred type for the 3rd argument of sample_callback_6/3 (atom()) is not a supertype of string(), which is expected type for this argument in the callback of the sample_behaviour behaviour
+sample_callback_wrong.erl:4: Undefined callback function sample_callback_1/0 (behaviour 'sample_behaviour')
diff --git a/lib/dialyzer/test/behaviour_SUITE_data/src/custom_sup.erl b/lib/dialyzer/test/behaviour_SUITE_data/src/custom_sup.erl
new file mode 100644
index 0000000000..8ec84d798f
--- /dev/null
+++ b/lib/dialyzer/test/behaviour_SUITE_data/src/custom_sup.erl
@@ -0,0 +1,37 @@
+%%% Dialyzer was giving a warning with this input because of a bug in the
+%%% substitution of remote types in specs. Remote types in the first element of
+%%% a tuple would not update the tuple's tag set and we could end up with a
+%%% non-normalized representation.
+%%%
+%%% Reported by Damian DobroczyƄski on 29/02/2012
+
+-module(custom_sup).
+
+-behavior(supervisor).
+
+-export([init/1]).
+
+-spec init(atom()) ->
+ {ok, {{supervisor:strategy(), non_neg_integer(), non_neg_integer()},
+ [supervisor:child_spec()]}} | ignore.
+
+init(StorageName) ->
+ Strategy = {one_for_all, 100, 1},
+ %% get application-wide storage parameters
+ case application:get_env(storage) of
+ undefined ->
+ ignore;
+ {ok, Storage} ->
+ BackendId = proplists:get_value(backend, Storage),
+ BackendArgs = proplists:get_value(args, Storage),
+ if
+ (BackendId =:= undefined) orelse (BackendArgs =:= undefined) ->
+ ignore;
+ true ->
+ {ok, {Strategy,
+ [{id1, {a_module, start_link, []},
+ permanent, 5000, worker, [a_module]},
+ {id2, {another_module, start_link, []},
+ permanent, 5000, worker, [another_module]}]}}
+ end
+ end.
diff --git a/lib/dialyzer/test/behaviour_SUITE_data/src/sample_behaviour/sample_callback_wrong.erl b/lib/dialyzer/test/behaviour_SUITE_data/src/sample_behaviour/sample_callback_wrong.erl
index 02a063fab7..430494c48c 100644
--- a/lib/dialyzer/test/behaviour_SUITE_data/src/sample_behaviour/sample_callback_wrong.erl
+++ b/lib/dialyzer/test/behaviour_SUITE_data/src/sample_behaviour/sample_callback_wrong.erl
@@ -1,6 +1,7 @@
-module(sample_callback_wrong).
--behaviour(sample_behaviour).
+%% This attribute uses the american spelling of 'behaviour'.
+-behavior(sample_behaviour).
-export([
% sample_callback_1/0,
diff --git a/lib/dialyzer/test/dialyzer_common.erl b/lib/dialyzer/test/dialyzer_common.erl
index 51766a4604..d2b1026c06 100644
--- a/lib/dialyzer/test/dialyzer_common.erl
+++ b/lib/dialyzer/test/dialyzer_common.erl
@@ -216,10 +216,13 @@ get_suites(Dir) ->
end.
suffix(String, Suffix) ->
- Index = string:rstr(String, Suffix),
- case string:substr(String, Index) =:= Suffix of
- true -> {yes, string:sub_string(String,1,Index-1)};
- false -> no
+ case string:rstr(String, Suffix) of
+ 0 -> no;
+ Index ->
+ case string:substr(String, Index) =:= Suffix of
+ true -> {yes, string:sub_string(String,1,Index-1)};
+ false -> no
+ end
end.
-spec create_suite(string()) -> 'ok'.
diff --git a/lib/dialyzer/test/opaque_SUITE_data/results/multiple_wrong_opaques b/lib/dialyzer/test/opaque_SUITE_data/results/multiple_wrong_opaques
new file mode 100644
index 0000000000..18ece8820c
--- /dev/null
+++ b/lib/dialyzer/test/opaque_SUITE_data/results/multiple_wrong_opaques
@@ -0,0 +1,2 @@
+
+multiple_wrong_opaques.erl:5: Invalid type specification for function multiple_wrong_opaques:weird/1. The success typing is ('gazonk') -> 42
diff --git a/lib/dialyzer/test/opaque_SUITE_data/src/multiple_wrong_opaques.erl b/lib/dialyzer/test/opaque_SUITE_data/src/multiple_wrong_opaques.erl
new file mode 100644
index 0000000000..9e695cec1d
--- /dev/null
+++ b/lib/dialyzer/test/opaque_SUITE_data/src/multiple_wrong_opaques.erl
@@ -0,0 +1,8 @@
+-module(multiple_wrong_opaques).
+
+-export([weird/1]).
+
+-spec weird(dict() | gb_tree()) -> 42.
+
+weird(gazonk) -> 42.
+
diff --git a/lib/dialyzer/test/options1_SUITE_data/results/compiler b/lib/dialyzer/test/options1_SUITE_data/results/compiler
index e82087ae86..6399e3e36b 100644
--- a/lib/dialyzer/test/options1_SUITE_data/results/compiler
+++ b/lib/dialyzer/test/options1_SUITE_data/results/compiler
@@ -20,6 +20,7 @@ cerl_inline.erl:2333: The pattern 'true' can never match the type 'false'
cerl_inline.erl:2355: The pattern 'true' can never match the type 'false'
cerl_inline.erl:238: The pattern 'true' can never match the type 'false'
cerl_inline.erl:2436: Function filename/1 will never be called
+cerl_inline.erl:244: Function counter_stats/0 will never be called
cerl_inline.erl:2700: The pattern 'true' can never match the type 'false'
cerl_inline.erl:2730: The pattern <{F, L, D}, Vs> can never match the type <[1..255,...],[any()]>
cerl_inline.erl:2738: The pattern <{F, L, D}, Vs> can never match the type <[1..255,...],[any()]>
diff --git a/lib/dialyzer/test/r9c_SUITE_data/results/inets b/lib/dialyzer/test/r9c_SUITE_data/results/inets
index 0e8ddf5492..d789d8d246 100644
--- a/lib/dialyzer/test/r9c_SUITE_data/results/inets
+++ b/lib/dialyzer/test/r9c_SUITE_data/results/inets
@@ -8,6 +8,7 @@ http_lib.erl:424: The variable _ can never match since previous clauses complete
http_lib.erl:438: The variable _ can never match since previous clauses completely covered the type any()
http_lib.erl:99: Function getHeaderValue/2 will never be called
httpc_handler.erl:660: Function exit_session_ok/2 has no local return
+httpc_handler.erl:676: Function format_time/0 will never be called
httpc_manager.erl:145: The pattern {ErrorReply, State2} can never match the type {{'ok',number()},number(),#state{reqid::number()}}
httpc_manager.erl:160: The pattern {ErrorReply, State2} can never match the type {{'ok',number()},number(),#state{reqid::number()}}
httpc_manager.erl:478: The pattern {'error', Reason} can never match the type 'ok' | {number(),#session{clientclose::boolean(),pipeline::[],quelength::1}}
diff --git a/lib/dialyzer/test/small_SUITE_data/results/cerl_hipeify b/lib/dialyzer/test/small_SUITE_data/results/cerl_hipeify
index 87bf6f309f..06dc0d63ee 100644
--- a/lib/dialyzer/test/small_SUITE_data/results/cerl_hipeify
+++ b/lib/dialyzer/test/small_SUITE_data/results/cerl_hipeify
@@ -1,4 +1,4 @@
cerl_hipeify.erl:370: Function will never be called
-cerl_hipeify.erl:370: Guard test fun((none()) -> none()) =:= F::{_,_,_} | {_,_,_,_} | {_,_,_,_,_} | {_,_,_,_,_,_} | {_,_,_,_,_,_,_} can never succeed
+cerl_hipeify.erl:370: Guard test fun((none()) -> no_return()) =:= F::{_,_,_} | {_,_,_,_} | {_,_,_,_,_} | {_,_,_,_,_,_} | {_,_,_,_,_,_,_} can never succeed
cerl_hipeify.erl:641: Function env__new_function_name/2 will never be called
diff --git a/lib/dialyzer/test/small_SUITE_data/results/inf_loop2 b/lib/dialyzer/test/small_SUITE_data/results/inf_loop2
index 7e9972ad98..142e4b2c37 100644
--- a/lib/dialyzer/test/small_SUITE_data/results/inf_loop2
+++ b/lib/dialyzer/test/small_SUITE_data/results/inf_loop2
@@ -1,4 +1,4 @@
inf_loop2.erl:18: Function test/0 has no local return
inf_loop2.erl:19: The call lists:reverse('gazonk') will never return since it differs in the 1st argument from the success typing arguments: ([any()])
-inf_loop2.erl:22: Function loop/0 has no local return
+inf_loop2.erl:22: Function loop/0 will never be called
diff --git a/lib/dialyzer/test/small_SUITE_data/results/no_local_return b/lib/dialyzer/test/small_SUITE_data/results/no_local_return
new file mode 100644
index 0000000000..6ca1ed51d8
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/results/no_local_return
@@ -0,0 +1,3 @@
+
+no_local_return.erl:11: Function bar/1 will never be called
+no_local_return.erl:8: Function foo/0 will never be called
diff --git a/lib/dialyzer/test/small_SUITE_data/src/no_local_return.erl b/lib/dialyzer/test/small_SUITE_data/src/no_local_return.erl
new file mode 100644
index 0000000000..4e1a0b015a
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/src/no_local_return.erl
@@ -0,0 +1,12 @@
+-module(no_local_return).
+
+%% NOTE: No function is exported. Dialyzer produced a bogus
+%% 'Function foo/0 has no local return' warning
+%% when in fact typer was finding correct return values for both
+%% these functions.
+
+foo() ->
+ bar(42).
+
+bar(X) ->
+ lists:duplicate(X, gazonk).
diff --git a/lib/dialyzer/test/small_SUITE_data/src/on_load.erl b/lib/dialyzer/test/small_SUITE_data/src/on_load.erl
new file mode 100644
index 0000000000..16533a9caa
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/src/on_load.erl
@@ -0,0 +1,11 @@
+%%% This is to ensure that "on_load" functions are never reported as unused.
+
+-module(on_load).
+
+-export([foo/0]).
+
+-on_load(bar/0).
+
+foo() -> ok.
+
+bar() -> ok.