@@ -43,118 +43,145 @@ module type WS = sig
43
43
val compare : t -> t -> int
44
44
end
45
45
46
- module Make (Witnesses : WS ) = struct
47
- (* * Abstract value for each component of the domain. *)
48
- module V = struct
49
- type t =
50
- | Top of Witnesses .t
51
- | Safe
52
- | Bot
53
-
54
- let join c1 c2 =
55
- match c1, c2 with
56
- | Bot , Bot -> Bot
57
- | Safe , Safe -> Safe
58
- | Top w1 , Top w2 -> Top (Witnesses. join w1 w2)
59
- | Safe , Bot | Bot , Safe -> Safe
60
- | Top w1 , Bot | Top w1 , Safe | Bot , Top w1 | Safe , Top w1 -> Top w1
61
-
62
- let meet c1 c2 =
63
- match c1, c2 with
64
- | Bot , Bot -> Bot
65
- | Safe , Safe -> Safe
66
- | Top w1 , Top w2 -> Top (Witnesses. meet w1 w2)
67
- | Safe , Bot | Bot , Safe -> Bot
68
- | Top _ , Bot | Bot , Top _ -> Bot
69
- | Top _ , Safe | Safe , Top _ -> Safe
70
-
71
- let lessequal v1 v2 =
72
- match v1, v2 with
73
- | Bot , Bot -> true
74
- | Safe , Safe -> true
75
- | Top w1 , Top w2 -> Witnesses. lessequal w1 w2
76
- | Bot , Safe -> true
77
- | Bot , Top _ -> true
78
- | Safe , Top _ -> true
79
- | Top _ , (Bot | Safe ) -> false
80
- | Safe , Bot -> false
81
-
82
- let compare t1 t2 =
83
- match t1, t2 with
84
- | Bot , Bot -> 0
85
- | Safe , Safe -> 0
86
- | Top w1 , Top w2 -> Witnesses. compare w1 w2
87
- | Bot , (Safe | Top _ ) -> - 1
88
- | (Safe | Top _ ), Bot -> 1
89
- | Safe , Top _ -> - 1
90
- | Top _ , Safe -> 1
91
-
92
- let is_not_safe = function Top _ -> true | Safe | Bot -> false
93
-
94
- let print ~witnesses ppf = function
95
- | Bot -> Format. fprintf ppf " bot"
96
- | Top w ->
97
- Format. fprintf ppf " top" ;
98
- if witnesses then Format. fprintf ppf " (%a)" Witnesses. print w
99
- | Safe -> Format. fprintf ppf " safe"
100
- end
46
+ module type Component = sig
47
+ type t
48
+
49
+ type witnesses
50
+
51
+ val top : witnesses -> t
52
+
53
+ val safe : t
54
+
55
+ val bot : t
56
+
57
+ val lessequal : t -> t -> bool
58
+
59
+ val join : t -> t -> t
60
+
61
+ val meet : t -> t -> t
101
62
102
- module Value = struct
103
- (* * Lifts V to triples *)
104
- type t =
105
- { nor : V .t ;
106
- exn : V .t ;
107
- div : V .t
108
- }
63
+ val compare : t -> t -> int
64
+
65
+ val print : witnesses :bool -> Format .formatter -> t -> unit
66
+ end
67
+
68
+ module Make_component (Witnesses : WS ) = struct
69
+ (* keep in sync with "resolved" values in Checkmach. *)
70
+ type t =
71
+ | Top of Witnesses .t
72
+ | Safe
73
+ | Bot
74
+
75
+ let bot = Bot
76
+
77
+ let top w = Top w
78
+
79
+ let safe = Safe
80
+
81
+ let join c1 c2 =
82
+ match c1, c2 with
83
+ | Bot , Bot -> Bot
84
+ | Safe , Safe -> Safe
85
+ | Top w1 , Top w2 -> Top (Witnesses. join w1 w2)
86
+ | Safe , Bot | Bot , Safe -> Safe
87
+ | Top w1 , Bot | Top w1 , Safe | Bot , Top w1 | Safe , Top w1 -> Top w1
88
+
89
+ let meet c1 c2 =
90
+ match c1, c2 with
91
+ | Bot , Bot -> Bot
92
+ | Safe , Safe -> Safe
93
+ | Top w1 , Top w2 -> Top (Witnesses. meet w1 w2)
94
+ | Safe , Bot | Bot , Safe -> Bot
95
+ | Top _ , Bot | Bot , Top _ -> Bot
96
+ | Top _ , Safe | Safe , Top _ -> Safe
97
+
98
+ let lessequal v1 v2 =
99
+ match v1, v2 with
100
+ | Bot , Bot -> true
101
+ | Safe , Safe -> true
102
+ | Top w1 , Top w2 -> Witnesses. lessequal w1 w2
103
+ | Bot , Safe -> true
104
+ | Bot , Top _ -> true
105
+ | Safe , Top _ -> true
106
+ | Top _ , (Bot | Safe ) -> false
107
+ | Safe , Bot -> false
108
+
109
+ let compare t1 t2 =
110
+ match t1, t2 with
111
+ | Bot , Bot -> 0
112
+ | Safe , Safe -> 0
113
+ | Top w1 , Top w2 -> Witnesses. compare w1 w2
114
+ | Bot , (Safe | Top _ ) -> - 1
115
+ | (Safe | Top _ ), Bot -> 1
116
+ | Safe , Top _ -> - 1
117
+ | Top _ , Safe -> 1
118
+
119
+ let print ~witnesses ppf = function
120
+ | Bot -> Format. fprintf ppf " bot"
121
+ | Top w ->
122
+ Format. fprintf ppf " top" ;
123
+ if witnesses then Format. fprintf ppf " (%a)" Witnesses. print w
124
+ | Safe -> Format. fprintf ppf " safe"
125
+ end
109
126
110
- let bot = { nor = V. Bot ; exn = V. Bot ; div = V. Bot }
127
+ module Make_value
128
+ (Witnesses : WS )
129
+ (V : Component with type witnesses := Witnesses.t ) =
130
+ struct
131
+ (* * Lifts V to triples *)
132
+ type t =
133
+ { nor : V .t ;
134
+ exn : V .t ;
135
+ div : V .t
136
+ }
111
137
112
- let lessequal v1 v2 =
113
- V. lessequal v1.nor v2.nor && V. lessequal v1.exn v2.exn
114
- && V. lessequal v1.div v2.div
138
+ let bot = { nor = V. bot; exn = V. bot; div = V. bot }
115
139
116
- let join v1 v2 =
117
- { nor = V. join v1.nor v2.nor;
118
- exn = V. join v1.exn v2.exn ;
119
- div = V. join v1.div v2.div
120
- }
140
+ let lessequal v1 v2 =
141
+ V. lessequal v1.nor v2.nor && V. lessequal v1.exn v2.exn
142
+ && V. lessequal v1.div v2.div
121
143
122
- let meet v1 v2 =
123
- { nor = V. meet v1.nor v2.nor;
124
- exn = V. meet v1.exn v2.exn ;
125
- div = V. meet v1.div v2.div
126
- }
144
+ let join v1 v2 =
145
+ { nor = V. join v1.nor v2.nor;
146
+ exn = V. join v1.exn v2.exn ;
147
+ div = V. join v1.div v2.div
148
+ }
127
149
128
- let normal_return = { bot with nor = V. Safe }
150
+ let meet v1 v2 =
151
+ { nor = V. meet v1.nor v2.nor;
152
+ exn = V. meet v1.exn v2.exn ;
153
+ div = V. meet v1.div v2.div
154
+ }
129
155
130
- let exn_escape = { bot with exn = V. Safe }
156
+ let normal_return = { bot with nor = V. safe }
131
157
132
- let diverges = { bot with div = V. Safe }
158
+ let exn_escape = { bot with exn = V. safe }
133
159
134
- let safe = { nor = V. Safe ; exn = V. Safe ; div = V. Safe }
160
+ let diverges = { bot with div = V. safe }
135
161
136
- let top w = { nor = V. Top w ; exn = V. Top w ; div = V. Top w }
162
+ let safe = { nor = V. safe ; exn = V. safe ; div = V. safe }
137
163
138
- let relaxed w = { nor = V. Safe ; exn = V. Top w; div = V. Top w }
164
+ let top w = { nor = V. top w ; exn = V. top w; div = V. top w }
139
165
140
- let of_annotation ~strict ~never_returns_normally ~never_raises =
141
- let res = if strict then safe else relaxed Witnesses. empty in
142
- let res = if never_raises then { res with exn = V. Bot } else res in
143
- if never_returns_normally then { res with nor = V. Bot } else res
166
+ let relaxed w = { nor = V. safe; exn = V. top w; div = V. top w }
144
167
145
- let print ~witnesses ppf { nor; exn; div } =
146
- let pp = V. print ~witnesses in
147
- Format. fprintf ppf " { nor=%a; exn=%a; div=%a }" pp nor pp exn pp div
168
+ let of_annotation ~strict ~never_returns_normally ~never_raises =
169
+ let res = if strict then safe else relaxed Witnesses. empty in
170
+ let res = if never_raises then { res with exn = V. bot } else res in
171
+ if never_returns_normally then { res with nor = V. bot } else res
148
172
149
- let compare { nor = n1 ; exn = e1 ; div = d1 }
150
- { nor = n2 ; exn = e2 ; div = d2 } =
151
- let c = V. compare n1 n2 in
152
- if c <> 0
153
- then c
154
- else
155
- let c = V. compare e1 e2 in
156
- if c <> 0 then c else V. compare d1 d2
157
- end
173
+ let print ~witnesses ppf { nor; exn; div } =
174
+ let pp = V. print ~witnesses in
175
+ Format. fprintf ppf " { nor=%a;@ exn=%a;@ div=%a }@," pp nor pp exn pp div
176
+
177
+ let compare { nor = n1 ; exn = e1 ; div = d1 } { nor = n2 ; exn = e2 ; div = d2 }
178
+ =
179
+ let c = V. compare n1 n2 in
180
+ if c <> 0
181
+ then c
182
+ else
183
+ let c = V. compare e1 e2 in
184
+ if c <> 0 then c else V. compare d1 d2
158
185
end
159
186
160
187
module Assume_info = struct
@@ -174,7 +201,8 @@ module Assume_info = struct
174
201
let compare _ _ = 0
175
202
end
176
203
177
- include Make (Witnesses )
204
+ module V = Make_component (Witnesses )
205
+ module Value = Make_value (Witnesses ) (V )
178
206
179
207
type t =
180
208
| No_assume
0 commit comments