Skip to content

Commit 13e2c8f

Browse files
authored
[Bennet] Re-impl old specialization (#465)
1 parent d5ead9d commit 13e2c8f

File tree

31 files changed

+1246
-73
lines changed

31 files changed

+1246
-73
lines changed

lib/testGeneration/bennet/abstractDomains/interpreter.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Make (GT : GenTerms.T) (I : Domain.T with type t = GT.AD.t) = struct
1616
match tm_ with
1717
| `Arbitrary -> (GT.arbitrary_ tag bt loc, [ d ])
1818
| `Symbolic -> (GT.symbolic_ tag bt loc, [ d ])
19+
| `ArbitrarySpecialized bounds ->
20+
(GT.arbitrary_specialized_ bounds tag bt loc, [ d ])
1921
| `ArbitraryDomain _ -> failwith ("unreachable @ " ^ __LOC__)
2022
| `Return _ ->
2123
let tm' = if should_assert then GT.assert_domain_ (d, tm) tag loc else tm in

lib/testGeneration/bennet/abstractDomains/interval_.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ module IntervalBasis = struct
112112
else if is_top b then
113113
!^""
114114
else if Z.equal start stop then
115-
!^(Z.to_string start)
115+
z start
116116
else
117-
brackets (!^(Z.to_string start) ^^ !^".." ^^ !^(Z.to_string stop))
117+
brackets (z start ^^ !^".." ^^ z stop)
118118

119119

120120
let forward_abs_binop (op : IT.binop) (b1 : t) (b2 : t) : t option =

lib/testGeneration/bennet/abstractDomains/wrappedInterval.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,9 @@ module WrappedIntervalBasis = struct
720720
else if is_top b then
721721
!^""
722722
else if Z.equal start stop then
723-
!^(Z.to_string start)
723+
z start
724724
else
725-
brackets (!^(Z.to_string start) ^^ !^".." ^^ !^(Z.to_string stop))
725+
brackets (z start ^^ !^".." ^^ z stop)
726726

727727

728728
(* Bitwise operation helpers *)

lib/testGeneration/bennet/bennet.ml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,38 @@ let debug_stage (stage : string) (str : string) : unit =
3232

3333

3434
let parse_domain (s : string list) : (module Domain.T) =
35-
let domain_names =
36-
s |> List.map String.trim |> List.filter (fun x -> String.length x > 0)
37-
in
38-
(* Parse individual domain names *)
39-
let parse_single_domain (name : string) : (module Domain.T) option =
40-
match name with
41-
| _ when String.equal name AbstractDomains.Ownership.name ->
42-
Pp.(warn_noloc !^"Ownership abstract domain is always included");
43-
None
44-
| _ when String.equal name AbstractDomains.Interval.name ->
45-
Some (module AbstractDomains.Interval)
46-
| _ when String.equal name AbstractDomains.WrappedInterval.name ->
47-
Some (module AbstractDomains.WrappedInterval)
48-
| _ ->
49-
Pp.warn_noloc Pp.(!^"Unknown abstract domain," ^^^ squotes !^name);
50-
None
51-
in
52-
match domain_names with
53-
| [] ->
54-
(* No domains specified - return ownership domain *)
55-
(module AbstractDomains.Ownership)
56-
| additional_domains ->
57-
(* Parse additional domains and filter out ownership if already specified *)
58-
let parsed_additional = List.filter_map parse_single_domain additional_domains in
59-
let ownership_module = (module AbstractDomains.Ownership : Domain.T) in
60-
(* Check if ownership is already in the list *)
61-
let all_domains = ownership_module :: parsed_additional in
62-
(match all_domains with
63-
| [ single ] -> single (* If only ownership, return it directly *)
64-
| multiple -> AbstractDomains.product_domains multiple)
35+
if List.is_empty s then (* Default *)
36+
AbstractDomains.product_domains
37+
[ (module AbstractDomains.Ownership); (module AbstractDomains.Interval) ]
38+
else (
39+
let domain_names =
40+
s |> List.map String.trim |> List.filter (fun x -> String.length x > 0)
41+
in
42+
(* Parse individual domain names *)
43+
let parse_single_domain (name : string) : (module Domain.T) option =
44+
match name with
45+
| _ when String.equal name AbstractDomains.Ownership.name -> None
46+
| _ when String.equal name AbstractDomains.Interval.name ->
47+
Some (module AbstractDomains.Interval)
48+
| _ when String.equal name AbstractDomains.WrappedInterval.name ->
49+
Some (module AbstractDomains.WrappedInterval)
50+
| _ ->
51+
Pp.warn_noloc Pp.(!^"Unknown abstract domain," ^^^ squotes !^name);
52+
None
53+
in
54+
match domain_names with
55+
| [] ->
56+
(* No domains specified - return ownership domain *)
57+
(module AbstractDomains.Ownership)
58+
| additional_domains ->
59+
(* Parse additional domains and filter out ownership if already specified *)
60+
let parsed_additional = List.filter_map parse_single_domain additional_domains in
61+
let ownership_module = (module AbstractDomains.Ownership : Domain.T) in
62+
(* Check if ownership is already in the list *)
63+
let all_domains = ownership_module :: parsed_additional in
64+
(match all_domains with
65+
| [ single ] -> single (* If only ownership, return it directly *)
66+
| multiple -> AbstractDomains.product_domains multiple))
6567

6668

6769
let test_setup () : Pp.document =

lib/testGeneration/bennet/genContext.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ module Make (GT : GenTerms.T) = struct
3030
let rec aux (gt : GT.t) : Sym.Set.t =
3131
let (Annot (gt_, _, _, _)) = gt in
3232
match gt_ with
33-
| `Arbitrary | `Symbolic | `ArbitraryDomain _ | `Return _ -> Sym.Set.empty
33+
| `Arbitrary | `Symbolic | `ArbitrarySpecialized _ | `ArbitraryDomain _
34+
| `Return _ ->
35+
Sym.Set.empty
3436
| `Pick gts -> gts |> List.map aux |> List.fold_left Sym.Set.union Sym.Set.empty
3537
| `PickSized wgts | `PickSizedElab (_, wgts) ->
3638
wgts

lib/testGeneration/bennet/genTerms.ml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module Base (AD : Domain.T) = struct
1111
type ('tag, 'recur) ast =
1212
[ `Arbitrary (** Generate arbitrary values *)
1313
| `Symbolic (** Generate symbolic values *)
14+
| `ArbitrarySpecialized of (IT.t option * IT.t option) * (IT.t option * IT.t option)
15+
(** Generate arbitrary values: ((min_inc, min_ex), (max_inc, max_ex)) *)
1416
| `ArbitraryDomain of AD.Relative.t
1517
| `Call of Sym.t * IT.t list
1618
(** Call a defined generator according to a [Sym.t] with arguments [IT.t list] *)
@@ -56,6 +58,13 @@ module type T = sig
5658

5759
val symbolic_ : tag_t -> BT.t -> Locations.t -> t
5860

61+
val arbitrary_specialized_
62+
: (IT.t option * IT.t option) * (IT.t option * IT.t option) ->
63+
tag_t ->
64+
BT.t ->
65+
Locations.t ->
66+
t
67+
5968
val arbitrary_domain_ : AD.Relative.t -> tag_t -> BT.t -> Locations.t -> t
6069

6170
val call_ : Sym.t * IT.t list -> tag_t -> BT.t -> Locations.t -> t
@@ -149,6 +158,17 @@ module Make (GT : T) = struct
149158
match tm_ with
150159
| `Arbitrary -> !^"arbitrary" ^^ angles (BT.pp bt) ^^ parens empty
151160
| `Symbolic -> !^"symbolic" ^^ angles (BT.pp bt) ^^ parens empty
161+
| `ArbitrarySpecialized ((min_inc, min_ex), (max_inc, max_ex)) ->
162+
let pp_opt = function
163+
| None -> !^"None"
164+
| Some it -> !^"Some" ^^^ parens (IT.pp it)
165+
in
166+
!^"arbitrary_specialized"
167+
^^ angles (BT.pp bt)
168+
^^ parens
169+
(parens (pp_opt min_inc ^^ comma ^^^ pp_opt min_ex)
170+
^^ comma
171+
^^^ parens (pp_opt max_inc ^^ comma ^^^ pp_opt max_ex))
152172
| `ArbitraryDomain d ->
153173
!^"arbitrary_domain" ^^ angles (BT.pp bt) ^^ parens (AD.Relative.pp d)
154174
| `Call (fsym, iargs) ->
@@ -255,6 +275,8 @@ module Make (GT : T) = struct
255275
let rec free_vars_bts_ (gt_ : GT.t_) : BT.t Sym.Map.t =
256276
match gt_ with
257277
| `Arbitrary | `ArbitraryDomain _ | `Symbolic -> Sym.Map.empty
278+
| `ArbitrarySpecialized ((min_inc, min_ex), (max_inc, max_ex)) ->
279+
IT.free_vars_bts_list (List.filter_map Fun.id [ min_inc; min_ex; max_inc; max_ex ])
258280
| `Call (_, iargs) | `CallSized (_, iargs, _) -> IT.free_vars_bts_list iargs
259281
| `Asgn ((it_addr, _), it_val, gt') | `AsgnElab (_, ((_, it_addr), _), it_val, gt') ->
260282
Sym.Map.union
@@ -323,7 +345,8 @@ module Make (GT : T) = struct
323345
let rec contains_call (gt : GT.t) : bool =
324346
let (Annot (gt_, _, _, _)) = gt in
325347
match gt_ with
326-
| `Arbitrary | `ArbitraryDomain _ | `Symbolic | `Return _ -> false
348+
| `Arbitrary | `ArbitraryDomain _ | `ArbitrarySpecialized _ | `Symbolic | `Return _ ->
349+
false
327350
| `Call _ | `CallSized _ -> true
328351
| `LetStar ((_, gt1), gt2) | `ITE (_, gt1, gt2) ->
329352
contains_call gt1 || contains_call gt2
@@ -344,7 +367,8 @@ module Make (GT : T) = struct
344367
let rec contains_constraint (gt : GT.t) : bool =
345368
let (Annot (gt_, _, _, _)) = gt in
346369
match gt_ with
347-
| `Arbitrary | `ArbitraryDomain _ | `Symbolic | `Return _ -> false
370+
| `Arbitrary | `ArbitraryDomain _ | `ArbitrarySpecialized _ | `Symbolic | `Return _ ->
371+
false
348372
| `Asgn _ | `AsgnElab _ | `Assert _ | `AssertDomain _ -> true
349373
| `Call _ | `CallSized _ -> true (* Could be less conservative... *)
350374
| `LetStar ((_, gt1), gt2) | `ITE (_, gt1, gt2) ->
@@ -362,6 +386,11 @@ module Make (GT : T) = struct
362386
let (Annot (gt_, _, _, _)) = gt in
363387
match gt_ with
364388
| `Arbitrary | `Symbolic | `ArbitraryDomain _ -> Sym.Set.empty
389+
| `ArbitrarySpecialized ((min_inc, min_ex), (max_inc, max_ex)) ->
390+
[ min_inc; min_ex; max_inc; max_ex ]
391+
|> List.filter_map Fun.id
392+
|> List.map IT.preds_of
393+
|> List.fold_left Sym.Set.union Sym.Set.empty
365394
| `Return it -> IT.preds_of it
366395
| `Call (_, its) | `CallSized (_, its, _) ->
367396
its |> List.map IT.preds_of |> List.fold_left Sym.Set.union Sym.Set.empty
@@ -392,6 +421,13 @@ module Make (GT : T) = struct
392421
match gt_ with
393422
| `Arbitrary -> arbitrary_ tag bt loc
394423
| `Symbolic -> symbolic_ tag bt loc
424+
| `ArbitrarySpecialized ((min_inc, min_ex), (max_inc, max_ex)) ->
425+
arbitrary_specialized_
426+
( (Option.map (IT.subst su) min_inc, Option.map (IT.subst su) min_ex),
427+
(Option.map (IT.subst su) max_inc, Option.map (IT.subst su) max_ex) )
428+
tag
429+
bt
430+
loc
395431
| `ArbitraryDomain ad -> arbitrary_domain_ ad tag bt loc
396432
| `Call (fsym, iargs) -> call_ (fsym, List.map (IT.subst su) iargs) tag bt loc
397433
| `CallSized (fsym, iargs, sz) ->
@@ -460,6 +496,7 @@ module Make (GT : T) = struct
460496
match gt_ with
461497
| `Arbitrary -> arbitrary_ tag bt loc
462498
| `Symbolic -> symbolic_ tag bt loc
499+
| `ArbitrarySpecialized bounds -> arbitrary_specialized_ bounds tag bt loc
463500
| `ArbitraryDomain ad -> arbitrary_domain_ ad tag bt loc
464501
| `Call (fsym, its) -> call_ (fsym, its) tag bt loc
465502
| `CallSized (fsym, its, sz) -> call_sized_ (fsym, its, sz) tag bt loc
@@ -502,6 +539,7 @@ module Make (GT : T) = struct
502539
match gt_ with
503540
| `Arbitrary -> arbitrary_ tag bt loc
504541
| `Symbolic -> symbolic_ tag bt loc
542+
| `ArbitrarySpecialized bounds -> arbitrary_specialized_ bounds tag bt loc
505543
| `ArbitraryDomain ad -> arbitrary_domain_ ad tag bt loc
506544
| `Call (fsym, its) -> call_ (fsym, its) tag bt loc
507545
| `CallSized (fsym, its, sz) -> call_sized_ (fsym, its, sz) tag bt loc
@@ -544,6 +582,7 @@ module Make (GT : T) = struct
544582
match tm with
545583
| `Arbitrary -> `Arbitrary
546584
| `Symbolic -> `Symbolic
585+
| `ArbitrarySpecialized bounds -> `ArbitrarySpecialized bounds
547586
| `ArbitraryDomain ad -> `ArbitraryDomain ad
548587
| `Call (fsym, iargs) -> `Call (fsym, iargs)
549588
| `CallSized (fsym, iargs, sz) -> `CallSized (fsym, iargs, sz)
@@ -576,6 +615,7 @@ module Make (GT : T) = struct
576615
match tm_ with
577616
| `Arbitrary -> arbitrary_ tag bt loc
578617
| `Symbolic -> symbolic_ tag bt loc
618+
| `ArbitrarySpecialized bounds -> arbitrary_specialized_ bounds tag bt loc
579619
| `ArbitraryDomain ad -> arbitrary_domain_ ad tag bt loc
580620
| `Call (fsym, iargs) -> call_ (fsym, iargs) tag bt loc
581621
| `CallSized (fsym, iargs, sz) -> call_sized_ (fsym, iargs, sz) tag bt loc
@@ -678,6 +718,8 @@ module Defaults (StageName : sig
678718
struct
679719
let unsupported name = failwith (name ^ " not supported in " ^ StageName.name ^ " DSL")
680720

721+
let arbitrary_specialized_ _ _ _ _ = unsupported "arbitrary_specialized_"
722+
681723
let arbitrary_domain_ _ _ _ _ = unsupported "arbitrary_domain_"
682724

683725
let pick_ _ _ _ _ = unsupported "pick_"

lib/testGeneration/bennet/stage3/smtPruning.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module Make (AD : Domain.T) = struct
1313
let here = Locations.other __LOC__ in
1414
let (Annot (tm_, (), bt, loc)) = tm in
1515
match tm_ with
16-
| `Arbitrary | `ArbitraryDomain _ | `Symbolic | `Return _ | `Call _ ->
16+
| `Arbitrary | `ArbitraryDomain _ | `ArbitrarySpecialized _ | `Symbolic | `Return _
17+
| `Call _ ->
1718
let@ check = provable loc in
1819
return
1920
(match check (LC.T (IT.bool_ false here)) with

0 commit comments

Comments
 (0)