From 764224139c2b3a246604455b0a1529ba757a0316 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 9 Jan 2018 08:09:45 -0800 Subject: [PATCH] [backend] change cluster type to source files and read list from cfg db Summary: This avoids relying on the directories in infer-out/captured/ being created, and instead gets the list of captured source files from the DB. This gives a better type to clusters: `SourceFile.t` instead of `DB.source_dir`, which makes the code a bit nicer too. Reviewed By: jeremydubreil Differential Revision: D6620460 fbshipit-source-id: c0edbf6 --- infer/src/IR/Cfg.ml | 7 +++++++ infer/src/IR/Cfg.mli | 2 ++ infer/src/backend/InferAnalyze.ml | 25 ++++++++----------------- infer/src/backend/cluster.ml | 2 +- infer/src/backend/cluster.mli | 2 +- infer/src/backend/clusterMakefile.ml | 2 +- infer/src/backend/exe_env.ml | 3 ++- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/infer/src/IR/Cfg.ml b/infer/src/IR/Cfg.ml index 7d238cb40..30b6545a8 100644 --- a/infer/src/IR/Cfg.ml +++ b/infer/src/IR/Cfg.ml @@ -628,3 +628,10 @@ let pp_proc_signatures fmt cfg = let exists_for_source_file source = (* simplistic implementation that allocates the cfg as this is only used for reactive capture for now *) load source |> Option.is_some + + +let get_captured_source_files () = + let db = ResultsDatabase.get_database () in + Sqlite3.prepare db "SELECT source_file FROM cfg" + |> SqliteUtils.sqlite_result_rev_list_step db ~log:"getting all source files" + |> List.filter_map ~f:(Option.map ~f:SourceFile.SQLite.deserialize) diff --git a/infer/src/IR/Cfg.mli b/infer/src/IR/Cfg.mli index 4e3a29e94..533ea8789 100644 --- a/infer/src/IR/Cfg.mli +++ b/infer/src/IR/Cfg.mli @@ -64,3 +64,5 @@ val specialize_with_block_args : val pp_proc_signatures : Format.formatter -> t -> unit val exists_for_source_file : SourceFile.t -> bool + +val get_captured_source_files : unit -> SourceFile.t list diff --git a/infer/src/backend/InferAnalyze.ml b/infer/src/backend/InferAnalyze.ml index 8225225df..d70017b62 100644 --- a/infer/src/backend/InferAnalyze.ml +++ b/infer/src/backend/InferAnalyze.ml @@ -77,23 +77,14 @@ let print_legend () = let cluster_should_be_analyzed ~changed_files cluster = - let fname = DB.source_dir_to_string cluster in (* whether [fname] is one of the [changed_files] *) - let is_changed_file = - (* set of source dirs to analyze inside infer-out/captured/ *) - let source_dirs_to_analyze changed_files = - SourceFile.Set.fold - (fun source_file source_dir_set -> - let source_dir = DB.source_dir_from_source_file source_file in - String.Set.add source_dir_set (DB.source_dir_to_string source_dir) ) - changed_files String.Set.empty - in - Option.map ~f:source_dirs_to_analyze changed_files - |> fun dirs_opt -> Option.map dirs_opt ~f:(fun dirs -> String.Set.mem dirs fname) - in + let is_changed_file = Option.map changed_files ~f:(SourceFile.Set.mem cluster) in let check_modified () = - let modified = DB.file_was_updated_after_start (DB.filename_from_string fname) in - if modified && Config.developer_mode then L.debug Analysis Medium "Modified: %s@." fname ; + let modified = + DB.source_dir_from_source_file cluster |> DB.source_dir_to_string |> DB.filename_from_string + |> DB.file_was_updated_after_start + in + if modified then L.debug Analysis Medium "Modified: %a@\n" SourceFile.pp cluster ; modified in match is_changed_file with @@ -128,7 +119,7 @@ let main ~changed_files ~makefile = (* delete all specs when doing a full analysis so that we do not report on procedures that do not exist anymore *) if not Config.reactive_mode then DB.Results_dir.clean_specs_dir () ; - let all_clusters = DB.find_source_dirs () in + let all_clusters = Cfg.get_captured_source_files () in let clusters_to_analyze = List.filter ~f:(cluster_should_be_analyzed ~changed_files) all_clusters in @@ -142,7 +133,7 @@ let main ~changed_files ~makefile = let is_java = lazy (List.exists - ~f:(fun cl -> DB.string_crc_has_extension ~ext:"java" (DB.source_dir_to_string cl)) + ~f:(fun cl -> Filename.check_suffix ".java" (SourceFile.to_string cl)) all_clusters) in print_legend () ; diff --git a/infer/src/backend/cluster.ml b/infer/src/backend/cluster.ml index 4c80e0a11..31e399a2f 100644 --- a/infer/src/backend/cluster.ml +++ b/infer/src/backend/cluster.ml @@ -14,7 +14,7 @@ module F = Format (** Module to process clusters of procedures. *) (** a cluster is a file *) -type t = DB.source_dir +type t = SourceFile.t (** type stored in .cluster file: (n,cl) indicates cl is cluster n *) type serializer_t = int * t diff --git a/infer/src/backend/cluster.mli b/infer/src/backend/cluster.mli index e1a6735e4..6f8cf3cad 100644 --- a/infer/src/backend/cluster.mli +++ b/infer/src/backend/cluster.mli @@ -13,7 +13,7 @@ module F = Format (** Module to process clusters of procedures. *) (** a cluster is a file *) -type t = DB.source_dir +type t = SourceFile.t (** type stored in .cluster file: (n,cl) indicates cl is cluster n *) type serializer_t = int * t diff --git a/infer/src/backend/clusterMakefile.ml b/infer/src/backend/clusterMakefile.ml index 79e753983..335c04a6d 100644 --- a/infer/src/backend/clusterMakefile.ml +++ b/infer/src/backend/clusterMakefile.ml @@ -42,7 +42,7 @@ let create_cluster_makefile (clusters: Cluster.t list) (fname: string) = let outc = Out_channel.create fname in let fmt = Format.formatter_of_out_channel outc in let do_cluster cluster_nr cluster = - F.fprintf fmt "#%s@\n" (DB.source_dir_to_string cluster) ; + F.fprintf fmt "#%a@\n" SourceFile.pp cluster ; Cluster.pp_cluster fmt (cluster_nr + 1, cluster) in pp_prolog fmt clusters ; diff --git a/infer/src/backend/exe_env.ml b/infer/src/backend/exe_env.ml index 5bf33e94a..c268ade7b 100644 --- a/infer/src/backend/exe_env.ml +++ b/infer/src/backend/exe_env.ml @@ -202,7 +202,8 @@ let get_proc_desc exe_env pname = (** Create an exe_env from a source dir *) let from_cluster cluster = let exe_env = create () in - add_cg exe_env cluster ; exe_env + add_cg exe_env (DB.source_dir_from_source_file cluster) ; + exe_env (** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *)