From e6069f3ef7e72038b63075c6244f696332e1d607 Mon Sep 17 00:00:00 2001 From: Fernando Gasperi Jabalera Date: Tue, 14 Jan 2020 02:47:58 -0800 Subject: [PATCH] Create RestartScheduler Summary: These changes introduce the RestartScheduler which for now is a copy of the FileScheduler: - added it as a possible argument to the recently added `--scheduler` option. - made the necessary changes in `InferAnalyze` to call it if it was chosen. Reviewed By: ngorogiannis Differential Revision: D19373505 fbshipit-source-id: 98f065057 --- infer/man/man1/infer-full.txt | 2 +- infer/src/backend/FileScheduler.ml | 1 + infer/src/backend/InferAnalyze.ml | 6 ++++-- infer/src/backend/RestartScheduler.ml | 22 ++++++++++++++++++++++ infer/src/backend/RestartScheduler.mli | 9 +++++++++ infer/src/base/Config.ml | 4 ++-- infer/src/base/Config.mli | 2 +- 7 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 infer/src/backend/RestartScheduler.ml create mode 100644 infer/src/backend/RestartScheduler.mli diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index ccec92908..7f2003fea 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -1690,7 +1690,7 @@ INTERNAL OPTIONS Reset the list of folders containing linters definitions to be empty (see linters-def-folder). - --scheduler { File | SyntacticCallGraph } + --scheduler { file | restart | callgraph } Specify the scheduler used for the analysis phase --scuba-logging diff --git a/infer/src/backend/FileScheduler.ml b/infer/src/backend/FileScheduler.ml index 845448cad..705902159 100644 --- a/infer/src/backend/FileScheduler.ml +++ b/infer/src/backend/FileScheduler.ml @@ -15,6 +15,7 @@ let make sources = in let next x = let res = gen.next x in + (* see defn of gen above to see why res should never match Some (Procname _) *) match res with None -> None | Some (Procname _) -> assert false | Some (File _) as v -> v in {gen with next} diff --git a/infer/src/backend/InferAnalyze.ml b/infer/src/backend/InferAnalyze.ml index ceecd9cd1..f493fc3ac 100644 --- a/infer/src/backend/InferAnalyze.ml +++ b/infer/src/backend/InferAnalyze.ml @@ -119,10 +119,12 @@ let schedule sources = SyntacticCallGraph.make sources ) else match Config.scheduler with - | SyntacticCallGraph -> - SyntacticCallGraph.make sources | File -> FileScheduler.make sources + | Restart -> + RestartScheduler.make sources + | SyntacticCallGraph -> + SyntacticCallGraph.make sources let analyze source_files_to_analyze = diff --git a/infer/src/backend/RestartScheduler.ml b/infer/src/backend/RestartScheduler.ml new file mode 100644 index 000000000..d557db215 --- /dev/null +++ b/infer/src/backend/RestartScheduler.ml @@ -0,0 +1,22 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) +open! IStd + +(** This behaves exactly the same as the FileScheduler so far. The goal is that it will use a work + queue and proc locking to avoid repeating work and hopefully get some in process cache hits. *) +let make sources = + let gen = + List.rev_map sources ~f:(fun sf -> SchedulerTypes.File sf) + |> List.permute ~random_state:(Random.State.make (Array.create ~len:1 0)) + |> ProcessPool.TaskGenerator.of_list + in + let next x = + let res = gen.next x in + (* see defn of gen above to see why res should never match Some (Procname _) *) + match res with None -> None | Some (Procname _) -> assert false | Some (File _) as v -> v + in + {gen with next} diff --git a/infer/src/backend/RestartScheduler.mli b/infer/src/backend/RestartScheduler.mli new file mode 100644 index 000000000..d4b8fc626 --- /dev/null +++ b/infer/src/backend/RestartScheduler.mli @@ -0,0 +1,9 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) +open! IStd + +val make : SourceFile.t list -> SchedulerTypes.target ProcessPool.TaskGenerator.t diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 5e5fea107..22a1110a2 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -92,7 +92,7 @@ type build_system = | BXcode [@@deriving compare] -type scheduler = File | SyntacticCallGraph [@@deriving equal] +type scheduler = File | Restart | SyntacticCallGraph [@@deriving equal] let equal_build_system = [%compare.equal: build_system] @@ -2357,7 +2357,7 @@ and export_changed_functions_output = and scheduler = CLOpt.mk_symbol ~long:"scheduler" ~default:File ~eq:equal_scheduler - ~symbols:[("File", File); ("SyntacticCallGraph", SyntacticCallGraph)] + ~symbols:[("file", File); ("restart", Restart); ("callgraph", SyntacticCallGraph)] "Specify the scheduler used for the analysis phase" diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 68a553938..90e5c0e74 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -25,7 +25,7 @@ type build_system = | BNdk | BXcode -type scheduler = File | SyntacticCallGraph [@@deriving equal] +type scheduler = File | Restart | SyntacticCallGraph [@@deriving equal] val equal_build_system : build_system -> build_system -> bool