rename process_file -> process_workitem
[hiphop-php.git] / hphp / hack / src / typing / service / typing_service_types.ml
blobed9637d480fdc5cfc820990ed99cf0cfb107214e
1 (*
2 * Copyright (c) Facebook, Inc. and its affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the "hack" directory of this source tree.
7 *)
9 open Hh_prelude
11 type check_file_workitem = {
12 path: Relative_path.t;
13 was_already_deferred: bool;
15 [@@deriving show]
17 type workitem =
18 | Check of check_file_workitem
19 | Declare of (Relative_path.t * string)
20 | Prefetch of Relative_path.t list
21 [@@deriving show]
23 (** This type is used for both input and output of typechecker jobs.
24 INPUT: [remaining] is the list of files that this job is expected to process, and [completed], [deferred] are empty.
25 OUTPUT: all the files that were processed by the job are placed in [completed] or [deferred];
26 if the job had to stop early, then [remaining] are the leftover files that the job failed to process. *)
27 type typing_progress = {
28 remaining: workitem list;
29 completed: workitem list;
30 deferred: workitem list;
32 [@@deriving show]
34 (** This type is used for both input and output of typechecker jobs.
35 It is also used to accumulate the results of all typechecker jobs.
36 JOB-INPUT: all the fields are empty
37 JOB-OUTPUT: process_files will merge what it discovered into the typing_result output by each job.
38 ACCUMULATE: we start with all fields empty, and then merge in the output of each job as it's done. *)
39 type typing_result = {
40 errors: Errors.t;
41 dep_edges: Typing_deps.dep_edges;
42 adhoc_profiling: Adhoc_profiler.CallTree.t;
43 telemetry: Telemetry.t;
46 let make_typing_result () =
48 errors = Errors.empty;
49 dep_edges = Typing_deps.dep_edges_make ();
50 telemetry = Telemetry.create ();
51 adhoc_profiling = Adhoc_profiler.CallTree.make ();
54 let accumulate_job_output
55 (produced_by_job : typing_result) (accumulated_so_far : typing_result) :
56 typing_result =
57 (* The Measure API is mutating, but we want to be functional, so we'll serialize+deserialize
58 This might sound expensive, but the actual implementation makes it cheap. *)
60 errors = Errors.merge produced_by_job.errors accumulated_so_far.errors;
61 dep_edges =
62 Typing_deps.merge_dep_edges
63 produced_by_job.dep_edges
64 accumulated_so_far.dep_edges;
65 adhoc_profiling =
66 Adhoc_profiler.CallTree.merge
67 produced_by_job.adhoc_profiling
68 accumulated_so_far.adhoc_profiling;
69 telemetry =
70 Telemetry.add produced_by_job.telemetry accumulated_so_far.telemetry;
73 type delegate_job_sig = unit -> typing_result * typing_progress
75 type progress_kind =
76 | Progress
77 | DelegateProgress of delegate_job_sig
79 type job_progress = {
80 kind: progress_kind;
81 progress: typing_progress;
84 type check_info = {
85 init_id: string;
86 check_reason: string;
87 recheck_id: string option;
88 use_max_typechecker_worker_memory_for_decl_deferral: bool;
89 per_file_profiling: HackEventLogger.PerFileProfilingConfig.t;
90 memtrace_dir: string option;
93 type workitems_to_process = workitem BigList.t
95 type workitems_in_progress = workitem list
97 type delegate_next_result = {
98 current_bucket: workitem list;
99 remaining_jobs: workitem BigList.t;
100 job: delegate_job_sig;
104 This module type exposes an API within hh_server running on the users' host
105 that a component that distributes the work to other hosts can call.
106 By analogy with MultiWorker, this component may be referred to as
107 the controller: it dispatches batches of files to process (e.g., declare
108 or type check) to workers.
110 There are specific hh_server modules that know how to:
111 - snapshot the naming table
112 - get the list of files that changed since the merge base
113 - import dependency graph edges
115 The controller needs to be able to do these things, but it doesn't need to
116 know how they are done and which server modules are responsible.
118 This is why this module exists: to present a small API surface to
119 the controller, providing only the functionality it needs from the server.
121 Finally, the existence of this module makes it easy to mock its internals
122 when testing the logic of the controller, instead of having to mock
123 the individual modules that are responsible for the various operations, such
124 as importing dependency graph edges.
126 module type LocalServerApi = sig
127 (* Called by the controller to update clients with its
128 current phase of execution *)
129 val send_progress : string -> unit
131 (* The state filename contains the state that should be updated.
132 This function is called by the controller after it receives a response
133 from a worker that contains such state.
134 It may be called many times during execution.
136 val update_state : state_filename:string -> check_id:string option -> unit
138 (* Tells the server to save the naming table state to a given
139 destination path.
141 val snapshot_naming_table_base : destination_path:string -> unit Future.t
143 (* Tells the server to save just the portion of the naming table that
144 changed since the loaded naming table base. If there were no base, then
145 the snapshot should be the entire naming table.
147 val snapshot_naming_table_diff : destination_path:string -> unit
149 (* Begins getting dirty files given a mergebase.
151 val begin_get_changed_files : mergebase:string option -> string list Future.t
153 (* Packages the files changed since the mergebase into a single file.
155 val write_changed_files : string list -> destination_path:string -> unit
158 type delegate_env = {
159 (* The amount of time to wait between heartbeat checks, in seconds *)
160 heartbeat_period: int;
161 init_id: string;
162 (* Whether to use mergebase to calculate changed files or not *)
163 use_mergebase: bool;
164 mergebase: Hg.hg_rev option;
165 num_workers: int;
166 recheck_id: string;
167 nonce: Int64.t;
168 root: string;
169 tcopt: TypecheckerOptions.t;
170 (* This module exposes to the controller the limited set of operations that
171 it needs, without exposing the underlying types or implementation details.
172 It is also helpful in simplifying the isolation of the controller
173 for unit testing. *)
174 server: (module LocalServerApi);
175 (* Represents the version of hh_server that the remote hosts should install,
176 if it's not the default that they would be otherwise using. This field
177 is only useful in development and should not be set in the normal course
178 of business during type checking user's code. *)
179 version_specifier: string option;
180 (* The minimum log level workers should be logging at *)
181 worker_min_log_level: Hh_logger.Level.t;
182 (* Optional transport channel used by remote type checking. None means default. *)
183 transport_channel: string option;
184 naming_table_manifold_path: string option;