···1515 is actually a suffix of `name` and raises Invalid_argument otherwise.
1616 (Xavier Leroy, report by whitequark, review by David Allsopp)
17171818+* #10482: mark the Stream and Genlex modules as deprecated, in preparation
1919+ for a future removal. These modules (without deprecation alert)
2020+ are now provided by the camlp-streams library.
2121+ (Xavier Leroy, review by Nicolás Ojeda Bär)
2222+1823### Other libraries:
19242025- #10192: Add support for Unix domain sockets on Windows and use them
···7580 This allows stacktraces to work in gdb through C and OCaml calls.
7681 (Edwin Török, review by Nicolás Ojeda Bär and Xavier Leroy)
77827878-- #10461: `caml_send*` helper functions take derived pointers as arguments.
7979- Those must be declared with type Addr instead of Val.
8080- (Vincent Laviron, review by Xavier Leroy)
8383+- #10461, #10498: `caml_send*` helper functions take derived pointers
8484+ as arguments. Those must be declared with type Addr instead of Val.
8585+ Moreover, poll point insertion must be disabled for `caml_send*`,
8686+ otherwise the derived pointer is live across a poll point.
8787+ (Vincent Laviron and Xavier Leroy, review by Xavier Leroy and Sadiq Jaffer)
818882898390OCaml 4.13.0
···8996 Add poll points to native generated code. These are effectively
9097 zero-sized allocations and fix some signal and remembered set
9198 issues. Also multicore prerequisite.
9292- (Sadiq Jaffer, Damien Doligez, Mark Shinwell, Anmol Sahoo, Stephen Dolan,
9393- Xavier Leroy reviewed by ??)
9999+ (Sadiq Jaffer, Stephen Dolan, Damien Doligez, Xavier Leroy,
100100+ Anmol Sahoo, Mark Shinwell, review by Damien Doligez, Xavier Leroy,
101101+ and Mark Shinwell)
9410295103- #9331: Improve error messages for functor application and functor types.
96104 (Florian Angeletti and Gabriel Radanne, review by Leo White)
···110118 One can now write '(Cstr (type a) (x, y : int * a))' to give a name to
111119 existentials freshly introduced by GADT constructors.
112120 (Jacques Garrigue, review by Leo White and Gabriel Scherer)
113113-114114-* #9811: remove propagation from previous branches
115115- Type information inferred from previous branches was propagated in
116116- non-principal mode. Revert this for better compatibility with
117117- -principal mode.
118118- For the time being, infringing code should result in a principality warning.
119119- (Jacques Garrigue, review by Thomas Refis and Gabriel Scherer)
120121121122- #10174: Make Tsubst more robust by avoiding strange workarounds
122123 (Takafumi Saikawa and Jacques Garrigue, review by Gabriel Scherer and
···442443 (Leo White, review by Florian Angeletti)
443444444445### Internal/compiler-libs changes:
446446+447447+- #8516: Change representation of class signatures
448448+ (Leo White, review by Thomas Refis)
445449446450- #9243, simplify parser rules for array indexing operations
447451 (Florian Angeletti, review by Damien Doligez and Gabriel Scherer)
+34-19
asmcomp/polling.ml
···9393 that does not go through an Ialloc or Ipoll instruction.
94949595 "Always_polls", therefore, means the function always polls (via Ialloc or
9696- Ipoll) before doing a PRTC.
9696+ Ipoll) before doing a PRTC. This includes the case where it does not
9797+ perform any PRTC.
9898+9999+ A note on Potentially Recursive Tail Calls
100100+ ------------------------------------------
101101+102102+ Tail calls can create infinite loops, of course. (Consider a function
103103+ that tail-calls itself.) But not all tail calls need to be flagged
104104+ as potential infinite loops.
105105+106106+ We optimise by making a partial ordering over Mach functions: in
107107+ definition order within a compilation unit, and dependency
108108+ order between compilation units. This order is acyclic, as
109109+ OCaml does not allow circular dependencies between modules.
110110+ It's also finite, so if there's an infinite sequence of
111111+ function calls then something has to make a forward reference.
112112+113113+ Also, in such an infinite sequence of function calls, at most finitely
114114+ many of them can be non-tail calls. (If there are infinitely many
115115+ non-tail calls, then the program soon terminates with a stack
116116+ overflow).
117117+118118+ So, every such infinite sequence must contain many forward-referencing
119119+ tail calls. These tail calls are the Potentially Recursive Tail Calls
120120+ (PTRCs). Polling only on those calls suffices.
121121+122122+ Several functions below take a parameter [future_funcnames]
123123+ which is the set of functions defined "after" the current function
124124+ in the current compilation unit. The PTRCs are tail calls
125125+ to known functions in [future_funcnames], or tail calls to
126126+ unknown functions.
97127*)
9812899129type polls_before_prtc = Might_not_poll | Always_polls
···125155 match i.desc with
126156 | Iend -> next
127157 | Iop (Ialloc _ | Ipoll _) -> Always_polls
128128- | Iop (Itailcall_ind) -> Might_not_poll
158158+ | Iop (Itailcall_ind) -> Might_not_poll (* this is a PTRC *)
129159 | Iop (Itailcall_imm { func }) ->
130130- (* We optimise by making a partial ordering over Mach functions: in
131131- definition order within a compilation unit, and dependency order
132132- between compilation units. This order is acyclic, as OCaml does not
133133- allow circular dependencies between modules. It's also finite, so if
134134- there's an infinite sequence of function calls then something has to
135135- make a forward reference.
136136-137137- Also, in such an infinite sequence of function calls, at most finitely
138138- many of them can be non-tail calls. (If there are infinitely many
139139- non-tail calls, then the program soon terminates with a stack
140140- overflow).
141141-142142- So, every such infinite sequence must contain many forward-referencing
143143- tail calls, so polling only on those suffices. This is checked using
144144- the set [future_funcnames]. *)
145160 if String.Set.mem func future_funcnames
146161 || function_is_assumed_to_never_poll func
147147- then Might_not_poll
148148- else Always_polls
162162+ then Might_not_poll (* this is a PTRC *)
163163+ else Always_polls (* this is not a PTRC *)
149164 | Iop op ->
150165 if operation_can_raise op
151166 then Polls_before_prtc.join next exn
···11+Private type declarations in module signatures, of the form
22+"type t = private ...", enable libraries to
33+reveal some, but not all aspects of the implementation of a type to
44+clients of the library. In this respect, they strike a middle ground
55+between abstract type declarations, where no information is revealed
66+on the type implementation, and data type definitions and type
77+abbreviations, where all aspects of the type implementation are
88+publicized. Private type declarations come in three flavors: for
99+variant and record types (section~\ref{ss:private-types-variant}),
1010+for type abbreviations (section~\ref{ss:private-types-abbrev}),
1111+and for row types (section~\ref{ss:private-rows}).
1212+1313+\subsection{ss:private-types-variant}{Private variant and record types}
1414+1515+1616+(Introduced in Objective Caml 3.07)
1717+1818+\begin{syntax}
1919+type-representation:
2020+ ...
2121+ | '=' 'private' [ '|' ] constr-decl { '|' constr-decl }
2222+ | '=' 'private' record-decl
2323+\end{syntax}
2424+2525+Values of a variant or record type declared @"private"@
2626+can be de-structured normally in pattern-matching or via
2727+the @expr '.' field@ notation for record accesses. However, values of
2828+these types cannot be constructed directly by constructor application
2929+or record construction. Moreover, assignment on a mutable field of a
3030+private record type is not allowed.
3131+3232+The typical use of private types is in the export signature of a
3333+module, to ensure that construction of values of the private type always
3434+go through the functions provided by the module, while still allowing
3535+pattern-matching outside the defining module. For example:
3636+\begin{caml_example*}{verbatim}
3737+module M : sig
3838+ type t = private A | B of int
3939+ val a : t
4040+ val b : int -> t
4141+end = struct
4242+ type t = A | B of int
4343+ let a = A
4444+ let b n = assert (n > 0); B n
4545+end
4646+\end{caml_example*}
4747+Here, the @"private"@ declaration ensures that in any value of type
4848+"M.t", the argument to the "B" constructor is always a positive integer.
4949+5050+With respect to the variance of their parameters, private types are
5151+handled like abstract types. That is, if a private type has
5252+parameters, their variance is the one explicitly given by prefixing
5353+the parameter by a `"+"' or a `"-"', it is invariant otherwise.
5454+5555+\subsection{ss:private-types-abbrev}{Private type abbreviations}
5656+5757+(Introduced in Objective Caml 3.11)
5858+5959+\begin{syntax}
6060+type-equation:
6161+ ...
6262+ | '=' 'private' typexpr
6363+\end{syntax}
6464+6565+Unlike a regular type abbreviation, a private type abbreviation
6666+declares a type that is distinct from its implementation type @typexpr@.
6767+However, coercions from the type to @typexpr@ are permitted.
6868+Moreover, the compiler ``knows'' the implementation type and can take
6969+advantage of this knowledge to perform type-directed optimizations.
7070+7171+The following example uses a private type abbreviation to define a
7272+module of nonnegative integers:
7373+\begin{caml_example*}{verbatim}
7474+module N : sig
7575+ type t = private int
7676+ val of_int: int -> t
7777+ val to_int: t -> int
7878+end = struct
7979+ type t = int
8080+ let of_int n = assert (n >= 0); n
8181+ let to_int n = n
8282+end
8383+\end{caml_example*}
8484+The type "N.t" is incompatible with "int", ensuring that nonnegative
8585+integers and regular integers are not confused. However, if "x" has
8686+type "N.t", the coercion "(x :> int)" is legal and returns the
8787+underlying integer, just like "N.to_int x". Deep coercions are also
8888+supported: if "l" has type "N.t list", the coercion "(l :> int list)"
8989+returns the list of underlying integers, like "List.map N.to_int l"
9090+but without copying the list "l".
9191+9292+Note that the coercion @"(" expr ":>" typexpr ")"@ is actually an abbreviated
9393+form,
9494+and will only work in presence of private abbreviations if neither the
9595+type of @expr@ nor @typexpr@ contain any type variables. If they do,
9696+you must use the full form @"(" expr ":" typexpr_1 ":>" typexpr_2 ")"@ where
9797+@typexpr_1@ is the expected type of @expr@. Concretely, this would be "(x :
9898+N.t :> int)" and "(l : N.t list :> int list)" for the above examples.
9999+100100+\subsection{ss:private-rows}{Private row types}
101101+\ikwd{private\@\texttt{private}}
102102+103103+(Introduced in Objective Caml 3.09)
104104+105105+\begin{syntax}
106106+type-equation:
107107+ ...
108108+ | '=' 'private' typexpr
109109+\end{syntax}
110110+111111+Private row types are type abbreviations where part of the
112112+structure of the type is left abstract. Concretely @typexpr@ in the
113113+above should denote either an object type or a polymorphic variant
114114+type, with some possibility of refinement left. If the private
115115+declaration is used in an interface, the corresponding implementation
116116+may either provide a ground instance, or a refined private type.
117117+\begin{caml_example*}{verbatim}
118118+module M : sig type c = private < x : int; .. > val o : c end =
119119+struct
120120+ class c = object method x = 3 method y = 2 end
121121+ let o = new c
122122+end
123123+\end{caml_example*}
124124+This declaration does more than hiding the "y" method, it also makes
125125+the type "c" incompatible with any other closed object type, meaning
126126+that only "o" will be of type "c". In that respect it behaves
127127+similarly to private record types. But private row types are
128128+more flexible with respect to incremental refinement. This feature can
129129+be used in combination with functors.
130130+\begin{caml_example*}{verbatim}
131131+module F(X : sig type c = private < x : int; .. > end) =
132132+struct
133133+ let get_x (o : X.c) = o#x
134134+end
135135+module G(X : sig type c = private < x : int; y : int; .. > end) =
136136+struct
137137+ include F(X)
138138+ let get_y (o : X.c) = o#y
139139+end
140140+\end{caml_example*}
141141+142142+A polymorphic variant type [t], for example
143143+\begin{caml_example*}{verbatim}
144144+type t = [ `A of int | `B of bool ]
145145+\end{caml_example*}
146146+can be refined in two ways. A definition [u] may add new field to [t],
147147+and the declaration
148148+\begin{caml_example*}{verbatim}
149149+type u = private [> t]
150150+\end{caml_example*}
151151+will keep those new fields abstract. Construction of values of type
152152+[u] is possible using the known variants of [t], but any
153153+pattern-matching will require a default case to handle the potential
154154+extra fields. Dually, a declaration [u] may restrict the fields of [t]
155155+through abstraction: the declaration
156156+\begin{caml_example*}{verbatim}
157157+type v = private [< t > `A]
158158+\end{caml_example*}
159159+corresponds to private variant types. One cannot create a value of the
160160+private type [v], except using the constructors that are explicitly
161161+listed as present, "(`A n)" in this example; yet, when
162162+patter-matching on a [v], one should assume that any of the
163163+constructors of [t] could be present.
164164+165165+Similarly to abstract types, the variance of type parameters
166166+is not inferred, and must be given explicitly.
···78787979Note that, in the @specification@ case, the @module-type@s must be
8080parenthesized if they use the @'with' mod-constraint@ construct.
8181-8282-\section{s:private-types}{Private types}
8383-%HEVEA\cutname{privatetypes.html}
8484-\ikwd{private\@\texttt{private}}
8585-8686-Private type declarations in module signatures, of the form
8787-"type t = private ...", enable libraries to
8888-reveal some, but not all aspects of the implementation of a type to
8989-clients of the library. In this respect, they strike a middle ground
9090-between abstract type declarations, where no information is revealed
9191-on the type implementation, and data type definitions and type
9292-abbreviations, where all aspects of the type implementation are
9393-publicized. Private type declarations come in three flavors: for
9494-variant and record types (section~\ref{ss:private-types-variant}),
9595-for type abbreviations (section~\ref{ss:private-types-abbrev}),
9696-and for row types (section~\ref{ss:private-rows}).
9797-9898-\subsection{ss:private-types-variant}{Private variant and record types}
9999-100100-101101-(Introduced in Objective Caml 3.07)
102102-103103-\begin{syntax}
104104-type-representation:
105105- ...
106106- | '=' 'private' [ '|' ] constr-decl { '|' constr-decl }
107107- | '=' 'private' record-decl
108108-\end{syntax}
109109-110110-Values of a variant or record type declared @"private"@
111111-can be de-structured normally in pattern-matching or via
112112-the @expr '.' field@ notation for record accesses. However, values of
113113-these types cannot be constructed directly by constructor application
114114-or record construction. Moreover, assignment on a mutable field of a
115115-private record type is not allowed.
116116-117117-The typical use of private types is in the export signature of a
118118-module, to ensure that construction of values of the private type always
119119-go through the functions provided by the module, while still allowing
120120-pattern-matching outside the defining module. For example:
121121-\begin{caml_example*}{verbatim}
122122-module M : sig
123123- type t = private A | B of int
124124- val a : t
125125- val b : int -> t
126126-end = struct
127127- type t = A | B of int
128128- let a = A
129129- let b n = assert (n > 0); B n
130130-end
131131-\end{caml_example*}
132132-Here, the @"private"@ declaration ensures that in any value of type
133133-"M.t", the argument to the "B" constructor is always a positive integer.
134134-135135-With respect to the variance of their parameters, private types are
136136-handled like abstract types. That is, if a private type has
137137-parameters, their variance is the one explicitly given by prefixing
138138-the parameter by a `"+"' or a `"-"', it is invariant otherwise.
139139-140140-\subsection{ss:private-types-abbrev}{Private type abbreviations}
141141-142142-(Introduced in Objective Caml 3.11)
143143-144144-\begin{syntax}
145145-type-equation:
146146- ...
147147- | '=' 'private' typexpr
148148-\end{syntax}
149149-150150-Unlike a regular type abbreviation, a private type abbreviation
151151-declares a type that is distinct from its implementation type @typexpr@.
152152-However, coercions from the type to @typexpr@ are permitted.
153153-Moreover, the compiler ``knows'' the implementation type and can take
154154-advantage of this knowledge to perform type-directed optimizations.
155155-156156-The following example uses a private type abbreviation to define a
157157-module of nonnegative integers:
158158-\begin{caml_example*}{verbatim}
159159-module N : sig
160160- type t = private int
161161- val of_int: int -> t
162162- val to_int: t -> int
163163-end = struct
164164- type t = int
165165- let of_int n = assert (n >= 0); n
166166- let to_int n = n
167167-end
168168-\end{caml_example*}
169169-The type "N.t" is incompatible with "int", ensuring that nonnegative
170170-integers and regular integers are not confused. However, if "x" has
171171-type "N.t", the coercion "(x :> int)" is legal and returns the
172172-underlying integer, just like "N.to_int x". Deep coercions are also
173173-supported: if "l" has type "N.t list", the coercion "(l :> int list)"
174174-returns the list of underlying integers, like "List.map N.to_int l"
175175-but without copying the list "l".
176176-177177-Note that the coercion @"(" expr ":>" typexpr ")"@ is actually an abbreviated
178178-form,
179179-and will only work in presence of private abbreviations if neither the
180180-type of @expr@ nor @typexpr@ contain any type variables. If they do,
181181-you must use the full form @"(" expr ":" typexpr_1 ":>" typexpr_2 ")"@ where
182182-@typexpr_1@ is the expected type of @expr@. Concretely, this would be "(x :
183183-N.t :> int)" and "(l : N.t list :> int list)" for the above examples.
184184-185185-\subsection{ss:private-rows}{Private row types}
186186-\ikwd{private\@\texttt{private}}
187187-188188-(Introduced in Objective Caml 3.09)
189189-190190-\begin{syntax}
191191-type-equation:
192192- ...
193193- | '=' 'private' typexpr
194194-\end{syntax}
195195-196196-Private row types are type abbreviations where part of the
197197-structure of the type is left abstract. Concretely @typexpr@ in the
198198-above should denote either an object type or a polymorphic variant
199199-type, with some possibility of refinement left. If the private
200200-declaration is used in an interface, the corresponding implementation
201201-may either provide a ground instance, or a refined private type.
202202-\begin{caml_example*}{verbatim}
203203-module M : sig type c = private < x : int; .. > val o : c end =
204204-struct
205205- class c = object method x = 3 method y = 2 end
206206- let o = new c
207207-end
208208-\end{caml_example*}
209209-This declaration does more than hiding the "y" method, it also makes
210210-the type "c" incompatible with any other closed object type, meaning
211211-that only "o" will be of type "c". In that respect it behaves
212212-similarly to private record types. But private row types are
213213-more flexible with respect to incremental refinement. This feature can
214214-be used in combination with functors.
215215-\begin{caml_example*}{verbatim}
216216-module F(X : sig type c = private < x : int; .. > end) =
217217-struct
218218- let get_x (o : X.c) = o#x
219219-end
220220-module G(X : sig type c = private < x : int; y : int; .. > end) =
221221-struct
222222- include F(X)
223223- let get_y (o : X.c) = o#y
224224-end
225225-\end{caml_example*}
226226-227227-A polymorphic variant type [t], for example
228228-\begin{caml_example*}{verbatim}
229229-type t = [ `A of int | `B of bool ]
230230-\end{caml_example*}
231231-can be refined in two ways. A definition [u] may add new field to [t],
232232-and the declaration
233233-\begin{caml_example*}{verbatim}
234234-type u = private [> t]
235235-\end{caml_example*}
236236-will keep those new fields abstract. Construction of values of type
237237-[u] is possible using the known variants of [t], but any
238238-pattern-matching will require a default case to handle the potential
239239-extra fields. Dually, a declaration [u] may restrict the fields of [t]
240240-through abstraction: the declaration
241241-\begin{caml_example*}{verbatim}
242242-type v = private [< t > `A]
243243-\end{caml_example*}
244244-corresponds to private variant types. One cannot create a value of the
245245-private type [v], except using the constructors that are explicitly
246246-listed as present, "(`A n)" in this example; yet, when
247247-patter-matching on a [v], one should assume that any of the
248248-constructors of [t] could be present.
249249-250250-Similarly to abstract types, the variance of type parameters
251251-is not inferred, and must be given explicitly.
···159159module type T = sig module type S val x: (module S) end
160160module type Error = T with module type S := sig end
161161\end{caml_example}
162162-163163-\section{s:module-alias}{Type-level module aliases}
164164-\ikwd{module\@\texttt{module}}
165165-%HEVEA\cutname{modulealias.html}
···8787 | Longident.Lapply(l1, l2) ->
8888 string_of_longident l1 ^ "(" ^ string_of_longident l2 ^ ")"
89899090-let get_fields type_expr =
9191- let (fields, _) = Ctype.flatten_fields (Ctype.object_fields type_expr) in
9292- List.fold_left
9393- (fun acc -> fun (label, field_kind, typ) ->
9494- match field_kind with
9595- Types.Fabsent ->
9696- acc
9797- | _ ->
9898- if label = "*dummy method*" then
9999- acc
100100- else
101101- acc @ [label, typ]
102102- )
103103- []
104104- fields
105105-10690let rec string_of_text t =
10791 let rec iter t_ele =
10892 match t_ele with
-4
ocamldoc/odoc_misc.mli
···2929(** This function creates a string from a Longident.t .*)
3030val string_of_longident : Longident.t -> string
31313232-(** This function returns the list of (label, type_expr) describing
3333- the methods of a type_expr in a Tobject.*)
3434-val get_fields : Types.type_expr -> (string * Types.type_expr) list
3535-3632(** get a string from a text *)
3733val string_of_text : Odoc_types.text -> string
3834
+10-12
ocamldoc/odoc_print.ml
···8787 | Cty_signature cs ->
8888 (* we delete vals and methods in order to not print them when
8989 displaying the type *)
9090+ let self_row =
9191+ Transient_expr.create Tnil
9292+ ~level:0 ~scope:Btype.lowest_level ~id:0
9393+ in
9094 let tself =
9195 let t = cs.csig_self in
9292- let t' = Transient_expr.create Tnil
9393- ~level:0 ~scope:Btype.lowest_level ~id:0 in
9494- let desc =
9595- Tobject (Transient_expr.type_expr t', ref None) in
9696+ let desc = Tobject (Transient_expr.type_expr self_row, ref None) in
9697 Transient_expr.create desc
9797- ~level:(get_level t)
9898- ~scope:(get_scope t)
9999- ~id:(get_id t)
9898+ ~level:(get_level t) ~scope:(get_scope t) ~id:(get_id t)
10099 in
101101- Cty_signature { csig_self = Transient_expr.type_expr tself;
100100+ Types.Cty_signature { csig_self = Transient_expr.type_expr tself;
101101+ csig_self_row = Transient_expr.type_expr self_row;
102102 csig_vars = Vars.empty ;
103103- csig_concr = Concr.empty ;
104104- csig_inher = []
105105- }
106106- | Cty_arrow (l, texp, ct) ->
103103+ csig_meths = Meths.empty ; }
104104+ | Types.Cty_arrow (l, texp, ct) ->
107105 let new_ct = iter ct in
108106 Cty_arrow (l, texp, new_ct)
109107 in
+2-2
ocamldoc/odoc_sig.ml
···104104 type_expr
105105106106 let search_method_type name class_sig =
107107- let fields = Odoc_misc.get_fields class_sig.Types.csig_self in
108108- List.assoc name fields
107107+ let (_, _, type_expr) = Types.Meths.find name class_sig.Types.csig_meths in
108108+ type_expr
109109 end
110110111111module type Info_retriever =
+2
stdlib/genlex.ml
···1313(* *)
1414(**************************************************************************)
15151616+[@@@ocaml.warning "-3"] (* ignore deprecation warning about module Stream *)
1717+1618type token =
1719 Kwd of string
1820 | Ident of string
+2
stdlib/genlex.mli
···4545 ["-pp"] command-line switch of the compilers.
4646*)
47474848+[@@@ocaml.warning "-3"] (* ignore deprecation warning about module Stream *)
4949+4850(** The type of tokens. The lexical classes are: [Int] and [Float]
4951 for integer and floating-point numbers; [String] for
5052 string literals, enclosed in double quotes; [Char] for
+2
stdlib/stdlib.mli
···14011401module Fun = Fun
14021402module Gc = Gc
14031403module Genlex = Genlex
14041404+[@@deprecated "Use the camlp-streams library instead."]
14041405module Hashtbl = Hashtbl
14051406module Int = Int
14061407module Int32 = Int32
···14351436module Stack = Stack
14361437module StdLabels = StdLabels
14371438module Stream = Stream
14391439+[@@deprecated "Use the camlp-streams library instead."]
14381440module String = String
14391441module StringLabels = StringLabels
14401442module Sys = Sys
+1
testsuite/tests/lib-stream/count_concat_bug.ml
···11(* TEST
22+ flags = "-w -3"
23 include testing
34*)
45
···1919type bar = < bar : unit >
2020type _ ty = Int : int ty
2121type dyn = Dyn : 'a ty -> dyn
2222-Lines 7-12, characters 0-5:
2323- 7 | class foo =
2424- 8 | object (this)
2222+Lines 8-12, characters 2-5:
2323+ 8 | ..object (this)
2524 9 | method foo (Dyn ty) =
262510 | match ty with
272611 | | Int -> (this :> bar)
282712 | end.................................
2929-Error: This class should be virtual.
3030- The following methods are undefined : bar
2828+Error: This non-virtual class has undeclared virtual methods.
2929+ The following methods were not declared : bar
3130|}];;
+5-5
testsuite/tests/typing-gadts/pr7391.ml
···2929 object ('a)
3030 method private virtual parent : < previous : 'a option; .. >
3131 end
3232-- : < child : child2; previous : child2 option > = <obj>
3232+- : < child : child1; previous : child1 option > = <obj>
3333|}]
34343535(* Worked in 4.03 *)
···4343 end
4444 end;;
4545[%%expect{|
4646-- : < child : unit -> child2; previous : child2 option > = <obj>
4646+- : < child : unit -> child1; previous : child1 option > = <obj>
4747|}]
48484949(* Worked in 4.03 *)
···5757 end
5858 end;;
5959[%%expect{|
6060-- : < child : unit -> child2; previous : child2 option > = <obj>
6060+- : < child : unit -> child1; previous : child1 option > = <obj>
6161|}]
62626363(* Didn't work in 4.03, but works in 4.07 *)
···7373 in o
7474 end;;
7575[%%expect{|
7676-- : < child : child2; previous : child2 option > = <obj>
7676+- : < child : child1; previous : child1 option > = <obj>
7777|}]
78787979(* Also didn't work in 4.03 *)
···9191 end;;
9292[%%expect{|
9393type gadt = Not_really_though : gadt
9494-- : < child : gadt -> child2; previous : child2 option > = <obj>
9494+- : < child : gadt -> child1; previous : child1 option > = <obj>
9595|}]
-9
testsuite/tests/typing-gadts/test.ml
···628628 in M.z
629629;; (* fails because of aliasing... *)
630630[%%expect{|
631631-Lines 2-4, characters 2-10:
632632-2 | ..match x with Int ->
633633-3 | let module M = struct type b = a let z = (y : b) end
634634-4 | in M.z
635635-Warning 18 [not-principal]:
636636- The return type of this pattern-matching is ambiguous.
637637- Please add a type annotation, as the choice of `a' is not principal.
638638-val f : 'a t -> 'a -> 'a = <fun>
639639-|}, Principal{|
640631Line 3, characters 46-47:
6416323 | let module M = struct type b = a let z = (y : b) end
642633 ^
···99end
1010[%%expect {|
1111class virtual t : object method virtual x : float end
1212-Line 4, characters 16-17:
1212+Line 4, characters 8-17:
13134 | inherit t
1414- ^
1414+ ^^^^^^^^^
1515Error: The method x has type int but is expected to have type float
1616 Type int is not compatible with type float
1717|}]
···1461463 | method foo = "foo"
1471474 | method private virtual cast: int
1481485 | end
149149-Error: The class type object method foo : string end
149149+Error: The class type
150150+ object method private virtual cast : int method foo : string end
150151 is not matched by the class type foo_t
151152 The virtual method cast cannot be hidden
152153|}]
+1-1
testsuite/tests/typing-misc/pr6416.ml
···219219 class b : a
220220 does not match
221221 class b : a/2
222222- The first class type has no method m
223222 The public method c cannot be hidden
223223+ The first class type has no method m
224224 Line 5, characters 4-74:
225225 Definition of class type a/1
226226 Line 2, characters 2-36:
···1212Error: The class type
1313 object
1414 val l :
1515- [ `Abs of
1616- string *
1717- ([> `App of
1818- [ `Abs of string * 'a | `App of expr * expr ] * exp ]
1919- as 'a)
2020- | `App of expr * expr ]
1515+ [ `Abs of string * ([> `App of 'a * exp ] as 'b)
1616+ | `App of expr * expr ] as 'a
2117 val r : exp
2222- method eval : (string, exp) Hashtbl.t -> 'a
1818+ method eval : (string, exp) Hashtbl.t -> 'b
2319 end
2420 is not matched by the class type exp
2521 The class type
2622 object
2723 val l :
2828- [ `Abs of
2929- string *
3030- ([> `App of
3131- [ `Abs of string * 'a | `App of expr * expr ] * exp ]
3232- as 'a)
3333- | `App of expr * expr ]
2424+ [ `Abs of string * ([> `App of 'a * exp ] as 'b)
2525+ | `App of expr * expr ] as 'a
3426 val r : exp
3535- method eval : (string, exp) Hashtbl.t -> 'a
2727+ method eval : (string, exp) Hashtbl.t -> 'b
3628 end
3729 is not matched by the class type
3830 object method eval : (string, exp) Hashtbl.t -> expr end
+2-3
testsuite/tests/typing-objects/Exemples.ml
···286286 Format.print_string ")"
287287end;;
288288[%%expect{|
289289-Line 3, characters 10-27:
289289+Line 3, characters 2-36:
2902903 | inherit printable_point y as super
291291- ^^^^^^^^^^^^^^^^^
291291+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292292Warning 13 [instance-variable-override]: the following instance variables are overridden by the class printable_point :
293293 x
294294-The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
295294class printable_color_point :
296295 int ->
297296 string ->
+355-17
testsuite/tests/typing-objects/Tests.ml
···1919end;;
2020[%%expect{|
2121class ['a] c : unit -> object constraint 'a = int method f : int c end
2222-and ['a] d : unit -> object constraint 'a = int method f : int c end
2222+and ['a] d : unit -> object constraint 'a = int method f : 'a c end
2323|}];;
2424(* class ['a] c : unit -> object constraint 'a = int method f : 'a c end *)
2525(* and ['a] d : unit -> object constraint 'a = int method f : 'a c end *)
···103103 method virtual f : int
104104end;;
105105[%%expect{|
106106-Lines 1-3, characters 0-3:
107107-1 | class x () = object
106106+Lines 1-3, characters 13-3:
107107+1 | .............object
1081082 | method virtual f : int
1091093 | end..
110110-Error: This class should be virtual. The following methods are undefined : f
110110+Error: This non-virtual class has virtual methods.
111111+ The following methods are virtual : f
111112|}];;
112113(* The class x should be virtual: its methods f is undefined *)
113114···162163class ['a, 'b] d :
163164 unit ->
164165 object
165165- constraint 'a = int -> 'c
166166- constraint 'b = 'a * < x : 'b > * 'c * 'd
167167- method f : 'a -> 'b -> unit
166166+ constraint 'a = int -> 'd
167167+ constraint 'b = 'a * (< x : 'b > as 'c) * 'd * 'e
168168+ method f : (int -> 'd) -> (int -> 'd) * 'c * 'd * 'e -> unit
168169 end
169170|}];;
170171···322323 constraint 'a = int -> bool
323324 val x : float list
324325 val y : 'b
325325- method f : 'a -> unit
326326+ method f : (int -> bool) -> unit
326327 method g : 'b
327328 end
328329|}];;
···335336 constraint 'a = int -> bool
336337 val x : float list
337338 val y : 'b
338338- method f : 'a -> unit
339339+ method f : (int -> bool) -> unit
339340 method g : 'b
340341 end
341342|}];;
···469470 method b = b
470471end;;
471472[%%expect{|
472472-Line 3, characters 10-13:
473473+Line 3, characters 2-13:
4734743 | inherit c 5
474474- ^^^
475475+ ^^^^^^^^^^^
475476Warning 13 [instance-variable-override]: the following instance variables are overridden by the class c :
476477 x
477477-The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
478478Line 4, characters 6-7:
4794794 | val y = 3
480480 ^
481481Warning 13 [instance-variable-override]: the instance variable y is overridden.
482482-The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
483483-Line 6, characters 10-13:
482482+Line 6, characters 2-13:
4844836 | inherit d 7
485485- ^^^
484484+ ^^^^^^^^^^^
486485Warning 13 [instance-variable-override]: the following instance variables are overridden by the class d :
487486 t z
488488-The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
489487Line 7, characters 6-7:
4904887 | val u = 3
491489 ^
492490Warning 13 [instance-variable-override]: the instance variable u is overridden.
493493-The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
494491class e :
495492 unit ->
496493 object
···923920Error: The ancestor variable super
924921 cannot be accessed from the definition of an instance variable
925922|}];;
923923+924924+(* Some more tests of class idiosyncrasies *)
925925+926926+class c = object method private m = 3 end
927927+ and d = object method o = object inherit c end end;;
928928+[%%expect {|
929929+class c : object method private m : int end
930930+and d : object method o : c end
931931+|}];;
932932+933933+class c = object(_ : 'self)
934934+ method o = object(_ : 'self) method o = assert false end
935935+end;;
936936+[%%expect {|
937937+Line 2, characters 13-58:
938938+2 | method o = object(_ : 'self) method o = assert false end
939939+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
940940+Error: Cannot close type of object literal: < o : '_weak3; _.. >
941941+ it has been unified with the self type of a class that is not yet
942942+ completely defined.
943943+|}];;
944944+945945+class c = object
946946+ method m = 1
947947+ inherit object (self)
948948+ method n = self#m
949949+ end
950950+ end;;
951951+[%%expect {|
952952+Line 4, characters 17-23:
953953+4 | method n = self#m
954954+ ^^^^^^
955955+Warning 17 [undeclared-virtual-method]: the virtual method m is not declared.
956956+class c : object method m : int method n : int end
957957+|}];;
958958+959959+class [ 'a ] c = object (_ : 'a) end;;
960960+let o = object
961961+ method m = 1
962962+ inherit [ < m : int > ] c
963963+ end;;
964964+[%%expect {|
965965+class ['a] c : object ('a) constraint 'a = < .. > end
966966+Line 4, characters 14-25:
967967+4 | inherit [ < m : int > ] c
968968+ ^^^^^^^^^^^
969969+Error: The type parameter < m : int >
970970+ does not meet its constraint: it should be < .. >
971971+ Self type cannot be unified with a closed object type
972972+|}];;
973973+974974+class type [ 'a ] d = object method a : 'a method b : 'a end
975975+class c : ['a] d = object (self) method a = 1 method b = assert false end;;
976976+[%%expect {|
977977+class type ['a] d = object method a : 'a method b : 'a end
978978+Line 2, characters 19-73:
979979+2 | class c : ['a] d = object (self) method a = 1 method b = assert false end;;
980980+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
981981+Error: The class type object method a : int method b : 'a end
982982+ is not matched by the class type ['_a] d
983983+ The class type object method a : int method b : 'a end
984984+ is not matched by the class type
985985+ object method a : 'a method b : 'a end
986986+ The method a has type int but is expected to have type 'a
987987+ Type int is not compatible with type 'a
988988+|}];;
989989+990990+class type ['a] ct = object ('a) end
991991+class c : [ < a : int; ..> ] ct = object method a = 3 end;;
992992+[%%expect {|
993993+class type ['a] ct = object ('a) constraint 'a = < .. > end
994994+Line 2, characters 10-31:
995995+2 | class c : [ < a : int; ..> ] ct = object method a = 3 end;;
996996+ ^^^^^^^^^^^^^^^^^^^^^
997997+Error: This non-virtual class has undeclared virtual methods.
998998+ The following methods were not declared : a
999999+|}];;
10001000+10011001+class virtual c : [ < a : int; ..> ] ct = object method a = 3 end;;
10021002+[%%expect {|
10031003+class virtual c : object method virtual a : int end
10041004+|}];;
10051005+10061006+class c : object
10071007+ method m : < m : 'a > as 'a
10081008+ end = object (self)
10091009+ method m = self
10101010+end;;
10111011+[%%expect {|
10121012+Lines 3-5, characters 8-3:
10131013+3 | ........object (self)
10141014+4 | method m = self
10151015+5 | end..
10161016+Error: The class type object ('a) method m : 'a end
10171017+ is not matched by the class type
10181018+ object method m : < m : 'a > as 'a end
10191019+ The method m has type < m : 'a; .. > as 'a
10201020+ but is expected to have type < m : 'b > as 'b
10211021+ Type 'a is not compatible with type < > as 'b
10221022+|}];;
10231023+10241024+class c :
10251025+ object
10261026+ method foo : < foo : int; .. > -> < foo : int> -> unit
10271027+ end =
10281028+ object
10291029+ method foo : 'a. (< foo : int; .. > as 'a) -> 'a -> unit = assert false
10301030+ end;;
10311031+[%%expect {|
10321032+Lines 5-7, characters 2-5:
10331033+5 | ..object
10341034+6 | method foo : 'a. (< foo : int; .. > as 'a) -> 'a -> unit = assert false
10351035+7 | end..
10361036+Error: The class type
10371037+ object method foo : (< foo : int; .. > as 'a) -> 'a -> unit end
10381038+ is not matched by the class type
10391039+ object method foo : < foo : int; .. > -> < foo : int > -> unit end
10401040+ The method foo has type 'a. (< foo : int; .. > as 'a) -> 'a -> unit
10411041+ but is expected to have type
10421042+ 'b. (< foo : int; .. > as 'b) -> < foo : int > -> unit
10431043+ Type 'c is not compatible with type < >
10441044+|}];;
10451045+10461046+10471047+class c = (fun x -> object(_:'foo) end) 3;;
10481048+[%%expect {|
10491049+class c : object end
10501050+|}];;
10511051+10521052+class virtual c =
10531053+ ((fun (x : 'self -> unit) -> object(_:'self) end) (fun (_ : < a : int; .. >) -> ())
10541054+ : object method virtual a : int end)
10551055+[%%expect {|
10561056+class virtual c : object method virtual a : int end
10571057+|}];;
10581058+10591059+class c = object
10601060+ val x = 3
10611061+ method o = {< x = 4; y = 5 >}
10621062+ val y = 4
10631063+end;;
10641064+[%%expect {|
10651065+class c : object ('a) val x : int val y : int method o : 'a end
10661066+|}];;
10671067+10681068+class c : object('self) method m : < m : 'a; x : int; ..> -> unit as 'a end =
10691069+ object (_ : 'self) method m (_ : 'self) = () end;;
10701070+[%%expect {|
10711071+Line 2, characters 4-52:
10721072+2 | object (_ : 'self) method m (_ : 'self) = () end;;
10731073+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10741074+Error: The class type object ('a) method m : 'a -> unit end
10751075+ is not matched by the class type
10761076+ object method m : < m : 'a; x : int; .. > -> unit as 'a end
10771077+ The method m has type (< m : 'a -> unit; .. > as 'a) -> unit
10781078+ but is expected to have type
10791079+ 'b. (< m : 'c; x : int; .. > as 'b) -> unit as 'c
10801080+ Type 'a is not compatible with type < x : int; .. >
10811081+|}];;
10821082+10831083+let is_empty (x : < >) = ()
10841084+class c = object (self) method private foo = is_empty self end;;
10851085+[%%expect {|
10861086+val is_empty : < > -> unit = <fun>
10871087+Line 2, characters 54-58:
10881088+2 | class c = object (self) method private foo = is_empty self end;;
10891089+ ^^^^
10901090+Error: This expression has type < .. > but an expression was expected of type
10911091+ < >
10921092+ Self type cannot be unified with a closed object type
10931093+|}];;
10941094+10951095+(* Warnings about private methods implicitly made public *)
10961096+let has_foo (x : < foo : 'a; .. >) = ()
10971097+10981098+class c = object (self) method private foo = 5 initializer has_foo self end;;
10991099+[%%expect {|
11001100+val has_foo : < foo : 'a; .. > -> unit = <fun>
11011101+Line 3, characters 10-75:
11021102+3 | class c = object (self) method private foo = 5 initializer has_foo self end;;
11031103+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11041104+Warning 15 [implicit-public-methods]: the following private methods were made public implicitly:
11051105+ foo.
11061106+class c : object method foo : int end
11071107+|}];;
11081108+11091109+class type c = object(< foo : 'a; ..>) method private foo : int end;;
11101110+[%%expect {|
11111111+class type c = object method foo : int end
11121112+|}];;
11131113+11141114+class ['a] p = object (_ : 'a) method private foo = 5 end;;
11151115+class c = [ < foo : int; .. > ] p;;
11161116+[%%expect {|
11171117+class ['a] p :
11181118+ object ('a) constraint 'a = < .. > method private foo : int end
11191119+class c : object method foo : int end
11201120+|}];;
11211121+11221122+(* Errors for undefined methods *)
11231123+11241124+class c = object method virtual foo : int end;;
11251125+[%%expect {|
11261126+Line 1, characters 10-45:
11271127+1 | class c = object method virtual foo : int end;;
11281128+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11291129+Error: This non-virtual class has virtual methods.
11301130+ The following methods are virtual : foo
11311131+|}];;
11321132+11331133+class type ct = object method virtual foo : int end;;
11341134+[%%expect {|
11351135+Line 1, characters 16-51:
11361136+1 | class type ct = object method virtual foo : int end;;
11371137+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11381138+Error: This non-virtual class type has virtual methods.
11391139+ The following methods are virtual : foo
11401140+|}];;
11411141+11421142+let o = object method virtual foo : int end;;
11431143+[%%expect {|
11441144+Line 1, characters 8-43:
11451145+1 | let o = object method virtual foo : int end;;
11461146+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11471147+Error: This object has virtual methods.
11481148+ The following methods are virtual : foo
11491149+|}];;
11501150+11511151+class c = object(self) initializer self#foo end;;
11521152+[%%expect {|
11531153+Line 1, characters 35-39:
11541154+1 | class c = object(self) initializer self#foo end;;
11551155+ ^^^^
11561156+Error: This expression has no method foo
11571157+|}];;
11581158+11591159+let o = object(self) initializer self#foo end;;
11601160+[%%expect {|
11611161+Line 1, characters 33-37:
11621162+1 | let o = object(self) initializer self#foo end;;
11631163+ ^^^^
11641164+Error: This expression has no method foo
11651165+|}];;
11661166+11671167+let has_foo (x : < foo : int; ..>) = ()
11681168+class c = object(self) initializer has_foo self end;;
11691169+[%%expect {|
11701170+val has_foo : < foo : int; .. > -> unit = <fun>
11711171+Line 2, characters 10-51:
11721172+2 | class c = object(self) initializer has_foo self end;;
11731173+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11741174+Error: This non-virtual class has undeclared virtual methods.
11751175+ The following methods were not declared : foo
11761176+|}];;
11771177+11781178+let o = object(self) initializer has_foo self end;;
11791179+[%%expect {|
11801180+Line 1, characters 41-45:
11811181+1 | let o = object(self) initializer has_foo self end;;
11821182+ ^^^^
11831183+Error: This expression has type < > but an expression was expected of type
11841184+ < foo : int; .. >
11851185+ The first object type has no method foo
11861186+|}];;
11871187+11881188+class c = object(_ : < foo : int; ..>) end;;
11891189+[%%expect {|
11901190+Line 1, characters 10-42:
11911191+1 | class c = object(_ : < foo : int; ..>) end;;
11921192+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11931193+Error: This non-virtual class has undeclared virtual methods.
11941194+ The following methods were not declared : foo
11951195+|}];;
11961196+11971197+class type ct = object(< foo : int; ..>) end;;
11981198+[%%expect {|
11991199+Line 1, characters 16-44:
12001200+1 | class type ct = object(< foo : int; ..>) end;;
12011201+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12021202+Error: This non-virtual class type has undeclared virtual methods.
12031203+ The following methods were not declared : foo
12041204+|}];;
12051205+12061206+let o = object(_ : < foo : int; ..>) end;;
12071207+[%%expect {|
12081208+Line 1, characters 8-40:
12091209+1 | let o = object(_ : < foo : int; ..>) end;;
12101210+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12111211+Error: This object has undeclared virtual methods.
12121212+ The following methods were not declared : foo
12131213+|}];;
12141214+12151215+(* Shadowing/overriding methods in class types *)
12161216+12171217+class type c = object
12181218+ val x : int
12191219+ val x : float
12201220+end;;
12211221+[%%expect {|
12221222+class type c = object val x : float end
12231223+|}];;
12241224+12251225+class type c = object
12261226+ val x : int
12271227+ val mutable x : int
12281228+end;;
12291229+[%%expect {|
12301230+class type c = object val mutable x : int end
12311231+|}];;
12321232+12331233+class type c = object
12341234+ val mutable x : int
12351235+ val x : int
12361236+end;;
12371237+[%%expect {|
12381238+class type c = object val x : int end
12391239+|}];;
12401240+12411241+class type virtual c = object
12421242+ val virtual x : int
12431243+ val x : int
12441244+end;;
12451245+[%%expect {|
12461246+class type c = object val x : int end
12471247+|}];;
12481248+12491249+class type virtual c = object
12501250+ val x : int
12511251+ val virtual x : int
12521252+end;;
12531253+[%%expect {|
12541254+class type c = object val x : int end
12551255+|}];;
12561256+12571257+class type virtual c = object
12581258+ val x : int
12591259+ val virtual x : float
12601260+end;;
12611261+[%%expect {|
12621262+class type c = object val x : float end
12631263+|}];;
+151-10
testsuite/tests/typing-objects/dummy.ml
···6060 end
6161end;;
6262[%%expect{|
6363-class foo1 : object method child : child2 method previous : child2 option end
6363+class foo1 : object method child : child1 method previous : child1 option end
6464|}]
65656666class nested = object
···7676[%%expect{|
7777class nested :
7878 object
7979- method obj : < child : unit -> child2; previous : child2 option >
7979+ method obj : < child : unit -> child1; previous : child1 option >
8080 end
8181|}]
8282···9393end;;
9494[%%expect{|
9595class just_to_see :
9696- object method child : child2 method previous : child2 option end
9696+ object method child : child1 method previous : child1 option end
9797|}]
98989999class just_to_see2 = object
···111111end;;
112112[%%expect{|
113113class just_to_see2 :
114114- object method obj : < child : child2; previous : child2 option > end
114114+ object method obj : < child : child1; previous : child1 option > end
115115|}]
116116117117type gadt = Not_really_though : gadt
···127127[%%expect{|
128128type gadt = Not_really_though : gadt
129129class just_to_see3 :
130130- object method child : gadt -> child2 method previous : child2 option end
130130+ object method child : gadt -> child1 method previous : child1 option end
131131|}]
132132133133class leading_up_to = object(self : 'a)
···1441445 | inherit child1 self
1451456 | inherit child2
1461467 | end
147147-Error: Cannot close type of object literal:
148148- < child : '_weak1; previous : 'a option; _.. > as 'a
149149- it has been unified with the self type of a class that is not yet
150150- completely defined.
147147+Error: This object has undeclared virtual methods.
148148+ The following methods were not declared : previous child
151149|}]
152150153151class assertion_failure = object(self : 'a)
···171169 9 | method child = assert false
17217010 | end
173171Error: Cannot close type of object literal:
174174- < child : '_weak2; previous : 'a option; _.. > as 'a
172172+ < child : '_weak1; previous : 'a option; _.. > as 'a
175173 it has been unified with the self type of a class that is not yet
176174 completely defined.
177175|}]
176176+177177+(* MPR#7894 and variations *)
178178+class parameter_contains_self app = object(self)
179179+ method invalidate : unit =
180180+ app#redrawWidget self
181181+end;;
182182+[%%expect{|
183183+class parameter_contains_self :
184184+ < redrawWidget : 'a -> unit; .. > ->
185185+ object ('a) method invalidate : unit end
186186+|}]
187187+188188+class closes_via_inheritance param =
189189+ let _ = new parameter_contains_self param in object
190190+ inherit parameter_contains_self param
191191+ end;;
192192+[%%expect{|
193193+Line 3, characters 36-41:
194194+3 | inherit parameter_contains_self param
195195+ ^^^^^
196196+Error: This expression has type
197197+ < redrawWidget : parameter_contains_self -> unit; .. >
198198+ but an expression was expected of type
199199+ < redrawWidget : (< invalidate : unit; .. > as 'a) -> unit; .. >
200200+ Type parameter_contains_self = < invalidate : unit >
201201+ is not compatible with type < invalidate : unit; .. > as 'a
202202+ Self type cannot be unified with a closed object type
203203+|}]
204204+205205+class closes_via_application param =
206206+ let _ = new parameter_contains_self param in
207207+ parameter_contains_self param;;
208208+[%%expect{|
209209+Line 3, characters 26-31:
210210+3 | parameter_contains_self param;;
211211+ ^^^^^
212212+Error: This expression has type
213213+ < redrawWidget : parameter_contains_self -> unit; .. >
214214+ but an expression was expected of type
215215+ < redrawWidget : (< invalidate : unit; .. > as 'a) -> unit; .. >
216216+ Type parameter_contains_self = < invalidate : unit >
217217+ is not compatible with type < invalidate : unit; .. > as 'a
218218+ Self type cannot be unified with a closed object type
219219+|}]
220220+221221+let escapes_via_inheritance param =
222222+ let module Local = struct
223223+ class c = object
224224+ inherit parameter_contains_self param
225225+ end
226226+ end in
227227+ ();;
228228+[%%expect{|
229229+Line 4, characters 38-43:
230230+4 | inherit parameter_contains_self param
231231+ ^^^^^
232232+Error: This expression has type 'a but an expression was expected of type
233233+ < redrawWidget : < invalidate : unit; .. > -> unit; .. >
234234+ Self type cannot escape its class
235235+|}]
236236+237237+let escapes_via_application param =
238238+ let module Local = struct
239239+ class c = parameter_contains_self param
240240+ end in
241241+ ();;
242242+[%%expect{|
243243+Line 3, characters 38-43:
244244+3 | class c = parameter_contains_self param
245245+ ^^^^^
246246+Error: This expression has type 'a but an expression was expected of type
247247+ < redrawWidget : < invalidate : unit; .. > -> unit; .. >
248248+ Self type cannot escape its class
249249+|}]
250250+251251+let can_close_object_via_inheritance param =
252252+ let _ = new parameter_contains_self param in object
253253+ inherit parameter_contains_self param
254254+ end;;
255255+[%%expect{|
256256+Line 3, characters 36-41:
257257+3 | inherit parameter_contains_self param
258258+ ^^^^^
259259+Error: This expression has type
260260+ < redrawWidget : parameter_contains_self -> unit; .. >
261261+ but an expression was expected of type
262262+ < redrawWidget : (< invalidate : unit; .. > as 'a) -> unit; .. >
263263+ Type parameter_contains_self = < invalidate : unit >
264264+ is not compatible with type < invalidate : unit; .. > as 'a
265265+ Self type cannot be unified with a closed object type
266266+|}]
267267+268268+let can_escape_object_via_inheritance param = object
269269+ inherit parameter_contains_self param
270270+ end;;
271271+[%%expect{|
272272+val can_escape_object_via_inheritance :
273273+ < redrawWidget : parameter_contains_self -> unit; .. > ->
274274+ parameter_contains_self = <fun>
275275+|}]
276276+277277+let can_close_object_explicitly = object (_ : < i : int >)
278278+ method i = 5
279279+end;;
280280+[%%expect{|
281281+val can_close_object_explicitly : < i : int > = <obj>
282282+|}]
283283+284284+let cannot_close_object_explicitly_with_inheritance = object
285285+ inherit object (_ : < i : int >)
286286+ method i = 5
287287+ end
288288+end;;
289289+[%%expect{|
290290+Line 2, characters 17-34:
291291+2 | inherit object (_ : < i : int >)
292292+ ^^^^^^^^^^^^^^^^^
293293+Error: This pattern cannot match self: it only matches values of type
294294+ < i : int >
295295+|}]
296296+297297+class closes_after_constraint =
298298+ ((fun (x : 'a) -> object (_:'a) end) : 'a -> object('a) end) (object end);;
299299+[%%expect{|
300300+Line 2, characters 63-75:
301301+2 | ((fun (x : 'a) -> object (_:'a) end) : 'a -> object('a) end) (object end);;
302302+ ^^^^^^^^^^^^
303303+Error: This expression has type < > but an expression was expected of type
304304+ < .. >
305305+ Self type cannot be unified with a closed object type
306306+|}];;
307307+308308+class type ['a] ct = object ('a) end
309309+class type closes_via_application = [ <m : int> ] ct;;
310310+[%%expect{|
311311+class type ['a] ct = object ('a) constraint 'a = < .. > end
312312+Line 2, characters 38-47:
313313+2 | class type closes_via_application = [ <m : int> ] ct;;
314314+ ^^^^^^^^^
315315+Error: The type parameter < m : int >
316316+ does not meet its constraint: it should be < .. >
317317+ Self type cannot be unified with a closed object type
318318+|}];;
+1-2
testsuite/tests/typing-objects/errors.ml
···4848Line 1, characters 37-41:
49491 | let foo = object (self) method foo = self#bar end;;
5050 ^^^^
5151-Error: This expression has type < foo : 'a >
5252- It has no method bar
5151+Error: This expression has no method bar
5352|}]
+1-2
testsuite/tests/typing-objects/pr6907_bad.ml
···1818 ^^^^^^^^^^^^^^^^^^^^^^^^^
1919Error: Some type variables are unbound in this type:
2020 class base : 'e -> ['e] t
2121- The method update has type 'e -> < update : 'a; .. > as 'a where 'e
2222- is unbound
2121+ The method update has type 'e -> #base where 'e is unbound
2322|}];;
+4-5
testsuite/tests/typing-poly/poly.ml
···11061106Warning 15 [implicit-public-methods]: the following private methods were made public implicitly:
11071107 n.
11081108val f : unit -> < m : int; n : int > = <fun>
11091109-Line 5, characters 11-56:
11091109+Line 5, characters 27-39:
111011105 | let f () = object (self:c) method n = 1 method m = 2 end;;
11111111- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11121112-Error: This object is expected to have type c but actually has type
11131113- < m : int; n : 'a >
11141114- The first object type has no method n
11111111+ ^^^^^^^^^^^^
11121112+Error: This object is expected to have type : c
11131113+ This type does not have a method n.
11151114|}];;
1116111511171116
···11+(* TEST
22+ flags = " -w +A "
33+ * expect
44+*)
55+66+class c = object
77+88+ val a =
99+ let b = 5 in ()
1010+ [@@warning "-26"]
1111+1212+ val x =
1313+ let y = 5 in ()
1414+1515+end;;
1616+[%%expect {|
1717+Line 8, characters 8-9:
1818+8 | let y = 5 in ()
1919+ ^
2020+Warning 26 [unused-var]: unused variable y.
2121+class c : object val a : unit val x : unit end
2222+|}];;
2323+2424+class c = object
2525+2626+ method a =
2727+ let b = 5 in ()
2828+ [@@warning "-26"]
2929+3030+ method x =
3131+ let y = 5 in ()
3232+3333+end;;
3434+[%%expect {|
3535+Line 8, characters 8-9:
3636+8 | let y = 5 in ()
3737+ ^
3838+Warning 26 [unused-var]: unused variable y.
3939+class c : object method a : unit method x : unit end
4040+|}];;
4141+4242+class c = object
4343+4444+ initializer
4545+ let b = 5 in ()
4646+ [@@warning "-26"]
4747+4848+ initializer
4949+ let y = 5 in ()
5050+5151+end;;
5252+[%%expect {|
5353+Line 8, characters 8-9:
5454+8 | let y = 5 in ()
5555+ ^
5656+Warning 26 [unused-var]: unused variable y.
5757+class c : object end
5858+|}];;
5959+6060+class c = (object
6161+6262+ val a =
6363+ let b = 5 in ()
6464+6565+end [@warning "-26"])
6666+[%%expect {|
6767+class c : object val a : unit end
6868+|}];;
6969+7070+class c = object
7171+7272+ val a =
7373+ let b = 5 in ()
7474+7575+ [@@@warning "-26"]
7676+7777+ val x =
7878+ let y = 5 in ()
7979+8080+end;;
8181+[%%expect {|
8282+Line 4, characters 8-9:
8383+4 | let b = 5 in ()
8484+ ^
8585+Warning 26 [unused-var]: unused variable b.
8686+class c : object val a : unit val x : unit end
8787+|}];;
8888+8989+type dep
9090+[@@deprecated "deprecated"]
9191+9292+class type c = object
9393+9494+ val a : dep
9595+ [@@warning "-3"]
9696+9797+ val x : dep
9898+9999+end;;
100100+[%%expect {|
101101+type dep
102102+Line 9, characters 10-13:
103103+9 | val x : dep
104104+ ^^^
105105+Alert deprecated: dep
106106+deprecated
107107+class type c = object val a : dep val x : dep end
108108+|}];;
109109+110110+class type c = object
111111+112112+ method a : dep
113113+ [@@warning "-3"]
114114+115115+ method x : dep
116116+117117+end;;
118118+[%%expect {|
119119+Line 6, characters 13-16:
120120+6 | method x : dep
121121+ ^^^
122122+Alert deprecated: dep
123123+deprecated
124124+class type c = object method a : dep method x : dep end
125125+|}];;
126126+127127+class type c = object [@warning "-3"]
128128+129129+ val a : dep
130130+131131+end
132132+[%%expect {|
133133+class type c = object val a : dep end
134134+|}];;
135135+136136+class type c = object
137137+138138+ val a : dep
139139+140140+ [@@@warning "-3"]
141141+142142+ val x : dep
143143+144144+end;;
145145+[%%expect {|
146146+Line 3, characters 10-13:
147147+3 | val a : dep
148148+ ^^^
149149+Alert deprecated: dep
150150+deprecated
151151+class type c = object val a : dep val x : dep end
152152+|}];;
···5858}
59596060#########################################################################
6161+# Display environment information
6262+uname -a
6363+for i in issue redhat-release ; do
6464+ if test -e /etc/$i ; then
6565+ echo "/etc/$i content:"
6666+ cat /etc/$i | sed -e 's/^/| /'
6767+ fi
6868+done
6969+if command -v gcc >/dev/null ; then
7070+ echo "gcc info:"
7171+ gcc --version --verbose 2>&1 | sed -e 's/^/| /'
7272+fi
7373+7474+#########################################################################
6175# be verbose
6276set -x
6377
+116-4
typing/btype.ml
···411411 it.it_class_type it cty
412412 | Cty_signature cs ->
413413 it.it_type_expr it cs.csig_self;
414414+ it.it_type_expr it cs.csig_self_row;
414415 Vars.iter (fun _ (_,_,ty) -> it.it_type_expr it ty) cs.csig_vars;
415415- List.iter
416416- (fun (p, tl) -> it.it_path p; List.iter (it.it_type_expr it) tl)
417417- cs.csig_inher
416416+ Meths.iter (fun _ (_,_,ty) -> it.it_type_expr it ty) cs.csig_meths
418417 | Cty_arrow (_, ty, cty) ->
419418 it.it_type_expr it ty;
420419 it.it_class_type it cty
···639638640639let extract_label l ls = extract_label_aux [] l ls
641640641641+ (*******************************)
642642+ (* Operations on class types *)
643643+ (*******************************)
644644+645645+let rec signature_of_class_type =
646646+ function
647647+ Cty_constr (_, _, cty) -> signature_of_class_type cty
648648+ | Cty_signature sign -> sign
649649+ | Cty_arrow (_, _, cty) -> signature_of_class_type cty
650650+651651+let rec class_body cty =
652652+ match cty with
653653+ Cty_constr _ ->
654654+ cty (* Only class bodies can be abbreviated *)
655655+ | Cty_signature _ ->
656656+ cty
657657+ | Cty_arrow (_, _, cty) ->
658658+ class_body cty
659659+660660+(* Fully expand the head of a class type *)
661661+let rec scrape_class_type =
662662+ function
663663+ Cty_constr (_, _, cty) -> scrape_class_type cty
664664+ | cty -> cty
665665+666666+let rec class_type_arity =
667667+ function
668668+ Cty_constr (_, _, cty) -> class_type_arity cty
669669+ | Cty_signature _ -> 0
670670+ | Cty_arrow (_, _, cty) -> 1 + class_type_arity cty
671671+672672+let rec abbreviate_class_type path params cty =
673673+ match cty with
674674+ Cty_constr (_, _, _) | Cty_signature _ ->
675675+ Cty_constr (path, params, cty)
676676+ | Cty_arrow (l, ty, cty) ->
677677+ Cty_arrow (l, ty, abbreviate_class_type path params cty)
678678+679679+let self_type cty =
680680+ (signature_of_class_type cty).csig_self
681681+682682+let self_type_row cty =
683683+ (signature_of_class_type cty).csig_self_row
684684+685685+(* Return the methods of a class signature *)
686686+let methods sign =
687687+ Meths.fold
688688+ (fun name _ l -> name :: l)
689689+ sign.csig_meths []
690690+691691+(* Return the virtual methods of a class signature *)
692692+let virtual_methods sign =
693693+ Meths.fold
694694+ (fun name (_priv, vr, _ty) l ->
695695+ match vr with
696696+ | Virtual -> name :: l
697697+ | Concrete -> l)
698698+ sign.csig_meths []
699699+700700+(* Return the concrete methods of a class signature *)
701701+let concrete_methods sign =
702702+ Meths.fold
703703+ (fun name (_priv, vr, _ty) s ->
704704+ match vr with
705705+ | Virtual -> s
706706+ | Concrete -> MethSet.add name s)
707707+ sign.csig_meths MethSet.empty
708708+709709+(* Return the public methods of a class signature *)
710710+let public_methods sign =
711711+ Meths.fold
712712+ (fun name (priv, _vr, _ty) l ->
713713+ match priv with
714714+ | Private -> l
715715+ | Public -> name :: l)
716716+ sign.csig_meths []
717717+718718+(* Return the instance variables of a class signature *)
719719+let instance_vars sign =
720720+ Vars.fold
721721+ (fun name _ l -> name :: l)
722722+ sign.csig_vars []
723723+724724+(* Return the virtual instance variables of a class signature *)
725725+let virtual_instance_vars sign =
726726+ Vars.fold
727727+ (fun name (_mut, vr, _ty) l ->
728728+ match vr with
729729+ | Virtual -> name :: l
730730+ | Concrete -> l)
731731+ sign.csig_vars []
732732+733733+(* Return the concrete instance variables of a class signature *)
734734+let concrete_instance_vars sign =
735735+ Vars.fold
736736+ (fun name (_mut, vr, _ty) s ->
737737+ match vr with
738738+ | Virtual -> s
739739+ | Concrete -> VarSet.add name s)
740740+ sign.csig_vars VarSet.empty
741741+742742+let method_type label sign =
743743+ match Meths.find label sign.csig_meths with
744744+ | (_, _, ty) -> ty
745745+ | exception Not_found -> assert false
746746+747747+let instance_variable_type label sign =
748748+ match Vars.find label sign.csig_vars with
749749+ | (_, _, ty) -> ty
750750+ | exception Not_found -> assert false
751751+642752 (**********************************)
643753 (* Utilities for level-marking *)
644754 (**********************************)
···693803694804let unmark_class_signature sign =
695805 unmark_type sign.csig_self;
696696- Vars.iter (fun _l (_m, _v, t) -> unmark_type t) sign.csig_vars
806806+ unmark_type sign.csig_self_row;
807807+ Vars.iter (fun _l (_m, _v, t) -> unmark_type t) sign.csig_vars;
808808+ Meths.iter (fun _l (_m, _v, t) -> unmark_type t) sign.csig_meths
697809698810let unmark_class_type cty =
699811 unmark_iterators.it_class_type unmark_iterators cty
+53
typing/btype.mli
···269269 whether (label, value) was at the head of the list,
270270 list without the extracted (label, value) *)
271271272272+(**** Utilities for class types ****)
273273+274274+(* Get the class signature within a class type *)
275275+val signature_of_class_type : class_type -> class_signature
276276+277277+(* Get the body of a class type (i.e. without parameters) *)
278278+val class_body : class_type -> class_type
279279+280280+(* Fully expand the head of a class type *)
281281+val scrape_class_type : class_type -> class_type
282282+283283+(* Return the number of parameters of a class type *)
284284+val class_type_arity : class_type -> int
285285+286286+(* Given a path and type parameters, add an abbreviation to a class type *)
287287+val abbreviate_class_type :
288288+ Path.t -> type_expr list -> class_type -> class_type
289289+290290+(* Get the self type of a class *)
291291+val self_type : class_type -> type_expr
292292+293293+(* Get the row variable of the self type of a class *)
294294+val self_type_row : class_type -> type_expr
295295+296296+(* Return the methods of a class signature *)
297297+val methods : class_signature -> string list
298298+299299+(* Return the virtual methods of a class signature *)
300300+val virtual_methods : class_signature -> string list
301301+302302+(* Return the concrete methods of a class signature *)
303303+val concrete_methods : class_signature -> MethSet.t
304304+305305+(* Return the public methods of a class signature *)
306306+val public_methods : class_signature -> string list
307307+308308+(* Return the instance variables of a class signature *)
309309+val instance_vars : class_signature -> string list
310310+311311+(* Return the virtual instance variables of a class signature *)
312312+val virtual_instance_vars : class_signature -> string list
313313+314314+(* Return the concrete instance variables of a class signature *)
315315+val concrete_instance_vars : class_signature -> VarSet.t
316316+317317+(* Return the type of a method.
318318+ @raises [Assert_failure] if the class has no such method. *)
319319+val method_type : label -> class_signature -> type_expr
320320+321321+(* Return the type of an instance variable.
322322+ @raises [Assert_failure] if the class has no such method. *)
323323+val instance_variable_type : label -> class_signature -> type_expr
324324+272325(**** Forward declarations ****)
273326val print_raw: (Format.formatter -> type_expr -> unit) ref
274327
+559-411
typing/ctype.ml
···232232(* Re-export generic type creators *)
233233234234let newty desc = newty2 ~level:!current_level desc
235235+let new_scoped_ty scope desc = newty3 ~level:!current_level ~scope desc
235236236237let newvar ?name () = newty2 ~level:!current_level (Tvar name)
237238let newvar2 ?name level = newty2 ~level:level (Tvar name)
···337338 in
338339 associate [] [] [] (fields1, fields2)
339340340340-let rec has_dummy_method ty =
341341- match get_desc ty with
342342- Tfield (m, _, _, ty2) ->
343343- m = dummy_method || has_dummy_method ty2
344344- | _ -> false
345345-346346-let is_self_type = function
347347- | Tobject (ty, _) -> has_dummy_method ty
348348- | _ -> false
349349-350341(**** Check whether an object is open ****)
351342352343(* +++ The abbreviation should eventually be expanded *)
···366357 | Tvar _ -> false
367358 | _ -> true
368359369369-(**** Close an object ****)
370370-371371-let close_object ty =
372372- let rec close ty =
373373- match get_desc ty with
374374- Tvar _ ->
375375- link_type ty (newty2 ~level:(get_level ty) Tnil); true
376376- | Tfield(lab, _, _, _) when lab = dummy_method ->
377377- false
378378- | Tfield(_, _, _, ty') -> close ty'
379379- | _ -> assert false
380380- in
381381- match get_desc ty with
382382- Tobject (ty, _) -> close ty
383383- | _ -> assert false
384384-385360(**** Row variable of an object type ****)
386361387387-let row_variable ty =
388388- let rec find ty =
389389- match get_desc ty with
390390- Tfield (_, _, _, ty) -> find ty
391391- | Tvar _ -> ty
392392- | _ -> assert false
393393- in
362362+let rec fields_row_variable ty =
394363 match get_desc ty with
395395- Tobject (fi, _) -> find fi
396396- | _ -> assert false
364364+ | Tfield (_, _, _, ty) -> fields_row_variable ty
365365+ | Tvar _ -> ty
366366+ | _ -> assert false
397367398368(**** Object name manipulation ****)
399369(* +++ Bientot obsolete *)
400370401401-let set_object_name id rv params ty =
371371+let set_object_name id params ty =
402372 match get_desc ty with
403403- Tobject (_fi, nm) ->
373373+ | Tobject (fi, nm) ->
374374+ let rv = fields_row_variable fi in
404375 set_name nm (Some (Path.Pident id, rv::params))
405405- | _ ->
406406- assert false
376376+ | Tconstr (_, _, _) -> ()
377377+ | _ -> fatal_error "Ctype.set_object_name"
407378408379let remove_object_name ty =
409380 match get_desc ty with
···411382 | Tconstr (_, _, _) -> ()
412383 | _ -> fatal_error "Ctype.remove_object_name"
413384414414-(**** Hiding of private methods ****)
415415-416416-let hide_private_methods ty =
417417- match get_desc ty with
418418- Tobject (fi, nm) ->
419419- nm := None;
420420- let (fl, _) = flatten_fields fi in
421421- List.iter
422422- (function (_, k, _) ->
423423- match field_kind_repr k with
424424- Fvar r -> set_kind r Fabsent
425425- | _ -> ())
426426- fl
427427- | _ ->
428428- assert false
429429-430430-431431- (*******************************)
432432- (* Operations on class types *)
433433- (*******************************)
434434-435435-436436-let rec signature_of_class_type =
437437- function
438438- Cty_constr (_, _, cty) -> signature_of_class_type cty
439439- | Cty_signature sign -> sign
440440- | Cty_arrow (_, _, cty) -> signature_of_class_type cty
441441-442442-let self_type cty =
443443- (signature_of_class_type cty).csig_self
444444-445445-let rec class_type_arity =
446446- function
447447- Cty_constr (_, _, cty) -> class_type_arity cty
448448- | Cty_signature _ -> 0
449449- | Cty_arrow (_, _, cty) -> 1 + class_type_arity cty
450450-451451-452385 (*******************************************)
453386 (* Miscellaneous operations on row types *)
454387 (*******************************************)
···609542 unmark_extension_constructor ext;
610543 Some ty
611544612612-type closed_class_failure =
613613- CC_Method of type_expr * bool * string * type_expr
614614- | CC_Value of type_expr * bool * string * type_expr
615615-616616-exception CCFailure of closed_class_failure
545545+exception CCFailure of (type_expr * bool * string * type_expr)
617546618547let closed_class params sign =
619619- let ty = object_fields sign.csig_self in
620620- let (fields, rest) = flatten_fields ty in
621548 List.iter mark_type params;
622622- mark_type rest;
623623- List.iter
624624- (fun (lab, _, ty) -> if lab = dummy_method then mark_type ty)
625625- fields;
549549+ ignore (try_mark_node sign.csig_self_row);
626550 try
627627- ignore (try_mark_node sign.csig_self);
628628- List.iter
629629- (fun (lab, kind, ty) ->
630630- if field_kind_repr kind = Fpresent then
631631- try closed_type ty with Non_closed (ty0, real) ->
632632- raise (CCFailure (CC_Method (ty0, real, lab, ty))))
633633- fields;
634634- mark_type_params sign.csig_self;
551551+ Meths.iter
552552+ (fun lab (priv, _, ty) ->
553553+ if priv = Public then begin
554554+ try closed_type ty with Non_closed (ty0, real) ->
555555+ raise (CCFailure (ty0, real, lab, ty))
556556+ end)
557557+ sign.csig_meths;
635558 List.iter unmark_type params;
636559 unmark_class_signature sign;
637560 None
638561 with CCFailure reason ->
639639- mark_type_params sign.csig_self;
640562 List.iter unmark_type params;
641563 unmark_class_signature sign;
642564 Some reason
···857779 end;
858780 set_level ty level;
859781 iter_type_expr (update_level env level expand) ty
860860- | Tfield (lab, _, ty1, _)
861861- when lab = dummy_method && get_level ty1 > level ->
782782+ | Tfield(lab, _, ty1, _)
783783+ when lab = dummy_method && level < get_scope ty1 ->
862784 raise_escape_exn Self
863785 | _ ->
864786 set_level ty level;
···936858 simple_abbrevs := Mnil;
937859 lower_contravariant env !nongen_level (Hashtbl.create 7) false ty
938860939939-(* Generalize a class type *)
940940-let rec generalize_class_type gen =
861861+let rec generalize_class_type' gen =
941862 function
942863 Cty_constr (_, params, cty) ->
943864 List.iter gen params;
944944- generalize_class_type gen cty
945945- | Cty_signature {csig_self = sty; csig_vars = vars; csig_inher = inher} ->
946946- gen sty;
947947- Vars.iter (fun _ (_, _, ty) -> gen ty) vars;
948948- List.iter (fun (_,tl) -> List.iter gen tl) inher
865865+ generalize_class_type' gen cty
866866+ | Cty_signature csig ->
867867+ gen csig.csig_self;
868868+ gen csig.csig_self_row;
869869+ Vars.iter (fun _ (_, _, ty) -> gen ty) csig.csig_vars;
870870+ Meths.iter (fun _ (_, _, ty) -> gen ty) csig.csig_meths
949871 | Cty_arrow (_, ty, cty) ->
950872 gen ty;
951951- generalize_class_type gen cty
873873+ generalize_class_type' gen cty
874874+875875+let generalize_class_type cty =
876876+ generalize_class_type' generalize cty
952877953953-let generalize_class_type vars =
954954- let gen = if vars then generalize else generalize_structure in
955955- generalize_class_type gen
878878+let generalize_class_type_structure cty =
879879+ generalize_class_type' generalize_structure cty
956880957881(* Correct the levels of type [ty]. *)
958882let correct_levels ty =
···1003927 if get_level ty <> generic_level then set_level ty !current_level)
1004928 graph
1005929930930+let limited_generalize_class_type rv cty =
931931+ generalize_class_type' (limited_generalize rv) cty
10069321007933(* Compute statically the free univars of all nodes in a type *)
1008934(* This avoids doing it repeatedly during instantiation *)
···13551281 | Cty_signature sign ->
13561282 Cty_signature
13571283 {csig_self = copy scope sign.csig_self;
12841284+ csig_self_row = copy scope sign.csig_self_row;
13581285 csig_vars =
13591359- Vars.map (function (m, v, ty) -> (m, v, copy scope ty))
12861286+ Vars.map
12871287+ (function (m, v, ty) -> (m, v, copy scope ty))
13601288 sign.csig_vars;
13611361- csig_concr = sign.csig_concr;
13621362- csig_inher =
13631363- List.map (fun (p,tl) -> (p, List.map (copy scope) tl))
13641364- sign.csig_inher}
12891289+ csig_meths =
12901290+ Meths.map
12911291+ (function (p, v, ty) -> (p, v, copy scope ty))
12921292+ sign.csig_meths}
13651293 | Cty_arrow (l, ty, cty) ->
13661294 Cty_arrow (l, copy scope ty, copy_class_type scope cty)
13671295 in
···27792707 begin match !umode with
27802708 | Expression ->
27812709 occur_for Unify !env t1' t2';
27822782- if is_self_type d1 (* PR#7711: do not abbreviate self type *)
27832783- then link_type t1' t2'
27842784- else link_type t1' t2
27102710+ link_type t1' t2
27852711 | Pattern ->
27862712 add_type_equality t1' t2'
27872713 end;
···33163242exception Filter_method_failed of filter_method_failure
3317324333183244(* Used by [filter_method]. *)
33193319-let rec filter_method_field env name priv ty =
33203320- let method_type level =
32453245+let rec filter_method_field env name ty =
32463246+ let method_type ~level =
33213247 let ty1 = newvar2 level and ty2 = newvar2 level in
33223322- let ty' = newty2 ~level (Tfield (name,
33233323- begin match priv with
33243324- Private -> Fvar (ref None)
33253325- | Public -> Fpresent
33263326- end,
33273327- ty1, ty2))
33283328- in
32483248+ let ty' = newty2 ~level (Tfield (name, Fpresent, ty1, ty2)) in
33293249 ty', ty1
33303250 in
33313251 let ty =
33323252 try expand_head_trace env ty
33333253 with Unify_trace trace ->
33343334- let ty', _ = method_type (get_level ty) in
32543254+ let level = get_level ty in
32553255+ let ty', _ = method_type ~level in
33353256 raise (Filter_method_failed
33363257 (Unification_error
33373258 (expand_to_unification_error
···33403261 in
33413262 match get_desc ty with
33423263 | Tvar _ ->
33433343- let ty', ty1 = method_type (get_level ty) in
32643264+ let level = get_level ty in
32653265+ let ty', ty1 = method_type ~level in
33443266 link_type ty ty';
33453267 ty1
33463268 | Tfield(n, kind, ty1, ty2) ->
33473269 let kind = field_kind_repr kind in
33483270 if (n = name) && (kind <> Fabsent) then begin
33493349- if priv = Public then
33503350- unify_kind kind Fpresent;
32713271+ unify_kind kind Fpresent;
33513272 ty1
33523273 end else
33533353- filter_method_field env name priv ty2
32743274+ filter_method_field env name ty2
33543275 | _ ->
33553276 raise (Filter_method_failed Not_a_method)
3356327733573278(* Unify [ty] and [< name : 'a; .. >]. Return ['a]. *)
33583358-let filter_method env name priv ty =
32793279+let filter_method env name ty =
33593280 let object_type ~level ~scope =
33603360- let ty1 = newvar () in
33613361- let ty' = newobj ty1 in
33623362- update_level_for Unify env level ty';
33633363- update_scope_for Unify scope ty';
33643364- let ty_meth = filter_method_field env name priv ty1 in
32813281+ let ty1 = newvar2 level in
32823282+ let ty' = newty3 ~level ~scope (Tobject (ty1, ref None)) in
32833283+ let ty_meth = filter_method_field env name ty1 in
33653284 (ty', ty_meth)
33663285 in
33673286 let ty =
33683287 try expand_head_trace env ty
33693288 with Unify_trace trace ->
33703370- let ty', _ = object_type ~level:(get_level ty) ~scope:(get_scope ty) in
32893289+ let level = get_level ty in
32903290+ let scope = get_scope ty in
32913291+ let ty', _ = object_type ~level ~scope in
33713292 raise (Filter_method_failed
33723293 (Unification_error
33733294 (expand_to_unification_error
···33763297 in
33773298 match get_desc ty with
33783299 | Tvar _ ->
33793379- let ty', ty_meth =
33803380- object_type ~level:(get_level ty) ~scope:(get_scope ty) in
33003300+ let level = get_level ty in
33013301+ let scope = get_scope ty in
33023302+ let ty', ty_meth = object_type ~level ~scope in
33813303 link_type ty ty';
33823304 ty_meth
33833305 | Tobject(f, _) ->
33843384- filter_method_field env name priv f
33063306+ filter_method_field env name f
33853307 | _ ->
33863308 raise (Filter_method_failed (Not_an_object ty))
3387330933883388-let check_filter_method env name priv ty =
33893389- ignore(filter_method env name priv ty)
33103310+exception Filter_method_row_failed
33113311+33123312+let rec filter_method_row env name priv ty =
33133313+ let ty = expand_head env ty in
33143314+ match get_desc ty with
33153315+ | Tvar _ ->
33163316+ let level = get_level ty in
33173317+ let field = newvar2 level in
33183318+ let row = newvar2 level in
33193319+ let kind =
33203320+ match priv with
33213321+ | Private -> Fvar (ref None)
33223322+ | Public -> Fpresent
33233323+ in
33243324+ let ty' = newty2 ~level (Tfield (name, kind, field, row)) in
33253325+ link_type ty ty';
33263326+ field, row
33273327+ | Tfield(n, kind, ty1, ty2) ->
33283328+ let kind = field_kind_repr kind in
33293329+ if (n = name) && (kind <> Fabsent) then begin
33303330+ if priv = Public then
33313331+ unify_kind kind Fpresent;
33323332+ ty1, ty2
33333333+ end else begin
33343334+ let level = get_level ty in
33353335+ let field, row = filter_method_row env name priv ty2 in
33363336+ let row = newty2 ~level (Tfield (n, kind, ty1, row)) in
33373337+ field, row
33383338+ end
33393339+ | Tnil ->
33403340+ if name = Btype.dummy_method then raise Filter_method_row_failed
33413341+ else begin
33423342+ match priv with
33433343+ | Public -> raise Filter_method_row_failed
33443344+ | Private ->
33453345+ let level = get_level ty in
33463346+ newvar2 level, ty
33473347+ end
33483348+ | _ ->
33493349+ raise Filter_method_row_failed
33503350+33513351+(* Operations on class signatures *)
33523352+33533353+let new_class_signature () =
33543354+ let row = newvar () in
33553355+ let self = newobj row in
33563356+ { csig_self = self;
33573357+ csig_self_row = row;
33583358+ csig_vars = Vars.empty;
33593359+ csig_meths = Meths.empty; }
33603360+33613361+let add_dummy_method env ~scope sign =
33623362+ let ty, row =
33633363+ filter_method_row env dummy_method Private sign.csig_self_row
33643364+ in
33653365+ unify env ty (new_scoped_ty scope (Ttuple []));
33663366+ sign.csig_self_row <- row
33673367+33683368+type add_method_failure =
33693369+ | Unexpected_method
33703370+ | Type_mismatch of Errortrace.unification_error
33713371+33723372+exception Add_method_failed of add_method_failure
33733373+33743374+let add_method env label priv virt ty sign =
33753375+ let meths = sign.csig_meths in
33763376+ let priv, virt =
33773377+ match Meths.find label meths with
33783378+ | (priv', virt', ty') -> begin
33793379+ let priv =
33803380+ match priv' with
33813381+ | Public -> Public
33823382+ | Private -> priv
33833383+ in
33843384+ let virt =
33853385+ match virt' with
33863386+ | Concrete -> Concrete
33873387+ | Virtual -> virt
33883388+ in
33893389+ match unify env ty ty' with
33903390+ | () -> priv, virt
33913391+ | exception Unify trace ->
33923392+ raise (Add_method_failed (Type_mismatch trace))
33933393+ end
33943394+ | exception Not_found -> begin
33953395+ let ty', row =
33963396+ match filter_method_row env label priv sign.csig_self_row with
33973397+ | ty', row ->
33983398+ ty', row
33993399+ | exception Filter_method_row_failed ->
34003400+ raise (Add_method_failed Unexpected_method)
34013401+ in
34023402+ match unify env ty ty' with
34033403+ | () ->
34043404+ sign.csig_self_row <- row;
34053405+ priv, virt
34063406+ | exception Unify trace ->
34073407+ raise (Add_method_failed (Type_mismatch trace))
34083408+ end
34093409+ in
34103410+ let meths = Meths.add label (priv, virt, ty) meths in
34113411+ sign.csig_meths <- meths
34123412+34133413+type add_instance_variable_failure =
34143414+ | Mutability_mismatch of mutable_flag
34153415+ | Type_mismatch of Errortrace.unification_error
34163416+34173417+exception Add_instance_variable_failed of add_instance_variable_failure
34183418+34193419+let check_mutability mut mut' =
34203420+ match mut, mut' with
34213421+ | Mutable, Mutable -> ()
34223422+ | Immutable, Immutable -> ()
34233423+ | Mutable, Immutable | Immutable, Mutable ->
34243424+ raise (Add_instance_variable_failed (Mutability_mismatch mut))
3390342533913391-let filter_self_method env lab priv meths ty =
33923392- let ty' = filter_method env lab priv ty in
33933393- try
33943394- Meths.find lab !meths
33953395- with Not_found ->
33963396- let pair = (Ident.create_local lab, ty') in
33973397- meths := Meths.add lab pair !meths;
33983398- pair
34263426+let add_instance_variable ~strict env label mut virt ty sign =
34273427+ let vars = sign.csig_vars in
34283428+ let virt =
34293429+ match Vars.find label vars with
34303430+ | (mut', virt', ty') ->
34313431+ let virt =
34323432+ match virt' with
34333433+ | Concrete -> Concrete
34343434+ | Virtual -> virt
34353435+ in
34363436+ if strict then begin
34373437+ check_mutability mut mut';
34383438+ match unify env ty ty' with
34393439+ | () -> ()
34403440+ | exception Unify trace ->
34413441+ raise (Add_instance_variable_failed (Type_mismatch trace))
34423442+ end;
34433443+ virt
34443444+ | exception Not_found -> virt
34453445+ in
34463446+ let vars = Vars.add label (mut, virt, ty) vars in
34473447+ sign.csig_vars <- vars
34483448+34493449+type inherit_class_signature_failure =
34503450+ | Self_type_mismatch of Errortrace.unification_error
34513451+ | Method of label * add_method_failure
34523452+ | Instance_variable of label * add_instance_variable_failure
34533453+34543454+exception Inherit_class_signature_failed of inherit_class_signature_failure
3399345534563456+let unify_self_types env sign1 sign2 =
34573457+ let self_type1 = sign1.csig_self in
34583458+ let self_type2 = sign2.csig_self in
34593459+ match unify env self_type1 self_type2 with
34603460+ | () -> ()
34613461+ | exception Unify err -> begin
34623462+ match err.trace with
34633463+ | Errortrace.Diff _ :: Errortrace.Incompatible_fields {name; _} :: rem ->
34643464+ let err = Errortrace.unification_error ~trace:rem in
34653465+ let failure = Method (name, Type_mismatch err) in
34663466+ raise (Inherit_class_signature_failed failure)
34673467+ | _ ->
34683468+ raise (Inherit_class_signature_failed (Self_type_mismatch err))
34693469+ end
34703470+34713471+(* Unify components of sign2 into sign1 *)
34723472+let inherit_class_signature ~strict env sign1 sign2 =
34733473+ unify_self_types env sign1 sign2;
34743474+ Meths.iter
34753475+ (fun label (priv, virt, ty) ->
34763476+ match add_method env label priv virt ty sign1 with
34773477+ | () -> ()
34783478+ | exception Add_method_failed failure ->
34793479+ let failure = Method(label, failure) in
34803480+ raise (Inherit_class_signature_failed failure))
34813481+ sign2.csig_meths;
34823482+ Vars.iter
34833483+ (fun label (mut, virt, ty) ->
34843484+ match add_instance_variable ~strict env label mut virt ty sign1 with
34853485+ | () -> ()
34863486+ | exception Add_instance_variable_failed failure ->
34873487+ let failure = Instance_variable(label, failure) in
34883488+ raise (Inherit_class_signature_failed failure))
34893489+ sign2.csig_vars
34903490+34913491+let update_class_signature env sign =
34923492+ let self = expand_head env sign.Types.csig_self in
34933493+ let fields, row = flatten_fields (object_fields self) in
34943494+ let meths, implicitly_public, implicitly_declared =
34953495+ List.fold_left
34963496+ (fun (meths, implicitly_public, implicitly_declared) (lab, k, ty) ->
34973497+ if lab = dummy_method then
34983498+ meths, implicitly_public, implicitly_declared
34993499+ else begin
35003500+ match Meths.find lab meths with
35013501+ | priv, virt, ty' ->
35023502+ let meths, implicitly_public =
35033503+ match priv, field_kind_repr k with
35043504+ | Public, _ -> meths, implicitly_public
35053505+ | Private, Fpresent ->
35063506+ let meths = Meths.add lab (Public, virt, ty') meths in
35073507+ let implicitly_public = lab :: implicitly_public in
35083508+ meths, implicitly_public
35093509+ | Private, _ -> meths, implicitly_public
35103510+ in
35113511+ meths, implicitly_public, implicitly_declared
35123512+ | exception Not_found ->
35133513+ let meths, implicitly_declared =
35143514+ match field_kind_repr k with
35153515+ | Fpresent ->
35163516+ let meths = Meths.add lab (Public, Virtual, ty) meths in
35173517+ let implicitly_declared = lab :: implicitly_declared in
35183518+ meths, implicitly_declared
35193519+ | Fvar _ ->
35203520+ let meths = Meths.add lab (Private, Virtual, ty) meths in
35213521+ let implicitly_declared = lab :: implicitly_declared in
35223522+ meths, implicitly_declared
35233523+ | Fabsent -> meths, implicitly_declared
35243524+ in
35253525+ meths, implicitly_public, implicitly_declared
35263526+ end)
35273527+ (sign.csig_meths, [], []) fields
35283528+ in
35293529+ sign.csig_meths <- meths;
35303530+ sign.csig_self_row <- row;
35313531+ implicitly_public, implicitly_declared
35323532+35333533+let hide_private_methods env sign =
35343534+ let self = expand_head env sign.Types.csig_self in
35353535+ let fields, _ = flatten_fields (object_fields self) in
35363536+ List.iter
35373537+ (fun (_, k, _) ->
35383538+ match field_kind_repr k with
35393539+ | Fvar r -> set_kind r Fabsent
35403540+ | _ -> ())
35413541+ fields
35423542+35433543+let close_class_signature env sign =
35443544+ let rec close env ty =
35453545+ let ty = expand_head env ty in
35463546+ match get_desc ty with
35473547+ | Tvar _ ->
35483548+ let level = get_level ty in
35493549+ link_type ty (newty2 ~level Tnil); true
35503550+ | Tfield(lab, _, _, _) when lab = dummy_method ->
35513551+ false
35523552+ | Tfield(_, _, _, ty') -> close env ty'
35533553+ | Tnil -> true
35543554+ | _ -> assert false
35553555+ in
35563556+ let self = expand_head env sign.csig_self in
35573557+ close env (object_fields self)
35583558+35593559+let generalize_class_signature_spine env sign =
35603560+ (* Generalize the spine of methods *)
35613561+ let meths = sign.csig_meths in
35623562+ Meths.iter (fun _ (_, _, ty) -> generalize_spine ty) meths;
35633563+ let new_meths =
35643564+ Meths.map
35653565+ (fun (priv, virt, ty) -> (priv, virt, generic_instance ty))
35663566+ meths
35673567+ in
35683568+ (* But keep levels correct on the type of self *)
35693569+ Meths.iter
35703570+ (fun _ (_, _, ty) -> unify_var env (newvar ()) ty)
35713571+ meths;
35723572+ sign.csig_meths <- new_meths
3400357334013574 (***********************************)
34023575 (* Matching between type schemes *)
···4024419740254198exception Failure of class_match_failure list
4026419942004200+let match_class_sig_shape ~strict sign1 sign2 =
42014201+ let errors =
42024202+ Meths.fold
42034203+ (fun lab (priv, vr, _) err ->
42044204+ match Meths.find lab sign1.csig_meths with
42054205+ | exception Not_found -> CM_Missing_method lab::err
42064206+ | (priv', vr', _) ->
42074207+ match priv', priv with
42084208+ | Public, Private -> CM_Public_method lab::err
42094209+ | Private, Public when strict -> CM_Private_method lab::err
42104210+ | _, _ ->
42114211+ match vr', vr with
42124212+ | Virtual, Concrete -> CM_Virtual_method lab::err
42134213+ | _, _ -> err)
42144214+ sign2.csig_meths []
42154215+ in
42164216+ let errors =
42174217+ Meths.fold
42184218+ (fun lab (priv, vr, _) err ->
42194219+ if Meths.mem lab sign2.csig_meths then err
42204220+ else begin
42214221+ let err =
42224222+ match priv with
42234223+ | Public -> CM_Hide_public lab :: err
42244224+ | Private -> err
42254225+ in
42264226+ match vr with
42274227+ | Virtual -> CM_Hide_virtual ("method", lab) :: err
42284228+ | Concrete -> err
42294229+ end)
42304230+ sign1.csig_meths errors
42314231+ in
42324232+ let errors =
42334233+ Vars.fold
42344234+ (fun lab (mut, vr, _) err ->
42354235+ match Vars.find lab sign1.csig_vars with
42364236+ | exception Not_found -> CM_Missing_value lab::err
42374237+ | (mut', vr', _) ->
42384238+ match mut', mut with
42394239+ | Immutable, Mutable -> CM_Non_mutable_value lab::err
42404240+ | _, _ ->
42414241+ match vr', vr with
42424242+ | Virtual, Concrete -> CM_Non_concrete_value lab::err
42434243+ | _, _ -> err)
42444244+ sign2.csig_vars errors
42454245+ in
42464246+ Vars.fold
42474247+ (fun lab (_,vr,_) err ->
42484248+ if vr = Virtual && not (Vars.mem lab sign2.csig_vars) then
42494249+ CM_Hide_virtual ("instance variable", lab) :: err
42504250+ else err)
42514251+ sign1.csig_vars errors
42524252+40274253let rec moregen_clty trace type_pairs env cty1 cty2 =
40284254 try
40294255 match cty1, cty2 with
40304030- Cty_constr (_, _, cty1), _ ->
42564256+ | Cty_constr (_, _, cty1), _ ->
40314257 moregen_clty true type_pairs env cty1 cty2
40324258 | _, Cty_constr (_, _, cty2) ->
40334259 moregen_clty true type_pairs env cty1 cty2
···40394265 end;
40404266 moregen_clty false type_pairs env cty1' cty2'
40414267 | Cty_signature sign1, Cty_signature sign2 ->
40424042- let ty1 = object_fields sign1.csig_self in
40434043- let ty2 = object_fields sign2.csig_self in
40444044- let (fields1, _rest1) = flatten_fields ty1
40454045- and (fields2, _rest2) = flatten_fields ty2 in
40464046- let (pairs, _miss1, _miss2) = associate_fields fields1 fields2 in
40474047- List.iter
40484048- (fun (lab, _k1, t1, _k2, t2) ->
40494049- try moregen true type_pairs env t1 t2 with Moregen_trace trace ->
40504050- raise (Failure [
40514051- CM_Meth_type_mismatch
40524052- (lab,
40534053- env,
40544054- Moregen_error (expand_to_moregen_error env trace))]))
40554055- pairs;
40564056- Vars.iter
40574057- (fun lab (_mut, _v, ty) ->
40584058- let (_mut', _v', ty') = Vars.find lab sign1.csig_vars in
40594059- try moregen true type_pairs env ty' ty with Moregen_trace trace ->
40604060- raise (Failure [
40614061- CM_Val_type_mismatch
40624062- (lab, env, Moregen_error(expand_to_moregen_error env trace))]))
40634063- sign2.csig_vars
40644064- | _ ->
40654065- raise (Failure [])
42684268+ Meths.iter
42694269+ (fun lab (_, _, ty) ->
42704270+ match Meths.find lab sign1.csig_meths with
42714271+ | exception Not_found ->
42724272+ (* This function is only called after checking that
42734273+ all methods in sign2 are present in sign1. *)
42744274+ assert false
42754275+ | (_, _, ty') ->
42764276+ match moregen true type_pairs env ty' ty with
42774277+ | () -> ()
42784278+ | exception Moregen_trace trace ->
42794279+ raise (Failure [
42804280+ CM_Meth_type_mismatch
42814281+ (lab,
42824282+ env,
42834283+ Moregen_error
42844284+ (expand_to_moregen_error env trace))]))
42854285+ sign2.csig_meths;
42864286+ Vars.iter
42874287+ (fun lab (_, _, ty) ->
42884288+ match Vars.find lab sign1.csig_vars with
42894289+ | exception Not_found ->
42904290+ (* This function is only called after checking that
42914291+ all instance variables in sign2 are present in sign1. *)
42924292+ assert false
42934293+ | (_, _, ty') ->
42944294+ match moregen true type_pairs env ty' ty with
42954295+ | () -> ()
42964296+ | exception Moregen_trace trace ->
42974297+ raise (Failure [
42984298+ CM_Val_type_mismatch
42994299+ (lab,
43004300+ env,
43014301+ Moregen_error
43024302+ (expand_to_moregen_error env trace))]))
43034303+ sign2.csig_vars
43044304+ | _ ->
43054305+ raise (Failure [])
40664306 with
40674307 Failure error when trace || error = [] ->
40684308 raise (Failure (CM_Class_type_mismatch (env, cty1, cty2)::error))
4069430940704310let match_class_types ?(trace=true) env pat_sch subj_sch =
40714071- let type_pairs = TypePairs.create 53 in
40724072- let old_level = !current_level in
40734073- current_level := generic_level - 1;
40744074- (*
40754075- Generic variables are first duplicated with [instance]. So,
40764076- their levels are lowered to [generic_level - 1]. The subject is
40774077- then copied with [duplicate_type]. That way, its levels won't be
40784078- changed.
40794079- *)
40804080- let (_, subj_inst) = instance_class [] subj_sch in
40814081- let subj = duplicate_class_type subj_inst in
40824082- current_level := generic_level;
40834083- (* Duplicate generic variables *)
40844084- let (_, patt) = instance_class [] pat_sch in
40854085- let res =
40864086- let sign1 = signature_of_class_type patt in
40874087- let sign2 = signature_of_class_type subj in
40884088- let t1 = sign1.csig_self in
40894089- let t2 = sign2.csig_self in
40904090- TypePairs.add type_pairs (t1, t2) ();
40914091- let (fields1, rest1) = flatten_fields (object_fields t1)
40924092- and (fields2, rest2) = flatten_fields (object_fields t2) in
40934093- let (pairs, miss1, miss2) = associate_fields fields1 fields2 in
40944094- let error =
40954095- List.fold_right
40964096- (fun (lab, k, _) err ->
40974097- let err =
40984098- let k = field_kind_repr k in
40994099- begin match k with
41004100- Fvar r -> set_kind r Fabsent; err
41014101- | _ -> CM_Hide_public lab::err
41024102- end
41034103- in
41044104- if lab = dummy_method || Concr.mem lab sign1.csig_concr then err
41054105- else CM_Hide_virtual ("method", lab) :: err)
41064106- miss1 []
41074107- in
41084108- let missing_method = List.map (fun (m, _, _) -> m) miss2 in
41094109- let error =
41104110- (List.map (fun m -> CM_Missing_method m) missing_method) @ error
41114111- in
41124112- (* Always succeeds *)
41134113- moregen true type_pairs env rest1 rest2;
41144114- let error =
41154115- List.fold_right
41164116- (fun (lab, k1, _t1, k2, _t2) err ->
41174117- match moregen_kind k1 k2 with
41184118- | () -> err
41194119- | exception Public_method_to_private_method ->
41204120- CM_Public_method lab :: err)
41214121- pairs error
41224122- in
41234123- let error =
41244124- Vars.fold
41254125- (fun lab (mut, vr, _ty) err ->
41264126- try
41274127- let (mut', vr', _ty') = Vars.find lab sign1.csig_vars in
41284128- if mut = Mutable && mut' <> Mutable then
41294129- CM_Non_mutable_value lab::err
41304130- else if vr = Concrete && vr' <> Concrete then
41314131- CM_Non_concrete_value lab::err
41324132- else
41334133- err
41344134- with Not_found ->
41354135- CM_Missing_value lab::err)
41364136- sign2.csig_vars error
41374137- in
41384138- let error =
41394139- Vars.fold
41404140- (fun lab (_,vr,_) err ->
41414141- if vr = Virtual && not (Vars.mem lab sign2.csig_vars) then
41424142- CM_Hide_virtual ("instance variable", lab) :: err
41434143- else err)
41444144- sign1.csig_vars error
41454145- in
41464146- let error =
41474147- List.fold_right
41484148- (fun e l ->
41494149- if List.mem e missing_method then l else CM_Virtual_method e::l)
41504150- (Concr.elements (Concr.diff sign2.csig_concr sign1.csig_concr))
41514151- error
41524152- in
41534153- match error with
41544154- [] ->
41554155- begin try
41564156- moregen_clty trace type_pairs env patt subj;
41574157- []
41584158- with
41594159- Failure r -> r
41604160- end
41614161- | error ->
41624162- CM_Class_type_mismatch (env, patt, subj)::error
41634163- in
41644164- begin match res with
41654165- | [] -> ()
41664166- | _::_ ->
41674167- (* If [res] is nonempty, we've found an error. Moregen splits the generic
41684168- level into two finer levels: [generic_level] and [generic_level - 1]. In
41694169- order to properly detect and print weak variables when printing this
41704170- error, we need to merge them back together, by regeneralizing the levels
41714171- of the types after they were instantiated at [generic_level - 1] above.
41724172- Because [moregen] does some unification that we need to preserve for more
41734173- legible error messages, we have to manually perform the regeneralization
41744174- rather than backtracking. *)
41754175- current_level := generic_level - 2;
41764176- generalize_class_type true subj_inst;
41774177- end;
41784178- current_level := old_level;
41794179- res
43114311+ let sign1 = signature_of_class_type pat_sch in
43124312+ let sign2 = signature_of_class_type subj_sch in
43134313+ let errors = match_class_sig_shape ~strict:false sign1 sign2 in
43144314+ match errors with
43154315+ | [] ->
43164316+ let old_level = !current_level in
43174317+ current_level := generic_level - 1;
43184318+ (*
43194319+ Generic variables are first duplicated with [instance]. So,
43204320+ their levels are lowered to [generic_level - 1]. The subject is
43214321+ then copied with [duplicate_type]. That way, its levels won't be
43224322+ changed.
43234323+ *)
43244324+ let (_, subj_inst) = instance_class [] subj_sch in
43254325+ let subj = duplicate_class_type subj_inst in
43264326+ current_level := generic_level;
43274327+ (* Duplicate generic variables *)
43284328+ let (_, patt) = instance_class [] pat_sch in
43294329+ let type_pairs = TypePairs.create 53 in
43304330+ let sign1 = signature_of_class_type patt in
43314331+ let sign2 = signature_of_class_type subj in
43324332+ let self1 = sign1.csig_self in
43334333+ let self2 = sign2.csig_self in
43344334+ let row1 = sign1.csig_self_row in
43354335+ let row2 = sign2.csig_self_row in
43364336+ TypePairs.add type_pairs (self1, self2) ();
43374337+ (* Always succeeds *)
43384338+ moregen true type_pairs env row1 row2;
43394339+ let res =
43404340+ match moregen_clty trace type_pairs env patt subj with
43414341+ | () -> []
43424342+ | exception Failure res ->
43434343+ (* We've found an error. Moregen splits the generic level into two
43444344+ finer levels: [generic_level] and [generic_level - 1]. In order
43454345+ to properly detect and print weak variables when printing this
43464346+ error, we need to merge them back together, by regeneralizing the
43474347+ levels of the types after they were instantiated at
43484348+ [generic_level - 1] above. Because [moregen] does some
43494349+ unification that we need to preserve for more legible error
43504350+ messages, we have to manually perform the regeneralization rather
43514351+ than backtracking. *)
43524352+ current_level := generic_level - 2;
43534353+ generalize_class_type subj_inst;
43544354+ res
43554355+ in
43564356+ current_level := old_level;
43574357+ res
43584358+ | errors ->
43594359+ CM_Class_type_mismatch (env, pat_sch, subj_sch) :: errors
4180436041814361let equal_clsig trace type_pairs subst env sign1 sign2 =
41824362 try
41834183- let ty1 = object_fields sign1.csig_self in
41844184- let ty2 = object_fields sign2.csig_self in
41854185- let (fields1, _rest1) = flatten_fields ty1
41864186- and (fields2, _rest2) = flatten_fields ty2 in
41874187- let (pairs, _miss1, _miss2) = associate_fields fields1 fields2 in
41884188- List.iter
41894189- (fun (lab, _k1, t1, _k2, t2) ->
41904190- begin try eqtype true type_pairs subst env t1 t2 with
41914191- Equality_trace trace ->
41924192- raise (Failure
41934193- [CM_Meth_type_mismatch
41944194- (lab,
41954195- env,
41964196- Equality_error
41974197- (expand_to_equality_error env trace !subst))])
41984198- end)
41994199- pairs;
43634363+ Meths.iter
43644364+ (fun lab (_, _, ty) ->
43654365+ match Meths.find lab sign1.csig_meths with
43664366+ | exception Not_found ->
43674367+ (* This function is only called after checking that
43684368+ all methods in sign2 are present in sign1. *)
43694369+ assert false
43704370+ | (_, _, ty') ->
43714371+ match eqtype true type_pairs subst env ty' ty with
43724372+ | () -> ()
43734373+ | exception Equality_trace trace ->
43744374+ raise (Failure [
43754375+ CM_Meth_type_mismatch
43764376+ (lab,
43774377+ env,
43784378+ Equality_error
43794379+ (expand_to_equality_error env trace !subst))]))
43804380+ sign2.csig_meths;
42004381 Vars.iter
42014382 (fun lab (_, _, ty) ->
42024202- let (_, _, ty') = Vars.find lab sign1.csig_vars in
42034203- try eqtype true type_pairs subst env ty' ty
42044204- with Equality_trace trace ->
42054205- raise (Failure
42064206- [CM_Val_type_mismatch
42074207- (lab,
42084208- env,
42094209- Equality_error
42104210- (expand_to_equality_error env trace !subst))]))
43834383+ match Vars.find lab sign1.csig_vars with
43844384+ | exception Not_found ->
43854385+ (* This function is only called after checking that
43864386+ all instance variables in sign2 are present in sign1. *)
43874387+ assert false
43884388+ | (_, _, ty') ->
43894389+ match eqtype true type_pairs subst env ty' ty with
43904390+ | () -> ()
43914391+ | exception Equality_trace trace ->
43924392+ raise (Failure [
43934393+ CM_Val_type_mismatch
43944394+ (lab,
43954395+ env,
43964396+ Equality_error
43974397+ (expand_to_equality_error env trace !subst))]))
42114398 sign2.csig_vars
42124399 with
42134400 Failure error when trace ->
···42154402 (env, Cty_signature sign1, Cty_signature sign2)::error))
4216440342174404let match_class_declarations env patt_params patt_type subj_params subj_type =
42184218- let type_pairs = TypePairs.create 53 in
42194219- let subst = ref [] in
42204405 let sign1 = signature_of_class_type patt_type in
42214406 let sign2 = signature_of_class_type subj_type in
42224222- let t1 = sign1.csig_self in
42234223- let t2 = sign2.csig_self in
42244224- TypePairs.add type_pairs (t1, t2) ();
42254225- let (fields1, rest1) = flatten_fields (object_fields t1)
42264226- and (fields2, rest2) = flatten_fields (object_fields t2) in
42274227- let (pairs, miss1, miss2) = associate_fields fields1 fields2 in
42284228- let error =
42294229- List.fold_right
42304230- (fun (lab, k, _) err ->
42314231- let err =
42324232- let k = field_kind_repr k in
42334233- begin match k with
42344234- Fvar _ -> err
42354235- | _ -> CM_Hide_public lab::err
42364236- end
42374237- in
42384238- if Concr.mem lab sign1.csig_concr then err
42394239- else CM_Hide_virtual ("method", lab) :: err)
42404240- miss1 []
42414241- in
42424242- let missing_method = List.map (fun (m, _, _) -> m) miss2 in
42434243- let error =
42444244- (List.map (fun m -> CM_Missing_method m) missing_method) @ error
42454245- in
42464246- (* Always succeeds *)
42474247- eqtype true type_pairs subst env rest1 rest2;
42484248- let error =
42494249- List.fold_right
42504250- (fun (lab, k1, _t1, k2, _t2) err ->
42514251- let k1 = field_kind_repr k1 in
42524252- let k2 = field_kind_repr k2 in
42534253- match k1, k2 with
42544254- (Fvar _, Fvar _)
42554255- | (Fpresent, Fpresent) -> err
42564256- | (Fvar _, Fpresent) -> CM_Private_method lab::err
42574257- | (Fpresent, Fvar _) -> CM_Public_method lab::err
42584258- | _ -> assert false)
42594259- pairs error
42604260- in
42614261- let error =
42624262- Vars.fold
42634263- (fun lab (mut, vr, _ty) err ->
42644264- try
42654265- let (mut', vr', _ty') = Vars.find lab sign1.csig_vars in
42664266- if mut = Mutable && mut' <> Mutable then
42674267- CM_Non_mutable_value lab::err
42684268- else if vr = Concrete && vr' <> Concrete then
42694269- CM_Non_concrete_value lab::err
42704270- else
42714271- err
42724272- with Not_found ->
42734273- CM_Missing_value lab::err)
42744274- sign2.csig_vars error
42754275- in
42764276- let error =
42774277- Vars.fold
42784278- (fun lab (_,vr,_) err ->
42794279- if vr = Virtual && not (Vars.mem lab sign2.csig_vars) then
42804280- CM_Hide_virtual ("instance variable", lab) :: err
42814281- else err)
42824282- sign1.csig_vars error
42834283- in
42844284- let error =
42854285- List.fold_right
42864286- (fun e l ->
42874287- if List.mem e missing_method then l else CM_Virtual_method e::l)
42884288- (Concr.elements (Concr.diff sign2.csig_concr sign1.csig_concr))
42894289- error
42904290- in
42914291- match error with
42924292- [] ->
42934293- begin try
44074407+ let errors = match_class_sig_shape ~strict:true sign1 sign2 in
44084408+ match errors with
44094409+ | [] -> begin
44104410+ try
44114411+ let subst = ref [] in
44124412+ let type_pairs = TypePairs.create 53 in
44134413+ let self1 = sign1.csig_self in
44144414+ let self2 = sign2.csig_self in
44154415+ let row1 = sign1.csig_self_row in
44164416+ let row2 = sign2.csig_self_row in
44174417+ TypePairs.add type_pairs (self1, self2) ();
44184418+ (* Always succeeds *)
44194419+ eqtype true type_pairs subst env row1 row2;
42944420 let lp = List.length patt_params in
42954421 let ls = List.length subj_params in
42964422 if lp <> ls then
···43104436 match_class_types ~trace:false env
43114437 (clty_params patt_params patt_type)
43124438 (clty_params subj_params subj_type)
43134313- with
43144314- Failure r -> r
43154315- end
44394439+ with Failure r -> r
44404440+ end
43164441 | error ->
43174442 error
43184443···48534978 | _ -> 0
4854497948554980(* Check for non-generalizable type variables *)
48564856-exception Non_closed0
49814981+exception Nongen
48574982let visited = ref TypeSet.empty
4858498348594859-let rec closed_schema_rec env ty =
49844984+let rec nongen_schema_rec env ty =
48604985 if TypeSet.mem ty !visited then () else begin
48614986 visited := TypeSet.add ty !visited;
48624987 match get_desc ty with
48634988 Tvar _ when get_level ty <> generic_level ->
48644864- raise Non_closed0
49894989+ raise Nongen
48654990 | Tconstr _ ->
48664991 let old = !visited in
48674867- begin try iter_type_expr (closed_schema_rec env) ty
48684868- with Non_closed0 -> try
49924992+ begin try iter_type_expr (nongen_schema_rec env) ty
49934993+ with Nongen -> try
48694994 visited := old;
48704870- closed_schema_rec env
48714871- (try_expand_head try_expand_safe env ty)
49954995+ nongen_schema_rec env (try_expand_head try_expand_safe env ty)
48724996 with Cannot_expand ->
48734873- raise Non_closed0
49974997+ raise Nongen
48744998 end
48754999 | Tfield(_, kind, t1, t2) ->
48765000 if field_kind_repr kind = Fpresent then
48774877- closed_schema_rec env t1;
48784878- closed_schema_rec env t2
50015001+ nongen_schema_rec env t1;
50025002+ nongen_schema_rec env t2
48795003 | Tvariant row ->
48805004 let row = row_repr row in
48814881- iter_row (closed_schema_rec env) row;
48824882- if not (static_row row) then closed_schema_rec env row.row_more
50055005+ iter_row (nongen_schema_rec env) row;
50065006+ if not (static_row row) then nongen_schema_rec env row.row_more
48835007 | _ ->
48844884- iter_type_expr (closed_schema_rec env) ty
50085008+ iter_type_expr (nongen_schema_rec env) ty
48855009 end
4886501048875011(* Return whether all variables of type [ty] are generic. *)
48884888-let closed_schema env ty =
50125012+let nongen_schema env ty =
48895013 visited := TypeSet.empty;
48905014 try
48914891- closed_schema_rec env ty;
50155015+ nongen_schema_rec env ty;
50165016+ visited := TypeSet.empty;
50175017+ false
50185018+ with Nongen ->
48925019 visited := TypeSet.empty;
48935020 true
48944894- with Non_closed0 ->
48954895- visited := TypeSet.empty;
48964896- false
50215021+50225022+(* Check that all type variables are generalizable *)
50235023+(* Use Env.empty to prevent expansion of recursively defined object types;
50245024+ cf. typing-poly/poly.ml *)
50255025+let rec nongen_class_type = function
50265026+ | Cty_constr (_, params, _) ->
50275027+ List.exists (nongen_schema Env.empty) params
50285028+ | Cty_signature sign ->
50295029+ nongen_schema Env.empty sign.csig_self
50305030+ || nongen_schema Env.empty sign.csig_self_row
50315031+ || Meths.exists
50325032+ (fun _ (_, _, ty) -> nongen_schema Env.empty ty)
50335033+ sign.csig_meths
50345034+ || Vars.exists
50355035+ (fun _ (_, _, ty) -> nongen_schema Env.empty ty)
50365036+ sign.csig_vars
50375037+ | Cty_arrow (_, ty, cty) ->
50385038+ nongen_schema Env.empty ty
50395039+ || nongen_class_type cty
50405040+50415041+let nongen_class_declaration cty =
50425042+ List.exists (nongen_schema Env.empty) cty.cty_params
50435043+ || nongen_class_type cty.cty_type
50445044+4897504548985046(* Normalize a type before printing, saving... *)
48995047(* Cannot use mark_type because deep_occur uses it too *)
···51535301(* Preserve sharing inside class types. *)
51545302let nondep_class_signature env id sign =
51555303 { csig_self = nondep_type_rec env id sign.csig_self;
53045304+ csig_self_row = nondep_type_rec env id sign.csig_self_row;
51565305 csig_vars =
51575306 Vars.map (function (m, v, t) -> (m, v, nondep_type_rec env id t))
51585307 sign.csig_vars;
51595159- csig_concr = sign.csig_concr;
51605160- csig_inher =
51615161- List.map (fun (p,tl) -> (p, List.map (nondep_type_rec env id) tl))
51625162- sign.csig_inher }
53085308+ csig_meths =
53095309+ Meths.map (function (p, v, t) -> (p, v, nondep_type_rec env id t))
53105310+ sign.csig_meths }
5163531151645312let rec nondep_class_type env ids =
51655313 function
+59-26
typing/ctype.mli
···5555val create_scope : unit -> int
56565757val newty: type_desc -> type_expr
5858+val new_scoped_ty: int -> type_desc -> type_expr
5859val newvar: ?name:string -> unit -> type_expr
5960val newvar2: ?name:string -> int -> type_expr
6061 (* Return a fresh variable *)
···9495 (string * field_kind * type_expr) list *
9596 (string * field_kind * type_expr) list
9697val opened_object: type_expr -> bool
9797-val close_object: type_expr -> bool
9898-val row_variable: type_expr -> type_expr
9999- (* Return the row variable of an open object type *)
10098val set_object_name:
101101- Ident.t -> type_expr -> type_expr list -> type_expr -> unit
9999+ Ident.t -> type_expr list -> type_expr -> unit
102100val remove_object_name: type_expr -> unit
103103-val hide_private_methods: type_expr -> unit
104101val find_cltype_for_path: Env.t -> Path.t -> type_declaration * type_expr
105102106103val sort_row_fields: (label * row_field) list -> (label * row_field) list
···119116val generalize_structure: type_expr -> unit
120117 (* Generalize the structure of a type, lowering variables
121118 to !current_level *)
122122-val generalize_class_type :
123123- bool -> class_type -> unit
119119+val generalize_class_type : class_type -> unit
124120 (* Generalize the components of a class type *)
125125-val generalize_spine: type_expr -> unit
126126- (* Special function to generalize a method during inference *)
121121+val generalize_class_type_structure : class_type -> unit
122122+ (* Generalize the structure of the components of a class type *)
123123+val generalize_class_signature_spine : Env.t -> class_signature -> unit
124124+ (* Special function to generalize methods during inference *)
127125val correct_levels: type_expr -> type_expr
128126 (* Returns a copy with decreasing levels *)
129127val limited_generalize: type_expr -> type_expr -> unit
130128 (* Only generalize some part of the type
131129 Make the remaining of the type non-generalizable *)
130130+val limited_generalize_class_type: type_expr -> class_type -> unit
131131+ (* Same, but for class types *)
132132133133val fully_generic: type_expr -> bool
134134···165165 (* Same as instance_declaration, but new nodes at generic_level *)
166166val instance_class:
167167 type_expr list -> class_type -> type_expr list * class_type
168168+168169val instance_poly:
169170 ?keep_names:bool ->
170171 bool -> type_expr list -> type_expr -> type_expr list * type_expr
···230231val filter_arrow: Env.t -> type_expr -> arg_label -> type_expr * type_expr
231232 (* A special case of unification with [l:'a -> 'b]. Raises
232233 [Filter_arrow_failed] instead of [Unify]. *)
233233-val filter_method: Env.t -> string -> private_flag -> type_expr -> type_expr
234234+val filter_method: Env.t -> string -> type_expr -> type_expr
234235 (* A special case of unification (with {m : 'a; 'b}). Raises
235236 [Filter_method_failed] instead of [Unify]. *)
236236-val check_filter_method: Env.t -> string -> private_flag -> type_expr -> unit
237237- (* A special case of unification (with {m : 'a; 'b}), returning unit.
238238- Raises [Filter_method_failed] instead of [Unify]. *)
239237val occur_in: Env.t -> type_expr -> type_expr -> bool
240238val deep_occur: type_expr -> type_expr -> bool
241241-val filter_self_method:
242242- Env.t -> string -> private_flag -> (Ident.t * type_expr) Meths.t ref ->
243243- type_expr -> Ident.t * type_expr
244244- (* Raises [Filter_method_failed] instead of [Unify], and only if the
245245- self type is closed at this point. *)
246239val moregeneral: Env.t -> bool -> type_expr -> type_expr -> unit
247240 (* Check if the first type scheme is more general than the second. *)
248241val is_moregeneral: Env.t -> bool -> type_expr -> type_expr -> bool
···327320 enforce and returns a function that enforces this
328321 constraints. *)
329322323323+(* Operations on class signatures *)
324324+325325+val new_class_signature : unit -> class_signature
326326+val add_dummy_method : Env.t -> scope:int -> class_signature -> unit
327327+328328+type add_method_failure =
329329+ | Unexpected_method
330330+ | Type_mismatch of Errortrace.unification_error
331331+332332+exception Add_method_failed of add_method_failure
333333+334334+val add_method : Env.t ->
335335+ label -> private_flag -> virtual_flag -> type_expr -> class_signature -> unit
336336+337337+type add_instance_variable_failure =
338338+ | Mutability_mismatch of mutable_flag
339339+ | Type_mismatch of Errortrace.unification_error
340340+341341+exception Add_instance_variable_failed of add_instance_variable_failure
342342+343343+val add_instance_variable : strict:bool -> Env.t ->
344344+ label -> mutable_flag -> virtual_flag -> type_expr -> class_signature -> unit
345345+346346+type inherit_class_signature_failure =
347347+ | Self_type_mismatch of Errortrace.unification_error
348348+ | Method of label * add_method_failure
349349+ | Instance_variable of label * add_instance_variable_failure
350350+351351+exception Inherit_class_signature_failed of inherit_class_signature_failure
352352+353353+val inherit_class_signature : strict:bool -> Env.t ->
354354+ class_signature -> class_signature -> unit
355355+356356+val update_class_signature :
357357+ Env.t -> class_signature -> label list * label list
358358+359359+val hide_private_methods : Env.t -> class_signature -> unit
360360+361361+val close_class_signature : Env.t -> class_signature -> bool
362362+330363exception Nondep_cannot_erase of Ident.t
331364332365val nondep_type: Env.t -> Ident.t list -> type_expr -> type_expr
···351384val is_contractive: Env.t -> Path.t -> bool
352385val normalize_type: type_expr -> unit
353386354354-val closed_schema: Env.t -> type_expr -> bool
387387+val nongen_schema: Env.t -> type_expr -> bool
355388 (* Check whether the given type scheme contains no non-generic
356389 type variables *)
357390391391+val nongen_class_declaration: class_declaration -> bool
392392+ (* Check whether the given class type contains no non-generic
393393+ type variables. Uses the empty environment. *)
394394+358395val free_variables: ?env:Env.t -> type_expr -> type_expr list
359396 (* If env present, then check for incomplete definitions too *)
360397val closed_type_decl: type_declaration -> type_expr option
361398val closed_extension_constructor: extension_constructor -> type_expr option
362362-type closed_class_failure =
363363- CC_Method of type_expr * bool * string * type_expr
364364- | CC_Value of type_expr * bool * string * type_expr
365399val closed_class:
366366- type_expr list -> class_signature -> closed_class_failure option
400400+ type_expr list -> class_signature ->
401401+ (type_expr * bool * string * type_expr) option
367402 (* Check whether all type variables are bound *)
368403369404val unalias: type_expr -> type_expr
370370-val signature_of_class_type: class_type -> class_signature
371371-val self_type: class_type -> type_expr
372372-val class_type_arity: class_type -> int
405405+373406val arity: type_expr -> int
374407 (* Return the arity (as for curried functions) of the given type. *)
375408
+2-2
typing/env.ml
···1441144114421442let used_persistent () =
14431443 Persistent_env.fold !persistent_env
14441444- (fun s _m r -> Concr.add s r)
14451445- Concr.empty
14441444+ (fun s _m r -> String.Set.add s r)
14451445+ String.Set.empty
1446144614471447let find_all_comps wrap proj s (p, mda) =
14481448 match get_components mda.mda_components with
+1-1
typing/env.mli
···7070 t -> iter_cont
7171val run_iter_cont: iter_cont list -> (Path.t * iter_cont) list
7272val same_types: t -> t -> bool
7373-val used_persistent: unit -> Concr.t
7373+val used_persistent: unit -> Stdlib.String.Set.t
7474val find_shadowed_types: Path.t -> t -> Path.t list
7575val without_cmis: ('a -> 'b) -> 'a -> 'b
7676(* [without_cmis f arg] applies [f] to [arg], but does not
+55-54
typing/printtyp.ml
···616616 cache for short-paths
617617 *)
618618let printing_old = ref Env.empty
619619-let printing_pers = ref Concr.empty
619619+let printing_pers = ref String.Set.empty
620620(** {!printing_old} and {!printing_pers} are the keys of the one-slot cache *)
621621622622let printing_depth = ref 0
···680680681681let same_printing_env env =
682682 let used_pers = Env.used_persistent () in
683683- Env.same_types !printing_old env && Concr.equal !printing_pers used_pers
683683+ Env.same_types !printing_old env && String.Set.equal !printing_pers used_pers
684684685685let set_printing_env env =
686686 printing_env := env;
···941941942942let proxy ty = Transient_expr.repr (proxy ty)
943943944944-let is_aliased ty = List.memq (proxy ty) !aliased
944944+let is_aliased_proxy px =
945945+ List.memq px !aliased
945946let add_alias_proxy px =
946947 if not (List.memq px !aliased) then begin
947948 aliased := px :: !aliased;
···11621163 Otyp_module (tree_of_path Module_type p, fl)
11631164 in
11641165 if List.memq px !delayed then delayed := List.filter ((!=) px) !delayed;
11651165- if is_aliased (Transient_expr.type_expr px) && aliasable ty then begin
11661166+ if is_aliased_proxy px && aliasable ty then begin
11661167 Names.check_name_of_type px;
11671168 Otyp_alias (pr_typ (), Names.name_of_type Names.new_name px) end
11681169 else pr_typ ()
···1537153815381539(* Print a class type *)
1539154015401540-let method_type (_, kind, ty) =
15411541- match field_kind_repr kind, get_desc ty with
15421542- Fpresent, Tpoly(ty, tyl) -> (ty, tyl)
15431543- | _ , _ -> (ty, [])
15411541+let method_type priv ty =
15421542+ match priv, get_desc ty with
15431543+ | Public, Tpoly(ty, tyl) -> (ty, tyl)
15441544+ | _ , _ -> (ty, [])
1544154515451545-let tree_of_metho mode concrete csil (lab, kind, ty) =
15461546- if lab <> dummy_method then begin
15471547- let kind = field_kind_repr kind in
15481548- let priv = kind <> Fpresent in
15491549- let virt = not (Concr.mem lab concrete) in
15501550- let (ty, tyl) = method_type (lab, kind, ty) in
15511551- let tty = tree_of_typexp mode ty in
15521552- Names.remove_names (List.map Transient_expr.repr tyl);
15531553- Ocsg_method (lab, priv, virt, tty) :: csil
15541554- end
15551555- else csil
15461546+let prepare_method _lab (priv, _virt, ty) =
15471547+ let ty, _ = method_type priv ty in
15481548+ mark_loops ty
15491549+15501550+let tree_of_method mode (lab, priv, virt, ty) =
15511551+ let (ty, tyl) = method_type priv ty in
15521552+ let tty = tree_of_typexp mode ty in
15531553+ Names.remove_names (List.map Transient_expr.repr tyl);
15541554+ let priv = priv = Private in
15551555+ let virt = virt = Virtual in
15561556+ Ocsg_method (lab, priv, virt, tty)
1556155715571558let rec prepare_class_type params = function
15581559 | Cty_constr (_p, tyl, cty) ->
15591559- let sty = Ctype.self_type cty in
15601560- if List.memq (proxy sty) !visited_objects
15601560+ let row = Btype.self_type_row cty in
15611561+ if List.memq (proxy row) !visited_objects
15611562 || not (List.for_all is_Tvar params)
15621562- || List.exists (deep_occur sty) tyl
15631563+ || List.exists (deep_occur row) tyl
15631564 then prepare_class_type params cty
15641565 else List.iter mark_loops tyl
15651566 | Cty_signature sign ->
15661567 (* Self may have a name *)
15671567- let px = proxy sign.csig_self in
15681568- if List.memq px !visited_objects then add_alias sign.csig_self
15681568+ let px = proxy sign.csig_self_row in
15691569+ if List.memq px !visited_objects then add_alias_proxy px
15691570 else visited_objects := px :: !visited_objects;
15701570- let (fields, _) =
15711571- Ctype.flatten_fields (Ctype.object_fields sign.csig_self)
15721572- in
15731573- List.iter (fun met -> mark_loops (fst (method_type met))) fields;
15741574- Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.csig_vars
15711571+ Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.csig_vars;
15721572+ Meths.iter prepare_method sign.csig_meths
15751573 | Cty_arrow (_, ty, cty) ->
15761574 mark_loops ty;
15771575 prepare_class_type params cty
···15791577let rec tree_of_class_type mode params =
15801578 function
15811579 | Cty_constr (p', tyl, cty) ->
15821582- let sty = Ctype.self_type cty in
15831583- if List.memq (proxy sty) !visited_objects
15801580+ let row = Btype.self_type_row cty in
15811581+ if List.memq (proxy row) !visited_objects
15841582 || not (List.for_all is_Tvar params)
15851583 then
15861584 tree_of_class_type mode params cty
···15881586 let namespace = Namespace.best_class_namespace p' in
15891587 Octy_constr (tree_of_path namespace p', tree_of_typlist Type_scheme tyl)
15901588 | Cty_signature sign ->
15911591- let sty = sign.csig_self in
15891589+ let px = proxy sign.csig_self_row in
15921590 let self_ty =
15931593- if is_aliased sty then
15941594- Some (Otyp_var (false, Names.name_of_type Names.new_name (proxy sty)))
15911591+ if is_aliased_proxy px then
15921592+ Some
15931593+ (Otyp_var (false, Names.name_of_type Names.new_name px))
15951594 else None
15961595 in
15971597- let (fields, _) =
15981598- Ctype.flatten_fields (Ctype.object_fields sign.csig_self)
15991599- in
16001596 let csil = [] in
16011597 let csil =
16021598 List.fold_left
···16151611 :: csil)
16161612 csil all_vars
16171613 in
16141614+ let all_meths =
16151615+ Meths.fold
16161616+ (fun l (p, v, t) all -> (l, p, v, t) :: all)
16171617+ sign.csig_meths []
16181618+ in
16191619+ let all_meths = List.rev all_meths in
16181620 let csil =
16191619- List.fold_left (tree_of_metho mode sign.csig_concr) csil fields
16211621+ List.fold_left
16221622+ (fun csil meth -> tree_of_method mode meth :: csil)
16231623+ csil all_meths
16201624 in
16211625 Octy_signature (self_ty, List.rev csil)
16221626 | Cty_arrow (l, ty, cty) ->
···16571661 reset_except_context ();
16581662 List.iter add_alias params;
16591663 prepare_class_type params cl.cty_type;
16601660- let sty = Ctype.self_type cl.cty_type in
16641664+ let px = proxy (Btype.self_type_row cl.cty_type) in
16611665 List.iter mark_loops params;
1662166616631667 List.iter Names.check_name_of_type (List.map proxy params);
16641664- if is_aliased sty then Names.check_name_of_type (proxy sty);
16681668+ if is_aliased_proxy px then Names.check_name_of_type px;
1665166916661670 let vir_flag = cl.cty_new = None in
16671671 Osig_class
···16791683 reset_except_context ();
16801684 List.iter add_alias params;
16811685 prepare_class_type params cl.clty_type;
16821682- let sty = Ctype.self_type cl.clty_type in
16861686+ let px = proxy (Btype.self_type_row cl.clty_type) in
16831687 List.iter mark_loops params;
1684168816851689 List.iter Names.check_name_of_type (List.map proxy params);
16861686- if is_aliased sty then Names.check_name_of_type (proxy sty);
16901690+ if is_aliased_proxy px then Names.check_name_of_type px;
1687169116881688- let sign = Ctype.signature_of_class_type cl.clty_type in
16891689-16901690- let virt =
16911691- let (fields, _) =
16921692- Ctype.flatten_fields (Ctype.object_fields sign.csig_self) in
16931693- List.exists
16941694- (fun (lab, _, _) ->
16951695- not (lab = dummy_method || Concr.mem lab sign.csig_concr))
16961696- fields
16971697- || Vars.fold (fun _ (_,vr,_) b -> vr = Virtual || b) sign.csig_vars false
16921692+ let sign = Btype.signature_of_class_type cl.clty_type in
16931693+ let has_virtual_vars =
16941694+ Vars.fold (fun _ (_,vr,_) b -> vr = Virtual || b)
16951695+ sign.csig_vars false
16961696+ in
16971697+ let has_virtual_meths =
16981698+ Meths.fold (fun _ (_,vr,_) b -> vr = Virtual || b)
16991699+ sign.csig_meths false
16981700 in
16991699-17001701 Osig_class_type
17011701- (virt, Ident.name id,
17021702+ (has_virtual_vars || has_virtual_meths, Ident.name id,
17021703 List.map2 tree_of_class_param params (class_variance cl.clty_variance),
17031704 tree_of_class_type Type_scheme params cl.clty_type,
17041705 tree_of_rec rs)
+8-7
typing/printtyped.ml
···396396 expression i ppf e1;
397397 expression i ppf e2;
398398 expression i ppf e3;
399399- | Texp_send (e, Tmeth_name s, eo) ->
399399+ | Texp_send (e, Tmeth_name s) ->
400400 line i ppf "Texp_send \"%s\"\n" s;
401401- expression i ppf e;
402402- option i expression ppf eo
403403- | Texp_send (e, Tmeth_val s, eo) ->
401401+ expression i ppf e
402402+ | Texp_send (e, Tmeth_val s) ->
403403+ line i ppf "Texp_send \"%a\"\n" fmt_ident s;
404404+ expression i ppf e
405405+ | Texp_send (e, Tmeth_ancestor(s, _)) ->
404406 line i ppf "Texp_send \"%a\"\n" fmt_ident s;
405405- expression i ppf e;
406406- option i expression ppf eo
407407+ expression i ppf e
407408 | Texp_new (li, _, _) -> line i ppf "Texp_new %a\n" fmt_path li;
408409 | Texp_setinstvar (_, s, _, e) ->
409410 line i ppf "Texp_setinstvar \"%a\"\n" fmt_path s;
···930931 expression (i+1) ppf x.vb_expr
931932932933and string_x_expression i ppf (s, _, e) =
933933- line i ppf "<override> \"%a\"\n" fmt_path s;
934934+ line i ppf "<override> \"%a\"\n" fmt_ident s;
934935 expression (i+1) ppf e;
935936936937and record_field i ppf = function
···124124 | Texp_for of
125125 Ident.t * Parsetree.pattern * expression * expression * direction_flag *
126126 expression
127127- | Texp_send of expression * meth * expression option
127127+ | Texp_send of expression * meth
128128 | Texp_new of Path.t * Longident.t loc * Types.class_declaration
129129 | Texp_instvar of Path.t * Path.t * string loc
130130 | Texp_setinstvar of Path.t * Path.t * string loc * expression
131131- | Texp_override of Path.t * (Path.t * string loc * expression) list
131131+ | Texp_override of Path.t * (Ident.t * string loc * expression) list
132132 | Texp_letmodule of
133133 Ident.t option * string option loc * Types.module_presence * module_expr *
134134 expression
···149149 | Texp_open of open_declaration * expression
150150151151and meth =
152152- Tmeth_name of string
152152+ | Tmeth_name of string
153153 | Tmeth_val of Ident.t
154154+ | Tmeth_ancestor of Ident.t * Path.t
154155155156and 'k case =
156157 {
···194195 | Tcl_let of rec_flag * value_binding list *
195196 (Ident.t * expression) list * class_expr
196197 | Tcl_constraint of
197197- class_expr * class_type option * string list * string list * Concr.t
198198+ class_expr * class_type option * string list * string list * MethSet.t
198199 (* Visible instance variables, methods and concrete methods *)
199200 | Tcl_open of open_description * class_expr
200201
+5-3
typing/typedtree.mli
···255255 | Texp_for of
256256 Ident.t * Parsetree.pattern * expression * expression * direction_flag *
257257 expression
258258- | Texp_send of expression * meth * expression option
258258+ | Texp_send of expression * meth
259259 | Texp_new of Path.t * Longident.t loc * Types.class_declaration
260260 | Texp_instvar of Path.t * Path.t * string loc
261261 | Texp_setinstvar of Path.t * Path.t * string loc * expression
262262- | Texp_override of Path.t * (Path.t * string loc * expression) list
262262+ | Texp_override of Path.t * (Ident.t * string loc * expression) list
263263 | Texp_letmodule of
264264 Ident.t option * string option loc * Types.module_presence * module_expr *
265265 expression
···283283and meth =
284284 Tmeth_name of string
285285 | Tmeth_val of Ident.t
286286+ | Tmeth_ancestor of Ident.t * Path.t
286287287288and 'k case =
288289 {
···328329 | Tcl_let of rec_flag * value_binding list *
329330 (Ident.t * expression) list * class_expr
330331 | Tcl_constraint of
331331- class_expr * class_type option * string list * string list * Types.Concr.t
332332+ class_expr * class_type option * string list * string list
333333+ * Types.MethSet.t
332334 (* Visible instance variables, methods and concrete methods *)
333335 | Tcl_open of open_description * class_expr
334336
+18-23
typing/typemod.ml
···8989 | With_cannot_remove_constrained_type
9090 | Repeated_name of Sig_component_kind.t * string
9191 | Non_generalizable of type_expr
9292- | Non_generalizable_class of Ident.t * class_declaration
9392 | Non_generalizable_module of module_type
9493 | Implementation_is_required of string
9594 | Interface_not_compiled of string
···18241823let path_of_module mexp =
18251824 try Some (path_of_module mexp) with Not_a_path -> None
1826182518271827-(* Check that all core type schemes in a structure are closed *)
18261826+(* Check that all core type schemes in a structure
18271827+ do not contain non-generalized type variable *)
1828182818291829-let rec closed_modtype env = function
18301830- Mty_ident _ -> true
18311831- | Mty_alias _ -> true
18291829+let rec nongen_modtype env = function
18301830+ Mty_ident _ -> false
18311831+ | Mty_alias _ -> false
18321832 | Mty_signature sg ->
18331833 let env = Env.add_signature sg env in
18341834- List.for_all (closed_signature_item env) sg
18341834+ List.exists (nongen_signature_item env) sg
18351835 | Mty_functor(arg_opt, body) ->
18361836 let env =
18371837 match arg_opt with
···18401840 | Named (Some id, param) ->
18411841 Env.add_module ~arg:true id Mp_present param env
18421842 in
18431843- closed_modtype env body
18431843+ nongen_modtype env body
1844184418451845-and closed_signature_item env = function
18461846- Sig_value(_id, desc, _) -> Ctype.closed_schema env desc.val_type
18471847- | Sig_module(_id, _, md, _, _) -> closed_modtype env md.md_type
18481848- | _ -> true
18451845+and nongen_signature_item env = function
18461846+ Sig_value(_id, desc, _) -> Ctype.nongen_schema env desc.val_type
18471847+ | Sig_module(_id, _, md, _, _) -> nongen_modtype env md.md_type
18481848+ | _ -> false
1849184918501850-let check_nongen_scheme env sig_item =
18501850+let check_nongen_signature_item env sig_item =
18511851 match sig_item with
18521852 Sig_value(_id, vd, _) ->
18531853- if not (Ctype.closed_schema env vd.val_type) then
18531853+ if Ctype.nongen_schema env vd.val_type then
18541854 raise (Error (vd.val_loc, env, Non_generalizable vd.val_type))
18551855 | Sig_module (_id, _, md, _, _) ->
18561856- if not (closed_modtype env md.md_type) then
18561856+ if nongen_modtype env md.md_type then
18571857 raise(Error(md.md_loc, env, Non_generalizable_module md.md_type))
18581858 | _ -> ()
1859185918601860-let check_nongen_schemes env sg =
18611861- List.iter (check_nongen_scheme env) sg
18601860+let check_nongen_signature env sg =
18611861+ List.iter (check_nongen_signature_item env) sg
1862186218631863(* Helpers for typing recursive modules *)
18641864···27272727 in
27282728 let mty = Mtype.scrape_for_type_of ~remove_aliases env tmty.mod_type in
27292729 (* PR#5036: must not contain non-generalized type variables *)
27302730- if not (closed_modtype env mty) then
27302730+ if nongen_modtype env mty then
27312731 raise(Error(smod.pmod_loc, env, Non_generalizable_module mty));
27322732 tmty, mty
27332733···29132913 Includemod.compunit initial_env ~mark:Mark_positive
29142914 sourcefile sg "(inferred signature)" simple_sg
29152915 in
29162916- check_nongen_schemes finalenv simple_sg;
29162916+ check_nongen_signature finalenv simple_sg;
29172917 normalize_signature simple_sg;
29182918 Typecore.force_delayed_checks ();
29192919 (* See comment above. Here the target signature contains all
···31073107 Location.errorf ~loc
31083108 "@[The type of this expression,@ %a,@ \
31093109 contains type variables that cannot be generalized@]" type_scheme typ
31103110- | Non_generalizable_class (id, desc) ->
31113111- Location.errorf ~loc
31123112- "@[The type of this class,@ %a,@ \
31133113- contains type variables that cannot be generalized@]"
31143114- (class_declaration id) desc
31153110 | Non_generalizable_module mty ->
31163111 Location.errorf ~loc
31173112 "@[The type of this module,@ %a,@ \
+1-2
typing/typemod.mli
···4343 Env.t -> Parsetree.signature -> Typedtree.signature
4444val transl_signature:
4545 Env.t -> Parsetree.signature -> Typedtree.signature
4646-val check_nongen_schemes:
4646+val check_nongen_signature:
4747 Env.t -> Types.signature -> unit
4848 (*
4949val type_open_:
···115115 | With_cannot_remove_constrained_type
116116 | Repeated_name of Sig_component_kind.t * string
117117 | Non_generalizable of type_expr
118118- | Non_generalizable_class of Ident.t * class_declaration
119118 | Non_generalizable_module of module_type
120119 | Implementation_is_required of string
121120 | Interface_not_compiled of string
+18-15
typing/types.ml
···135135136136(* Maps of methods and instance variables *)
137137138138+module MethSet = Misc.Stdlib.String.Set
139139+module VarSet = Misc.Stdlib.String.Set
140140+138141module Meths = Misc.Stdlib.String.Map
139139-module Vars = Meths
142142+module Vars = Misc.Stdlib.String.Map
143143+140144141145(* Value descriptions *)
142146···152156 Val_reg (* Regular value *)
153157 | Val_prim of Primitive.description (* Primitive *)
154158 | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *)
155155- | Val_self of (Ident.t * type_expr) Meths.t ref *
156156- (Ident.t * Asttypes.mutable_flag *
157157- Asttypes.virtual_flag * type_expr) Vars.t ref *
158158- string * type_expr
159159+ | Val_self of
160160+ class_signature * self_meths * Ident.t Vars.t * string
159161 (* Self *)
160160- | Val_anc of (string * Ident.t) list * string
162162+ | Val_anc of class_signature * Ident.t Meths.t * string
161163 (* Ancestor *)
164164+165165+and self_meths =
166166+ | Self_concrete of Ident.t Meths.t
167167+ | Self_virtual of Ident.t Meths.t ref
168168+169169+and class_signature =
170170+ { csig_self: type_expr;
171171+ mutable csig_self_row: type_expr;
172172+ mutable csig_vars: (mutable_flag * virtual_flag * type_expr) Vars.t;
173173+ mutable csig_meths: (private_flag * virtual_flag * type_expr) Meths.t; }
162174163175(* Variance *)
164176···301313302314(* Type expressions for the class language *)
303315304304-module Concr = Misc.Stdlib.String.Set
305305-306316type class_type =
307317 Cty_constr of Path.t * type_expr list * class_type
308318 | Cty_signature of class_signature
309319 | Cty_arrow of arg_label * type_expr * class_type
310310-311311-and class_signature =
312312- { csig_self: type_expr;
313313- csig_vars:
314314- (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t;
315315- csig_concr: Concr.t;
316316- csig_inher: (Path.t * type_expr list) list }
317320318321type class_declaration =
319322 { cty_params: type_expr list;
+16-14
typing/types.mli
···308308 include Identifiable.S with type t := t
309309end
310310311311-(* Maps of methods and instance variables *)
311311+(* Sets and maps of methods and instance variables *)
312312+313313+module MethSet : Set.S with type elt = string
314314+module VarSet : Set.S with type elt = string
312315313316module Meths : Map.S with type key = string
314317module Vars : Map.S with type key = string
···327330 Val_reg (* Regular value *)
328331 | Val_prim of Primitive.description (* Primitive *)
329332 | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *)
330330- | Val_self of (Ident.t * type_expr) Meths.t ref *
331331- (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t ref *
332332- string * type_expr
333333+ | Val_self of class_signature * self_meths * Ident.t Vars.t * string
333334 (* Self *)
334334- | Val_anc of (string * Ident.t) list * string
335335+ | Val_anc of class_signature * Ident.t Meths.t * string
335336 (* Ancestor *)
337337+338338+and self_meths =
339339+ | Self_concrete of Ident.t Meths.t
340340+ | Self_virtual of Ident.t Meths.t ref
341341+342342+and class_signature =
343343+ { csig_self: type_expr;
344344+ mutable csig_self_row: type_expr;
345345+ mutable csig_vars: (mutable_flag * virtual_flag * type_expr) Vars.t;
346346+ mutable csig_meths: (private_flag * virtual_flag * type_expr) Meths.t; }
336347337348(* Variance *)
338349···479490480491(* Type expressions for the class language *)
481492482482-module Concr : Set.S with type elt = string
483483-484493type class_type =
485494 Cty_constr of Path.t * type_expr list * class_type
486495 | Cty_signature of class_signature
487496 | Cty_arrow of arg_label * type_expr * class_type
488488-489489-and class_signature =
490490- { csig_self: type_expr;
491491- csig_vars:
492492- (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t;
493493- csig_concr: Concr.t;
494494- csig_inher: (Path.t * type_expr list) list }
495497496498type class_declaration =
497499 { cty_params: type_expr list;
+3-2
typing/untypeast.ml
···470470 Pexp_for (name,
471471 sub.expr sub exp1, sub.expr sub exp2,
472472 dir, sub.expr sub exp3)
473473- | Texp_send (exp, meth, _) ->
473473+ | Texp_send (exp, meth) ->
474474 Pexp_send (sub.expr sub exp, match meth with
475475 Tmeth_name name -> mkloc name loc
476476- | Tmeth_val id -> mkloc (Ident.name id) loc)
476476+ | Tmeth_val id -> mkloc (Ident.name id) loc
477477+ | Tmeth_ancestor(id, _) -> mkloc (Ident.name id) loc)
477478 | Texp_new (_path, lid, _) -> Pexp_new (map_loc sub lid)
478479 | Texp_instvar (_, path, name) ->
479480 Pexp_ident ({loc = sub.location sub name.loc ; txt = lident_of_path path})
+14-16
utils/warnings.ml
···437437 let (set, pos) = (!current).alert_errors in
438438 Misc.Stdlib.String.Set.mem kind set = pos
439439440440+let with_state state f =
441441+ let prev = backup () in
442442+ restore state;
443443+ try
444444+ let r = f () in
445445+ restore prev;
446446+ r
447447+ with exn ->
448448+ restore prev;
449449+ raise exn
450450+440451let mk_lazy f =
441452 let state = backup () in
442442- lazy
443443- (
444444- let prev = backup () in
445445- restore state;
446446- try
447447- let r = f () in
448448- restore prev;
449449- r
450450- with exn ->
451451- restore prev;
452452- raise exn
453453- )
453453+ lazy (with_state state f)
454454455455let set_alert ~error ~enable s =
456456 let upd =
···730730 | Redundant_case -> "this match case is unused."
731731 | Redundant_subpat -> "this sub-pattern is unused."
732732 | Instance_variable_override [lab] ->
733733- "the instance variable " ^ lab ^ " is overridden.\n" ^
734734- "The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
733733+ "the instance variable " ^ lab ^ " is overridden."
735734 | Instance_variable_override (cname :: slist) ->
736735 String.concat " "
737736 ("the following instance variables are overridden by the class"
738738- :: cname :: ":\n " :: slist) ^
739739- "\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
737737+ :: cname :: ":\n " :: slist)
740738 | Instance_variable_override [] -> assert false
741739 | Illegal_backslash -> "illegal backslash escape in string."
742740 | Implicit_public_methods l ->
+1
utils/warnings.mli
···148148type state
149149val backup: unit -> state
150150val restore: state -> unit
151151+val with_state : state -> (unit -> 'a) -> 'a
151152val mk_lazy: (unit -> 'a) -> 'a Lazy.t
152153 (** Like [Lazy.of_fun], but the function is applied with
153154 the warning/alert settings at the time [mk_lazy] is called. *)