Remove enable_disk_heap setting
[hiphop-php.git] / hphp / hack / src / parser / ast_and_decl_service.ml
blob0c759ae0fe9628ca8a5223fd01d891fc808cd935
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 let process_parse_result
12 ctx
13 ?(ide = false)
14 ~quick
15 ~trace
16 ~cache_decls
17 ~start_time
18 (acc, errorl, error_files)
20 (errorl', (ast, decls))
21 popt =
22 let start_parse_time = start_time in
23 let start_process_time = Unix.gettimeofday () in
24 let { Parser_return.file_mode; comments = _; ast; content } = ast in
25 let ast =
27 Relative_path.(is_hhi (Relative_path.prefix fn))
28 && ParserOptions.deregister_php_stdlib popt
29 then
30 Nast.deregister_ignored_attributes ast
31 else
32 ast
34 let bytes = String.length content in
35 let content =
36 if ide then
37 File_provider.Ide content
38 else
39 File_provider.Disk content
41 if Option.is_some file_mode then (
42 (* If this file was parsed from a tmp directory,
43 save it to the main directory instead *)
44 let fn =
45 match Relative_path.prefix fn with
46 | Relative_path.Tmp -> Relative_path.to_root fn
47 | _ -> fn
49 if quick then File_provider.provide_file_hint fn content;
50 let mode =
51 if quick then
52 Ast_provider.Decl
53 else
54 Ast_provider.Full
56 Ast_provider.provide_ast_hint fn ast mode;
57 if cache_decls then
58 Direct_decl_utils.cache_decls ctx fn decls.Direct_decl_utils.pfh_decls;
59 let defs = Direct_decl_parser.decls_to_fileinfo fn decls in
60 let acc = Relative_path.Map.add acc ~key:fn ~data:defs in
61 let errorl = Errors.merge errorl' errorl in
62 let error_files =
63 if Errors.is_empty errorl' then
64 error_files
65 else
66 Relative_path.Set.add error_files fn
68 if trace then
69 Hh_logger.log
70 "[%dk, %.0f+%.0fms] %s - %s"
71 (bytes / 1024)
72 ((start_process_time -. start_parse_time) *. 1000.0)
73 ((Unix.gettimeofday () -. start_process_time) *. 1000.0)
74 (Relative_path.suffix fn)
75 (FileInfo.to_string defs);
76 (acc, errorl, error_files)
77 ) else (
78 File_provider.provide_file_hint fn content;
79 (* we also now keep in the file_info regular php files
80 * as we need at least their names in hack build
82 let acc = Relative_path.Map.add acc ~key:fn ~data:FileInfo.empty_t in
83 (acc, errorl, error_files)
86 let parse ctx ~quick ~show_all_errors ~trace ~cache_decls popt acc fn =
87 if not @@ FindUtils.path_filter fn then
88 acc
89 else
90 let start_time = Unix.gettimeofday () in
91 let res =
92 Errors.do_with_context fn Errors.Parsing @@ fun () ->
93 Full_fidelity_ast.ast_and_decls_from_file ~quick ~show_all_errors popt fn
95 process_parse_result
96 ctx
97 ~quick
98 ~start_time
99 ~trace
100 ~cache_decls
104 popt
106 let merge_parse (acc1, status1, files1) (acc2, status2, files2) =
107 ( Relative_path.Map.union acc1 acc2,
108 Errors.merge status1 status2,
109 Relative_path.Set.union files1 files2 )
111 let go
112 (ctx : Provider_context.t)
113 ?(quick = false)
114 ?(show_all_errors = false)
115 (workers : MultiWorker.worker list option)
116 ~(get_next : Relative_path.t list MultiWorker.Hh_bucket.next)
117 (popt : ParserOptions.t)
118 ~(trace : bool)
119 ~(cache_decls : bool)
120 ~(worker_call : MultiWorker.call_wrapper) :
121 FileInfo.t Relative_path.Map.t * Errors.t * Relative_path.Set.t =
122 worker_call.MultiWorker.f
123 workers
124 ~job:(fun init ->
125 List.fold_left
126 ~init
127 ~f:(parse ctx ~quick ~show_all_errors ~trace ~cache_decls popt))
128 ~neutral:(Relative_path.Map.empty, Errors.empty, Relative_path.Set.empty)
129 ~merge:merge_parse
130 ~next:get_next