Skip to content

Commit 02220e9

Browse files
committed
Strengthen everything inside includes
1 parent 18ddbc8 commit 02220e9

File tree

12 files changed

+107
-28
lines changed

12 files changed

+107
-28
lines changed

src/loader/cmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ and read_include env parent incl =
530530
| Some m when not (contains_signature m) ->
531531
let decl = ModuleType m in
532532
let expansion = { content; shadowed; } in
533-
[Include {parent; doc; decl; expansion; inline=false }]
533+
[Include {parent; doc; decl; expansion; inline=false; strengthened=None }]
534534
| Some (ModuleType.U.Signature { items; _ }) ->
535535
items
536536
| _ ->

src/loader/cmti.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ and read_include env parent incl =
691691
| Some uexpr when not (contains_signature uexpr) ->
692692
let decl = Include.ModuleType uexpr in
693693
let expansion = { content; shadowed; } in
694-
[Include {parent; doc; decl; expansion; inline=false }]
694+
[Include {parent; doc; decl; expansion; inline=false; strengthened=None }]
695695
| Some ModuleType.U.Signature { items; _ } when is_inlinable items ->
696696
items
697697
| _ ->

src/model/lang.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ and Include : sig
168168

169169
type t = {
170170
parent : Identifier.Signature.t;
171+
strengthened : Path.Module.t option;
171172
doc : Comment.docs;
172173
decl : decl;
173174
inline : bool;

src/xref2/compile.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,14 @@ and include_ : Env.t -> Include.t -> Include.t =
329329
i.expansion
330330
| Ok sg ->
331331
let map = { Lang_of.empty with shadowed = i.expansion.shadowed } in
332-
let e = Lang_of.(simple_expansion map i.parent (Signature sg)) in
332+
let sg' =
333+
match i.strengthened with
334+
| Some p ->
335+
let cp = Component.Of_Lang.(module_path empty p) in
336+
Strengthen.signature cp sg
337+
| None -> sg
338+
in
339+
let e = Lang_of.(simple_expansion map i.parent (Signature sg')) in
333340

334341
let expansion_sg =
335342
match e with

src/xref2/component.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ and Include : sig
326326

327327
type t = {
328328
parent : Odoc_model.Paths.Identifier.Signature.t;
329+
strengthened : Cpath.module_ option;
329330
doc : CComment.docs;
330331
shadowed : Odoc_model.Lang.Include.shadowed;
331332
expansion_ : Signature.t;
@@ -2117,6 +2118,7 @@ module Of_Lang = struct
21172118
doc = docs ident_map i.doc;
21182119
shadowed = i.expansion.shadowed;
21192120
expansion_ = apply_sig_map ident_map i.expansion.content;
2121+
strengthened = option module_path ident_map i.strengthened;
21202122
decl;
21212123
}
21222124

src/xref2/component.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ and Include : sig
304304

305305
type t = {
306306
parent : Odoc_model.Paths.Identifier.Signature.t;
307+
strengthened : Cpath.module_ option;
307308
doc : CComment.docs;
308309
shadowed : Odoc_model.Lang.Include.shadowed;
309310
expansion_ : Signature.t;

src/xref2/lang_of.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -586,20 +586,26 @@ and include_decl :
586586

587587
and include_ parent map i =
588588
let open Component.Include in
589-
{
590-
Odoc_model.Lang.Include.parent;
591-
doc = docs (parent :> Identifier.LabelParent.t) i.doc;
592-
decl = include_decl map parent i.decl;
593-
expansion =
594-
{
595-
shadowed = i.shadowed;
596-
content =
597-
signature parent
598-
{ map with shadowed = combine_shadowed map.shadowed i.shadowed }
599-
i.expansion_;
600-
};
601-
inline = false;
602-
}
589+
try
590+
{
591+
Odoc_model.Lang.Include.parent;
592+
doc = docs (parent :> Identifier.LabelParent.t) i.doc;
593+
decl = include_decl map parent i.decl;
594+
expansion =
595+
{
596+
shadowed = i.shadowed;
597+
content =
598+
signature parent
599+
{ map with shadowed = combine_shadowed map.shadowed i.shadowed }
600+
i.expansion_;
601+
};
602+
inline = false;
603+
strengthened = Opt.map (Path.module_ map) i.strengthened;
604+
}
605+
with e ->
606+
Format.eprintf "Caught exception %s\n%!" (Printexc.to_string e);
607+
Format.eprintf "%a\n" Component.Fmt.include_ i;
608+
raise e
603609

604610
and open_ parent map o =
605611
let open Component.Open in

src/xref2/strengthen.ml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ open Delayed
2020
let rec signature :
2121
Cpath.module_ -> ?canonical:Cpath.module_ -> Signature.t -> Signature.t =
2222
fun prefix ?canonical sg ->
23+
let sg', strengthened_modules = sig_items prefix ?canonical sg in
24+
(* Format.eprintf "Invalidating modules: %a\n%!" (Format.pp_print_list Ident.fmt) strengthened_modules; *)
25+
let substs =
26+
List.fold_left
27+
(fun s mid -> Subst.path_invalidate_module (mid :> Ident.path_module) s)
28+
Subst.identity strengthened_modules
29+
in
30+
Subst.signature substs sg'
31+
32+
and sig_items prefix ?canonical sg =
2333
let open Signature in
24-
let items, strengthened_modules =
34+
let items, ids =
2535
List.fold_left
2636
(fun (items, s) item ->
2737
match item with
@@ -51,19 +61,15 @@ let rec signature :
5161
type_decl (`Dot (prefix, Ident.Name.type_ id)) (get t)) )
5262
:: items,
5363
s )
64+
| Include i ->
65+
let i', strengthened = include_ prefix i in
66+
(Include i' :: items, strengthened @ s)
5467
| Exception _ | TypExt _ | Value _ | External _ | Class _ | ClassType _
55-
| Include _ | ModuleSubstitution _ | TypeSubstitution _ | Comment _
56-
| Open _ ->
68+
| ModuleSubstitution _ | TypeSubstitution _ | Comment _ | Open _ ->
5769
(item :: items, s))
5870
([], []) sg.items
5971
in
60-
(* Format.eprintf "Invalidating modules: %a\n%!" (Format.pp_print_list Ident.fmt) strengthened_modules; *)
61-
let substs =
62-
List.fold_left
63-
(fun s mid -> Subst.path_invalidate_module (mid :> Ident.path_module) s)
64-
Subst.identity strengthened_modules
65-
in
66-
Subst.signature substs { sg with items = List.rev items }
72+
({ sg with items = List.rev items }, ids)
6773

6874
and module_ :
6975
?canonical:Cpath.module_ ->
@@ -109,3 +115,8 @@ and type_decl : Cpath.type_ -> TypeDecl.t -> TypeDecl.t =
109115
}
110116
in
111117
{ t with equation }
118+
119+
and include_ : Cpath.module_ -> Include.t -> Include.t * Ident.module_ list =
120+
fun path i ->
121+
let expansion_, strengthened = sig_items path i.expansion_ in
122+
({ i with expansion_; strengthened = Some path }, strengthened)

src/xref2/subst.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ and include_ s i =
724724
{
725725
i with
726726
decl = include_decl s i.decl;
727+
strengthened = option_ module_path s i.strengthened;
727728
expansion_ = apply_sig_map_sg s i.expansion_;
728729
}
729730

src/xref2/tools.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,9 @@ and fragmap :
12781278
compiled = false;
12791279
}
12801280
in
1281-
Ok (Component.Signature.Include { i with decl; expansion_ })
1281+
Ok
1282+
(Component.Signature.Include
1283+
{ i with decl; expansion_; strengthened = None })
12821284
else Ok item
12831285
in
12841286
component >>= fun c ->

0 commit comments

Comments
 (0)