From 7c3a98b560a80878c603fabe26ca4a572bfe9122 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Fri, 20 Jan 2012 16:18:23 +0100 Subject: Cleanup debug messages in dialyzer_dataflow --- lib/dialyzer/src/dialyzer_dataflow.erl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_dataflow.erl') diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl index 6008dba080..8930054210 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). @@ -2913,7 +2909,7 @@ state__warning_mode(#state{warning_mode = 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, -- cgit v1.2.3 From 4ca72667f3e655d175c7587b8998aa7d22f50985 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Sun, 22 Jan 2012 17:43:48 +0100 Subject: Zero-arity unused functions Dialyzer patch Dialyzer was not reporting unused functions with 0 arity. This was not a real issue, until we found out that there could be cases where this could lead to false warnings. This was the case in "no_local_return.erl". --- lib/dialyzer/src/dialyzer_dataflow.erl | 54 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_dataflow.erl') diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl index 8930054210..887b2dd049 100644 --- a/lib/dialyzer/src/dialyzer_dataflow.erl +++ b/lib/dialyzer/src/dialyzer_dataflow.erl @@ -316,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), @@ -2888,22 +2887,16 @@ 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. @@ -2981,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 -> @@ -3075,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) -> @@ -3095,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)), @@ -3111,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. @@ -3137,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). -- cgit v1.2.3 From 7a99d71dd3f003bc6179bb69569ece27b38b57eb Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 23 Jan 2012 16:40:42 +0100 Subject: Cleanups in dialyzer_callgraph and dialyzer_dataflow Refactorings, code movements and reflection of mutable variables in the code. --- lib/dialyzer/src/dialyzer_dataflow.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_dataflow.erl') diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl index 887b2dd049..aba13278ff 100644 --- a/lib/dialyzer/src/dialyzer_dataflow.erl +++ b/lib/dialyzer/src/dialyzer_dataflow.erl @@ -272,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); @@ -282,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), @@ -309,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) -- cgit v1.2.3