From dc0b91662a52055ebd59d04fab759aadf45a7001 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Wed, 27 Jan 2016 11:02:25 -0800 Subject: [PATCH] Save space/simplify by deleting Exe.file_map Reviewed By: jeremydubreil Differential Revision: D2868560 fb-gh-sync-id: b8f9155 --- infer/src/backend/DB.ml | 2 ++ infer/src/backend/DB.mli | 3 +++ infer/src/backend/exe_env.ml | 48 ++++++++++------------------------- infer/src/backend/exe_env.mli | 8 ------ 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/infer/src/backend/DB.ml b/infer/src/backend/DB.ml index a5439946b..7b5b8064b 100644 --- a/infer/src/backend/DB.ml +++ b/infer/src/backend/DB.ml @@ -38,6 +38,8 @@ end module SourceFileMap = Map.Make(OrderedSourceFile) +module SourceFileSet = Set.Make(OrderedSourceFile) + let source_file_from_string path = if Filename.is_relative path then Relative path diff --git a/infer/src/backend/DB.mli b/infer/src/backend/DB.mli index d0101a793..4aa754986 100644 --- a/infer/src/backend/DB.mli +++ b/infer/src/backend/DB.mli @@ -63,6 +63,9 @@ type source_file (** Maps from source_file *) module SourceFileMap : Map.S with type key = source_file +(** Set of source files *) +module SourceFileSet : Set.S with type elt = source_file + (** current source file *) val current_source : source_file ref diff --git a/infer/src/backend/exe_env.ml b/infer/src/backend/exe_env.ml index 0cfe5e2ef..0753ac728 100644 --- a/infer/src/backend/exe_env.ml +++ b/infer/src/backend/exe_env.ml @@ -50,7 +50,6 @@ let new_file_data source nLOC cg_fname = type t = { cg: Cg.t; (** global call graph *) proc_map: file_data Procname.Hash.t; (** map from procedure name to file data *) - file_map: (DB.source_file, file_data) Hashtbl.t; (** map from filaname to file data *) mutable active_opt : Procname.Set.t option; (** if not None, restrict the active procedures to the given set *) mutable procs_defined_in_several_files : Procname.Set.t; (** Procedures defined in more than one file *) } @@ -65,7 +64,6 @@ let freeze exe_env = exe_env (* TODO: unclear what this function is used for *) let create procset_opt = { cg = Cg.create (); proc_map = Procname.Hash.create 17; - file_map = Hashtbl.create 17; active_opt = procset_opt; procs_defined_in_several_files = Procname.Set.empty; } @@ -109,26 +107,12 @@ let add_cg_exclude_fun (exe_env: t) (source_dir : DB.source_dir) exclude_fun = source < old_source (* when a procedure is defined in several files, map to the first alphabetically *) else true in if should_update then Procname.Hash.replace exe_env.proc_map pname file_data) defined_procs; - Hashtbl.add exe_env.file_map source file_data; Some cg (** add call graph from fname in the spec db, with relative tenv and cfg, to the execution environment *) let add_cg exe_env (source_dir : DB.source_dir) = add_cg_exclude_fun exe_env source_dir (fun _ -> false) -(** add a new source file -> file data mapping. arguments are the components of the file_data - * record *) -let add_file_mapping exe_env source nLOC tenv_file tenv cfg_file cfg = - let file_data = - { source = source; - nLOC = nLOC; - tenv_file = tenv_file; - tenv = tenv; - cfg_file = cfg_file; - cfg = cfg; - } in - Hashtbl.add exe_env.file_map source file_data - (** get the procedures defined in more than one file *) let get_procs_defined_in_several_files exe_env = exe_env.procs_defined_in_several_files @@ -152,12 +136,7 @@ let get_file_data exe_env pname = let nLOC = loc.Location.nLOC in let source_dir = DB.source_dir_from_source_file source_file in let cg_fname = DB.source_dir_get_internal_file source_dir ".cg" in - let file_data = - try Hashtbl.find exe_env.file_map source_file with - | Not_found -> - let file_data = new_file_data source_file nLOC cg_fname in - Hashtbl.replace exe_env.file_map source_file file_data; - file_data in + let file_data = new_file_data source_file nLOC cg_fname in Procname.Hash.replace exe_env.proc_map pname file_data; file_data end @@ -214,16 +193,15 @@ let get_cfg exe_env pname = (** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *) let iter_files f exe_env = - let do_file fname file_data = - DB.current_source := fname; - Config.nLOC := file_data.nLOC; - f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data) in - Hashtbl.iter do_file exe_env.file_map - -(** [fold_files f exe_env] folds f through the source file, tenv, and cfg for each file in [exe_env] *) -let fold_files f acc exe_env = - let fold_file fname file_data acc = - DB.current_source := fname; - Config.nLOC := file_data.nLOC; - f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data) acc in - Hashtbl.fold fold_file exe_env.file_map acc + let do_file _ file_data seen_files_acc = + let fname = file_data.source in + if DB.SourceFileSet.mem fname seen_files_acc + then seen_files_acc + else + begin + DB.current_source := fname; + Config.nLOC := file_data.nLOC; + f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data); + DB.SourceFileSet.add fname seen_files_acc + end in + ignore (Procname.Hash.fold do_file exe_env.proc_map DB.SourceFileSet.empty) diff --git a/infer/src/backend/exe_env.mli b/infer/src/backend/exe_env.mli index 680b5c1bf..cc3b17650 100644 --- a/infer/src/backend/exe_env.mli +++ b/infer/src/backend/exe_env.mli @@ -30,11 +30,6 @@ val add_cg : initial -> DB.source_dir -> Cg.t option (** like add_cg, but use exclude_fun to determine files to be excluded *) val add_cg_exclude_fun : initial -> DB.source_dir -> (DB.source_file -> bool) -> Cg.t option -(** add a new source file -> file data mapping. arguments are the components of the file_data - * record *) -val add_file_mapping : t -> DB.source_file -> int -> DB.filename -> Sil.tenv option -> DB.filename - -> Cfg.cfg option -> unit - (** get the global call graph *) val get_cg : t -> Cg.t @@ -53,9 +48,6 @@ val get_cfg : t -> Procname.t -> Cfg.cfg (** [iter_files f exe_env] applies [f] to the source file and tenv and cfg for each file in [exe_env] *) val iter_files : (DB.source_file -> Sil.tenv -> Cfg.cfg -> unit) -> t -> unit -(** [fold_files f exe_env] folds f through the source file, tenv, and cfg for each file in [exe_env] *) -val fold_files : (DB.source_file -> Sil.tenv -> Cfg.cfg -> 'a -> 'a) -> 'a -> t -> 'a - (** check if a procedure is marked as active *) val proc_is_active : t -> Procname.t -> bool