Skip to content

Commit 0be71b4

Browse files
committed
Shadowing simplification
This still isn't quite right, but it's definitely less wrong with this fix. Signed-off-by: Jon Ludlam <[email protected]>
1 parent 523b6f5 commit 0be71b4

File tree

5 files changed

+39
-65
lines changed

5 files changed

+39
-65
lines changed

src/loader/cmi.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
901901
let vd = read_value_description env parent id v in
902902
let shadowed =
903903
if Env.is_shadowed env id
904-
then { shadowed with s_values = (Ident.name id, (Env.find_value_identifier env id)) :: shadowed.s_values }
904+
then { shadowed with s_values = Ident.name id :: shadowed.s_values }
905905
else shadowed
906906
in
907907
loop (vd :: acc, shadowed) rest
@@ -912,7 +912,7 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
912912
let decl = read_type_declaration env parent id decl in
913913
let shadowed =
914914
if Env.is_shadowed env id
915-
then { shadowed with s_types = (Ident.name id, decl.id) :: shadowed.s_types }
915+
then { shadowed with s_types = Ident.name id :: shadowed.s_types }
916916
else shadowed
917917
in
918918
loop (Type (read_type_rec_status rec_status, decl)::acc, shadowed) rest
@@ -937,15 +937,15 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
937937
let md = read_module_declaration env parent id md in
938938
let shadowed =
939939
if Env.is_shadowed env id
940-
then { shadowed with s_modules = (Ident.name id, md.id) :: shadowed.s_modules }
940+
then { shadowed with s_modules = Ident.name id :: shadowed.s_modules }
941941
else shadowed
942942
in
943943
loop (Module (read_module_rec_status rec_status, md)::acc, shadowed) rest
944944
| Sig_modtype(id, mtd, _) :: rest ->
945945
let mtd = read_module_type_declaration env parent id mtd in
946946
let shadowed =
947947
if Env.is_shadowed env id
948-
then { shadowed with s_module_types = (Ident.name id, mtd.id) :: shadowed.s_module_types }
948+
then { shadowed with s_module_types = Ident.name id :: shadowed.s_module_types }
949949
else shadowed
950950
in
951951
loop (ModuleType mtd :: acc, shadowed) rest
@@ -954,15 +954,15 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
954954
let cl = read_class_declaration env parent id cl in
955955
let shadowed =
956956
if Env.is_shadowed env id
957-
then { shadowed with s_classes = (Ident.name id, cl.id) :: shadowed.s_classes }
957+
then { shadowed with s_classes = Ident.name id :: shadowed.s_classes }
958958
else shadowed
959959
in
960960
loop (Class (read_type_rec_status rec_status, cl)::acc, shadowed) rest
961961
| Sig_class_type(id, cltyp, rec_status, _)::Sig_type _::Sig_type _::rest ->
962962
let cltyp = read_class_type_declaration env parent id cltyp in
963963
let shadowed =
964964
if Env.is_shadowed env id
965-
then { shadowed with s_class_types = (Ident.name id, cltyp.id) :: shadowed.s_class_types }
965+
then { shadowed with s_class_types = Ident.name id :: shadowed.s_class_types }
966966
else shadowed
967967
in
968968
loop (ClassType (read_type_rec_status rec_status, cltyp)::acc, shadowed) rest

src/model/lang.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ end =
148148

149149
and Include : sig
150150
type shadowed = {
151-
s_modules : (string * Identifier.Module.t) list;
152-
s_module_types : (string * Identifier.ModuleType.t) list;
153-
s_values : (string * Identifier.Value.t) list;
154-
s_types : (string * Identifier.Type.t) list;
155-
s_classes : (string * Identifier.Class.t) list;
156-
s_class_types : (string * Identifier.ClassType.t) list;
151+
s_modules : string list;
152+
s_module_types : string list;
153+
s_values : string list;
154+
s_types : string list;
155+
s_classes : string list;
156+
s_class_types : string list;
157157
}
158158

159159
type expansion = { shadowed : shadowed; content : Signature.t }

src/model_desc/lang_desc.ml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,12 @@ and include_shadowed =
216216
let open Lang.Include in
217217
Record
218218
[
219-
F ("s_modules", (fun t -> t.s_modules), List (Pair (string, identifier)));
220-
F
221-
( "s_module_types",
222-
(fun t -> t.s_module_types),
223-
List (Pair (string, identifier)) );
224-
F ("s_values", (fun t -> t.s_values), List (Pair (string, identifier)));
225-
F ("s_types", (fun t -> t.s_types), List (Pair (string, identifier)));
226-
F ("s_classes", (fun t -> t.s_classes), List (Pair (string, identifier)));
227-
F
228-
( "s_class_types",
229-
(fun t -> t.s_class_types),
230-
List (Pair (string, identifier)) );
219+
F ("s_modules", (fun t -> t.s_modules), List string);
220+
F ("s_module_types", (fun t -> t.s_module_types), List string);
221+
F ("s_values", (fun t -> t.s_values), List string);
222+
F ("s_types", (fun t -> t.s_types), List string);
223+
F ("s_classes", (fun t -> t.s_classes), List string);
224+
F ("s_class_types", (fun t -> t.s_class_types), List string);
231225
]
232226

233227
and include_expansion =

src/xref2/lang_of.ml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,11 @@ module ExtractIDs = struct
247247
let rec type_decl parent map id =
248248
let name = Ident.Name.type_ id in
249249
let identifier =
250-
if List.mem_assoc name map.shadowed.s_types then
251-
List.assoc name map.shadowed.s_types
250+
if List.mem name map.shadowed.s_types then
251+
`Type
252+
( parent,
253+
Odoc_model.Names.TypeName.internal_of_string (Ident.Name.type_ id)
254+
)
252255
else `Type (parent, Ident.Name.typed_type id)
253256
in
254257
{
@@ -262,20 +265,19 @@ module ExtractIDs = struct
262265
}
263266

264267
and module_ parent map id =
265-
let name' = Ident.Name.typed_module id in
266-
let name = ModuleName.to_string name' in
268+
let name = Ident.Name.module_ id in
267269
let identifier =
268-
if List.mem_assoc name map.shadowed.s_modules then
269-
List.assoc name map.shadowed.s_modules
270-
else `Module (parent, name')
270+
if List.mem name map.shadowed.s_modules then
271+
`Module (parent, ModuleName.internal_of_string name)
272+
else `Module (parent, Ident.Name.typed_module id)
271273
in
272274
{ map with module_ = Component.ModuleMap.add id identifier map.module_ }
273275

274276
and module_type parent map id =
275277
let name = Ident.Name.module_type id in
276278
let identifier =
277-
if List.mem_assoc name map.shadowed.s_module_types then
278-
List.assoc name map.shadowed.s_module_types
279+
if List.mem name map.shadowed.s_module_types then
280+
`ModuleType (parent, ModuleTypeName.internal_of_string name)
279281
else `ModuleType (parent, Ident.Name.typed_module_type id)
280282
in
281283
{
@@ -286,8 +288,8 @@ module ExtractIDs = struct
286288
and class_ parent map id =
287289
let name = Ident.Name.class_ id in
288290
let identifier =
289-
if List.mem_assoc name map.shadowed.s_classes then
290-
List.assoc name map.shadowed.s_classes
291+
if List.mem name map.shadowed.s_classes then
292+
`Class (parent, ClassName.internal_of_string name)
291293
else `Class (parent, Ident.Name.typed_class id)
292294
in
293295
{
@@ -308,8 +310,8 @@ module ExtractIDs = struct
308310
and class_type parent map (id : Ident.class_type) =
309311
let name = Ident.Name.class_type id in
310312
let identifier =
311-
if List.mem_assoc name map.shadowed.s_class_types then
312-
List.assoc name map.shadowed.s_class_types
313+
if List.mem name map.shadowed.s_class_types then
314+
`ClassType (parent, ClassTypeName.internal_of_string name)
313315
else `ClassType (parent, Ident.Name.typed_class_type id)
314316
in
315317
{
@@ -522,7 +524,12 @@ and instance_variable map parent id i =
522524

523525
and external_ map parent id e =
524526
let open Component.External in
525-
let identifier = `Value (parent, Ident.Name.typed_value id) in
527+
let name = Ident.Name.value id in
528+
let identifier =
529+
if List.mem name map.shadowed.s_values then
530+
`Value (parent, ValueName.internal_of_string name)
531+
else `Value (parent, Ident.Name.typed_value id)
532+
in
526533
{
527534
id = identifier;
528535
doc = docs (parent :> Identifier.LabelParent.t) e.doc;
Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
11
A quick test to repro the issue found in #587
22

33
$ ./build.sh
4-
odoc: internal error, uncaught exception:
5-
Failure("Error")
6-
Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
7-
Called from Odoc_xref2__Subst.rename_bound_idents.new_module_id in file "src/xref2/subst.ml", line 771, characters 13-29
8-
Called from Odoc_xref2__Subst.rename_bound_idents.(fun) in file "src/xref2/subst.ml", line 809, characters 16-32
9-
Called from Odoc_xref2__Subst.rename_bound_idents.(fun) in file "src/xref2/subst.ml", line 868, characters 8-69
10-
Called from Odoc_xref2__Subst.signature in file "src/xref2/subst.ml", line 907, characters 17-50
11-
Called from Odoc_xref2__Subst.simple_expansion in file "src/xref2/subst.ml", line 503, characters 30-46
12-
Called from Odoc_xref2__Subst.option_ in file "src/xref2/subst.ml", line 412, characters 51-61
13-
Called from Odoc_xref2__Subst.module_type_expr in file "src/xref2/subst.ml", line 599, characters 24-62
14-
Called from Odoc_xref2__Subst.module_type in file "src/xref2/subst.ml", line 509, characters 37-59
15-
Called from Odoc_xref2__Tools.handle_module_type_lookup.(fun) in file "src/xref2/tools.ml", line 415, characters 13-37
16-
Called from Odoc_xref2__Tools.resolve_module_type.(fun) in file "src/xref2/tools.ml", line 708, characters 8-68
17-
Called from Odoc_xref2__Expand_tools.aux_expansion_of_u_module_type_expr in file "src/xref2/expand_tools.ml", line 111, characters 6-61
18-
Called from Odoc_xref2__Compile.include_.get_expansion in file "src/xref2/compile.ml", line 325, characters 10-66
19-
Called from Odoc_xref2__Compile.signature_items.(fun) in file "src/xref2/compile.ml", line 240, characters 21-35
20-
Called from Stdlib__list.fold_left in file "list.ml", line 121, characters 24-34
21-
Called from Odoc_xref2__Compile.signature_items in file "src/xref2/compile.ml", line 204, characters 4-1023
22-
Called from Odoc_xref2__Compile.signature in file "src/xref2/compile.ml", line 273, characters 16-46
23-
Called from Odoc_xref2__Compile.content.(fun) in file "src/xref2/compile.ml", line 66, characters 13-54
24-
Called from Odoc_xref2__Compile.unit in file "src/xref2/compile.ml", line 59, characters 21-47
25-
Called from Odoc_xref2__Lookup_failures.catch_failures in file "src/xref2/lookup_failures.ml", line 18, characters 10-14
26-
Called from Odoc_odoc__Compile.resolve_and_substitute.(fun) in file "src/odoc/compile.ml", line 74, characters 2-37
27-
Called from Cmdliner_term.app.(fun) in file "cmdliner_term.ml", line 25, characters 19-24
28-
Called from Cmdliner_term.app.(fun) in file "cmdliner_term.ml", line 23, characters 12-19
29-
Called from Cmdliner.Term.run in file "cmdliner.ml", line 117, characters 32-39
30-
[2]
314

325

0 commit comments

Comments
 (0)