types.mli 11.4 KB
Newer Older
1 2
open Ident

3
type const =
4
  | Integer of Intervals.V.t
5
  | Atom of Atoms.V.t
6 7 8 9 10 11
  | Char of Chars.V.t
  | Pair of const * const
  | Xml of const * const
  | Record of const label_map
  | String of U.uindex * U.uindex * U.t * const

12 13
type service_params =
  | TProd of service_params * service_params
14
  | TOption of service_params
15 16 17 18 19 20 21
  | TList of string * service_params
  | TSet of service_params
  | TSum of service_params * service_params
  | TString of string
  | TInt of string
  | TInt32 of string
  | TInt64 of string
22
  | TFloat of string
23 24 25
  | TBool of string
  | TFile of string
      (* | TUserType of string * (string -> 'a) * ('a -> string) *)
26
  | TCoord of string
27
  | TCoordv of service_params * string
28
  | TESuffix of string
29 30 31
  | TESuffixs of string
      (*  | TESuffixu of (string * (string -> 'a) * ('a -> string)) *)
  | TSuffix of (bool * service_params)
32
  | TUnit
33 34
  | TAny
  | TConst of string;;
35

36
module Const: Custom.T with type t = const
37

38
(*
39 40 41
module CompUnit : sig
  include Custom.T

42
  val get_current: unit -> t
43 44
  val mk: U.t -> t
  val value: t -> U.t
45
  val print_qual: Format.formatter -> t -> unit
46 47 48 49 50 51 52 53 54

  val enter: t -> unit
  val leave: unit -> unit
  val close_serialize: unit -> t list

  val pervasives: t

  module Tbl : Inttbl.S with type key = t
end
55
*)
56

57
module Abstracts : sig
58 59
  module T : Custom.T with type t = string
  type abs = T.t
60 61 62
  type t
  val any: t
  val atom: abs -> t
63
  val compare: t -> t -> int
64

65
  module V : sig type t = abs * Obj.t end
66 67 68 69

  val contains: abs -> t -> bool
end

70 71
(** Algebra **)

72 73
module BoolAtoms : BoolVar.S with
  type s = Atoms.t and
74
  type elem = Atoms.t Var.var_or_atom
75 76
module BoolIntervals : BoolVar.S with
  type s = Intervals.t and
77
  type elem = Intervals.t Var.var_or_atom
78 79
module BoolChars : BoolVar.S with
  type s = Chars.t and
80
  type elem = Chars.t Var.var_or_atom
81 82
module BoolAbstracts: BoolVar.S with
  type s = Abstracts.t and
83
  type elem = Abstracts.t Var.var_or_atom
84

85 86
include Custom.T
module Node : Custom.T
87

88
type descr = t
89

90 91
val make: unit -> Node.t
val define: Node.t -> t -> unit
92

93 94
val cons: t -> Node.t
val internalize: Node.t -> Node.t
95

96 97
val id: Node.t -> int
val descr: Node.t -> t
98

99 100
(** Boolean connectives **)

101 102 103 104 105 106
val cup    : t -> t -> t
val cap    : t -> t -> t
val diff   : t -> t -> t
val neg    : t -> t
val empty  : t
val any    : t
107

108 109
val no_var  : t -> bool
val is_var  : t -> bool
110
val has_tlv : t -> bool
111
val is_closed : Var.Set.t -> t -> bool
112

113
val any_node : Node.t
114
val empty_node : Node.t
115

116
val non_constructed : t
117
val non_constructed_or_absent : t
118

119 120
(** Constructors **)

121 122
type pair_kind = [ `Normal | `XML ]

123
val var      : Var.var -> t
124 125
val interval : Intervals.t -> t
val atom     : Atoms.t -> t
126 127 128 129
val times    : Node.t -> Node.t -> t
val xml      : Node.t -> Node.t -> t
val arrow    : Node.t -> Node.t -> t
val record   : label -> Node.t -> t
130
  (** bool = true -> open record; bool = false -> closed record *)
131
val record_fields : bool * Node.t label_map -> t
132
val char     : Chars.t -> t
133
val constant : const -> t
134
val abstract : Abstracts.t -> t
135

136 137
(** Helpers *)

138
val all_vars : t -> Var.Set.t
139 140
val tuple : Node.t list -> t

141
val rec_of_list: bool -> (bool * Ns.Label.t * t) list -> t
142

143
val empty_closed_record: t
144
val empty_open_record: t
145

146 147
(** Positive systems and least solutions **)

148
module Positive : sig
149 150 151
  type v
  val forward: unit -> v
  val define: v -> v -> unit
152
  val ty: t -> v
153 154
  val cup: v list -> v
  val times: v -> v -> v
155
  val xml: v -> v -> v
156
  val solve: v -> Node.t
157

158 159 160 161 162
  val substitute : t -> (Var.var * t) -> t
  val substitute_list : t -> (Var.var * t) list -> t
  val solve_rectype : t -> Var.var -> t
  val substitute_free : Var.Set.t -> t -> t
  val clean_type : Var.Set.t -> t -> t
163 164 165 166 167
end

(** Normalization **)

module Product : sig
168 169
  val any : t
  val any_xml : t
170
  val any_of: pair_kind -> t
171 172
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
173 174 175

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
176
  val is_empty: t -> bool
177
  val get: ?kind:pair_kind -> descr -> t
178 179
  val pi1: t -> descr
  val pi2: t -> descr
180
  val pi2_restricted: descr -> t -> descr
181

182 183 184 185 186 187
  (* Intersection with (pi1,Any) *)
  val restrict_1: t -> descr -> t

  (* List of non-empty rectangles whose first projection
     are pair-wise disjunct *)
  type normal = t
188
  val normal: ?kind:pair_kind -> descr -> normal
189

190 191 192 193
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

194 195
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
196 197 198

  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
199 200 201
end

module Record : sig
202
  val any : t
203 204
  val absent : t
  val absent_node : Node.t
205 206
  val or_absent: t -> t
  val any_or_absent: t
207
  val any_or_absent_node : Node.t
208

209 210
  val has_absent: t -> bool
  val has_record: t -> bool
211

212 213
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
214

215 216 217
  val pi : label -> t -> t
    (* May contain absent *)

218
  val project : t -> label -> t
219 220
    (* Raise Not_found if label is not necessarily present *)

221
  val condition : t -> label -> t -> t
222
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
223 224
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
225

226
  val first_label: t -> label
227
  val all_labels: t -> LabelSet.t
228

229
  val empty_cases: t -> bool * bool
230

231 232
  val merge: t -> t -> t
  val remove_field: t -> label -> t
233

234
  val get: t -> ((bool * t) label_map * bool * bool) list
235 236 237 238 239 240

  type t
  val focus: descr -> label -> t
  val get_this: t -> descr
  val need_others: t -> bool
  val constraint_on_others: t -> descr -> descr
241 242
end

243
module Arrow : sig
244
  val any : t
245

246
  val sample: t -> t
247

Pietro Abate's avatar
Pietro Abate committed
248 249 250 251 252 253
  (** [check_strenghten t s]
     Assume that [t] is an intersection of arrow types
     representing the interface of an abstraction;
     check that this abstraction has type [s] (otherwise raise Not_found)
     and returns a refined type for this abstraction.
  *)
254
  val check_strenghten: t -> t -> t
255

256
  val check_iface: (t * t) list -> t -> bool
257

258
  type t = descr * (descr * descr) list list
259
  val is_empty: t -> bool
260 261
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
262

263
  val domain: t -> descr
Pietro Abate's avatar
Pietro Abate committed
264 265

  (* Always succeed; no check on the domain *)
266
  val apply: t -> descr -> descr
267

Pietro Abate's avatar
Pietro Abate committed
268 269 270
  (** True if the type of the argument is needed to obtain
     the type of the result (must use [apply]; otherwise,
     [apply_noarg] is enough *)
271
  val need_arg : t -> bool
Pietro Abate's avatar
Pietro Abate committed
272

273
  val apply_noarg : t -> descr
274

Pietro Abate's avatar
Pietro Abate committed
275
end
276

277
module Int : sig
278
  val has_int : t -> Intervals.V.t -> bool
279
  val get: t -> BoolIntervals.t
280
  val any : t
281 282
end

283
module Atom : sig
284
  val has_atom : t -> Atoms.V.t -> bool
285
  val get: t -> BoolAtoms.t
286
  val any : t
287 288
end

289
module Char : sig
290
  val has_char : t -> Chars.V.t -> bool
291
  val is_empty : t -> bool
292
  val get: t -> BoolChars.t
293
  val any : t
294 295
end

296 297 298 299 300 301 302 303
module Abstract : sig
  val has_abstract : t -> Abstracts.T.t -> bool
  val get: t -> BoolAbstracts.t
  val any : t
end
(*
val get_abstract: t -> Abstracts.t
*)
304

305
val normalize : t -> t
306

307
(** Subtyping  **)
308

309 310 311
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
312
val disjoint : t -> t -> bool
313
val equiv : t -> t -> bool
314

315 316 317 318 319 320 321 322
(** Tools for compilation of PM **)

val cond_partition: t -> (t * t) list -> t list
  (* The second argument is a list of pair of types (ti,si)
     interpreted as the question "member of ti under the assumption si".
     The result is a partition of the first argument which is precise enough
     to answer all the questions. *)

323
module Print : sig
324
  type gname = string * Ns.QName.t * (Var.var * t) list
325
  val register_global : gname -> t -> unit
326 327 328
  val pp_const : Format.formatter -> const -> unit
  val pp_type: Format.formatter -> t -> unit
  val pp_node: Format.formatter -> Node.t -> unit
329 330

  (* Don't try to find a global name at toplevel *)
331
  val pp_noname: Format.formatter -> t -> unit
332

333 334
  val string_of_type: t -> string
  val string_of_node: Node.t -> string
335
  val printf : t -> unit
336
end
337

338
module Service : sig
339 340 341 342
  val to_service_params: t -> service_params
  val to_string: service_params -> string
end

343
module Witness : sig
344
  type witness
345 346
  val pp: Format.formatter -> witness -> unit
  val printf : witness -> unit
347 348
end
val witness: t -> Witness.witness
349

350

351
module Cache : sig
352 353 354 355 356 357
  type 'a cache
  val emp: 'a cache
  val find: (t -> 'a) -> t -> 'a cache -> 'a cache * 'a

  val memo: (t -> 'a) -> (t -> 'a)
end
358 359

module Tallying : sig
360 361 362 363

  type constr =
  |Pos of (Var.var * t) (** alpha <= t | alpha \in P *)
  |Neg of (t * Var.var) (** t <= alpha | alpha \in N *)
364

365
  exception UnSatConstr of string
366 367
  exception Step1Fail
  exception Step2Fail
368

369
  module CS : sig
370
    module M : sig
371 372 373 374
      type key = Var.var
      type t
      val compare  : t -> t -> int
      val empty : t
375
      val add : Var.Set.t -> key -> descr*descr -> t -> t
376
      val singleton : key -> descr*descr -> t
377
      val pp : Format.formatter -> t -> unit
378
      val inter : Var.Set.t -> t -> t -> t
379 380 381
    end
    module E : sig
      include Map.S with type key = Var.var
382
      val pp : Format.formatter -> descr t -> unit
383
    end
384 385
    module ES : sig
      include Set.S with type elt = descr E.t
386
      val pp : Format.formatter -> t -> unit
387
    end
388
    module S : sig
389 390 391 392 393 394 395
      type t = M.t list
      val empty : t
      val add : M.t -> t -> t
      val singleton : M.t -> t
      val union : t -> t -> t
      val elements : t -> M.t list
      val fold : (M.t -> 'b -> 'b) -> M.t list -> 'b -> 'b
396
      val pp : Format.formatter -> t -> unit
397 398 399
    end

    type s = S.t
400
    type m =  M.t
401
    type es = ES.t
402
    type sigma = t E.t
403
    type sl = sigma list
404

405 406
    val pp_s  : Format.formatter -> s -> unit
    val pp_m  : Format.formatter -> m -> unit
407
    val pp_e  : Format.formatter -> sigma -> unit
408
    val pp_sl : Format.formatter -> sl -> unit
409

410
    (* val merge : m -> m -> m *)
411
    val singleton : constr -> s
412 413
    val sat : s
    val unsat : s
Pietro Abate's avatar
Pietro Abate committed
414
    val union : s -> s -> s
415
    val prod : Var.Set.t -> s -> s -> s
416 417
  end

418 419
  val norm : Var.Set.t -> t -> CS.s
  val merge : Var.Set.t -> CS.m -> CS.s
420
  val solve : Var.Set.t -> CS.s -> CS.es
421
  val unify : CS.sigma -> CS.sigma
422 423 424

  (* [s1 ... sn] . si is a solution for tallying problem
     if si # delta and for all (s,t) in C si @ s < si @ t *)
425
  val tallying : Var.Set.t -> (t * t) list -> CS.sl
426

427
  val (>>) : t -> CS.sigma -> t
428 429 430 431 432 433 434

  (** Symbolic Substitution Set *)
  type symsubst =
    |I (** Identity *)
    |S of CS.sigma (** Substitution *)
    |A of (symsubst * symsubst) (** Composition si (sj t) *)

435
  (** Cartesian Product of two symbolic substitution sets *)
436 437 438 439 440
  val ( ++ ) : symsubst list -> symsubst list -> symsubst list

  (** Evaluation of a substitution *)
  val (@@) : t -> symsubst -> t

441
  val domain : CS.sl -> Var.Set.t
442
  val codomain : CS.sl -> Var.Set.t
443
  val is_identity : CS.sl -> bool
444 445
  val identity : CS.sl
  val filter : (Var.t -> bool) -> CS.sl -> CS.sl
446

447 448
end

449 450
(** Square Subtype relation. [squaresubtype delta s t] .
    True if there exists a substitution such that s < t only
Pietro Abate's avatar
Pietro Abate committed
451
    considering variables that are not in delta *)
452
val squaresubtype : Var.Set.t -> t -> t -> Tallying.CS.sl
453
val is_squaresubtype : Var.Set.t -> t -> t -> bool
454

455
(** apply_raw s t returns the 4-tuple (subst,ss, tt, res) where
456 457
   subst is the set of substitution that make the application succeed,
   ss and tt are the expansions of s and t corresponding to that substitution
Pietro Abate's avatar
Pietro Abate committed
458 459 460 461 462 463
   and res is the type of the result of the application *)
val apply_full : Var.Set.t -> t -> t -> t

val apply_raw : Var.Set.t -> t -> t -> Tallying.CS.sl * t * t * t

val squareapply : Var.Set.t -> t -> t -> (Tallying.CS.sl * t)