@@ -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
678718struct
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_"
0 commit comments