1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Operations on module types *)
|
|
|
|
|
|
|
|
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
|
|
|
|
Tmty_ident p ->
|
1995-11-03 05:23:03 -08:00
|
|
|
begin try
|
|
|
|
match Env.find_modtype p env with
|
|
|
|
Tmodtype_abstract -> mty
|
|
|
|
| Tmodtype_manifest mty' -> scrape env mty'
|
|
|
|
with Not_found ->
|
|
|
|
mty
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
|
|
|
| _ -> mty
|
|
|
|
|
|
|
|
let rec strengthen env mty p =
|
|
|
|
match scrape env mty with
|
|
|
|
Tmty_signature sg ->
|
|
|
|
Tmty_signature(strengthen_sig env sg p)
|
1995-08-23 04:55:54 -07:00
|
|
|
| Tmty_functor(param, arg, res) ->
|
|
|
|
Tmty_functor(param, arg, strengthen env res (Papply(p, Pident param)))
|
1995-05-04 03:15:53 -07:00
|
|
|
| mty ->
|
|
|
|
mty
|
|
|
|
|
|
|
|
and strengthen_sig env sg p =
|
|
|
|
match sg with
|
|
|
|
[] -> []
|
|
|
|
| (Tsig_value(id, desc) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
|
|
|
| Tsig_type(id, decl) :: rem ->
|
|
|
|
let newdecl =
|
1995-09-26 13:23:29 -07:00
|
|
|
match decl.type_manifest with
|
|
|
|
None ->
|
1995-05-04 03:15:53 -07:00
|
|
|
{ type_params = decl.type_params;
|
|
|
|
type_arity = decl.type_arity;
|
1995-09-26 13:23:29 -07:00
|
|
|
type_kind = decl.type_kind;
|
1996-04-22 04:15:41 -07:00
|
|
|
type_manifest = Some(Ctype.newgenty(
|
|
|
|
Tconstr(Pdot(p, Ident.name id, nopos),
|
|
|
|
decl.type_params,
|
1997-01-21 09:43:53 -08:00
|
|
|
ref Mnil))) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| _ -> decl in
|
|
|
|
Tsig_type(id, newdecl) :: strengthen_sig env rem p
|
|
|
|
| (Tsig_exception(id, d) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
|
|
|
| Tsig_module(id, mty) :: rem ->
|
|
|
|
Tsig_module(id, strengthen env mty (Pdot(p, Ident.name id, nopos))) ::
|
|
|
|
strengthen_sig (Env.add_module id mty env) rem p
|
|
|
|
(* Need to add the module in case it defines manifest module types *)
|
|
|
|
| Tsig_modtype(id, decl) :: rem ->
|
|
|
|
let newdecl =
|
|
|
|
match decl with
|
|
|
|
Tmodtype_abstract ->
|
|
|
|
Tmodtype_manifest(Tmty_ident(Pdot(p, Ident.name id, nopos)))
|
|
|
|
| Tmodtype_manifest _ ->
|
|
|
|
decl in
|
|
|
|
Tsig_modtype(id, newdecl) ::
|
|
|
|
strengthen_sig (Env.add_modtype id decl env) rem p
|
|
|
|
(* Need to add the module type in case it is manifest *)
|
1996-04-22 04:15:41 -07:00
|
|
|
| (Tsig_class(id, decl) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
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
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let rec nondep_mty va mty =
|
1995-05-04 03:15:53 -07:00
|
|
|
match mty with
|
|
|
|
Tmty_ident p ->
|
1995-05-22 04:58:12 -07:00
|
|
|
if Path.isfree mid p then begin
|
1995-05-04 03:15:53 -07:00
|
|
|
match Env.find_modtype p env with
|
|
|
|
Tmodtype_abstract -> raise Not_found
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tmodtype_manifest mty -> nondep_mty va mty
|
1995-05-04 03:15:53 -07:00
|
|
|
end else mty
|
|
|
|
| Tmty_signature sg ->
|
1996-04-22 04:15:41 -07:00
|
|
|
Tmty_signature(nondep_sig va sg)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmty_functor(param, arg, res) ->
|
|
|
|
let var_inv =
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with Co -> Contra | Contra -> Co | Strict -> Strict in
|
|
|
|
Tmty_functor(param, nondep_mty var_inv arg, nondep_mty va res)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
and nondep_sig va = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] -> []
|
|
|
|
| item :: rem ->
|
1996-04-22 04:15:41 -07:00
|
|
|
let rem' = nondep_sig va rem in
|
1995-05-04 03:15:53 -07:00
|
|
|
match item with
|
|
|
|
Tsig_value(id, d) ->
|
1995-10-17 03:02:47 -07:00
|
|
|
Tsig_value(id, {val_type = Ctype.nondep_type env mid d.val_type;
|
1996-04-22 04:15:41 -07:00
|
|
|
val_kind = d.val_kind}) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_type(id, d) ->
|
1996-04-22 04:15:41 -07:00
|
|
|
Tsig_type(id, nondep_type_decl va d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_exception(id, d) ->
|
1995-10-17 03:02:47 -07:00
|
|
|
Tsig_exception(id, List.map (Ctype.nondep_type env mid) d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_module(id, mty) ->
|
1996-04-22 04:15:41 -07:00
|
|
|
Tsig_module(id, nondep_mty va mty) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_modtype(id, d) ->
|
|
|
|
begin try
|
|
|
|
Tsig_modtype(id, nondep_modtype_decl d) :: rem'
|
|
|
|
with Not_found ->
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with
|
1995-05-04 03:15:53 -07:00
|
|
|
Co -> Tsig_modtype(id, Tmodtype_abstract) :: rem'
|
|
|
|
| _ -> raise Not_found
|
|
|
|
end
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tsig_class(id, d) ->
|
|
|
|
Tsig_class(id, Ctype.nondep_class_type env mid d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
and nondep_type_decl va d =
|
1995-05-04 03:15:53 -07:00
|
|
|
{type_params = d.type_params;
|
|
|
|
type_arity = d.type_arity;
|
|
|
|
type_kind =
|
1995-10-18 08:33:15 -07:00
|
|
|
begin try
|
|
|
|
match d.type_kind with
|
|
|
|
Type_abstract ->
|
|
|
|
Type_abstract
|
|
|
|
| Type_variant cstrs ->
|
|
|
|
Type_variant(List.map
|
|
|
|
(fun (c, tl) -> (c, List.map (Ctype.nondep_type env mid) tl))
|
|
|
|
cstrs)
|
|
|
|
| Type_record lbls ->
|
|
|
|
Type_record(List.map
|
|
|
|
(fun (c, mut, t) -> (c, mut, Ctype.nondep_type env mid t))
|
|
|
|
lbls)
|
|
|
|
with Not_found ->
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with Co -> Type_abstract | _ -> raise Not_found
|
1995-09-26 13:23:29 -07:00
|
|
|
end;
|
|
|
|
type_manifest =
|
1995-10-18 08:33:15 -07:00
|
|
|
begin try
|
|
|
|
match d.type_manifest with
|
|
|
|
None -> None
|
|
|
|
| Some ty -> Some(Ctype.nondep_type env mid ty)
|
|
|
|
with Not_found ->
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with Co -> None | _ -> raise Not_found
|
1995-09-26 13:23:29 -07:00
|
|
|
end}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and nondep_modtype_decl = function
|
|
|
|
Tmodtype_abstract -> Tmodtype_abstract
|
|
|
|
| Tmodtype_manifest mty -> Tmodtype_manifest(nondep_mty Strict mty)
|
|
|
|
|
|
|
|
in
|
|
|
|
nondep_mty Co mty
|