this repo has no description

Further fixes for duplicate identifiers

As well as during loading, we also have to handle `includes` with
potentially duplicate identifiers during `lang_of.ml`. This commit
moves the 'synthetic parent' functions into path.ml and uses them
both in cmti.ml and lang_of.ml

authored by jon.recoil.org and committed by

Jon Ludlam's Agent 4e51ebde 5f4bdb4a

+23 -15
+1 -14
src/loader/cmti.ml
··· 34 34 let cmti_builddir : string ref = ref "" 35 35 let read_module_expr : (env -> Identifier.Signature.t -> Identifier.LabelParent.t -> Typedtree.module_expr -> ModuleType.expr) ref = ref (fun _ _ _ _ -> failwith "unset") 36 36 37 - (* Counter for generating unique synthetic parents for include expressions. 38 - Items inside an include's module type expression need a different parent 39 - to avoid identifier conflicts with items in the enclosing signature. *) 40 - let include_parent_counter = ref 0 41 - 42 - (* Create a synthetic parent identifier for items inside an include's module 43 - type expression. Uses a lowercase module name (illegal in normal OCaml) 44 - to ensure no clashes with real identifiers. *) 45 - let make_include_parent (parent : Identifier.Signature.t) : Identifier.Signature.t = 46 - incr include_parent_counter; 47 - let name = Printf.sprintf "include%d_" !include_parent_counter in 48 - (Identifier.Mk.module_ (parent, Odoc_model.Names.ModuleName.make_std name) :> Identifier.Signature.t) 49 - 50 37 let opt_map f = function 51 38 | None -> None 52 39 | Some x -> Some (f x) ··· 914 901 identifier conflicts with items in the enclosing signature. Items inside 915 902 the include expression (like TypeSubstitutions) will get identifiers under 916 903 this synthetic parent, which won't clash with the real parent's items. *) 917 - let include_parent = make_include_parent parent in 904 + let include_parent = Identifier.fresh_include_parent parent in 918 905 let include_container = (include_parent :> Identifier.LabelParent.t) in 919 906 let expr = read_module_type env include_parent include_container incl.incl_mod in 920 907 let umty = Odoc_model.Lang.umty_of_mty expr in
+13
src/model/paths.ml
··· 644 644 `SourceLocationInternal (p, n)) 645 645 end 646 646 647 + (* Counter for generating unique synthetic parents for include expressions. 648 + Items inside an include's module type expression need a different parent 649 + to avoid identifier conflicts with items in the enclosing signature. *) 650 + let include_parent_counter = ref 0 651 + 652 + (* Create a synthetic parent identifier for items inside an include's module 653 + type expression. Uses a lowercase module name (illegal in normal OCaml) 654 + to ensure no clashes with real identifiers. *) 655 + let fresh_include_parent (parent : Signature.t) : Signature.t = 656 + incr include_parent_counter; 657 + let name = Printf.sprintf "include%d_" !include_parent_counter in 658 + (Mk.module_ (parent, ModuleName.make_std name) :> Signature.t) 659 + 647 660 module Hashtbl = struct 648 661 module Any = Hashtbl.Make (Any) 649 662 module ContainerPage = Hashtbl.Make (ContainerPage)
+6
src/model/paths.mli
··· 358 358 SourcePage.t * LocalName.t -> 359 359 [> `SourceLocationInternal of SourcePage.t * LocalName.t ] id 360 360 end 361 + 362 + (** Create a synthetic parent identifier for items inside an include's 363 + module type expression. Uses a lowercase module name (illegal in normal 364 + OCaml) to ensure no clashes with real identifiers. Each call returns a 365 + fresh identifier. *) 366 + val fresh_include_parent : Signature.t -> Signature.t 361 367 end 362 368 363 369 (** Normal OCaml paths (i.e. the ones present in types) *)
+3 -1
src/xref2/lang_of.ml
··· 651 651 (* Don't start shadowing within any signatures *) 652 652 match d with 653 653 | Alias p -> Alias (Path.module_ map p) 654 - | ModuleType mty -> ModuleType (u_module_type_expr map identifier mty) 654 + | ModuleType mty -> 655 + let include_parent = Identifier.fresh_include_parent identifier in 656 + ModuleType (u_module_type_expr map include_parent mty) 655 657 656 658 and include_ parent map i = 657 659 let open Component.Include in