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 *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Inclusion checks for the core language *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Path
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1995-05-04 03:15:53 -07:00
|
|
|
open Typedtree
|
|
|
|
|
1995-05-05 03:05:18 -07:00
|
|
|
(* Inclusion between value descriptions *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-10-23 09:59:41 -07:00
|
|
|
exception Dont_match
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let value_descriptions env vd1 vd2 =
|
1997-04-01 12:52:36 -08:00
|
|
|
if Ctype.moregeneral env true vd1.val_type vd2.val_type then begin
|
1996-04-22 04:15:41 -07:00
|
|
|
match (vd1.val_kind, vd2.val_kind) with
|
|
|
|
(Val_prim p1, Val_prim p2) ->
|
1995-10-23 09:59:41 -07:00
|
|
|
if p1 = p2 then Tcoerce_none else raise Dont_match
|
1996-04-22 04:15:41 -07:00
|
|
|
| (Val_prim p, _) -> Tcoerce_primitive p
|
|
|
|
| (_, Val_prim p) -> raise Dont_match
|
|
|
|
| (_, _) -> Tcoerce_none
|
1995-10-23 09:59:41 -07:00
|
|
|
end else
|
|
|
|
raise Dont_match
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Inclusion between type declarations *)
|
|
|
|
|
|
|
|
let type_declarations env id decl1 decl2 =
|
2000-11-22 05:48:55 -08:00
|
|
|
decl1.type_arity = decl2.type_arity &&
|
2003-02-27 22:59:19 -08:00
|
|
|
let rec incl_tkinds = function
|
1995-09-26 13:23:29 -07:00
|
|
|
(_, Type_abstract) -> true
|
1995-05-04 03:15:53 -07:00
|
|
|
| (Type_variant cstrs1, Type_variant cstrs2) ->
|
2000-11-22 05:48:55 -08:00
|
|
|
Misc.for_all2
|
1995-05-04 03:15:53 -07:00
|
|
|
(fun (cstr1, arg1) (cstr2, arg2) ->
|
2000-11-22 05:48:55 -08:00
|
|
|
cstr1 = cstr2 &&
|
|
|
|
Misc.for_all2
|
1995-05-04 03:15:53 -07:00
|
|
|
(fun ty1 ty2 ->
|
1997-02-20 12:39:02 -08:00
|
|
|
Ctype.equal env true (ty1::decl1.type_params)
|
|
|
|
(ty2::decl2.type_params))
|
1995-05-04 03:15:53 -07:00
|
|
|
arg1 arg2)
|
|
|
|
cstrs1 cstrs2
|
2000-03-21 06:43:25 -08:00
|
|
|
| (Type_record(labels1, rep1), Type_record(labels2, rep2)) ->
|
|
|
|
rep1 = rep2 &&
|
2000-11-22 05:48:55 -08:00
|
|
|
Misc.for_all2
|
1995-05-04 03:15:53 -07:00
|
|
|
(fun (lbl1, mut1, ty1) (lbl2, mut2, ty2) ->
|
2000-11-22 05:48:55 -08:00
|
|
|
lbl1 = lbl2 && mut1 = mut2 &&
|
1997-02-20 12:39:02 -08:00
|
|
|
Ctype.equal env true (ty1::decl1.type_params)
|
|
|
|
(ty2::decl2.type_params))
|
1995-05-04 03:15:53 -07:00
|
|
|
labels1 labels2
|
2003-05-01 15:22:37 -07:00
|
|
|
| (Type_private tkind1, Type_private tkind2) -> incl_tkinds (tkind1, tkind2)
|
|
|
|
| (tkind1, Type_private tkind2) -> incl_tkinds (tkind1, tkind2)
|
2003-02-27 22:59:19 -08:00
|
|
|
| (_, _) -> false in
|
|
|
|
incl_tkinds (decl1.type_kind, decl2.type_kind)
|
|
|
|
&&
|
1995-09-26 13:23:29 -07:00
|
|
|
begin match (decl1.type_manifest, decl2.type_manifest) with
|
1997-02-20 12:39:02 -08:00
|
|
|
(_, None) ->
|
|
|
|
Ctype.equal env true decl1.type_params decl2.type_params
|
1995-09-26 13:23:29 -07:00
|
|
|
| (Some ty1, Some ty2) ->
|
1997-02-20 12:39:02 -08:00
|
|
|
Ctype.equal env true (ty1::decl1.type_params)
|
|
|
|
(ty2::decl2.type_params)
|
1995-09-26 13:23:29 -07:00
|
|
|
| (None, Some ty2) ->
|
1996-04-22 04:15:41 -07:00
|
|
|
let ty1 =
|
1997-03-24 12:11:22 -08:00
|
|
|
Btype.newgenty (Tconstr(Pident id, decl2.type_params, ref Mnil))
|
|
|
|
in
|
2000-11-22 05:48:55 -08:00
|
|
|
Ctype.equal env true decl1.type_params decl2.type_params &&
|
1997-03-24 12:11:22 -08:00
|
|
|
Ctype.equal env false [ty1] [ty2]
|
2000-09-06 03:21:07 -07:00
|
|
|
end &&
|
2001-03-04 06:39:18 -08:00
|
|
|
begin decl2.type_kind <> Type_abstract || decl2.type_manifest <> None ||
|
2000-09-06 03:21:07 -07:00
|
|
|
List.for_all2
|
|
|
|
(fun (co1,cn1) (co2,cn2) -> (not co1 || co2) && (not cn1 || cn2))
|
|
|
|
decl1.type_variance decl2.type_variance
|
2001-03-04 06:39:18 -08:00
|
|
|
end
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Inclusion between exception declarations *)
|
|
|
|
|
|
|
|
let exception_declarations env ed1 ed2 =
|
2000-11-22 05:48:55 -08:00
|
|
|
Misc.for_all2 (fun ty1 ty2 -> Ctype.equal env false [ty1] [ty2]) ed1 ed2
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
(* Inclusion between class types *)
|
1996-05-14 08:38:36 -07:00
|
|
|
let encode_val (mut, ty) rem =
|
|
|
|
begin match mut with
|
|
|
|
Asttypes.Mutable -> Predef.type_unit
|
1998-07-03 10:40:39 -07:00
|
|
|
| Asttypes.Immutable -> Btype.newgenty Tvar
|
1996-05-14 08:38:36 -07:00
|
|
|
end
|
|
|
|
::ty::rem
|
|
|
|
|
1997-05-11 14:48:21 -07:00
|
|
|
let meths meths1 meths2 =
|
|
|
|
Meths.fold
|
|
|
|
(fun nam t2 (ml1, ml2) ->
|
|
|
|
(begin try
|
|
|
|
Meths.find nam meths1 :: ml1
|
|
|
|
with Not_found ->
|
|
|
|
ml1
|
|
|
|
end,
|
|
|
|
t2 :: ml2))
|
|
|
|
meths2 ([], [])
|
|
|
|
|
1996-05-14 08:38:36 -07:00
|
|
|
let vars vars1 vars2 =
|
|
|
|
Vars.fold
|
|
|
|
(fun lab v2 (vl1, vl2) ->
|
|
|
|
(begin try
|
|
|
|
encode_val (Vars.find lab vars1) vl1
|
|
|
|
with Not_found ->
|
|
|
|
vl1
|
|
|
|
end,
|
|
|
|
encode_val v2 vl2))
|
|
|
|
vars2 ([], [])
|