Clean specs directory before running capture

Summary:
Currently, the specs directory is cleaned after running capture. This means that the `changed-files` are interpreted in the context of the second set of source files. Therefore if a procedure is deleted from the second set of source files, its specs file will not be deleted.

This moves the cleaning of the specs directory to before capture, to avoid this problem.

Reviewed By: ngorogiannis

Differential Revision: D17093980

fbshipit-source-id: e1a8d8a54
master
Phoebe Nichols 6 years ago committed by Facebook Github Bot
parent a294085d9a
commit 6874926b10

@ -142,29 +142,38 @@ let analyze source_files_to_analyze =
let invalidate_changed_procedures changed_files = let invalidate_changed_procedures changed_files =
L.progress "Incremental analysis: invalidating procedures that have been changed@." ; if Config.incremental_analysis then (
let reverse_callgraph = CallGraph.create CallGraph.default_initial_capacity in let changed_files =
ReverseAnalysisCallGraph.build reverse_callgraph ; match changed_files with
let total_nodes = CallGraph.n_procs reverse_callgraph in | Some cf ->
SourceFile.Set.iter cf
(fun sf -> | None ->
SourceFiles.proc_names_of_source sf L.die InternalError "Incremental analysis enabled without specifying changed files"
|> List.iter ~f:(CallGraph.flag_reachable reverse_callgraph) ) in
changed_files ; L.progress "Incremental analysis: invalidating procedures that have been changed@." ;
if Config.debug_level_analysis > 0 then let reverse_callgraph = CallGraph.create CallGraph.default_initial_capacity in
CallGraph.to_dotty reverse_callgraph "reverse_analysis_callgraph.dot" ; ReverseAnalysisCallGraph.build reverse_callgraph ;
let invalidated_nodes = let total_nodes = CallGraph.n_procs reverse_callgraph in
CallGraph.fold_flagged reverse_callgraph SourceFile.Set.iter
~f:(fun node acc -> SpecsFiles.delete node.pname ; acc + 1) (fun sf ->
0 SourceFiles.proc_names_of_source sf
in |> List.iter ~f:(CallGraph.flag_reachable reverse_callgraph) )
L.progress changed_files ;
"Incremental analysis: %d nodes in reverse analysis call graph, %d of which were invalidated @." if Config.debug_level_analysis > 0 then
total_nodes invalidated_nodes ; CallGraph.to_dotty reverse_callgraph "reverse_analysis_callgraph.dot" ;
ScubaLogging.log_count ~label:"incremental_analysis.total_nodes" ~value:total_nodes ; let invalidated_nodes =
ScubaLogging.log_count ~label:"incremental_analysis.invalidated_nodes" ~value:invalidated_nodes ; CallGraph.fold_flagged reverse_callgraph
(* save some memory *) ~f:(fun node acc -> SpecsFiles.delete node.pname ; acc + 1)
CallGraph.reset reverse_callgraph 0
in
L.progress
"Incremental analysis: %d nodes in reverse analysis call graph, %d of which were \
invalidated @."
total_nodes invalidated_nodes ;
ScubaLogging.log_count ~label:"incremental_analysis.total_nodes" ~value:total_nodes ;
ScubaLogging.log_count ~label:"incremental_analysis.invalidated_nodes" ~value:invalidated_nodes ;
(* save some memory *)
CallGraph.reset reverse_callgraph )
let main ~changed_files = let main ~changed_files =
@ -173,13 +182,7 @@ let main ~changed_files =
L.progress "Invalidating procedures to be reanalyzed@." ; L.progress "Invalidating procedures to be reanalyzed@." ;
Summary.OnDisk.reset_all ~filter:(Lazy.force Filtering.procedures_filter) () ; Summary.OnDisk.reset_all ~filter:(Lazy.force Filtering.procedures_filter) () ;
L.progress "Done@." ) L.progress "Done@." )
else if Config.incremental_analysis then else if not Config.incremental_analysis then DB.Results_dir.clean_specs_dir () ;
match changed_files with
| Some cf ->
invalidate_changed_procedures cf
| None ->
L.die InternalError "Incremental analysis enabled without specifying changed files"
else DB.Results_dir.clean_specs_dir () ;
let source_files = get_source_files_to_analyze ~changed_files in let source_files = get_source_files_to_analyze ~changed_files in
(* empty all caches to minimize the process heap to have less work to do when forking *) (* empty all caches to minimize the process heap to have less work to do when forking *)
clear_caches () ; clear_caches () ;

@ -12,3 +12,6 @@ open! IStd
val main : changed_files:SourceFile.Set.t option -> unit val main : changed_files:SourceFile.Set.t option -> unit
(** Given a name of the Makefile to use for multicore analysis, analyze the captured code *) (** Given a name of the Makefile to use for multicore analysis, analyze the captured code *)
val invalidate_changed_procedures : SourceFile.Set.t option -> unit
(** Invalidate specs files for procedures that have changed. Used for incremental analysis. *)

@ -17,6 +17,7 @@ let run driver_mode =
let open Driver in let open Driver in
run_prologue driver_mode ; run_prologue driver_mode ;
let changed_files = read_config_changed_files () in let changed_files = read_config_changed_files () in
InferAnalyze.invalidate_changed_procedures changed_files ;
capture driver_mode ~changed_files ; capture driver_mode ~changed_files ;
analyze_and_report driver_mode ~changed_files ; analyze_and_report driver_mode ~changed_files ;
run_epilogue () run_epilogue ()

@ -1 +1 @@
{"top":{"current":0,"previous":0},"zero":{"current":6,"previous":6},"degrees":[{"degree":0,"current":3,"previous":4},{"degree":100,"current":3,"previous":1},{"degree":200,"current":0,"previous":1}]} {"top":{"current":0,"previous":0},"zero":{"current":7,"previous":6},"degrees":[{"degree":0,"current":3,"previous":4},{"degree":100,"current":4,"previous":1},{"degree":200,"current":0,"previous":1}]}

@ -5,21 +5,24 @@ digraph callgraph {
N5 [ label = "void Test.main(java.lang.String[])", flag = true ]; N5 [ label = "void Test.main(java.lang.String[])", flag = true ];
N0 [ label = "Object.<init>()", flag = false ]; N0 [ label = "Object.<init>()", flag = false ];
N0 -> N6 ; N0 -> N7 ;
N0 -> N1 ; N0 -> N1 ;
N7 [ label = "void PrintStream.println(String)", flag = false ]; N7 [ label = "Unchanged.<init>()", flag = false ];
N7 -> N2 ;
N6 [ label = "Unchanged.<init>()", flag = false ]; N6 [ label = "void Test.newMethod(int)", flag = true ];
N4 [ label = "void Test.complexityIncrease(int)", flag = true ]; N4 [ label = "void Test.complexityIncrease(int)", flag = true ];
N4 -> N5 ; N4 -> N5 ;
N2 [ label = "void Unchanged.orderN(int)", flag = false ]; N2 [ label = "void Unchanged.orderN(int)", flag = false ];
N2 -> N6 ;
N2 -> N4 ; N2 -> N4 ;
N2 -> N3 ; N2 -> N3 ;
N8 [ label = "void PrintStream.println(String)", flag = false ];
N8 -> N2 ;
N3 [ label = "void Test.complexityDecrease(int)", flag = true ]; N3 [ label = "void Test.complexityDecrease(int)", flag = true ];
N3 -> N5 ; N3 -> N5 ;

@ -7,6 +7,10 @@
class Test { class Test {
public static void newMethod(int n) {
Unchanged.orderN(n);
}
public static void complexityDecrease(int n) { public static void complexityDecrease(int n) {
Unchanged.orderN(n); Unchanged.orderN(n);
} }

@ -1,13 +1,13 @@
digraph callgraph { digraph callgraph {
N1 [ label = "b", flag = true ]; N1 [ label = "b", flag = false ];
N0 [ label = "c", flag = true ]; N0 [ label = "c", flag = false ];
N0 -> N1 ; N0 -> N1 ;
N2 [ label = "a", flag = true ]; N2 [ label = "a", flag = false ];
N2 -> N3 ; N2 -> N3 ;
N3 [ label = "main", flag = true ]; N3 [ label = "main", flag = false ];
} }

Loading…
Cancel
Save