Skip to content

Commit c50efff

Browse files
grievejiafacebook-github-bot
authored andcommitted
Add a new check command to Pyre binary (5/5) -- run check
Reviewed By: dkgi Differential Revision: D28916455 fbshipit-source-id: fe91417c0fb8c031cc784ec2d74726e416192d3d
1 parent e6dfeb6 commit c50efff

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

source/command/newCheckCommand.ml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,69 @@ module CheckConfiguration = struct
193193
()
194194
end
195195

196+
let with_performance_tracking ~debug f =
197+
let timer = Timer.start () in
198+
let result = f () in
199+
let { Caml.Gc.minor_collections; major_collections; compactions; _ } = Caml.Gc.stat () in
200+
Statistics.performance
201+
~name:"check"
202+
~timer
203+
~integers:
204+
[
205+
"gc_minor_collections", minor_collections;
206+
"gc_major_collections", major_collections;
207+
"gc_compactions", compactions;
208+
]
209+
~normals:["request kind", "FullCheck"]
210+
();
211+
if debug then
212+
Memory.report_statistics ();
213+
result
214+
215+
216+
let do_check configuration =
217+
Scheduler.with_scheduler ~configuration ~f:(fun scheduler ->
218+
with_performance_tracking ~debug:configuration.debug (fun () ->
219+
let { Service.Check.errors; environment } =
220+
Service.Check.check
221+
~scheduler
222+
~configuration
223+
~call_graph_builder:(module Analysis.Callgraph.DefaultBuilder)
224+
in
225+
( errors,
226+
Analysis.TypeEnvironment.ast_environment environment
227+
|> Analysis.AstEnvironment.read_only )))
228+
229+
230+
let compute_errors ~configuration ~build_system () =
231+
let errors, ast_environment = do_check configuration in
232+
List.map
233+
errors
234+
~f:(Newserver.RequestHandler.instantiate_error ~build_system ~configuration ~ast_environment)
235+
236+
237+
let print_errors errors =
238+
Yojson.Safe.to_string
239+
(`Assoc
240+
[
241+
( "errors",
242+
`List
243+
(List.map ~f:(fun error -> Analysis.AnalysisError.Instantiated.to_yojson error) errors)
244+
);
245+
])
246+
|> Log.print "%s"
247+
248+
196249
let run_check check_configuration =
197250
let { CheckConfiguration.source_paths; _ } = check_configuration in
198-
Newserver.BuildSystem.with_build_system source_paths ~f:(fun _build_system ->
199-
let _analysis_configuration =
200-
CheckConfiguration.analysis_configuration_of check_configuration
251+
Newserver.BuildSystem.with_build_system source_paths ~f:(fun build_system ->
252+
let errors =
253+
compute_errors
254+
~configuration:(CheckConfiguration.analysis_configuration_of check_configuration)
255+
~build_system
256+
()
201257
in
202-
Log.warning "Coming soon...";
258+
print_errors errors;
203259
Lwt.return 0)
204260

205261

source/new_server/requestHandler.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
55
* LICENSE file in the root directory of this source tree.
66
*)
77

8+
val instantiate_error
9+
: build_system:BuildSystem.t ->
10+
configuration:Configuration.Analysis.t ->
11+
ast_environment:Analysis.AstEnvironment.ReadOnly.t ->
12+
Analysis.AnalysisError.t ->
13+
Analysis.AnalysisError.Instantiated.t
14+
815
val process_request : state:ServerState.t -> Request.t -> (ServerState.t * Response.t) Lwt.t

0 commit comments

Comments
 (0)