Guest User

Untitled

a guest
Feb 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. diff --git a/typing/ctype.ml b/typing/ctype.ml
  2. index 61e6a18..1e1159f 100644
  3. --- a/typing/ctype.ml
  4. +++ b/typing/ctype.ml
  5. @@ -4434,3 +4434,13 @@ let rec collapse_conj env visited ty =
  6.  
  7. let collapse_conj_params env params =
  8. List.iter (collapse_conj env []) params
  9. +
  10. +let same_constr env t1 t2 =
  11. + let t1 = expand_head env t1 in
  12. + let t2 = expand_head env t2 in
  13. + match t1.desc, t2.desc with
  14. + | Tconstr (p1, _, _), Tconstr (p2, _, _) -> Path.same p1 p2
  15. + | _ -> false
  16. +
  17. +let () =
  18. + Env.same_constr := same_constr
  19. diff --git a/typing/env.ml b/typing/env.ml
  20. index 3b991fd..e5b75cf 100644
  21. --- a/typing/env.ml
  22. +++ b/typing/env.ml
  23. @@ -123,18 +123,18 @@ module EnvTbl =
  24. let empty = Ident.empty
  25. let nothing = fun () -> ()
  26.  
  27. - let already_defined s tbl =
  28. - try ignore (Ident.find_name s tbl); true
  29. - with Not_found -> false
  30. + let already_defined wrap s tbl x =
  31. + try Some (wrap (fst (Ident.find_name s tbl)), wrap x)
  32. + with Not_found -> None
  33.  
  34. - let add kind slot id x tbl ref_tbl =
  35. + let add kind slot wrap id x tbl ref_tbl =
  36. let slot =
  37. match slot with
  38. | None -> nothing
  39. | Some f ->
  40. (fun () ->
  41. let s = Ident.name id in
  42. - f kind s (already_defined s ref_tbl)
  43. + f kind s (already_defined wrap s ref_tbl x)
  44. )
  45. in
  46. Ident.add id (x, slot) tbl
  47. @@ -211,6 +211,9 @@ and functor_components = {
  48. fcomp_subst_cache: (Path.t, module_type) Hashtbl.t
  49. }
  50.  
  51. +let same_constr = ref (fun _ _ _ -> assert false)
  52. +
  53. +
  54. let subst_modtype_maker (subst, mty) = Subst.modtype subst mty
  55.  
  56. let empty = {
  57. @@ -1388,7 +1391,7 @@ and store_value ?check slot id path decl env renv =
  58. check_value_name (Ident.name id) decl.val_loc;
  59. may (fun f -> check_usage decl.val_loc id f value_declarations) check;
  60. { env with
  61. - values = EnvTbl.add "value" slot id (path, decl) env.values renv.values;
  62. + values = EnvTbl.add "value" slot (fun x -> `Value x) id (path, decl) env.values renv.values;
  63. summary = Env_value(env.summary, id, decl) }
  64.  
  65. and store_type ~check slot id path info env renv =
  66. @@ -1424,16 +1427,17 @@ and store_type ~check slot id path info env renv =
  67. constrs =
  68. List.fold_right
  69. (fun (id, descr) constrs ->
  70. - EnvTbl.add "constructor" slot id descr constrs renv.constrs)
  71. + EnvTbl.add "constructor" slot (fun x -> `Constructor x) id descr constrs renv.constrs)
  72. constructors
  73. env.constrs;
  74. labels =
  75. List.fold_right
  76. (fun (id, descr) labels ->
  77. - EnvTbl.add "label" slot id descr labels renv.labels)
  78. + EnvTbl.add "label" slot (fun x -> `Label x) id descr labels renv.labels)
  79. labels
  80. env.labels;
  81. - types = EnvTbl.add "type" slot id (path, (info, descrs)) env.types
  82. + types =
  83. + EnvTbl.add "type" slot (fun x -> `Type x) id (path, (info, descrs)) env.types
  84. renv.types;
  85. summary = Env_type(env.summary, id, info) }
  86.  
  87. @@ -1444,7 +1448,7 @@ and store_type_infos slot id path info env renv =
  88. keep track of type abbreviations (e.g. type t = float) in the
  89. computation of label representations. *)
  90. { env with
  91. - types = EnvTbl.add "type" slot id (path, (info,([],[]))) env.types
  92. + types = EnvTbl.add "type" slot (fun x -> `Type x) id (path, (info,([],[]))) env.types
  93. renv.types;
  94. summary = Env_type(env.summary, id, info) }
  95.  
  96. @@ -1470,34 +1474,34 @@ and store_extension ~check slot id path ext env renv =
  97. end;
  98. end;
  99. { env with
  100. - constrs = EnvTbl.add "constructor" slot id
  101. + constrs = EnvTbl.add "constructor" slot (fun x -> `Constructor x) id
  102. (Datarepr.extension_descr path ext)
  103. env.constrs renv.constrs;
  104. summary = Env_extension(env.summary, id, ext) }
  105.  
  106. and store_module slot id path md env renv =
  107. { env with
  108. - modules = EnvTbl.add "module" slot id (path, md) env.modules renv.modules;
  109. + modules = EnvTbl.add "module" slot (fun x -> `Module x) id (path, md) env.modules renv.modules;
  110. components =
  111. - EnvTbl.add "module" slot id
  112. + EnvTbl.add "module" slot (fun x -> `Component x) id
  113. (path, components_of_module env Subst.identity path md.md_type)
  114. env.components renv.components;
  115. summary = Env_module(env.summary, id, md) }
  116.  
  117. and store_modtype slot id path info env renv =
  118. { env with
  119. - modtypes = EnvTbl.add "module type" slot id (path, info) env.modtypes
  120. + modtypes = EnvTbl.add "module type" slot (fun x -> `Module_type x) id (path, info) env.modtypes
  121. renv.modtypes;
  122. summary = Env_modtype(env.summary, id, info) }
  123.  
  124. and store_class slot id path desc env renv =
  125. { env with
  126. - classes = EnvTbl.add "class" slot id (path, desc) env.classes renv.classes;
  127. + classes = EnvTbl.add "class" slot (fun x -> `Class x) id (path, desc) env.classes renv.classes;
  128. summary = Env_class(env.summary, id, desc) }
  129.  
  130. and store_cltype slot id path desc env renv =
  131. { env with
  132. - cltypes = EnvTbl.add "class type" slot id (path, desc) env.cltypes
  133. + cltypes = EnvTbl.add "class type" slot (fun x -> `Class_type x) id (path, desc) env.cltypes
  134. renv.cltypes;
  135. summary = Env_cltype(env.summary, id, desc) }
  136.  
  137. @@ -1643,7 +1647,7 @@ let open_pers_signature name env =
  138. open_signature None (Pident(Ident.create_persistent name))
  139. (Lazy.force ps.ps_sig) env
  140.  
  141. -let open_signature ?(loc = Location.none) ?(toplevel = false) ovf root sg env =
  142. +let open_signature ?(loc = Location.none) ?(toplevel = false) ovf root sg (env : t) =
  143. if not toplevel && ovf = Asttypes.Fresh && not loc.Location.loc_ghost
  144. && (Warnings.is_active (Warnings.Unused_open "")
  145. || Warnings.is_active (Warnings.Open_shadow_identifier ("", ""))
  146. @@ -1657,7 +1661,16 @@ let open_signature ?(loc = Location.none) ?(toplevel = false) ovf root sg env =
  147. );
  148. let shadowed = ref [] in
  149. let slot kind s b =
  150. - if b && not (List.mem (kind, s) !shadowed) then begin
  151. + let really_shadow =
  152. + match b with
  153. + | Some (`Constructor c1, `Constructor c2) ->
  154. + not (!same_constr env c1.cstr_res c2.cstr_res)
  155. + | Some (`Label l1, `Label l2) ->
  156. + not (!same_constr env l1.lbl_res l2.lbl_res)
  157. + | Some _ -> true
  158. + | None -> false
  159. + in
  160. + if really_shadow && not (List.mem (kind, s) !shadowed) then begin
  161. shadowed := (kind, s) :: !shadowed;
  162. let w =
  163. match kind with
  164. diff --git a/typing/env.mli b/typing/env.mli
  165. index 367299a..b744924 100644
  166. --- a/typing/env.mli
  167. +++ b/typing/env.mli
  168. @@ -231,6 +231,8 @@ val check_modtype_inclusion:
  169. val add_delayed_check_forward: ((unit -> unit) -> unit) ref
  170. (* Forward declaration to break mutual recursion with Mtype. *)
  171. val strengthen: (t -> module_type -> Path.t -> module_type) ref
  172. +(* Forward declaration to break mutual recursion with Ctype. *)
  173. +val same_constr: (t -> type_expr -> type_expr -> bool) ref
  174.  
  175. (** Folding over all identifiers (for analysis purpose) *)
Add Comment
Please, Sign In to add comment