-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixConfig.ml
165 lines (141 loc) · 5.79 KB
/
fixConfig.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
(*
* Copyright © 2009 The Regents of the University of California. All rights reserved.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION
* TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*)
module Sy = Ast.Symbol
module SM = Sy.SMap
module Q = Qualifier
module C = FixConstraint
module So = Ast.Sort
open Misc.Ops
exception UnmappedKvar of Ast.Symbol.t
type qbind = Q.t list
type solbind = Ast.Symbol.t * ((Ast.Symbol.t * (Ast.expr list)) list)
type deft = Srt of Ast.Sort.t
| Axm of Ast.pred
| Cst of FixConstraint.t
| Wfc of FixConstraint.wf
| Con of Ast.Symbol.t * Ast.Sort.t
| Sol of solbind
(* | Sol of Ast.Symbol.t * (Ast.pred * (Ast.Symbol.t * Ast.Subst.t)) list *)
| Qul of Q.t
| Dep of FixConstraint.dep
type 'bind cfg = {
a : int (* Tag arity *)
; ts : Ast.Sort.t list (* New sorts, now = []*)
; ps : Ast.pred list (* New axioms, now = [] *)
; cs : FixConstraint.t list
; ws : FixConstraint.wf list
; ds : FixConstraint.dep list
; qs : Q.t list
; bm : 'bind SM.t (* Initial Sol Bindings *)
; uops : Ast.Sort.t Ast.Symbol.SMap.t (* Globals: measures + distinct consts) *)
; cons : Ast.Symbol.t list (* Distinct Constants, defined in uops *)
; assm : FixConstraint.soln (* Seed Solution -- must be a fixpoint over constraints *)
}
let get_arity = function
| [] -> Constants.logPrintf "WARNING: NO CONSTRAINTS!"; 0
| c::_ -> c |> FixConstraint.tag_of_t |> fst |> List.length
(* {{{
let qual_rename i q =
Q.rename ((Q.name_of_t q)^(string_of_int i)) q
let sift_quals ds =
ds |> Misc.map_partial (function Qul q -> Some q | _ -> None)
|> List.fold_left begin fun (i, m) q ->
let n = Q.name_of_t q in
let (i',q') = if MSM.mem n m then (i+1, qual_rename i q) else (i, q) in
(i', MSM.add (Q.name_of_t q') q' m)
end (0, MSM.empty)
>> (fun (i, _) -> if i <> 0 then Constants.logPrintf "WARNING: duplicate qualifier names")
|> snd
}}} *)
let sift_quals ds =
ds |> Misc.map_partial (function Qul q -> Some q | _ -> None)
>> (fun _ -> print_now "BEGIN: Q.normalize\n")
|> Q.normalize
>> (fun _ -> print_now "DONE: Q.normalize\n")
|> Misc.map (Misc.pad_fst Q.name_of_t)
|> SM.of_list
let extend f cfg = function
| Srt t -> {cfg with ts = t :: cfg.ts }
| Axm p -> {cfg with ps = p :: cfg.ps }
| Cst c -> {cfg with cs = c :: cfg.cs }
| Wfc w -> {cfg with ws = w :: cfg.ws }
| Dep d -> {cfg with ds = d :: cfg.ds }
| Qul q -> {cfg with qs = q :: cfg.qs }
| Sol (k, fess) -> {cfg with bm = SM.add k (List.map f fess) cfg.bm }
| Con (s,t) -> {cfg with cons = if So.is_func t then cfg.cons else s :: cfg.cons
; uops = SM.add s t cfg.uops}
let empty = { a = 0 ; ts = []; ps = []
; cs = []; ws = []; ds = []
; qs = []; bm = SM.empty
; cons = []; uops = SM.empty
; assm = FixConstraint.empty_solution }
let fes2q qm (f, es) =
let q = SM.safeFind f qm "name2qual" in
q |> Q.all_params_of_t
|> List.map fst
|> Misc.flip (Misc.combine "FixConfig.fes2q") es
|> Q.inst q
(* API *)
let create ds =
let qm = sift_quals ds in
ds |> List.fold_left (extend (fes2q qm)) empty
|> (fun cfg -> {cfg with a = get_arity cfg.cs})
|> (fun cfg -> {cfg with ws = C.add_wf_ids cfg.ws})
(* API *)
let create_raw ts env ps a ds cs ws qs assm =
{ empty with
a = a
; ts = ts
; uops = env
; ps = ps
; ds = ds
; cs = cs
; ws = C.add_wf_ids ws
; qs = Q.normalize qs
; assm = assm
}
module type DOMAIN = sig
type t
type bind
val empty : t
(* val meet : t -> t -> t *)
val min_read : t -> FixConstraint.soln
val read : t -> FixConstraint.soln
val read_bind : t -> Ast.Symbol.t -> bind
val top : t -> Ast.Symbol.t list -> t
val refine : t -> FixConstraint.t -> (bool * t)
val unsat : t -> FixConstraint.t -> bool
val create : bind cfg -> FixConstraint.soln option -> t
val print : Format.formatter -> t -> unit
val print_stats : Format.formatter -> t -> unit
val dump : t -> unit
val ctr_examples : t -> FixConstraint.t list -> FixConstraint.t list -> Counterexample.cex list
val mkbind : qbind -> bind
end
(* type t = Ast.Qualifier.def list list cfg *)
let print ppf me =
(* Print cs *)
Format.fprintf ppf "@[%a@] \n" (Misc.pprint_many true "\n" (C.print_t None)) me.cs;
(* Print ws *)
Format.fprintf ppf "@[%a@] \n" (Misc.pprint_many true "\n" (C.print_wf None)) me.ws;
(* Print qs *)
Format.fprintf ppf "@[%a@] \n" (Misc.pprint_many true "\n" Q.print) (Q.normalize me.qs)