diff --git a/infer/src/IR/Attributes.ml b/infer/src/IR/Attributes.ml index ecaa1ef00..1c3769026 100644 --- a/infer/src/IR/Attributes.ml +++ b/infer/src/IR/Attributes.ml @@ -42,14 +42,14 @@ let replace_statement = values so the lexicographic ordering for (:akind, :sfile) is done by hand *) ResultsDatabase.register_statement {| -INSERT OR REPLACE INTO attributes +INSERT OR REPLACE INTO procedures SELECT :pname, :akind, :sfile, :pattr FROM ( SELECT NULL FROM ( SELECT COALESCE(MAX(attr_kind),-1) AS attr_kind, COALESCE(MAX(source_file),"") AS source_file - FROM attributes + FROM procedures WHERE proc_name = :pname ) WHERE attr_kind < :akind OR (attr_kind = :akind AND source_file < :sfile) )|} @@ -72,7 +72,7 @@ let find_more_defined_statement = ResultsDatabase.register_statement {| SELECT attr_kind -FROM attributes +FROM procedures WHERE proc_name = :pname AND attr_kind > :akind |} @@ -90,12 +90,12 @@ let should_try_to_update pname_blob akind = let select_statement = - ResultsDatabase.register_statement "SELECT proc_attributes FROM attributes WHERE proc_name = :k" + ResultsDatabase.register_statement "SELECT proc_attributes FROM procedures WHERE proc_name = :k" let select_defined_statement = ResultsDatabase.register_statement - "SELECT proc_attributes FROM attributes WHERE proc_name = :k AND attr_kind = %Ld" + "SELECT proc_attributes FROM procedures WHERE proc_name = :k AND attr_kind = %Ld" (int64_of_attributes_kind ProcDefined) diff --git a/infer/src/IR/Cfg.ml b/infer/src/IR/Cfg.ml index 30b6545a8..2405085d7 100644 --- a/infer/src/IR/Cfg.ml +++ b/infer/src/IR/Cfg.ml @@ -92,7 +92,7 @@ let check_cfg_connectedness cfg = let load_statement = - ResultsDatabase.register_statement "SELECT cfgs FROM cfg WHERE source_file = :k" + ResultsDatabase.register_statement "SELECT cfgs FROM source_files WHERE source_file = :k" module SQLite = SqliteUtils.MarshalledData (struct @@ -277,7 +277,7 @@ let mark_unchanged_pdescs cfg_new cfg_old = let store_statement = - ResultsDatabase.register_statement "INSERT OR REPLACE INTO cfg VALUES (:source, :cfgs)" + ResultsDatabase.register_statement "INSERT OR REPLACE INTO source_files VALUES (:source, :cfgs)" let store source_file cfg = @@ -632,6 +632,6 @@ let exists_for_source_file source = let get_captured_source_files () = let db = ResultsDatabase.get_database () in - Sqlite3.prepare db "SELECT source_file FROM cfg" + Sqlite3.prepare db "SELECT source_file FROM source_files" |> 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/base/MergeResults.ml b/infer/src/base/MergeResults.ml index 62ceeb349..dab9304f8 100644 --- a/infer/src/base/MergeResults.ml +++ b/infer/src/base/MergeResults.ml @@ -9,7 +9,7 @@ open! IStd module L = Logging -let merge_attributes_table ~db_file = +let merge_procedures_table ~db_file = let db = ResultsDatabase.get_database () in (* Do the merge purely in SQL for great speed. The query works by doing a left join between the sub-table and the main one, and applying the same "more defined" logic as in Attributes in the @@ -17,11 +17,11 @@ let merge_attributes_table ~db_file = NULL). All the rows that pass this filter are inserted/updated into the main table. *) Sqlite3.exec db {| -INSERT OR REPLACE INTO attributes +INSERT OR REPLACE INTO procedures SELECT sub.proc_name, sub.attr_kind, sub.source_file, sub.proc_attributes FROM ( - attached.attributes AS sub - LEFT OUTER JOIN attributes AS main + attached.procedures AS sub + LEFT OUTER JOIN procedures AS main ON sub.proc_name = main.proc_name ) WHERE main.attr_kind IS NULL @@ -29,13 +29,14 @@ WHERE OR (main.attr_kind = sub.attr_kind AND main.source_file < sub.source_file) |} |> SqliteUtils.check_sqlite_error db - ~log:(Printf.sprintf "copying attributes of database '%s'" db_file) + ~log:(Printf.sprintf "copying procedures of database '%s'" db_file) -let merge_cfg_table ~db_file = +let merge_source_files_table ~db_file = let db = ResultsDatabase.get_database () in - Sqlite3.exec db "INSERT OR REPLACE INTO cfg SELECT * FROM attached.cfg" - |> SqliteUtils.check_sqlite_error db ~log:(Printf.sprintf "copying cfg of database '%s'" db_file) + Sqlite3.exec db "INSERT OR REPLACE INTO source_files SELECT * FROM attached.source_files" + |> SqliteUtils.check_sqlite_error db + ~log:(Printf.sprintf "copying source_files of database '%s'" db_file) let merge ~db_file = @@ -43,8 +44,8 @@ let merge ~db_file = Sqlite3.exec main_db (Printf.sprintf "ATTACH '%s' AS attached" db_file) |> SqliteUtils.check_sqlite_error ~fatal:true main_db ~log:(Printf.sprintf "attaching database '%s'" db_file) ; - merge_attributes_table ~db_file ; - merge_cfg_table ~db_file ; + merge_procedures_table ~db_file ; + merge_source_files_table ~db_file ; Sqlite3.exec main_db "DETACH attached" |> SqliteUtils.check_sqlite_error ~fatal:true main_db ~log:(Printf.sprintf "detaching database '%s'" db_file) ; diff --git a/infer/src/base/ResultsDatabase.ml b/infer/src/base/ResultsDatabase.ml index 6d40dce6f..4fe0356b5 100644 --- a/infer/src/base/ResultsDatabase.ml +++ b/infer/src/base/ResultsDatabase.ml @@ -17,24 +17,24 @@ let database_filename = "results.db" let database_fullpath = Config.results_dir ^/ database_filename -let create_attributes_table db = +let create_procedures_table db = (* it would be nice to use "WITHOUT ROWID" here but ancient versions of sqlite do not support it *) - SqliteUtils.exec db ~log:"creating attributes table" + SqliteUtils.exec db ~log:"creating procedures table" ~stmt: {| -CREATE TABLE IF NOT EXISTS attributes +CREATE TABLE IF NOT EXISTS procedures ( proc_name TEXT PRIMARY KEY , attr_kind INTEGER NOT NULL , source_file TEXT NOT NULL , proc_attributes BLOB NOT NULL )|} -let create_cfg_table db = - SqliteUtils.exec db ~log:"creating cfg table" +let create_source_files_table db = + SqliteUtils.exec db ~log:"creating source_files table" ~stmt: {| -CREATE TABLE IF NOT EXISTS cfg +CREATE TABLE IF NOT EXISTS source_files ( source_file TEXT PRIMARY KEY , cfgs BLOB NOT NULL )|} @@ -42,8 +42,8 @@ CREATE TABLE IF NOT EXISTS cfg let create_db () = let temp_db = Filename.temp_file ~in_dir:Config.results_dir database_filename ".tmp" in let db = Sqlite3.db_open ~mutex:`FULL temp_db in - create_attributes_table db ; - create_cfg_table db ; + create_procedures_table db ; + create_source_files_table db ; (* This should be the default but better be sure, otherwise we cannot access the database concurrently. This has to happen before setting WAL mode. *) SqliteUtils.exec db ~log:"locking mode=NORMAL" ~stmt:"PRAGMA locking_mode=NORMAL" ; ( match Config.sqlite_vfs with @@ -70,10 +70,10 @@ let get_database () = Option.value_exn !database let reset_capture_tables () = let db = get_database () in - SqliteUtils.exec db ~log:"drop attributes table" ~stmt:"DROP TABLE attributes" ; - create_attributes_table db ; - SqliteUtils.exec db ~log:"drop cfg table" ~stmt:"DROP TABLE cfg" ; - create_cfg_table db + SqliteUtils.exec db ~log:"drop procedures table" ~stmt:"DROP TABLE procedures" ; + create_procedures_table db ; + SqliteUtils.exec db ~log:"drop source_files table" ~stmt:"DROP TABLE source_files" ; + create_source_files_table db let db_canonicalize () =