Skip to content

Commit 116505a

Browse files
committed
Combine shape and uid_to_id to one field in Lang
1 parent af9c421 commit 116505a

File tree

7 files changed

+42
-33
lines changed

7 files changed

+42
-33
lines changed

src/loader/implementation.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,20 @@ let read_cmt_infos source_id_opt id cmt_info =
512512
let map, source_infos =
513513
of_cmt source_id id impl uid_to_loc
514514
in
515-
( Some shape,
516-
map,
515+
( Some (shape, map),
517516
Some
518517
{
519518
Odoc_model.Lang.Source_info.id = source_id;
520519
infos = source_infos;
521520
} )
522-
| _, _ -> (Some shape, Odoc_model.Compat.empty_map, None))
523-
| None -> (None, Odoc_model.Compat.empty_map, None)
521+
| _, _ -> (Some (shape, Odoc_model.Compat.empty_map), None))
522+
| None -> (None, None)
524523

525524

526525

527526
#else
528527

529-
let read_cmt_infos _source_id_opt _id ~filename:_ () =
530-
(None, Odoc_model.Compat.empty_map, None)
528+
let read_cmt_infos _source_id_opt _id _cmt_info =
529+
(None, None)
531530

532531
#endif

src/loader/implementation.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ val read_cmt_infos :
22
Odoc_model.Paths.Identifier.Id.source_page option ->
33
Odoc_model.Paths.Identifier.Id.root_module ->
44
Cmt_format.cmt_infos ->
5-
Odoc_model.Compat.shape option
5+
(Odoc_model.Compat.shape
66
* Odoc_model.Paths.Identifier.Id.source_location
7-
Odoc_model.Compat.shape_uid_map
7+
Odoc_model.Compat.shape_uid_map)
8+
option
89
* Odoc_model.Lang.Source_info.t option
910
(** Extract all implementation information from a [cmt]: the shape, and the
1011
{{!Odoc_model.Lang.Source_info.infos}source infos} (local and global

src/loader/odoc_loader.ml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let read_cmt_infos source_id_opt id ~filename () =
5252

5353

5454
let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
55-
?canonical ?shape ~uid_to_id ~source_info content =
55+
?canonical ?shape_info ~source_info content =
5656
let open Odoc_model.Lang.Compilation_unit in
5757
let interface, digest =
5858
match interface with
@@ -89,16 +89,15 @@ let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
8989
linked = false;
9090
canonical;
9191
source_info;
92-
shape;
93-
uid_to_id;
92+
shape_info;
9493
}
9594

9695

9796
let compilation_unit_of_sig ~make_root ~imports ~interface ?sourcefile ~name ~id
98-
?canonical ?shape ~uid_to_id sg =
97+
?canonical ?shape_info sg =
9998
let content = Odoc_model.Lang.Compilation_unit.Module sg in
10099
make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
101-
?canonical ?shape ~uid_to_id content
100+
?canonical ?shape_info content
102101

103102
let read_cmti ~make_root ~parent ~filename ~cmt_filename_opt ~source_id_opt () =
104103
let cmt_info = Cmt_format.read_cmt filename in
@@ -114,14 +113,14 @@ let read_cmti ~make_root ~parent ~filename ~cmt_filename_opt ~source_id_opt () =
114113
cmt_info.cmt_builddir )
115114
in
116115
let id, sg, canonical = Cmti.read_interface parent name intf in
117-
let shape, uid_to_id, source_info =
116+
let shape_info, source_info =
118117
match cmt_filename_opt with
119118
| Some cmt_filename ->
120119
read_cmt_infos source_id_opt id ~filename:cmt_filename ()
121-
| None -> (None, Odoc_model.Compat.empty_map, None)
120+
| None -> (None, None)
122121
in
123122
compilation_unit_of_sig ~make_root ~imports:cmt_info.cmt_imports
124-
~interface ~sourcefile ~name ~id ?shape ~uid_to_id ~source_info
123+
~interface ~sourcefile ~name ~id ?shape_info ~source_info
125124
?canonical sg)
126125
| _ -> raise Not_an_interface
127126

@@ -165,14 +164,14 @@ let read_cmt ~make_root ~parent ~filename ~source_id_opt () =
165164
in
166165
let content = Odoc_model.Lang.Compilation_unit.Pack items in
167166
make_compilation_unit ~make_root ~imports ~interface ~sourcefile ~name
168-
~id ~uid_to_id:Odoc_model.Compat.empty_map ~source_info:None content
167+
~id ~source_info:None content
169168
| Implementation impl ->
170169
let id, sg, canonical = Cmt.read_implementation parent name impl in
171-
let shape, uid_to_id, source_info =
170+
let shape_info, source_info =
172171
read_cmt_infos source_id_opt id ~filename ()
173172
in
174173
compilation_unit_of_sig ~make_root ~imports ~interface ~sourcefile
175-
~name ~id ?canonical ?shape ~uid_to_id ~source_info sg
174+
~name ~id ?canonical ?shape_info ~source_info sg
176175
| _ -> raise Not_an_implementation)
177176

178177
let read_cmi ~make_root ~parent ~filename () =
@@ -184,7 +183,7 @@ let read_cmi ~make_root ~parent ~filename () =
184183
(Odoc_model.Compat.signature cmi_info.cmi_sign)
185184
in
186185
compilation_unit_of_sig ~make_root ~imports ~interface ~name ~id
187-
~source_info:None ~uid_to_id:Odoc_model.Compat.empty_map sg
186+
~source_info:None sg
188187
| _ -> raise Corrupted
189188

190189
(** Catch errors from reading the object files and some internal errors *)

src/model/lang.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,9 @@ module rec Compilation_unit : sig
486486
linked : bool; (** Whether this unit has been linked. *)
487487
canonical : Path.Module.t option;
488488
source_info : Source_info.t option;
489-
shape : Compat.shape option;
490-
uid_to_id : Paths.Identifier.SourceLocation.t Compat.shape_uid_map;
489+
shape_info :
490+
(Compat.shape * Paths.Identifier.SourceLocation.t Compat.shape_uid_map)
491+
option;
491492
}
492493
end =
493494
Compilation_unit

src/odoc/odoc_link.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ let from_odoc ~resolver ~warnings_options input output =
4646
|> handle_warnings ~input_warnings ~warnings_options
4747
>>= fun (m, warnings) ->
4848
(* Remove the shape here so that we only depend upon odoc types
49-
rather than odoc and ocaml types. This means we should be able
50-
save an odocl file with odoc x.y compiled with one version of
51-
the compiler and load it in odoc x.y compiled with a different
52-
version of the compiler. This is an important use case for
53-
voodoo. *)
54-
let m = { m with Odoc_model.Lang.Compilation_unit.shape = None } in
49+
rather than odoc and ocaml types. This means we don't break
50+
being able save an odocl file with odoc x.y compiled with one
51+
version of the compiler and load it in odoc x.y compiled with
52+
a different version of the compiler, provided the compiler
53+
itself doesn't break cross-version marshalling! This ability
54+
is currently being used by voodoo. *)
55+
let m =
56+
let open Odoc_model.Lang.Compilation_unit in
57+
{ m with shape_info = None }
58+
in
5559
Odoc_file.save_unit output ~warnings m;
5660
Ok (`Module m)

src/xref2/shape_tools.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ let rec shape_of_id env :
2121
match id.iv with
2222
| `Root (_, name) -> begin
2323
match Env.lookup_unit (ModuleName.to_string name) env with
24-
| Some (Env.Found unit) -> unit.shape
24+
| Some (Env.Found unit) -> (
25+
match unit.shape_info with | Some (shape, _) -> Some shape | None -> None)
2526
| _ -> None
2627
end
2728
| `Module (parent, name) ->
@@ -69,7 +70,8 @@ let lookup_shape :
6970
let fuel = 10
7071
let read_unit_shape ~unit_name =
7172
match Env.lookup_unit unit_name env with
72-
| Some (Found unit) -> unit.shape
73+
| Some (Found unit) -> (
74+
match unit.shape_info with | Some (shape, _) -> Some shape | None -> None)
7375
| _ -> None
7476
let find_shape _ _ = raise Not_found
7577
end) in
@@ -82,7 +84,11 @@ let lookup_shape :
8284
| Some Forward_reference
8385
| Some (Not_found) -> None
8486
| Some (Found unit) ->
85-
let uid_to_id = unit.uid_to_id in
87+
let uid_to_id =
88+
match unit.shape_info with
89+
| Some (_, uid_to_id) -> uid_to_id
90+
| None -> Odoc_model.Compat.empty_map
91+
in
8692
match Shape.Uid.Map.find_opt uid uid_to_id with
8793
| Some x -> Some x
8894
| None -> (

test/xref2/lib/common.cppo.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ let my_compilation_unit id (s : Odoc_model.Lang.Signature.t) =
616616
; linked = false
617617
; canonical = None
618618
; source_info = None
619-
; shape = None
620-
; uid_to_id = Odoc_model.Compat.empty_map
619+
; shape_info = None
621620
}
622621

623622
let mkresolver () =

0 commit comments

Comments
 (0)