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
|
|
|
(* Operations on core types *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
open Asttypes
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-03-08 14:04:36 -08:00
|
|
|
exception Unify of (type_expr * type_expr) list
|
1999-11-30 08:07:38 -08:00
|
|
|
exception Tags of label * label
|
1997-03-08 14:04:36 -08:00
|
|
|
exception Subtype of
|
|
|
|
(type_expr * type_expr) list * (type_expr * type_expr) list
|
|
|
|
exception Cannot_expand
|
1997-03-18 13:05:27 -08:00
|
|
|
exception Cannot_apply
|
1997-03-08 14:04:36 -08:00
|
|
|
exception Recursive_abbrev
|
|
|
|
|
1996-07-15 09:35:35 -07:00
|
|
|
val init_def: int -> unit
|
|
|
|
(* Set the initial variable level *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val begin_def: unit -> unit
|
|
|
|
(* Raise the variable level by one at the beginning of a definition. *)
|
|
|
|
val end_def: unit -> unit
|
|
|
|
(* Lower the variable level by one at the end of a definition *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val begin_class_def: unit -> unit
|
|
|
|
val raise_nongen_level: unit -> unit
|
1996-04-22 04:15:41 -07:00
|
|
|
val reset_global_level: unit -> unit
|
2002-08-04 22:58:08 -07:00
|
|
|
(* Reset the global level before typing an expression *)
|
|
|
|
val increase_global_level: unit -> int
|
|
|
|
val restore_global_level: int -> unit
|
|
|
|
(* This pair of functions is only used in Typetexp *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
val newty: type_desc -> type_expr
|
1995-05-04 03:15:53 -07:00
|
|
|
val newvar: unit -> type_expr
|
|
|
|
(* Return a fresh variable *)
|
1995-10-31 07:58:31 -08:00
|
|
|
val new_global_var: unit -> type_expr
|
|
|
|
(* Return a fresh variable, bound at toplevel
|
|
|
|
(as type variables ['a] in type constraints). *)
|
1996-04-22 04:15:41 -07:00
|
|
|
val newobj: type_expr -> type_expr
|
1998-06-24 12:22:26 -07:00
|
|
|
val newconstr: Path.t -> type_expr list -> type_expr
|
1997-03-08 14:04:36 -08:00
|
|
|
val none: type_expr
|
|
|
|
(* A dummy type expression *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val repr: type_expr -> type_expr
|
|
|
|
(* Return the canonical representative of a type. *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
2003-11-25 01:20:45 -08:00
|
|
|
val dummy_method: label
|
1998-06-24 12:22:26 -07:00
|
|
|
val object_fields: type_expr -> type_expr
|
|
|
|
val flatten_fields:
|
1997-05-11 14:35:00 -07:00
|
|
|
type_expr -> (string * field_kind * type_expr) list * type_expr
|
1997-05-19 08:42:21 -07:00
|
|
|
(* Transform a field type into a list of pairs label-type *)
|
1998-06-24 12:22:26 -07:00
|
|
|
(* The fields are sorted *)
|
|
|
|
val associate_fields:
|
|
|
|
(string * field_kind * type_expr) list ->
|
|
|
|
(string * field_kind * type_expr) list ->
|
|
|
|
(string * field_kind * type_expr * field_kind * type_expr) list *
|
|
|
|
(string * field_kind * type_expr) list *
|
|
|
|
(string * field_kind * type_expr) list
|
1997-03-08 14:04:36 -08:00
|
|
|
val opened_object: type_expr -> bool
|
|
|
|
val close_object: type_expr -> unit
|
1998-06-24 12:22:26 -07:00
|
|
|
val row_variable: type_expr -> type_expr
|
|
|
|
(* Return the row variable of an open object type *)
|
1997-03-08 14:04:36 -08:00
|
|
|
val set_object_name:
|
1998-06-24 12:22:26 -07:00
|
|
|
Ident.t -> type_expr -> type_expr list -> type_expr -> unit
|
1997-03-08 14:04:36 -08:00
|
|
|
val remove_object_name: type_expr -> unit
|
1997-05-11 14:35:00 -07:00
|
|
|
val hide_private_methods: type_expr -> unit
|
2003-11-25 01:20:45 -08:00
|
|
|
val find_cltype_for_path: Env.t -> Path.t -> type_declaration * type_expr
|
1997-03-08 14:04:36 -08:00
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
val sort_row_fields: (label * row_field) list -> (label * row_field) list
|
|
|
|
val merge_row_fields:
|
|
|
|
(label * row_field) list -> (label * row_field) list ->
|
|
|
|
(label * row_field) list * (label * row_field) list *
|
|
|
|
(label * row_field * row_field) list
|
|
|
|
val filter_row_fields:
|
|
|
|
bool -> (label * row_field) list -> (label * row_field) list
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val generalize: type_expr -> unit
|
|
|
|
(* Generalize in-place the given type *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val iterative_generalization: int -> type_expr list -> type_expr list
|
|
|
|
(* Efficient repeated generalization of a type *)
|
2002-12-02 18:57:23 -08:00
|
|
|
val generalize_expansive: Env.t -> type_expr -> unit
|
|
|
|
(* Generalize the covariant part of a type, making
|
|
|
|
contravariant branches non-generalizable *)
|
2002-04-18 00:27:47 -07:00
|
|
|
val generalize_global: type_expr -> unit
|
2002-12-02 18:57:23 -08:00
|
|
|
(* Generalize the structure of a type, lowering variables
|
|
|
|
to !global_level *)
|
2002-04-18 00:27:47 -07:00
|
|
|
val generalize_structure: type_expr -> unit
|
|
|
|
(* Same, but variables are only lowered to !current_level *)
|
|
|
|
val generalize_spine: type_expr -> unit
|
|
|
|
(* Special function to generalize a method during inference *)
|
1997-03-24 12:11:26 -08:00
|
|
|
val correct_levels: type_expr -> type_expr
|
|
|
|
(* Returns a copy with decreasing levels *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val limited_generalize: type_expr -> type_expr -> unit
|
|
|
|
(* Only generalize some part of the type
|
|
|
|
Make the remaining of the type non-generalizable *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val instance: type_expr -> type_expr
|
|
|
|
(* Take an instance of a type scheme *)
|
1997-02-20 12:39:02 -08:00
|
|
|
val instance_list: type_expr list -> type_expr list
|
|
|
|
(* Take an instance of a list of type schemes *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val instance_constructor:
|
|
|
|
constructor_description -> type_expr list * type_expr
|
|
|
|
(* Same, for a constructor *)
|
1997-03-08 14:04:36 -08:00
|
|
|
val instance_parameterized_type:
|
1997-05-19 08:42:21 -07:00
|
|
|
type_expr list -> type_expr -> type_expr list * type_expr
|
1997-03-08 14:04:36 -08:00
|
|
|
val instance_parameterized_type_2:
|
1997-05-19 08:42:21 -07:00
|
|
|
type_expr list -> type_expr list -> type_expr ->
|
1997-03-08 14:04:36 -08:00
|
|
|
type_expr list * type_expr list * type_expr
|
1996-04-22 04:15:41 -07:00
|
|
|
val instance_class:
|
1998-06-24 12:22:26 -07:00
|
|
|
type_expr list -> class_type -> type_expr list * class_type
|
2002-04-18 00:27:47 -07:00
|
|
|
val instance_poly:
|
|
|
|
bool -> type_expr list -> type_expr -> type_expr list * type_expr
|
|
|
|
(* Take an instance of a type scheme containing free univars *)
|
|
|
|
val instance_label:
|
|
|
|
bool -> label_description -> type_expr list * type_expr * type_expr
|
|
|
|
(* Same, for a label *)
|
1997-03-18 13:05:27 -08:00
|
|
|
val apply:
|
|
|
|
Env.t -> type_expr list -> type_expr -> type_expr list -> type_expr
|
|
|
|
(* [apply [p1...pN] t [a1...aN]] match the arguments [ai] to
|
|
|
|
the parameters [pi] and returns the corresponding instance of
|
|
|
|
[t]. Exception [Cannot_apply] is raised in case of failure. *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
2003-06-19 08:53:53 -07:00
|
|
|
val expand_head_once: Env.t -> type_expr -> type_expr
|
1997-03-07 14:49:24 -08:00
|
|
|
val expand_head: Env.t -> type_expr -> type_expr
|
2007-11-01 11:36:43 -07:00
|
|
|
val expand_head_opt: Env.t -> type_expr -> type_expr
|
|
|
|
(** The compiler's own version of [expand_head] necessary for type-based
|
|
|
|
optimisations. *)
|
1997-03-08 14:04:36 -08:00
|
|
|
val full_expand: Env.t -> type_expr -> type_expr
|
|
|
|
|
1999-11-08 15:05:03 -08:00
|
|
|
val enforce_constraints: Env.t -> type_expr -> unit
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val unify: Env.t -> type_expr -> type_expr -> unit
|
|
|
|
(* Unify the two types given. Raise [Unify] if not possible. *)
|
2002-04-18 00:27:47 -07:00
|
|
|
val unify_var: Env.t -> type_expr -> type_expr -> unit
|
|
|
|
(* Same as [unify], but allow free univars when first type
|
|
|
|
is a variable. *)
|
1999-11-30 08:07:38 -08:00
|
|
|
val filter_arrow: Env.t -> type_expr -> label -> type_expr * type_expr
|
|
|
|
(* A special case of unification (with l:'a -> 'b). *)
|
1997-05-11 14:35:00 -07:00
|
|
|
val filter_method: Env.t -> string -> private_flag -> type_expr -> type_expr
|
1997-05-19 08:42:21 -07:00
|
|
|
(* A special case of unification (with {m : 'a; 'b}). *)
|
1998-11-12 06:53:46 -08:00
|
|
|
val check_filter_method: Env.t -> string -> private_flag -> type_expr -> unit
|
|
|
|
(* A special case of unification (with {m : 'a; 'b}), returning unit. *)
|
2002-06-09 19:39:35 -07:00
|
|
|
val deep_occur: type_expr -> type_expr -> bool
|
1998-06-24 12:22:26 -07:00
|
|
|
val filter_self_method:
|
|
|
|
Env.t -> string -> private_flag -> (Ident.t * type_expr) Meths.t ref ->
|
|
|
|
type_expr -> Ident.t * type_expr
|
1997-04-01 12:52:36 -08:00
|
|
|
val moregeneral: Env.t -> bool -> type_expr -> type_expr -> bool
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Check if the first type scheme is more general than the second. *)
|
2003-06-30 01:04:42 -07:00
|
|
|
|
2003-06-28 03:46:32 -07:00
|
|
|
val rigidify: type_expr -> type_expr list
|
|
|
|
(* "Rigidify" a type and return its type variable *)
|
2003-07-08 03:01:10 -07:00
|
|
|
val all_distinct_vars: Env.t -> type_expr list -> bool
|
2003-06-30 01:04:42 -07:00
|
|
|
(* Check those types are all distinct type variables *)
|
|
|
|
val matches : Env.t -> type_expr -> type_expr -> bool
|
|
|
|
(* Same as [moregeneral false], implemented using the two above
|
|
|
|
functions and backtracking. Ignore levels *)
|
2003-06-28 03:46:32 -07:00
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
type class_match_failure =
|
|
|
|
CM_Virtual_class
|
|
|
|
| CM_Parameter_arity_mismatch of int * int
|
|
|
|
| CM_Type_parameter_mismatch of (type_expr * type_expr) list
|
|
|
|
| CM_Class_type_mismatch of class_type * class_type
|
|
|
|
| CM_Parameter_mismatch of (type_expr * type_expr) list
|
|
|
|
| CM_Val_type_mismatch of string * (type_expr * type_expr) list
|
|
|
|
| CM_Meth_type_mismatch of string * (type_expr * type_expr) list
|
|
|
|
| CM_Non_mutable_value of string
|
2006-04-04 19:28:13 -07:00
|
|
|
| CM_Non_concrete_value of string
|
1998-06-24 12:22:26 -07:00
|
|
|
| CM_Missing_value of string
|
|
|
|
| CM_Missing_method of string
|
|
|
|
| CM_Hide_public of string
|
2006-04-04 19:28:13 -07:00
|
|
|
| CM_Hide_virtual of string * string
|
1998-06-24 12:22:26 -07:00
|
|
|
| CM_Public_method of string
|
|
|
|
| CM_Private_method of string
|
|
|
|
| CM_Virtual_method of string
|
|
|
|
val match_class_types:
|
|
|
|
Env.t -> class_type -> class_type -> class_match_failure list
|
|
|
|
(* Check if the first class type is more general than the second. *)
|
1997-02-20 12:39:02 -08:00
|
|
|
val equal: Env.t -> bool -> type_expr list -> type_expr list -> bool
|
1995-05-04 03:15:53 -07:00
|
|
|
(* [equal env [x1...xn] tau [y1...yn] sigma]
|
|
|
|
checks whether the parameterized types
|
|
|
|
[/\x1.../\xn.tau] and [/\y1.../\yn.sigma] are equivalent. *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val match_class_declarations:
|
|
|
|
Env.t -> type_expr list -> class_type -> type_expr list ->
|
|
|
|
class_type -> class_match_failure list
|
|
|
|
(* Check if the first class type is more general than the second. *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
2002-05-29 23:24:45 -07:00
|
|
|
val enlarge_type: Env.t -> type_expr -> type_expr * bool
|
|
|
|
(* Make a type larger, flag is true if some pruning had to be done *)
|
2003-11-25 01:20:45 -08:00
|
|
|
val subtype: Env.t -> type_expr -> type_expr -> unit -> unit
|
1997-01-20 09:11:47 -08:00
|
|
|
(* [subtype env t1 t2] checks that [t1] is a subtype of [t2].
|
|
|
|
It accumulates the constraints the type variables must
|
|
|
|
enforce and returns a function that inforce this
|
|
|
|
constraints. *)
|
1997-03-08 14:04:36 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val nondep_type: Env.t -> Ident.t -> type_expr -> type_expr
|
|
|
|
(* Return a type equivalent to the given type but without
|
|
|
|
references to the given module identifier. Raise [Not_found]
|
1995-11-13 06:25:55 -08:00
|
|
|
if no such type exists. *)
|
1997-03-09 10:40:54 -08:00
|
|
|
val nondep_type_decl:
|
|
|
|
Env.t -> Ident.t -> Ident.t -> bool -> type_declaration ->
|
|
|
|
type_declaration
|
|
|
|
(* Same for type declarations. *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val nondep_class_declaration:
|
|
|
|
Env.t -> Ident.t -> class_declaration -> class_declaration
|
|
|
|
(* Same for class declarations. *)
|
|
|
|
val nondep_cltype_declaration:
|
|
|
|
Env.t -> Ident.t -> cltype_declaration -> cltype_declaration
|
|
|
|
(* Same for class type declarations. *)
|
2003-07-01 06:05:43 -07:00
|
|
|
val correct_abbrev: Env.t -> Path.t -> type_expr list -> type_expr -> unit
|
1997-06-29 06:16:47 -07:00
|
|
|
val cyclic_abbrev: Env.t -> Ident.t -> type_expr -> bool
|
2000-02-24 02:18:25 -08:00
|
|
|
val normalize_type: Env.t -> type_expr -> unit
|
1997-03-08 14:04:36 -08:00
|
|
|
|
1997-03-18 13:05:27 -08:00
|
|
|
val closed_schema: type_expr -> bool
|
1997-03-08 14:04:36 -08:00
|
|
|
(* Check whether the given type scheme contains no non-generic
|
|
|
|
type variables *)
|
|
|
|
|
2004-12-09 04:40:53 -08:00
|
|
|
val free_variables: type_expr -> type_expr list
|
1998-06-24 12:22:26 -07:00
|
|
|
val closed_type_decl: type_declaration -> type_expr option
|
|
|
|
type closed_class_failure =
|
1998-11-30 05:06:53 -08:00
|
|
|
CC_Method of type_expr * bool * string * type_expr
|
|
|
|
| CC_Value of type_expr * bool * string * type_expr
|
1998-06-24 12:22:26 -07:00
|
|
|
val closed_class:
|
|
|
|
type_expr list -> class_signature -> closed_class_failure option
|
|
|
|
(* Check whether all type variables are bound *)
|
|
|
|
|
1997-02-20 12:39:02 -08:00
|
|
|
val unalias: type_expr -> type_expr
|
1998-06-24 12:22:26 -07:00
|
|
|
val signature_of_class_type: class_type -> class_signature
|
|
|
|
val self_type: class_type -> type_expr
|
|
|
|
val class_type_arity: class_type -> int
|
1995-05-04 03:15:53 -07:00
|
|
|
val arity: type_expr -> int
|
|
|
|
(* Return the arity (as for curried functions) of the given type. *)
|
2002-10-07 23:55:58 -07:00
|
|
|
|
|
|
|
val collapse_conj_params: Env.t -> type_expr list -> unit
|
|
|
|
(* Collapse conjunctive types in class parameters *)
|