2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1995-08-09 08:06:35 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Operations on module types *)
|
|
|
|
|
2007-10-19 06:25:21 -07:00
|
|
|
open Asttypes
|
1995-05-04 03:15:53 -07:00
|
|
|
open Path
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
let rec scrape env mty =
|
|
|
|
match mty with
|
2012-05-30 07:52:37 -07:00
|
|
|
Mty_ident p ->
|
1995-11-03 05:23:03 -08:00
|
|
|
begin try
|
1999-11-25 08:47:47 -08:00
|
|
|
scrape env (Env.find_modtype_expansion p env)
|
1995-11-03 05:23:03 -08:00
|
|
|
with Not_found ->
|
|
|
|
mty
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
|
|
|
| _ -> mty
|
|
|
|
|
2004-02-14 09:38:02 -08:00
|
|
|
let freshen mty =
|
|
|
|
Subst.modtype Subst.identity mty
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let rec strengthen env mty p =
|
|
|
|
match scrape env mty with
|
2012-05-30 07:52:37 -07:00
|
|
|
Mty_signature sg ->
|
2014-10-01 02:07:14 -07:00
|
|
|
Mty_signature(strengthen_sig env sg p 0)
|
2013-12-16 19:52:50 -08:00
|
|
|
| Mty_functor(param, arg, res)
|
|
|
|
when !Clflags.applicative_functors && Ident.name param <> "*" ->
|
2012-05-30 07:52:37 -07:00
|
|
|
Mty_functor(param, arg, strengthen env res (Papply(p, Pident param)))
|
1995-05-04 03:15:53 -07:00
|
|
|
| mty ->
|
|
|
|
mty
|
|
|
|
|
2014-10-01 02:07:14 -07:00
|
|
|
and strengthen_sig env sg p pos =
|
1995-05-04 03:15:53 -07:00
|
|
|
match sg with
|
|
|
|
[] -> []
|
2016-03-09 02:40:16 -08:00
|
|
|
| (Sig_value(_, desc) as sigelt) :: rem ->
|
2014-12-22 00:45:55 -08:00
|
|
|
let nextpos = match desc.val_kind with Val_prim _ -> pos | _ -> pos+1 in
|
|
|
|
sigelt :: strengthen_sig env rem p nextpos
|
2016-03-09 02:40:16 -08:00
|
|
|
| Sig_type(id, {type_kind=Type_abstract}, _) ::
|
2015-09-09 19:34:04 -07:00
|
|
|
(Sig_type(id', {type_private=Private}, _) :: _ as rem)
|
|
|
|
when Ident.name id = Ident.name id' ^ "#row" ->
|
|
|
|
strengthen_sig env rem p pos
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_type(id, decl, rs) :: rem ->
|
1995-05-04 03:15:53 -07:00
|
|
|
let newdecl =
|
2012-01-09 19:01:50 -08:00
|
|
|
match decl.type_manifest, decl.type_private, decl.type_kind with
|
|
|
|
Some _, Public, _ -> decl
|
|
|
|
| Some _, Private, (Type_record _ | Type_variant _) -> decl
|
2005-09-28 00:18:30 -07:00
|
|
|
| _ ->
|
2009-07-20 04:51:50 -07:00
|
|
|
let manif =
|
|
|
|
Some(Btype.newgenty(Tconstr(Pdot(p, Ident.name id, nopos),
|
|
|
|
decl.type_params, ref Mnil))) in
|
|
|
|
if decl.type_kind = Type_abstract then
|
|
|
|
{ decl with type_private = Public; type_manifest = manif }
|
|
|
|
else
|
|
|
|
{ decl with type_manifest = manif }
|
2005-09-28 00:18:30 -07:00
|
|
|
in
|
2014-10-01 02:07:14 -07:00
|
|
|
Sig_type(id, newdecl, rs) :: strengthen_sig env rem p pos
|
2016-03-09 02:40:16 -08:00
|
|
|
| (Sig_typext _ as sigelt) :: rem ->
|
2014-10-01 02:07:14 -07:00
|
|
|
sigelt :: strengthen_sig env rem p (pos+1)
|
2013-09-27 10:05:39 -07:00
|
|
|
| Sig_module(id, md, rs) :: rem ->
|
2014-10-01 02:07:14 -07:00
|
|
|
let str =
|
|
|
|
if Env.is_functor_arg p env then
|
|
|
|
strengthen_decl env md (Pdot(p, Ident.name id, pos))
|
|
|
|
else
|
|
|
|
{md with md_type = Mty_alias (Pdot(p, Ident.name id, pos))}
|
|
|
|
in
|
2013-09-27 10:05:39 -07:00
|
|
|
Sig_module(id, str, rs)
|
2014-10-01 02:07:14 -07:00
|
|
|
:: strengthen_sig (Env.add_module_declaration id md env) rem p (pos+1)
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Need to add the module in case it defines manifest module types *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_modtype(id, decl) :: rem ->
|
1995-05-04 03:15:53 -07:00
|
|
|
let newdecl =
|
2013-10-01 08:14:04 -07:00
|
|
|
match decl.mtd_type with
|
|
|
|
None ->
|
2014-04-12 03:17:02 -07:00
|
|
|
{decl with mtd_type = Some(Mty_ident(Pdot(p,Ident.name id,nopos)))}
|
2013-10-01 08:14:04 -07:00
|
|
|
| Some _ ->
|
|
|
|
decl
|
|
|
|
in
|
2012-05-30 07:52:37 -07:00
|
|
|
Sig_modtype(id, newdecl) ::
|
2014-10-01 02:07:14 -07:00
|
|
|
strengthen_sig (Env.add_modtype id decl env) rem p pos
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Need to add the module type in case it is manifest *)
|
2016-03-09 02:40:16 -08:00
|
|
|
| (Sig_class _ as sigelt) :: rem ->
|
2014-10-01 02:07:14 -07:00
|
|
|
sigelt :: strengthen_sig env rem p (pos+1)
|
2016-03-09 02:40:16 -08:00
|
|
|
| (Sig_class_type _ as sigelt) :: rem ->
|
2014-10-01 02:07:14 -07:00
|
|
|
sigelt :: strengthen_sig env rem p pos
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-09-27 10:05:39 -07:00
|
|
|
and strengthen_decl env md p =
|
|
|
|
{md with md_type = strengthen env md.md_type p}
|
|
|
|
|
2013-11-10 21:00:10 -08:00
|
|
|
let () = Env.strengthen := strengthen
|
2013-09-27 10:05:39 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* In nondep_supertype, env is only used for the type it assigns to id.
|
|
|
|
Hence there is no need to keep env up-to-date by adding the bindings
|
|
|
|
traversed. *)
|
|
|
|
|
|
|
|
type variance = Co | Contra | Strict
|
|
|
|
|
1995-05-22 04:58:12 -07:00
|
|
|
let nondep_supertype env mid mty =
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2009-05-19 01:17:02 -07:00
|
|
|
let rec nondep_mty env va mty =
|
1995-05-04 03:15:53 -07:00
|
|
|
match mty with
|
2012-05-30 07:52:37 -07:00
|
|
|
Mty_ident p ->
|
1997-04-01 12:53:02 -08:00
|
|
|
if Path.isfree mid p then
|
2009-05-19 01:17:02 -07:00
|
|
|
nondep_mty env va (Env.find_modtype_expansion p env)
|
1997-04-01 12:53:02 -08:00
|
|
|
else mty
|
2013-09-29 00:22:34 -07:00
|
|
|
| Mty_alias p ->
|
|
|
|
if Path.isfree mid p then
|
2013-09-30 06:54:59 -07:00
|
|
|
nondep_mty env va (Env.find_module p env).md_type
|
2013-09-29 00:22:34 -07:00
|
|
|
else mty
|
2012-05-30 07:52:37 -07:00
|
|
|
| Mty_signature sg ->
|
|
|
|
Mty_signature(nondep_sig env va sg)
|
|
|
|
| Mty_functor(param, arg, res) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
let var_inv =
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with Co -> Contra | Contra -> Co | Strict -> Strict in
|
2013-12-16 19:52:50 -08:00
|
|
|
Mty_functor(param, Misc.may_map (nondep_mty env var_inv) arg,
|
|
|
|
nondep_mty
|
2014-01-09 23:53:33 -08:00
|
|
|
(Env.add_module ~arg:true param
|
|
|
|
(Btype.default_mty arg) env) va res)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2009-05-19 01:17:02 -07:00
|
|
|
and nondep_sig env va = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] -> []
|
|
|
|
| item :: rem ->
|
2009-05-19 01:17:02 -07:00
|
|
|
let rem' = nondep_sig env va rem in
|
1995-05-04 03:15:53 -07:00
|
|
|
match item with
|
2012-05-30 07:52:37 -07:00
|
|
|
Sig_value(id, d) ->
|
2013-09-26 08:24:11 -07:00
|
|
|
Sig_value(id,
|
|
|
|
{d with val_type = Ctype.nondep_type env mid d.val_type})
|
|
|
|
:: rem'
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_type(id, d, rs) ->
|
|
|
|
Sig_type(id, Ctype.nondep_type_decl env mid id (va = Co) d, rs)
|
2004-06-12 01:55:49 -07:00
|
|
|
:: rem'
|
2014-05-04 16:08:45 -07:00
|
|
|
| Sig_typext(id, ext, es) ->
|
|
|
|
Sig_typext(id, Ctype.nondep_extension_constructor env mid ext, es)
|
|
|
|
:: rem'
|
2013-09-27 10:05:39 -07:00
|
|
|
| Sig_module(id, md, rs) ->
|
|
|
|
Sig_module(id, {md with md_type=nondep_mty env va md.md_type}, rs)
|
|
|
|
:: rem'
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_modtype(id, d) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
begin try
|
2012-05-30 07:52:37 -07:00
|
|
|
Sig_modtype(id, nondep_modtype_decl env d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
with Not_found ->
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with
|
2014-01-30 04:18:34 -08:00
|
|
|
Co -> Sig_modtype(id, {mtd_type=None; mtd_loc=Location.none;
|
|
|
|
mtd_attributes=[]}) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| _ -> raise Not_found
|
|
|
|
end
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_class(id, d, rs) ->
|
|
|
|
Sig_class(id, Ctype.nondep_class_declaration env mid d, rs)
|
2004-06-12 01:55:49 -07:00
|
|
|
:: rem'
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_class_type(id, d, rs) ->
|
|
|
|
Sig_class_type(id, Ctype.nondep_cltype_declaration env mid d, rs)
|
2004-06-12 01:55:49 -07:00
|
|
|
:: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-10-01 08:14:04 -07:00
|
|
|
and nondep_modtype_decl env mtd =
|
|
|
|
{mtd with mtd_type = Misc.may_map (nondep_mty env Strict) mtd.mtd_type}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
in
|
2009-05-19 01:17:02 -07:00
|
|
|
nondep_mty env Co mty
|
2003-06-19 08:53:53 -07:00
|
|
|
|
|
|
|
let enrich_typedecl env p decl =
|
|
|
|
match decl.type_manifest with
|
2016-03-09 02:40:16 -08:00
|
|
|
Some _ -> decl
|
2003-06-19 08:53:53 -07:00
|
|
|
| None ->
|
|
|
|
try
|
|
|
|
let orig_decl = Env.find_type p env in
|
2010-01-22 04:48:24 -08:00
|
|
|
if orig_decl.type_arity <> decl.type_arity
|
2003-06-19 08:53:53 -07:00
|
|
|
then decl
|
|
|
|
else {decl with type_manifest =
|
|
|
|
Some(Btype.newgenty(Tconstr(p, decl.type_params, ref Mnil)))}
|
|
|
|
with Not_found ->
|
|
|
|
decl
|
|
|
|
|
|
|
|
let rec enrich_modtype env p mty =
|
|
|
|
match mty with
|
2012-05-30 07:52:37 -07:00
|
|
|
Mty_signature sg ->
|
|
|
|
Mty_signature(List.map (enrich_item env p) sg)
|
2003-06-19 08:53:53 -07:00
|
|
|
| _ ->
|
|
|
|
mty
|
|
|
|
|
|
|
|
and enrich_item env p = function
|
2012-05-30 07:52:37 -07:00
|
|
|
Sig_type(id, decl, rs) ->
|
|
|
|
Sig_type(id,
|
2004-06-12 01:55:49 -07:00
|
|
|
enrich_typedecl env (Pdot(p, Ident.name id, nopos)) decl, rs)
|
2013-09-27 10:05:39 -07:00
|
|
|
| Sig_module(id, md, rs) ->
|
2012-05-30 07:52:37 -07:00
|
|
|
Sig_module(id,
|
2013-09-27 10:05:39 -07:00
|
|
|
{md with
|
|
|
|
md_type = enrich_modtype env
|
|
|
|
(Pdot(p, Ident.name id, nopos)) md.md_type},
|
|
|
|
rs)
|
2003-06-19 08:53:53 -07:00
|
|
|
| item -> item
|
2003-07-01 06:05:43 -07:00
|
|
|
|
|
|
|
let rec type_paths env p mty =
|
|
|
|
match scrape env mty with
|
2016-03-09 02:40:16 -08:00
|
|
|
Mty_ident _ -> []
|
|
|
|
| Mty_alias _ -> []
|
2012-05-30 07:52:37 -07:00
|
|
|
| Mty_signature sg -> type_paths_sig env p 0 sg
|
2016-03-09 02:40:16 -08:00
|
|
|
| Mty_functor _ -> []
|
2003-07-01 06:05:43 -07:00
|
|
|
|
|
|
|
and type_paths_sig env p pos sg =
|
|
|
|
match sg with
|
|
|
|
[] -> []
|
2016-03-09 02:40:16 -08:00
|
|
|
| Sig_value(_id, decl) :: rem ->
|
2003-07-01 06:05:43 -07:00
|
|
|
let pos' = match decl.val_kind with Val_prim _ -> pos | _ -> pos + 1 in
|
|
|
|
type_paths_sig env p pos' rem
|
2016-03-09 02:40:16 -08:00
|
|
|
| Sig_type(id, _decl, _) :: rem ->
|
2003-07-01 06:05:43 -07:00
|
|
|
Pdot(p, Ident.name id, nopos) :: type_paths_sig env p pos rem
|
2013-09-27 10:05:39 -07:00
|
|
|
| Sig_module(id, md, _) :: rem ->
|
|
|
|
type_paths env (Pdot(p, Ident.name id, pos)) md.md_type @
|
|
|
|
type_paths_sig (Env.add_module_declaration id md env) p (pos+1) rem
|
2012-05-30 07:52:37 -07:00
|
|
|
| Sig_modtype(id, decl) :: rem ->
|
2003-07-01 06:05:43 -07:00
|
|
|
type_paths_sig (Env.add_modtype id decl env) p pos rem
|
2014-05-04 16:08:45 -07:00
|
|
|
| (Sig_typext _ | Sig_class _) :: rem ->
|
2003-07-01 06:05:43 -07:00
|
|
|
type_paths_sig env p (pos+1) rem
|
2012-05-30 07:52:37 -07:00
|
|
|
| (Sig_class_type _) :: rem ->
|
2003-07-01 06:05:43 -07:00
|
|
|
type_paths_sig env p pos rem
|
2004-04-09 06:32:28 -07:00
|
|
|
|
|
|
|
let rec no_code_needed env mty =
|
|
|
|
match scrape env mty with
|
2016-03-09 02:40:16 -08:00
|
|
|
Mty_ident _ -> false
|
2012-05-30 07:52:37 -07:00
|
|
|
| Mty_signature sg -> no_code_needed_sig env sg
|
|
|
|
| Mty_functor(_, _, _) -> false
|
2016-03-09 02:40:16 -08:00
|
|
|
| Mty_alias _ -> true
|
2004-04-09 06:32:28 -07:00
|
|
|
|
|
|
|
and no_code_needed_sig env sg =
|
|
|
|
match sg with
|
|
|
|
[] -> true
|
2016-03-09 02:40:16 -08:00
|
|
|
| Sig_value(_id, decl) :: rem ->
|
2004-04-09 06:32:28 -07:00
|
|
|
begin match decl.val_kind with
|
|
|
|
| Val_prim _ -> no_code_needed_sig env rem
|
|
|
|
| _ -> false
|
|
|
|
end
|
2013-09-27 10:05:39 -07:00
|
|
|
| Sig_module(id, md, _) :: rem ->
|
|
|
|
no_code_needed env md.md_type &&
|
|
|
|
no_code_needed_sig (Env.add_module_declaration id md env) rem
|
2012-05-30 07:52:37 -07:00
|
|
|
| (Sig_type _ | Sig_modtype _ | Sig_class_type _) :: rem ->
|
2004-04-09 06:32:28 -07:00
|
|
|
no_code_needed_sig env rem
|
2016-03-09 02:40:16 -08:00
|
|
|
| (Sig_typext _ | Sig_class _) :: _ ->
|
2004-04-09 06:32:28 -07:00
|
|
|
false
|
2013-12-16 19:52:50 -08:00
|
|
|
|
|
|
|
|
|
|
|
(* Check whether a module type may return types *)
|
|
|
|
|
|
|
|
let rec contains_type env = function
|
|
|
|
Mty_ident path ->
|
2014-08-22 06:45:02 -07:00
|
|
|
begin try match (Env.find_modtype path env).mtd_type with
|
|
|
|
| None -> raise Exit (* PR#6427 *)
|
|
|
|
| Some mty -> contains_type env mty
|
|
|
|
with Not_found -> raise Exit
|
|
|
|
end
|
2013-12-16 19:52:50 -08:00
|
|
|
| Mty_signature sg ->
|
|
|
|
contains_type_sig env sg
|
|
|
|
| Mty_functor (_, _, body) ->
|
|
|
|
contains_type env body
|
2014-01-09 23:53:33 -08:00
|
|
|
| Mty_alias _ ->
|
|
|
|
()
|
2013-12-16 19:52:50 -08:00
|
|
|
|
|
|
|
and contains_type_sig env = List.iter (contains_type_item env)
|
|
|
|
|
|
|
|
and contains_type_item env = function
|
|
|
|
Sig_type (_,({type_manifest = None} |
|
|
|
|
{type_kind = Type_abstract; type_private = Private}),_)
|
2014-10-14 08:51:30 -07:00
|
|
|
| Sig_modtype _
|
|
|
|
| Sig_typext (_, {ext_args = Cstr_record _}, _) ->
|
|
|
|
(* We consider that extension constructors with an inlined
|
|
|
|
record create a type (the inlined record), even though
|
|
|
|
it would be technically safe to ignore that considering
|
|
|
|
the current constraints which guarantee that this type
|
|
|
|
is kept local to expressions. *)
|
2013-12-16 19:52:50 -08:00
|
|
|
raise Exit
|
|
|
|
| Sig_module (_, {md_type = mty}, _) ->
|
|
|
|
contains_type env mty
|
|
|
|
| Sig_value _
|
|
|
|
| Sig_type _
|
2014-05-04 16:08:45 -07:00
|
|
|
| Sig_typext _
|
2013-12-16 19:52:50 -08:00
|
|
|
| Sig_class _
|
|
|
|
| Sig_class_type _ ->
|
|
|
|
()
|
|
|
|
|
|
|
|
let contains_type env mty =
|
|
|
|
try contains_type env mty; false with Exit -> true
|
2014-03-09 19:54:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
(* Remove module aliases from a signature *)
|
|
|
|
|
2016-05-09 02:54:33 -07:00
|
|
|
module PathSet = Set.Make (Path)
|
|
|
|
module PathMap = Map.Make (Path)
|
2015-11-28 06:09:09 -08:00
|
|
|
module IdentSet = Set.Make (Ident)
|
2014-03-09 19:54:02 -07:00
|
|
|
|
|
|
|
let rec get_prefixes = function
|
|
|
|
Pident _ -> PathSet.empty
|
|
|
|
| Pdot (p, _, _)
|
|
|
|
| Papply (p, _) -> PathSet.add p (get_prefixes p)
|
|
|
|
|
|
|
|
let rec get_arg_paths = function
|
|
|
|
Pident _ -> PathSet.empty
|
|
|
|
| Pdot (p, _, _) -> get_arg_paths p
|
|
|
|
| Papply (p1, p2) ->
|
|
|
|
PathSet.add p2
|
|
|
|
(PathSet.union (get_prefixes p2)
|
|
|
|
(PathSet.union (get_arg_paths p1) (get_arg_paths p2)))
|
|
|
|
|
|
|
|
let rec rollback_path subst p =
|
|
|
|
try Pident (PathMap.find p subst)
|
|
|
|
with Not_found ->
|
|
|
|
match p with
|
|
|
|
Pident _ | Papply _ -> p
|
|
|
|
| Pdot (p1, s, n) ->
|
|
|
|
let p1' = rollback_path subst p1 in
|
|
|
|
if Path.same p1 p1' then p else rollback_path subst (Pdot (p1', s, n))
|
|
|
|
|
|
|
|
let rec collect_ids subst bindings p =
|
|
|
|
begin match rollback_path subst p with
|
|
|
|
Pident id ->
|
|
|
|
let ids =
|
|
|
|
try collect_ids subst bindings (Ident.find_same id bindings)
|
|
|
|
with Not_found -> IdentSet.empty
|
|
|
|
in
|
|
|
|
IdentSet.add id ids
|
|
|
|
| _ -> IdentSet.empty
|
|
|
|
end
|
|
|
|
|
|
|
|
let collect_arg_paths mty =
|
|
|
|
let open Btype in
|
|
|
|
let paths = ref PathSet.empty
|
|
|
|
and subst = ref PathMap.empty
|
|
|
|
and bindings = ref Ident.empty in
|
|
|
|
(* let rt = Ident.create "Root" in
|
|
|
|
and prefix = ref (Path.Pident rt) in *)
|
|
|
|
let it_path p = paths := PathSet.union (get_arg_paths p) !paths
|
|
|
|
and it_signature_item it si =
|
|
|
|
type_iterators.it_signature_item it si;
|
|
|
|
match si with
|
|
|
|
Sig_module (id, {md_type=Mty_alias p}, _) ->
|
|
|
|
bindings := Ident.add id p !bindings
|
|
|
|
| Sig_module (id, {md_type=Mty_signature sg}, _) ->
|
|
|
|
List.iter
|
|
|
|
(function Sig_module (id', _, _) ->
|
|
|
|
subst :=
|
|
|
|
PathMap.add (Pdot (Pident id, Ident.name id', -1)) id' !subst
|
|
|
|
| _ -> ())
|
|
|
|
sg
|
|
|
|
| _ -> ()
|
|
|
|
in
|
|
|
|
let it = {type_iterators with it_path; it_signature_item} in
|
|
|
|
it.it_module_type it mty;
|
2014-04-15 23:16:05 -07:00
|
|
|
it.it_module_type unmark_iterators mty;
|
2014-03-09 19:54:02 -07:00
|
|
|
PathSet.fold (fun p -> IdentSet.union (collect_ids !subst !bindings p))
|
|
|
|
!paths IdentSet.empty
|
|
|
|
|
|
|
|
let rec remove_aliases env excl mty =
|
|
|
|
match mty with
|
|
|
|
Mty_signature sg ->
|
|
|
|
Mty_signature (remove_aliases_sig env excl sg)
|
|
|
|
| Mty_alias _ ->
|
2014-10-15 06:34:58 -07:00
|
|
|
let mty' = Env.scrape_alias env mty in
|
|
|
|
if mty' = mty then mty else
|
|
|
|
remove_aliases env excl mty'
|
2014-03-09 19:54:02 -07:00
|
|
|
| mty ->
|
|
|
|
mty
|
|
|
|
|
|
|
|
and remove_aliases_sig env excl sg =
|
|
|
|
match sg with
|
|
|
|
[] -> []
|
|
|
|
| Sig_module(id, md, rs) :: rem ->
|
|
|
|
let mty =
|
|
|
|
match md.md_type with
|
|
|
|
Mty_alias _ when IdentSet.mem id excl ->
|
|
|
|
md.md_type
|
|
|
|
| mty ->
|
|
|
|
remove_aliases env excl mty
|
|
|
|
in
|
|
|
|
Sig_module(id, {md with md_type = mty} , rs) ::
|
|
|
|
remove_aliases_sig (Env.add_module id mty env) excl rem
|
|
|
|
| Sig_modtype(id, mtd) :: rem ->
|
|
|
|
Sig_modtype(id, mtd) ::
|
|
|
|
remove_aliases_sig (Env.add_modtype id mtd env) excl rem
|
|
|
|
| it :: rem ->
|
|
|
|
it :: remove_aliases_sig env excl rem
|
|
|
|
|
|
|
|
let remove_aliases env sg =
|
|
|
|
let excl = collect_arg_paths sg in
|
|
|
|
(* PathSet.iter (fun p -> Format.eprintf "%a@ " Printtyp.path p) excl;
|
|
|
|
Format.eprintf "@."; *)
|
|
|
|
remove_aliases env excl sg
|