@@ -162,14 +162,10 @@ let populate_local_defs source_id poses loc_to_id local_ident_to_loc =
162
162
Odoc_model.Names.LocalName. make_std
163
163
(Printf. sprintf " local_%s_%d" (Ident. name id) (counter () ))
164
164
in
165
- (match source_id with
166
- | Some source_id ->
167
- let identifier =
168
- Odoc_model.Paths.Identifier.Mk. source_location_int
169
- (source_id, name)
170
- in
171
- LocHashtbl. add loc_to_id loc identifier
172
- | None -> () );
165
+ let identifier =
166
+ Odoc_model.Paths.Identifier.Mk. source_location_int (source_id, name)
167
+ in
168
+ LocHashtbl. add loc_to_id loc identifier;
173
169
IdentHashtbl. add local_ident_to_loc id loc
174
170
| _ -> () )
175
171
poses
@@ -256,44 +252,38 @@ let anchor_of_identifier id =
256
252
(* Adds the global definitions, found in the [uid_to_loc], to the [loc_to_id]
257
253
and [uid_to_id] tables. *)
258
254
let populate_global_defs env source_id loc_to_id uid_to_loc uid_to_id =
259
- match source_id with
260
- | None -> ()
261
- | Some source_id ->
262
- let mk_src_id id =
263
- let name =
264
- Odoc_model.Names.DefName. make_std (anchor_of_identifier id)
265
- in
266
- (Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
267
- :> Odoc_model.Paths.Identifier.SourceLocation. t)
268
- in
269
- let () =
270
- Ident_env. iter_located_identifier env @@ fun loc id ->
271
- LocHashtbl. add loc_to_id loc (mk_src_id id)
272
- in
273
- let mk_src_id () =
274
- let name =
275
- Odoc_model.Names.DefName. make_std
276
- (Printf. sprintf " def_%d" (counter () ))
277
- in
278
- (Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
279
- :> Odoc_model.Paths.Identifier.SourceLocation. t)
280
- in
281
- Shape.Uid.Tbl. iter
282
- (fun uid loc ->
283
- if loc.Location. loc_ghost then ()
284
- else
285
- match LocHashtbl. find_opt loc_to_id loc with
286
- | Some id -> UidHashtbl. add uid_to_id uid id
287
- | None -> (
288
- (* In case there is no entry for the location of the uid, we add one. *)
289
- match uid with
290
- | Item _ ->
291
- let id = mk_src_id () in
292
- LocHashtbl. add loc_to_id loc id;
293
- UidHashtbl. add uid_to_id uid id
294
- | Compilation_unit _ -> ()
295
- | _ -> () ))
296
- uid_to_loc
255
+ let mk_src_id id =
256
+ let name = Odoc_model.Names.DefName. make_std (anchor_of_identifier id) in
257
+ (Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
258
+ :> Odoc_model.Paths.Identifier.SourceLocation. t)
259
+ in
260
+ let () =
261
+ Ident_env. iter_located_identifier env @@ fun loc id ->
262
+ LocHashtbl. add loc_to_id loc (mk_src_id id)
263
+ in
264
+ let mk_src_id () =
265
+ let name =
266
+ Odoc_model.Names.DefName. make_std (Printf. sprintf " def_%d" (counter () ))
267
+ in
268
+ (Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
269
+ :> Odoc_model.Paths.Identifier.SourceLocation. t)
270
+ in
271
+ Shape.Uid.Tbl. iter
272
+ (fun uid loc ->
273
+ if loc.Location. loc_ghost then ()
274
+ else
275
+ match LocHashtbl. find_opt loc_to_id loc with
276
+ | Some id -> UidHashtbl. add uid_to_id uid id
277
+ | None -> (
278
+ (* In case there is no entry for the location of the uid, we add one. *)
279
+ match uid with
280
+ | Item _ ->
281
+ let id = mk_src_id () in
282
+ LocHashtbl. add loc_to_id loc id;
283
+ UidHashtbl. add uid_to_id uid id
284
+ | Compilation_unit _ -> ()
285
+ | _ -> () ))
286
+ uid_to_loc
297
287
298
288
(* Extract [Typedtree_traverse] occurrence information and turn them into proper
299
289
source infos *)
@@ -377,10 +367,16 @@ let read_cmt_infos source_id_opt id cmt_info ~count_occurrences =
377
367
and local_ident_to_loc = IdentHashtbl. create 10
378
368
and uid_to_id = UidHashtbl. create 10 in
379
369
let () =
380
- (* populate [loc_to_id], [ident_to_id] and [uid_to_id] *)
381
- populate_local_defs source_id traverse_infos loc_to_id
382
- local_ident_to_loc;
383
- populate_global_defs env source_id loc_to_id uid_to_loc uid_to_id
370
+ match source_id with
371
+ | None -> ()
372
+ (* populate [loc_to_id], [ident_to_id] and [uid_to_id] only when
373
+ rendering source code, as these are only used to compute source
374
+ locations id *)
375
+ | Some source_id ->
376
+ populate_local_defs source_id traverse_infos loc_to_id
377
+ local_ident_to_loc;
378
+ populate_global_defs env source_id loc_to_id uid_to_loc
379
+ uid_to_id
384
380
in
385
381
let source_infos =
386
382
process_occurrences env traverse_infos loc_to_id local_ident_to_loc
0 commit comments