types.mli 11.1 KB
Newer Older
1 2
open Ident

3
module BoolAtoms : BoolVar.S with
4
  type s = Atoms.t and
5
  type elem = Atoms.t Var.pairvar
6
module BoolIntervals : BoolVar.S with
7
  type s = Intervals.t and
8
  type elem = Intervals.t Var.pairvar
9
module BoolChars : BoolVar.S with
10
  type s = Chars.t and
11
  type elem = Chars.t Var.pairvar
12

13
type const =
14
  | Integer of Intervals.V.t
15
  | Atom of Atoms.V.t
16 17 18 19 20 21
  | 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

Jérôme Maloberti's avatar
Jérôme Maloberti committed
22 23
type service_params =
  | TProd of service_params * service_params
24
  | TOption of service_params
Jérôme Maloberti's avatar
Jérôme Maloberti committed
25 26 27 28 29 30 31
  | 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
32
  | TFloat of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
33 34 35
  | TBool of string
  | TFile of string
      (* | TUserType of string * (string -> 'a) * ('a -> string) *)
36
  | TCoord of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
37
  | TCoordv of service_params * string
38
  | TESuffix of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
39 40 41
  | TESuffixs of string
      (*  | TESuffixu of (string * (string -> 'a) * ('a -> string)) *)
  | TSuffix of (bool * service_params)
42
  | TUnit
Jérôme Maloberti's avatar
Jérôme Maloberti committed
43 44
  | TAny
  | TConst of string;;
45

46
module Const: Custom.T with type t = const
47

48
(*
49 50 51
module CompUnit : sig
  include Custom.T

52
  val get_current: unit -> t
53 54
  val mk: U.t -> t
  val value: t -> U.t
55
  val print_qual: Format.formatter -> t -> unit
56 57 58 59 60 61 62 63 64

  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
65
*)
66

67
module Abstract : sig
68 69
  module T : Custom.T with type t = string
  type abs = T.t
70 71 72
  type t
  val any: t
  val atom: abs -> t
73
  val compare: t -> t -> int
74 75 76 77 78 79 80 81

  module V : sig
    type t = abs * Obj.t
  end

  val contains: abs -> t -> bool
end

82 83
(** Algebra **)

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

87
module Pair : Bool.S with type elem = (Node.t * Node.t)
88 89 90
module BoolPair : BoolVar.S with 
  type s = Pair.t and 
  type elem = Pair.t Var.pairvar
91 92

module Rec : Bool.S with type elem = bool * Node.t Ident.label_map
93 94 95
module BoolRec : BoolVar.S with
  type s = Rec.t and 
  type elem = Rec.t Var.pairvar
96

97
type descr = t
98

99 100
val make: unit -> Node.t
val define: Node.t -> t -> unit
101

102 103
val cons: t -> Node.t
val internalize: Node.t -> Node.t
104

105 106
val id: Node.t -> int
val descr: Node.t -> t
107

108 109
(** Boolean connectives **)

110 111 112 113 114 115
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
116

Pietro Abate's avatar
Pietro Abate committed
117 118
val no_var  : t -> bool
val is_var  : t -> bool
119
val has_tlv : t -> bool
Pietro Abate's avatar
Pietro Abate committed
120
val is_closed : Var.Set.t -> t -> bool
121

122
val any_node : Node.t
123
val empty_node : Node.t
124

125
val non_constructed : t
126
val non_constructed_or_absent : t
127

128 129
(** Constructors **)

130 131
type pair_kind = [ `Normal | `XML ]

132
val var      : Var.var -> t
133 134
val interval : Intervals.t -> t
val atom     : Atoms.t -> t
135 136 137 138
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
139
  (** bool = true -> open record; bool = false -> closed record *)
140
val record_fields : bool * Node.t label_map -> t
141
val char     : Chars.t -> t
142
val constant : const -> t
143
val abstract : Abstract.t -> t
144

145 146
(** Helpers *)

147
val all_vars : t -> Var.Set.t
148 149
val tuple : Node.t list -> t

150
val rec_of_list: bool -> (bool * Ns.Label.t * t) list -> t
151

152
val empty_closed_record: t
153
val empty_open_record: t
154

155 156 157 158 159 160 161
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
162
  val ty: t -> v
163 164
  val cup: v list -> v
  val times: v -> v -> v
165
  val xml: v -> v -> v
166

Pietro Abate's avatar
WIP  
Pietro Abate committed
167
  (* val decompose : t -> v *)
Pietro Abate's avatar
Pietro Abate committed
168 169
  val substitute : t -> (Var.var * t) -> t
  val substituterec : t -> Var.var -> t
170
  val solve: v -> Node.t
Pietro Abate's avatar
Pietro Abate committed
171
  val substitutefree : t -> t
172 173 174 175 176
end

(** Normalization **)

module Product : sig
177 178
  val any : t
  val any_xml : t
179
  val any_of: pair_kind -> t
180 181
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
182 183 184

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
185
  val is_empty: t -> bool
186
  val get: ?kind:pair_kind -> descr -> t
187 188
  val pi1: t -> descr
  val pi2: t -> descr
189
  val pi2_restricted: descr -> t -> descr
190

191 192 193 194 195 196
  (* 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
197
  val normal: ?kind:pair_kind -> descr -> normal
198

199 200 201 202
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

203 204
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
205 206 207 208


  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
209 210 211
end

module Record : sig
212
  val any : t
213 214
  val absent : t
  val absent_node : Node.t
215 216
  val or_absent: t -> t
  val any_or_absent: t
217
  val any_or_absent_node : Node.t
218

219 220
  val has_absent: t -> bool
  val has_record: t -> bool
221

222 223
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
224

225 226 227
  val pi : label -> t -> t
    (* May contain absent *)

228
  val project : t -> label -> t
229 230
    (* Raise Not_found if label is not necessarily present *)

231
  val condition : t -> label -> t -> t
232
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
233 234
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
235

236
  val first_label: t -> label
237
  val all_labels: t -> LabelSet.t
238

239
  val empty_cases: t -> bool * bool
240

241 242
  val merge: t -> t -> t
  val remove_field: t -> label -> t
243

244
  val get: t -> ((bool * t) label_map * bool * bool) list
245 246 247 248 249 250

  type t
  val focus: descr -> label -> t
  val get_this: t -> descr
  val need_others: t -> bool
  val constraint_on_others: t -> descr -> descr
251 252
end

253
module Arrow : sig
254
  val any : t
255

256
  val sample: t -> t
257

Pietro Abate's avatar
Pietro Abate committed
258 259 260 261 262 263
  (** [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.
  *)
264
  val check_strenghten: t -> t -> t
265

266
  val check_iface: (t * t) list -> t -> bool
267

268
  type t = descr * (descr * descr) list list
269
  val is_empty: t -> bool
270 271
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
272

273
  val domain: t -> descr
Pietro Abate's avatar
Pietro Abate committed
274 275

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

Pietro Abate's avatar
Pietro Abate committed
278 279 280
  (** True if the type of the argument is needed to obtain
     the type of the result (must use [apply]; otherwise,
     [apply_noarg] is enough *)
281
  val need_arg : t -> bool
Pietro Abate's avatar
Pietro Abate committed
282

283
  val apply_noarg : t -> descr
284

Pietro Abate's avatar
Pietro Abate committed
285
end
286

287
module Int : sig
288
  val has_int : t -> Intervals.V.t -> bool
289
  val get: t -> BoolIntervals.t
290
  val any : t
291 292
end

293
module Atom : sig
294
  val has_atom : t -> Atoms.V.t -> bool
295
  val get: t -> BoolAtoms.t
296
  val any : t
297 298
end

299
module Char : sig
300
  val has_char : t -> Chars.V.t -> bool
301
  val is_empty : t -> bool
302
  val get: t -> BoolChars.t
303
  val any : t
304 305
end

306 307
val get_abstract: t -> Abstract.t

308
val normalize : t -> t
309

310
(** Subtyping  **)
311

312 313 314
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
315
val disjoint : t -> t -> bool
316
val equiv : t -> t -> bool
317

318 319 320 321 322 323 324 325
(** 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. *)

326 327
module Print :
sig
328
  val register_global : string -> Ns.QName.t -> t -> unit
329 330 331
  val pp_const : Format.formatter -> const -> unit
  val pp_type: Format.formatter -> t -> unit
  val pp_node: Format.formatter -> Node.t -> unit
332 333

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

336 337
  val string_of_type: t -> string
  val string_of_node: Node.t -> string
338
end
339

Jérôme Maloberti's avatar
Jérôme Maloberti committed
340 341 342 343 344 345
module Service :
sig
  val to_service_params: t -> service_params
  val to_string: service_params -> string
end

346
module Witness : sig
347 348 349 350
  type witness
  val print_witness: Format.formatter -> witness -> unit
end
val witness: t -> Witness.witness
351

352

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

  val memo: (t -> 'a) -> (t -> 'a)
end
360 361

module Tallying : sig
362 363 364 365

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

367
  exception UnSatConstr of string
368 369
  exception Step1Fail
  exception Step2Fail
370

371
  module CS : sig
372
    module M : sig
373 374 375 376 377 378
      type key = Var.var
      type t
      val compare  : t -> t -> int
      val empty : t
      val add : key -> descr*descr -> t -> t
      val singleton : key -> descr*descr -> t
Pietro Abate's avatar
Pietro Abate committed
379
      val pp : Format.formatter -> t -> unit
380
      val merge : t -> t -> t
381 382 383
    end
    module E : sig
      include Map.S with type key = Var.var
Pietro Abate's avatar
Pietro Abate committed
384
      val pp : Format.formatter -> descr t -> unit
385
    end
386 387
    module ES : sig
      include Set.S with type elt = descr E.t
Pietro Abate's avatar
Pietro Abate committed
388
      val pp : Format.formatter -> t -> unit
389
    end
390
    module S : sig
391 392 393 394 395 396 397
      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
Pietro Abate's avatar
Pietro Abate committed
398
      val pp : Format.formatter -> t -> unit
399 400 401
    end

    type s = S.t
402
    type m =  M.t
403
    type es = ES.t
404
    type sigma = t E.t
Pietro Abate's avatar
Pietro Abate committed
405
    type sl = sigma list
406

407 408
    val pp_s  : Format.formatter -> s -> unit
    val pp_m  : Format.formatter -> m -> unit
409
    val pp_e  : Format.formatter -> sigma -> unit
410
    val pp_sl : Format.formatter -> sl -> unit
411 412 413 414 415

    val merge : m -> m -> m
    val singleton : constr -> s
    val sat : s
    val unsat : s
Pietro Abate's avatar
Pietro Abate committed
416 417
    val union : s -> s -> s
    val prod : s -> s -> s
418 419
  end

420
  val norm : t -> CS.s
421
  val merge : CS.m -> CS.s
422
  val solve : CS.s -> CS.es
423
  val unify : CS.sigma -> CS.sigma
Pietro Abate's avatar
Pietro Abate committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

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

  val ($$) : t -> CS.sigma -> t

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

  (** Cartesian Product of two symbolic substitution sets *) 
  val ( ++ ) : symsubst list -> symsubst list -> symsubst list

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

443
  val domain : CS.sl -> Var.Set.t
444
  val codomain : CS.sl -> Var.Set.t
445
  val is_identity : CS.sl -> bool
446

447 448
end

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

454
(** apply_raw s t returns the 4-tuple (subst,ss, tt, res) where
455 456
   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
457 458 459 460 461 462
   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)
463