Skip to content

Commit 8ed3329

Browse files
committed
Fix YAML witness tests by distinguishing missing labels from empty labels
1 parent a58b789 commit 8ed3329

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/analyses/unassumeAnalysis.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ struct
216216
let validate_invariant i (invariant: YamlWitnessType.InvariantSet.Invariant.t) =
217217
let target_type = YamlWitnessType.InvariantSet.InvariantType.invariant_type invariant.invariant_type in
218218
match YamlWitness.invariant_type_enabled target_type, invariant.invariant_type with
219-
| true, LocationInvariant ({labels = []; _} as x) ->
219+
| true, LocationInvariant ({labels = (None | Some []); _} as x) ->
220220
unassume_location_invariant ~i x
221-
| true, LoopInvariant ({labels = []; _} as x) ->
221+
| true, LoopInvariant ({labels = (None | Some []); _} as x) ->
222222
unassume_loop_invariant ~i x
223223
| false, (LocationInvariant _ | LoopInvariant _) ->
224224
M.info_noloc ~category:Witness "disabled invariant of type %s" target_type

src/witness/yamlWitness.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct
104104
location;
105105
value = invariant;
106106
format = "c_expression";
107-
labels = [];
107+
labels = None;
108108
};
109109
}
110110

@@ -114,7 +114,7 @@ struct
114114
location;
115115
value = invariant;
116116
format = "c_expression";
117-
labels = [];
117+
labels = None;
118118
};
119119
}
120120

@@ -864,9 +864,9 @@ struct
864864
let validate_invariant (invariant: YamlWitnessType.InvariantSet.Invariant.t) =
865865
let target_type = YamlWitnessType.InvariantSet.InvariantType.invariant_type invariant.invariant_type in
866866
match invariant_type_enabled target_type, invariant.invariant_type with
867-
| true, LocationInvariant ({labels = []; _} as x) ->
867+
| true, LocationInvariant ({labels = (None | Some []); _} as x) ->
868868
validate_location_invariant x
869-
| true, LoopInvariant ({labels = []; _} as x) ->
869+
| true, LoopInvariant ({labels = (None | Some []); _} as x) ->
870870
validate_loop_invariant x
871871
| false, (LocationInvariant _ | LoopInvariant _) ->
872872
incr cnt_disabled;

src/witness/yamlWitnessType.ml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct
275275
location: Location.t;
276276
value: string;
277277
format: string;
278-
labels: string list;
278+
labels: string list option;
279279
}
280280
[@@deriving eq, ord, hash]
281281

@@ -286,15 +286,18 @@ struct
286286
("location", Location.to_yaml location);
287287
("value", `String value);
288288
("format", `String format);
289-
("labels", `A (List.map (fun label -> `String label) labels));
290-
]
289+
] @ match labels with
290+
| Some labels -> [
291+
("labels", `A (List.map (fun label -> `String label) labels));
292+
]
293+
| None -> []
291294

292295
let of_yaml y =
293296
let open GobYaml in
294297
let+ location = y |> find "location" >>= Location.of_yaml
295298
and+ value = y |> find "value" >>= to_string
296299
and+ format = y |> find "format" >>= to_string
297-
and+ labels = y |> find "labels" >>= list >>= list_map to_string in
300+
and+ labels = y |> Yaml.Util.find "labels" >>= option_map (fun y -> y |> list >>= list_map to_string) in
298301
{location; value; format; labels}
299302
end
300303

@@ -390,7 +393,7 @@ struct
390393
requires: string;
391394
ensures: string;
392395
format: string;
393-
labels: string list;
396+
labels: string list option;
394397
}
395398
[@@deriving eq, ord, hash]
396399

@@ -402,16 +405,19 @@ struct
402405
("requires", `String requires);
403406
("ensures", `String ensures);
404407
("format", `String format);
405-
("labels", `A (List.map (fun label -> `String label) labels));
406-
]
408+
] @ match labels with
409+
| Some labels -> [
410+
("labels", `A (List.map (fun label -> `String label) labels));
411+
]
412+
| None -> []
407413

408414
let of_yaml y =
409415
let open GobYaml in
410416
let+ location = y |> find "location" >>= Location.of_yaml
411417
and+ requires = y |> find "requires" >>= to_string
412418
and+ ensures = y |> find "ensures" >>= to_string
413419
and+ format = y |> find "format" >>= to_string
414-
and+ labels = y |> find "labels" >>= list >>= list_map to_string in
420+
and+ labels = y |> Yaml.Util.find "labels" >>= option_map (fun y -> y |> list >>= list_map to_string) in
415421
{location; requires; ensures; format; labels}
416422
end
417423

0 commit comments

Comments
 (0)