Skip to content

Commit bec5181

Browse files
committed
Add YAML witness loop_transition_invariant and location_transition_invariant parsing support
1 parent 2fa1e42 commit bec5181

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/analyses/unassumeAnalysis.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ struct
222222
unassume_loop_invariant ~i x
223223
| false, (LocationInvariant _ | LoopInvariant _) ->
224224
M.info_noloc ~category:Witness "disabled invariant of type %s" target_type
225+
| _ ->
226+
M.warn_noloc ~category:Witness "cannot unassume invariant of type %s" target_type
225227
in
226228

227229
List.iteri validate_invariant invariant_set.content

src/witness/yamlWitness.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,10 @@ struct
866866
validate_loop_invariant x
867867
| false, (LocationInvariant _ | LoopInvariant _) ->
868868
incr cnt_disabled;
869-
M.info_noloc ~category:Witness "disabled invariant of type %s" target_type;
869+
M.info_noloc ~category:Witness "disabled invariant of type %s" target_type
870+
| _ ->
871+
incr cnt_unsupported;
872+
M.warn_noloc ~category:Witness "cannot validate invariant of type %s" target_type
870873
in
871874

872875
List.iter validate_invariant invariant_set.content

src/witness/yamlWitnessType.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,41 @@ struct
302302
let invariant_type = "location_invariant"
303303
end
304304

305+
module LoopTransitionInvariant =
306+
struct
307+
include LoopInvariant
308+
309+
let invariant_type = "loop_transition_invariant"
310+
end
311+
312+
module LocationTransitionInvariant =
313+
struct
314+
include LoopTransitionInvariant
315+
316+
let invariant_type = "location_transition_invariant"
317+
end
318+
305319
(* TODO: could maybe use GADT, but adds ugly existential layer to entry type pattern matching *)
306320
module InvariantType =
307321
struct
308322
type t =
309323
| LocationInvariant of LocationInvariant.t
310324
| LoopInvariant of LoopInvariant.t
325+
| LoopTransitionInvariant of LoopTransitionInvariant.t
326+
| LocationTransitionInvariant of LocationTransitionInvariant.t
311327
[@@deriving eq, ord, hash]
312328

313329
let invariant_type = function
314330
| LocationInvariant _ -> LocationInvariant.invariant_type
315331
| LoopInvariant _ -> LoopInvariant.invariant_type
332+
| LoopTransitionInvariant _ -> LoopTransitionInvariant.invariant_type
333+
| LocationTransitionInvariant _ -> LocationTransitionInvariant.invariant_type
316334

317335
let to_yaml' = function
318336
| LocationInvariant x -> LocationInvariant.to_yaml' x
319337
| LoopInvariant x -> LoopInvariant.to_yaml' x
338+
| LoopTransitionInvariant x -> LoopTransitionInvariant.to_yaml' x
339+
| LocationTransitionInvariant x -> LocationTransitionInvariant.to_yaml' x
320340

321341
let of_yaml y =
322342
let open GobYaml in
@@ -327,6 +347,12 @@ struct
327347
else if invariant_type = LoopInvariant.invariant_type then
328348
let+ x = y |> LoopInvariant.of_yaml in
329349
LoopInvariant x
350+
else if invariant_type = LoopTransitionInvariant.invariant_type then
351+
let+ x = y |> LoopTransitionInvariant.of_yaml in
352+
LoopTransitionInvariant x
353+
else if invariant_type = LocationTransitionInvariant.invariant_type then
354+
let+ x = y |> LocationTransitionInvariant.of_yaml in
355+
LocationTransitionInvariant x
330356
else
331357
Error (`Msg "type")
332358
end

tests/util/yamlWitnessStripCommon.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ struct
2525
LocationInvariant {x with location = location_strip_file_hash x.location}
2626
| LoopInvariant x ->
2727
LoopInvariant {x with location = location_strip_file_hash x.location}
28+
| LoopTransitionInvariant x ->
29+
LoopTransitionInvariant {x with location = location_strip_file_hash x.location}
30+
| LocationTransitionInvariant x ->
31+
LocationTransitionInvariant {x with location = location_strip_file_hash x.location}
2832
in
2933
{invariant_type}
3034
in

0 commit comments

Comments
 (0)