66
77[@@@ alert " -unsafe" ]
88
9- (* * Result of processing a single CMT file *)
109type cmt_file_result = {
1110 dce_data : DceFileProcessing .file_data option ;
1211 exception_data : Exception .file_result option ;
1312}
13+ (* * Result of processing a single CMT file *)
1414
15- (* * Result of processing all CMT files *)
1615type all_files_result = {
1716 dce_data_list : DceFileProcessing .file_data list ;
1817 exception_results : Exception .file_result list ;
1918}
19+ (* * Result of processing all CMT files *)
2020
21- (* * Cached file_data for a single CMT file.
22- We cache the processed result, not just the raw CMT data. *)
2321type cached_file = {
2422 path : string ;
2523 file_data : DceFileProcessing .file_data option ;
2624 exception_data : Exception .file_result option ;
2725}
26+ (* * Cached file_data for a single CMT file.
27+ We cache the processed result, not just the raw CMT data. *)
2828
2929(* * The file cache - maps CMT paths to processed results *)
3030let file_cache : (string, cached_file) Hashtbl.t = Hashtbl. create 1024
@@ -81,60 +81,62 @@ let process_cmt_infos ~config ~cmtFilePath cmt_infos : cmt_file_result option =
8181 Returns the cached result if the file hasn't changed since last access. *)
8282let process_cmt_cached ~config cmtFilePath : cmt_file_result option =
8383 match CmtCache. read_cmt_if_changed cmtFilePath with
84- | None ->
84+ | None -> (
8585 (* File unchanged - return cached result *)
86- ( match Hashtbl. find_opt file_cache cmtFilePath with
87- | Some cached ->
88- Some { dce_data = cached.file_data; exception_data = cached.exception_data }
89- | None ->
90- (* First time seeing this file - shouldn't happen, but handle gracefully *)
91- None )
86+ match Hashtbl. find_opt file_cache cmtFilePath with
87+ | Some cached ->
88+ Some {dce_data = cached.file_data; exception_data = cached.exception_data}
89+ | None ->
90+ (* First time seeing this file - shouldn't happen, but handle gracefully *)
91+ None )
9292 | Some cmt_infos ->
9393 (* File changed or new - process it *)
9494 let result = process_cmt_infos ~config ~cmt FilePath cmt_infos in
9595 (* Cache the result *)
9696 (match result with
97- | Some r ->
98- Hashtbl. replace file_cache cmtFilePath {
99- path = cmtFilePath;
100- file_data = r.dce_data;
101- exception_data = r.exception_data;
102- }
103- | None -> () );
97+ | Some r ->
98+ Hashtbl. replace file_cache cmtFilePath
99+ {
100+ path = cmtFilePath;
101+ file_data = r.dce_data;
102+ exception_data = r.exception_data;
103+ }
104+ | None -> () );
104105 result
105106
106107(* * Process all files incrementally.
107108 First run processes all files. Subsequent runs only process changed files. *)
108109let process_files_incremental ~config cmtFilePaths : all_files_result =
109110 Timing. time_phase `FileLoading (fun () ->
110- let dce_data_list = ref [] in
111- let exception_results = ref [] in
112- let processed = ref 0 in
113- let from_cache = ref 0 in
114-
115- cmtFilePaths |> List. iter (fun cmtFilePath ->
116- (* Check if file was in cache *before* processing *)
117- let was_cached = Hashtbl. mem file_cache cmtFilePath in
118- match process_cmt_cached ~config cmtFilePath with
119- | Some {dce_data; exception_data} ->
120- (match dce_data with
121- | Some data -> dce_data_list := data :: ! dce_data_list
122- | None -> () );
123- (match exception_data with
124- | Some data -> exception_results := data :: ! exception_results
125- | None -> () );
126- (* Track whether it was from cache *)
127- if was_cached then
128- incr from_cache
129- else
130- incr processed
131- | None -> ()
132- );
133-
134- if ! Cli. timing then
135- Printf. eprintf " Reactive: %d files processed, %d from cache\n %!" ! processed ! from_cache;
136-
137- {dce_data_list = List. rev ! dce_data_list; exception_results = List. rev ! exception_results})
111+ let dce_data_list = ref [] in
112+ let exception_results = ref [] in
113+ let processed = ref 0 in
114+ let from_cache = ref 0 in
115+
116+ cmtFilePaths
117+ |> List. iter (fun cmtFilePath ->
118+ (* Check if file was in cache *before* processing *)
119+ let was_cached = Hashtbl. mem file_cache cmtFilePath in
120+ match process_cmt_cached ~config cmtFilePath with
121+ | Some {dce_data; exception_data} ->
122+ (match dce_data with
123+ | Some data -> dce_data_list := data :: ! dce_data_list
124+ | None -> () );
125+ (match exception_data with
126+ | Some data -> exception_results := data :: ! exception_results
127+ | None -> () );
128+ (* Track whether it was from cache *)
129+ if was_cached then incr from_cache else incr processed
130+ | None -> () );
131+
132+ if ! Cli. timing then
133+ Printf. eprintf " Reactive: %d files processed, %d from cache\n %!"
134+ ! processed ! from_cache;
135+
136+ {
137+ dce_data_list = List. rev ! dce_data_list;
138+ exception_results = List. rev ! exception_results;
139+ })
138140
139141(* * Clear all cached file data *)
140142let clear () =
@@ -146,4 +148,3 @@ let stats () =
146148 let file_count = Hashtbl. length file_cache in
147149 let cmt_stats = CmtCache. stats () in
148150 (file_count, cmt_stats)
149-
0 commit comments