From 8a3ea1fa45cac31cdc1241a6ea1e1a0d857c1429 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Thu, 22 Dec 2011 19:50:13 +0200 Subject: Convert remaining codeserver fields to ETS tables --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 2c4622155a..7221d81a72 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -348,12 +348,9 @@ compile_common(File, AbstrCode, CompOpts, Callgraph, CServer, UseContracts) -> store_core(Mod, Core, NoWarn, Callgraph, CServer) -> Exp = get_exports_from_core(Core), - OldExpTypes = dialyzer_codeserver:get_temp_exported_types(CServer), - NewExpTypes = get_exported_types_from_core(Core), - MergedExpTypes = sets:union(NewExpTypes, OldExpTypes), + ExpTypes = get_exported_types_from_core(Core), CServer1 = dialyzer_codeserver:insert_exports(Exp, CServer), - CServer2 = dialyzer_codeserver:insert_temp_exported_types(MergedExpTypes, - CServer1), + CServer2 = dialyzer_codeserver:insert_temp_exported_types(ExpTypes, CServer1), {LabeledCore, CServer3} = label_core(Core, CServer2), store_code_and_build_callgraph(Mod, LabeledCore, Callgraph, CServer3, NoWarn). -- cgit v1.2.3 From e6fa01359a41d3b054260d01d2880820c867ca2b Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Fri, 10 Feb 2012 14:42:30 +0100 Subject: Parallel typesig analysis --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 7221d81a72..7060028d17 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -179,22 +179,21 @@ analyze_callgraph(Callgraph, State) -> Parent = State#analysis_state.parent, 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, + {dialyzer_succ_typings:analyze_callgraph(Callgraph, Plt, Codeserver, Parent), DocPlt}; succ_typings -> NoWarn = State#analysis_state.no_warn_unused, {Warnings, NewPlt0, NewDocPlt0} = - dialyzer_succ_typings:get_warnings(Callgraph1, Plt, DocPlt, + dialyzer_succ_typings:get_warnings(Callgraph, Plt, DocPlt, Codeserver, NoWarn, Parent), send_warnings(State#analysis_state.parent, Warnings), {NewPlt0, NewDocPlt0} end, - dialyzer_callgraph:delete(Callgraph1), + dialyzer_callgraph:delete(Callgraph), State#analysis_state{plt = NewPlt, doc_plt = NewDocPlt}. %%-------------------------------------------------------------------- -- cgit v1.2.3 From 08d6fa6c97be82c4b4a480ec04aa06ae8e781783 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Sun, 19 Feb 2012 01:40:54 +0100 Subject: Parallel compilation of files under analysis --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 105 +++++++++++++---------- 1 file changed, 61 insertions(+), 44 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 7060028d17..e009b8f43f 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -30,6 +30,11 @@ -export([start/3]). +-export([compile_coordinator_init/0, + add_to_result/3, + start_compilation/2, + continue_compilation/2]). + -include("dialyzer.hrl"). -record(analysis_state, @@ -212,33 +217,15 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, Includes = [{i, D} || D <- Dirs], Defines = [{d, Macro, Val} || {Macro, Val} <- Defs], Callgraph = dialyzer_callgraph:new(), - Fun = case StartFrom of - src_code -> - fun(File, {TmpCG, TmpCServer, TmpFailed, TmpNoWarn, TmpMods}) -> - case compile_src(File, Includes, Defines, TmpCG, - TmpCServer, UseContracts) of - {error, Reason} -> - {TmpCG, TmpCServer, [{File, Reason}|TmpFailed], TmpNoWarn, - TmpMods}; - {ok, NewCG, NoWarn, NewCServer, Mod} -> - {NewCG, NewCServer, TmpFailed, NoWarn++TmpNoWarn, - [Mod|TmpMods]} - end - end; - byte_code -> - fun(File, {TmpCG, TmpCServer, TmpFailed, TmpNoWarn, TmpMods}) -> - case compile_byte(File, TmpCG, TmpCServer, UseContracts) of - {error, Reason} -> - {TmpCG, TmpCServer, [{File, Reason}|TmpFailed], TmpNoWarn, - TmpMods}; - {ok, NewCG, NoWarn, NewCServer, Mod} -> - {NewCG, NewCServer, TmpFailed, NoWarn++TmpNoWarn, - [Mod|TmpMods]} - end - end - end, - {NewCallgraph1, NewCServer, Failed, NoWarn, Modules} = - lists:foldl(Fun, {Callgraph, CServer, [], [], []}, Files), + Servers = {Callgraph, CServer, StartFrom, Includes, Defines, UseContracts}, + Coordinator = dialyzer_coordinator:start(compile, Servers), + Spawner = fun(F) -> dialyzer_coordinator:compiler_spawn(F, Coordinator) end, + lists:foreach(Spawner, Files), + dialyzer_coordinator:all_spawned(Coordinator), + {{V, E, Failed, NoWarn, Modules}, NextLabel} = + dialyzer_coordinator:receive_compilation_data(), + CServer2 = dialyzer_codeserver:set_next_core_label(NextLabel, CServer), + Callgraph = dialyzer_callgraph:add_edges(E, V, Callgraph), case Failed =:= [] of true -> NewFiles = lists:zip(lists:reverse(Modules), Files), @@ -254,11 +241,41 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, {T2, _} = statistics(runtime), Msg1 = io_lib:format("done in ~.2f secs\nRemoving edges... ", [(T2-T1)/1000]), send_log(Parent, Msg1), - NewCallgraph2 = cleanup_callgraph(State, NewCServer, NewCallgraph1, Modules), + Callgraph = cleanup_callgraph(State, CServer2, Callgraph, Modules), {T3, _} = statistics(runtime), Msg2 = io_lib:format("done in ~.2f secs\n", [(T3-T2)/1000]), send_log(Parent, Msg2), - {NewCallgraph2, sets:from_list(NoWarn), NewCServer}. + {Callgraph, sets:from_list(NoWarn), CServer2}. + +-type servers() :: term(). +-type result() :: term(). +-type file_result() :: term(). +-type data() :: term(). + +-spec compile_coordinator_init() -> result(). + +compile_coordinator_init() -> {[], [], [], [], []}. + +-spec add_to_result(file:filename(), file_result(), result()) -> result(). + +add_to_result(File, NewData, {V, E, Failed, NoWarn, Mods}) -> + case NewData of + {error, Reason} -> + {[{File, Reason}|Failed], NoWarn, Mods}; + {ok, NV, NE, NewNoWarn, Mod} -> + {NV ++ V, NE ++ E, Failed, NewNoWarn ++ NoWarn, [Mod|Mods]} + end. + +-spec start_compilation(file:filename(), servers()) -> data(). + +start_compilation(File, {Callgraph, Codeserver, StartFrom, + Includes, Defines, UseContracts}) -> + case StartFrom of + src_code -> + compile_src(File, Includes, Defines, Callgraph, Codeserver, UseContracts); + byte_code -> + compile_byte(File, Callgraph, Codeserver, UseContracts) + end. cleanup_callgraph(#analysis_state{plt = InitPlt, parent = Parent, codeserver = CodeServer @@ -348,10 +365,17 @@ compile_common(File, AbstrCode, CompOpts, Callgraph, CServer, UseContracts) -> store_core(Mod, Core, NoWarn, Callgraph, CServer) -> Exp = get_exports_from_core(Core), ExpTypes = get_exported_types_from_core(Core), - CServer1 = dialyzer_codeserver:insert_exports(Exp, CServer), - CServer2 = dialyzer_codeserver:insert_temp_exported_types(ExpTypes, CServer1), - {LabeledCore, CServer3} = label_core(Core, CServer2), - store_code_and_build_callgraph(Mod, LabeledCore, Callgraph, CServer3, NoWarn). + CServer = dialyzer_codeserver:insert_exports(Exp, CServer), + CServer = dialyzer_codeserver:insert_temp_exported_types(ExpTypes, CServer), + CoreTree = cerl:from_records(Core), + {cerl_trees:size(CoreTree), {Mod, CoreTree, NoWarn, Callgraph, CServer}}. + +-spec continue_compilation(integer(), data()) -> {integer(), file_result()}. + +continue_compilation(NextLabel, {Mod, CoreTree, NoWarn, Callgraph, CServer}) -> + {LabeledTree, _NewNextLabel} = cerl_trees:label(CoreTree, NextLabel), + LabeledCore = cerl:to_records(LabeledTree), + store_code_and_build_callgraph(Mod, LabeledCore, Callgraph, NoWarn, CServer). abs_get_nowarn(Abs, M) -> Opts = lists:flatten([C || {attribute, _, compile, C} <- Abs]), @@ -384,18 +408,11 @@ get_exports_from_core(Core) -> M = cerl:atom_val(cerl:module_name(Tree)), [{M, F, A} || {F, A} <- Exports2]. -label_core(Core, CServer) -> - NextLabel = dialyzer_codeserver:get_next_core_label(CServer), - CoreTree = cerl:from_records(Core), - {LabeledTree, NewNextLabel} = cerl_trees:label(CoreTree, NextLabel), - {cerl:to_records(LabeledTree), - dialyzer_codeserver:set_next_core_label(NewNextLabel, CServer)}. - -store_code_and_build_callgraph(Mod, Core, Callgraph, CServer, NoWarn) -> +store_code_and_build_callgraph(Mod, Core, Callgraph, NoWarn, CServer) -> CoreTree = cerl:from_records(Core), - NewCallgraph = dialyzer_callgraph:scan_core_tree(CoreTree, Callgraph), - CServer2 = dialyzer_codeserver:insert(Mod, CoreTree, CServer), - {ok, NewCallgraph, NoWarn, CServer2, Mod}. + {Vertices, Edges} = dialyzer_callgraph:scan_core_tree(CoreTree, Callgraph), + CServer = dialyzer_codeserver:insert(Mod, CoreTree, CServer), + {ok, Vertices, Edges, NoWarn, Mod}. %%-------------------------------------------------------------------- %% Utilities -- cgit v1.2.3 From b8ab5bc3211fdee28000e2fd35a47dafa2a4316c Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Sun, 19 Feb 2012 22:05:47 +0100 Subject: Fix types and specs in Dialyzer --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index e009b8f43f..febaf56e40 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -35,6 +35,10 @@ start_compilation/2, continue_compilation/2]). +-export_type([compilation_data/0, + result/0, + servers/0]). + -include("dialyzer.hrl"). -record(analysis_state, @@ -247,10 +251,10 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, send_log(Parent, Msg2), {Callgraph, sets:from_list(NoWarn), CServer2}. --type servers() :: term(). --type result() :: term(). --type file_result() :: term(). --type data() :: term(). +-type servers() :: term(). %%opaque +-type result() :: term(). %%opaque +-type file_result() :: term(). %%opaque +-type compilation_data() :: term(). %%opaque -spec compile_coordinator_init() -> result(). @@ -266,7 +270,8 @@ add_to_result(File, NewData, {V, E, Failed, NoWarn, Mods}) -> {NV ++ V, NE ++ E, Failed, NewNoWarn ++ NoWarn, [Mod|Mods]} end. --spec start_compilation(file:filename(), servers()) -> data(). +-spec start_compilation(file:filename(), servers()) -> + {error, term()} |{ok, integer(), compilation_data()}. start_compilation(File, {Callgraph, Codeserver, StartFrom, Includes, Defines, UseContracts}) -> @@ -368,9 +373,9 @@ store_core(Mod, Core, NoWarn, Callgraph, CServer) -> CServer = dialyzer_codeserver:insert_exports(Exp, CServer), CServer = dialyzer_codeserver:insert_temp_exported_types(ExpTypes, CServer), CoreTree = cerl:from_records(Core), - {cerl_trees:size(CoreTree), {Mod, CoreTree, NoWarn, Callgraph, CServer}}. + {ok, cerl_trees:size(CoreTree), {Mod, CoreTree, NoWarn, Callgraph, CServer}}. --spec continue_compilation(integer(), data()) -> {integer(), file_result()}. +-spec continue_compilation(integer(), compilation_data()) -> file_result(). continue_compilation(NextLabel, {Mod, CoreTree, NoWarn, Callgraph, CServer}) -> {LabeledTree, _NewNextLabel} = cerl_trees:label(CoreTree, NextLabel), -- cgit v1.2.3 From 60e682897f98d9374b96c6324759f302170b2a17 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 20 Feb 2012 13:56:25 +0100 Subject: Add --time option to Dialyzer --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index febaf56e40..30eb087fcf 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -134,7 +134,8 @@ analysis_start(Parent, Analysis) -> use_contracts = Analysis#analysis.use_contracts }, Files = ordsets:from_list(Analysis#analysis.files), - {Callgraph, NoWarn, TmpCServer0} = compile_and_store(Files, State), + {Callgraph, NoWarn, TmpCServer0} = + ?timing("compile",compile_and_store(Files, State)), %% Remote type postprocessing NewCServer = try -- cgit v1.2.3 From a6ab15d61cd4b36ba9d4eab7a3d290330b5c3798 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 20 Feb 2012 16:45:54 +0100 Subject: Add better timing labels --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 30eb087fcf..02108d6e38 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -134,8 +134,7 @@ analysis_start(Parent, Analysis) -> use_contracts = Analysis#analysis.use_contracts }, Files = ordsets:from_list(Analysis#analysis.files), - {Callgraph, NoWarn, TmpCServer0} = - ?timing("compile",compile_and_store(Files, State)), + {Callgraph, NoWarn, TmpCServer0} = compile_and_store(Files, State), %% Remote type postprocessing NewCServer = try @@ -156,7 +155,8 @@ analysis_start(Parent, Analysis) -> dialyzer_codeserver:insert_temp_exported_types(MergedExpTypes, TmpCServer1), TmpCServer3 = dialyzer_utils:process_record_remote_types(TmpCServer2), - dialyzer_contracts:process_contract_remote_types(TmpCServer3) + ?timing("remote", + dialyzer_contracts:process_contract_remote_types(TmpCServer3)) catch throw:{error, _ErrorMsg} = Error -> exit(Error) end, @@ -228,9 +228,10 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, lists:foreach(Spawner, Files), dialyzer_coordinator:all_spawned(Coordinator), {{V, E, Failed, NoWarn, Modules}, NextLabel} = - dialyzer_coordinator:receive_compilation_data(), + ?timing("compile", _C1, dialyzer_coordinator:receive_compilation_data()), CServer2 = dialyzer_codeserver:set_next_core_label(NextLabel, CServer), - Callgraph = dialyzer_callgraph:add_edges(E, V, Callgraph), + Callgraph = + ?timing("digraph", _C2, dialyzer_callgraph:add_edges(E, V, Callgraph)), case Failed =:= [] of true -> NewFiles = lists:zip(lists:reverse(Modules), Files), @@ -246,7 +247,9 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, {T2, _} = statistics(runtime), Msg1 = io_lib:format("done in ~.2f secs\nRemoving edges... ", [(T2-T1)/1000]), send_log(Parent, Msg1), - Callgraph = cleanup_callgraph(State, CServer2, Callgraph, Modules), + Callgraph = + ?timing("clean", _C3, + cleanup_callgraph(State, CServer2, Callgraph, Modules)), {T3, _} = statistics(runtime), Msg2 = io_lib:format("done in ~.2f secs\n", [(T3-T2)/1000]), send_log(Parent, Msg2), -- cgit v1.2.3 From 1630eaa34f2cb8d6fceefbb752cfe94ac8e44b6a Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Tue, 28 Feb 2012 22:49:04 +0100 Subject: Coordinator is no longer a separate process --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 91 ++++++++++++++---------- 1 file changed, 53 insertions(+), 38 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 02108d6e38..e2e65d2e25 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -30,14 +30,14 @@ -export([start/3]). --export([compile_coordinator_init/0, - add_to_result/3, +-export([compile_init_result/0, + add_to_result/4, start_compilation/2, continue_compilation/2]). --export_type([compilation_data/0, - result/0, - servers/0]). +-export_type([compile_mid_data/0, + compile_result/0, + compile_init_data/0]). -include("dialyzer.hrl"). @@ -210,28 +210,37 @@ analyze_callgraph(Callgraph, State) -> %% Build the callgraph and fill the codeserver. %%-------------------------------------------------------------------- +-record(compile_init,{ + callgraph :: dialyzer_callgraph:callgraph(), + codeserver :: dialyzer_codeserver:codeserver(), + defines = [] :: [dial_define()], + include_dirs = [] :: [file:filename()], + start_from = byte_code :: start_from(), + use_contracts = true :: boolean() + }). + +make_compile_init(#analysis_state{codeserver = Codeserver, + defines = Defs, + include_dirs = Dirs, + use_contracts = UseContracts, + start_from = StartFrom}, Callgraph) -> + #compile_init{callgraph = Callgraph, + codeserver = Codeserver, + defines = [{d, Macro, Val} || {Macro, Val} <- Defs], + include_dirs = [{i, D} || D <- Dirs], + use_contracts = UseContracts, + start_from = StartFrom}. + compile_and_store(Files, #analysis_state{codeserver = CServer, - defines = Defs, - include_dirs = Dirs, - parent = Parent, - use_contracts = UseContracts, - start_from = StartFrom - } = State) -> + parent = Parent} = State) -> send_log(Parent, "Reading files and computing callgraph... "), {T1, _} = statistics(runtime), - Includes = [{i, D} || D <- Dirs], - Defines = [{d, Macro, Val} || {Macro, Val} <- Defs], Callgraph = dialyzer_callgraph:new(), - Servers = {Callgraph, CServer, StartFrom, Includes, Defines, UseContracts}, - Coordinator = dialyzer_coordinator:start(compile, Servers), - Spawner = fun(F) -> dialyzer_coordinator:compiler_spawn(F, Coordinator) end, - lists:foreach(Spawner, Files), - dialyzer_coordinator:all_spawned(Coordinator), - {{V, E, Failed, NoWarn, Modules}, NextLabel} = - ?timing("compile", _C1, dialyzer_coordinator:receive_compilation_data()), + CompileInit = make_compile_init(State, Callgraph), + {{Failed, NoWarn, Modules}, NextLabel} = + ?timing("compile", + dialyzer_coordinator:parallel_job(compile, Files, CompileInit)), CServer2 = dialyzer_codeserver:set_next_core_label(NextLabel, CServer), - Callgraph = - ?timing("digraph", _C2, dialyzer_callgraph:add_edges(E, V, Callgraph)), case Failed =:= [] of true -> NewFiles = lists:zip(lists:reverse(Modules), Files), @@ -255,33 +264,39 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, send_log(Parent, Msg2), {Callgraph, sets:from_list(NoWarn), CServer2}. --type servers() :: term(). %%opaque --type result() :: term(). %%opaque --type file_result() :: term(). %%opaque --type compilation_data() :: term(). %%opaque +-type compile_init_data() :: #compile_init{}. +-type compile_result() :: {list(), list(), list()}. %%opaque +-type one_file_result() :: term(). %%opaque +-type compile_mid_data() :: term(). %%opaque --spec compile_coordinator_init() -> result(). +-spec compile_init_result() -> compile_result(). -compile_coordinator_init() -> {[], [], [], [], []}. +compile_init_result() -> {[], [], []}. --spec add_to_result(file:filename(), file_result(), result()) -> result(). +-spec add_to_result(file:filename(), one_file_result(), compile_result(), + compile_init_data()) -> compile_result(). -add_to_result(File, NewData, {V, E, Failed, NoWarn, Mods}) -> +add_to_result(File, NewData, {Failed, NoWarn, Mods}, InitData) -> case NewData of {error, Reason} -> {[{File, Reason}|Failed], NoWarn, Mods}; - {ok, NV, NE, NewNoWarn, Mod} -> - {NV ++ V, NE ++ E, Failed, NewNoWarn ++ NoWarn, [Mod|Mods]} + {ok, V, E, NewNoWarn, Mod} -> + Callgraph = InitData#compile_init.callgraph, + dialyzer_callgraph:add_edges(E, V, Callgraph), + {Failed, NewNoWarn ++ NoWarn, [Mod|Mods]} end. --spec start_compilation(file:filename(), servers()) -> - {error, term()} |{ok, integer(), compilation_data()}. +-spec start_compilation(file:filename(), compile_init_data()) -> + {error, term()} |{ok, integer(), compile_mid_data()}. -start_compilation(File, {Callgraph, Codeserver, StartFrom, - Includes, Defines, UseContracts}) -> +start_compilation(File, + #compile_init{callgraph = Callgraph, codeserver = Codeserver, + defines = Defines, include_dirs = IncludeD, + use_contracts = UseContracts, + start_from = StartFrom}) -> case StartFrom of src_code -> - compile_src(File, Includes, Defines, Callgraph, Codeserver, UseContracts); + compile_src(File, IncludeD, Defines, Callgraph, Codeserver, UseContracts); byte_code -> compile_byte(File, Callgraph, Codeserver, UseContracts) end. @@ -379,7 +394,7 @@ store_core(Mod, Core, NoWarn, Callgraph, CServer) -> CoreTree = cerl:from_records(Core), {ok, cerl_trees:size(CoreTree), {Mod, CoreTree, NoWarn, Callgraph, CServer}}. --spec continue_compilation(integer(), compilation_data()) -> file_result(). +-spec continue_compilation(integer(), compile_mid_data()) -> one_file_result(). continue_compilation(NextLabel, {Mod, CoreTree, NoWarn, Callgraph, CServer}) -> {LabeledTree, _NewNextLabel} = cerl_trees:label(CoreTree, NextLabel), -- cgit v1.2.3 From 76b7c72882ee521a7c5a39d33ecf1009a72ee4e3 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 5 Mar 2012 13:01:11 +0100 Subject: Fix types and specs --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index e2e65d2e25..67c5b3241d 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -35,9 +35,9 @@ start_compilation/2, continue_compilation/2]). --export_type([compile_mid_data/0, - compile_result/0, - compile_init_data/0]). +-export_type([compile_init_data/0, + one_file_result/0, + compile_result/0]). -include("dialyzer.hrl"). @@ -265,9 +265,15 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, {Callgraph, sets:from_list(NoWarn), CServer2}. -type compile_init_data() :: #compile_init{}. --type compile_result() :: {list(), list(), list()}. %%opaque --type one_file_result() :: term(). %%opaque --type compile_mid_data() :: term(). %%opaque +-type error_reason() :: string(). +-type compile_result() :: {[{file:filename(), error_reason()}], [mfa()], + [module()]}. %%opaque +-type one_file_result() :: {error, error_reason()} | + {ok, [dialyzer_callgraph:callgraph_edge()], + [mfa_or_funlbl()], [mfa()], module()}. %%opaque +-type compile_mid_data() :: {module(), cerl:cerl(), [mfa()], + dialyzer_callgraph:callgraph(), + dialyzer_codeserver:codeserver()}. -spec compile_init_result() -> compile_result(). @@ -287,7 +293,7 @@ add_to_result(File, NewData, {Failed, NoWarn, Mods}, InitData) -> end. -spec start_compilation(file:filename(), compile_init_data()) -> - {error, term()} |{ok, integer(), compile_mid_data()}. + {error, error_reason()} |{ok, integer(), compile_mid_data()}. start_compilation(File, #compile_init{callgraph = Callgraph, codeserver = Codeserver, -- cgit v1.2.3 From 4e1ed3a5666c13d442759e710d9d08280362c0bb Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Thu, 22 Mar 2012 10:21:18 +0100 Subject: Relocate start and stop of timing server --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 67c5b3241d..641b7eb22a 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -64,12 +64,14 @@ -spec start(pid(), [dial_warn_tag()], #analysis{}) -> 'ok'. start(Parent, LegalWarnings, Analysis) -> + dialyzer_timing:init(Analysis#analysis.timing), RacesOn = ordsets:is_element(?WARN_RACE_CONDITION, LegalWarnings), Analysis0 = Analysis#analysis{race_detection = RacesOn}, Analysis1 = expand_files(Analysis0), Analysis2 = run_analysis(Analysis1), State = #server_state{parent = Parent, legal_warnings = LegalWarnings}, - loop(State, Analysis2, none). + loop(State, Analysis2, none), + dialyzer_timing:stop(). run_analysis(Analysis) -> Self = self(), -- cgit v1.2.3 From 5c52ff6b5f10c7bd9ce06cdf607e88035c16e079 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Thu, 29 Mar 2012 14:44:08 +0200 Subject: Anonymous time server --- lib/dialyzer/src/dialyzer_analysis_callgraph.erl | 42 ++++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'lib/dialyzer/src/dialyzer_analysis_callgraph.erl') diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl index 641b7eb22a..3bbde12481 100644 --- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl @@ -52,7 +52,8 @@ parent :: pid(), plt :: dialyzer_plt:plt(), start_from = byte_code :: start_from(), - use_contracts = true :: boolean() + use_contracts = true :: boolean(), + timing_server :: dialyzer_timing:timing_server() }). -record(server_state, {parent :: pid(), legal_warnings :: [dial_warn_tag()]}). @@ -64,14 +65,15 @@ -spec start(pid(), [dial_warn_tag()], #analysis{}) -> 'ok'. start(Parent, LegalWarnings, Analysis) -> - dialyzer_timing:init(Analysis#analysis.timing), + TimingServer = dialyzer_timing:init(Analysis#analysis.timing), RacesOn = ordsets:is_element(?WARN_RACE_CONDITION, LegalWarnings), - Analysis0 = Analysis#analysis{race_detection = RacesOn}, + Analysis0 = + Analysis#analysis{race_detection = RacesOn, timing_server = TimingServer}, Analysis1 = expand_files(Analysis0), Analysis2 = run_analysis(Analysis1), State = #server_state{parent = Parent, legal_warnings = LegalWarnings}, loop(State, Analysis2, none), - dialyzer_timing:stop(). + dialyzer_timing:stop(TimingServer). run_analysis(Analysis) -> Self = self(), @@ -133,7 +135,8 @@ analysis_start(Parent, Analysis) -> plt = Plt, parent = Parent, start_from = Analysis#analysis.start_from, - use_contracts = Analysis#analysis.use_contracts + use_contracts = Analysis#analysis.use_contracts, + timing_server = Analysis#analysis.timing_server }, Files = ordsets:from_list(Analysis#analysis.files), {Callgraph, NoWarn, TmpCServer0} = compile_and_store(Files, State), @@ -157,7 +160,7 @@ analysis_start(Parent, Analysis) -> dialyzer_codeserver:insert_temp_exported_types(MergedExpTypes, TmpCServer1), TmpCServer3 = dialyzer_utils:process_record_remote_types(TmpCServer2), - ?timing("remote", + ?timing(State#analysis_state.timing_server, "remote", dialyzer_contracts:process_contract_remote_types(TmpCServer3)) catch throw:{error, _ErrorMsg} = Error -> exit(Error) @@ -186,22 +189,23 @@ analysis_start(Parent, Analysis) -> send_codeserver_plt(Parent, CServer, State3#analysis_state.plt), send_analysis_done(Parent, Plt2, State3#analysis_state.doc_plt). -analyze_callgraph(Callgraph, State) -> - Codeserver = State#analysis_state.codeserver, - Parent = State#analysis_state.parent, - DocPlt = State#analysis_state.doc_plt, +analyze_callgraph(Callgraph, #analysis_state{codeserver = Codeserver, + doc_plt = DocPlt, + timing_server = TimingServer, + parent = Parent} = State) -> Plt = dialyzer_plt:insert_callbacks(State#analysis_state.plt, Codeserver), {NewPlt, NewDocPlt} = case State#analysis_state.analysis_type of plt_build -> - {dialyzer_succ_typings:analyze_callgraph(Callgraph, Plt, - Codeserver, Parent), - DocPlt}; + NewPlt0 = + dialyzer_succ_typings:analyze_callgraph(Callgraph, Plt, Codeserver, + TimingServer, Parent), + {NewPlt0, DocPlt}; succ_typings -> NoWarn = State#analysis_state.no_warn_unused, {Warnings, NewPlt0, NewDocPlt0} = - dialyzer_succ_typings:get_warnings(Callgraph, Plt, DocPlt, - Codeserver, NoWarn, Parent), + dialyzer_succ_typings:get_warnings(Callgraph, Plt, DocPlt, Codeserver, + NoWarn, TimingServer, Parent), send_warnings(State#analysis_state.parent, Warnings), {NewPlt0, NewDocPlt0} end, @@ -234,14 +238,16 @@ make_compile_init(#analysis_state{codeserver = Codeserver, start_from = StartFrom}. compile_and_store(Files, #analysis_state{codeserver = CServer, + timing_server = Timing, parent = Parent} = State) -> send_log(Parent, "Reading files and computing callgraph... "), {T1, _} = statistics(runtime), Callgraph = dialyzer_callgraph:new(), CompileInit = make_compile_init(State, Callgraph), {{Failed, NoWarn, Modules}, NextLabel} = - ?timing("compile", - dialyzer_coordinator:parallel_job(compile, Files, CompileInit)), + ?timing(Timing, "compile", _C1, + dialyzer_coordinator:parallel_job(compile, Files, + CompileInit, Timing)), CServer2 = dialyzer_codeserver:set_next_core_label(NextLabel, CServer), case Failed =:= [] of true -> @@ -259,7 +265,7 @@ compile_and_store(Files, #analysis_state{codeserver = CServer, Msg1 = io_lib:format("done in ~.2f secs\nRemoving edges... ", [(T2-T1)/1000]), send_log(Parent, Msg1), Callgraph = - ?timing("clean", _C3, + ?timing(Timing, "clean", _C2, cleanup_callgraph(State, CServer2, Callgraph, Modules)), {T3, _} = statistics(runtime), Msg2 = io_lib:format("done in ~.2f secs\n", [(T3-T2)/1000]), -- cgit v1.2.3