Skip to content

Commit

Permalink
Try base_quickcheck deriving
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 7, 2024
1 parent 0fd9c4b commit 44c715d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 34 deletions.
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
unionFind
ocamlformat
(junit_alcotest :with-test)
ocaml-lsp-server)) ; After upgrading to opam 2.2 use with-dev https://opam.ocaml.org/blog/opam-2-2-0/
ocaml-lsp-server
(base_quickcheck (>= 0.17.0)))) ; After upgrading to opam 2.2 use with-dev https://opam.ocaml.org/blog/opam-2-2-0/

; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
2 changes: 1 addition & 1 deletion dune-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(env
(dev
(flags
(:standard -warn-error -A)))
(:standard -w +30 -warn-error -A)))
(release
(flags
(:standard -warn-error +A-58))))
1 change: 1 addition & 0 deletions hazel.opam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hazel.opam.locked

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/haz3lcore/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
js_of_ocaml-ppx
ppx_let
ppx_sexp_conv
ppx_deriving.show)))
ppx_deriving.show
base_quickcheck.ppx_quickcheck)))

(env
(dev
Expand Down
6 changes: 3 additions & 3 deletions src/haz3lcore/dynamics/FilterAction.re
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type action =
| Step
| Eval;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type count =
| One
| All;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t = (action, count);

let string_of_t = v => {
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/dynamics/InvalidOperationError.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t =
| InvalidOfString
| IndexOutOfBounds
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lcore/dynamics/VarBstMap.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Util;
open Ppx_yojson_conv_lib.Yojson_conv;
open Base_quickcheck;
module Sexp = Sexplib.Sexp;

module Inner = {
Expand Down Expand Up @@ -206,6 +207,9 @@ module Ordered = {
let without_keys = (keys, m) => {
filterk(((s, _)) => !List.exists(x => x == s, keys), m);
};

let quickcheck_observer_t_ = __ => Observer.opaque;
let quickcheck_shrinker_t_ = __ => Shrinker.atomic;
};

include VarBstMap0;
5 changes: 5 additions & 0 deletions src/haz3lcore/dynamics/VarBstMap.rei
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ module Ordered: {
[without_keys] removes all entires with the given keys from the map
*/
let without_keys: (list(Var.t), t_('a)) => t_('a);

let quickcheck_observer_t_:
Base_quickcheck.Observer.t('a) => Base_quickcheck.Observer.t(t_('a));
let quickcheck_shrinker_t_:
Base_quickcheck.Shrinker.t('a) => Base_quickcheck.Shrinker.t(t_('a));
};
20 changes: 10 additions & 10 deletions src/haz3lcore/lang/Operators.re
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_un_bool =
| Not;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_un_meta =
| Unquote;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_un_int =
| Minus;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_bin_bool =
| And
| Or;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_bin_int =
| Plus
| Minus
Expand All @@ -29,7 +29,7 @@ type op_bin_int =
| Equals
| NotEquals;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_bin_float =
| Plus
| Minus
Expand All @@ -43,25 +43,25 @@ type op_bin_float =
| Equals
| NotEquals;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_bin_string =
| Concat
| Equals;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_un =
| Meta(op_un_meta)
| Int(op_un_int)
| Bool(op_un_bool);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type op_bin =
| Int(op_bin_int)
| Float(op_bin_float)
| Bool(op_bin_bool)
| String(op_bin_string);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type ap_direction =
| Forward
| Reverse;
Expand Down
3 changes: 2 additions & 1 deletion src/haz3lcore/lang/term/IdTagged.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Util;
open Base_quickcheck;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t('a) = {
[@show.opaque]
ids: list(Id.t),
Expand Down
7 changes: 4 additions & 3 deletions src/haz3lcore/statics/Constructor.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
type t = string;
open Base_quickcheck;
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t =
[@quickcheck.generator Generator.string_of(Generator.char_alpha)] string;

let equal = String.equal;
6 changes: 3 additions & 3 deletions src/haz3lcore/statics/ConstructorMap.re
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
open Util.OptUtil.Syntax;
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
open Base_quickcheck;
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type variant('a) =
| Variant(Constructor.t, list(Id.t), option('a))
| BadEntry('a);

// Invariant: Must not have duplicate constructors
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t('a) = list(variant('a));

let mk =
Expand Down
10 changes: 6 additions & 4 deletions src/haz3lcore/statics/TermBase.re
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
open Util;
open Base_quickcheck;

let continue = x => x;
let stop = (_, x) => x;
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type deferral_position_t =
| InAp
| OutsideAp;
Expand Down Expand Up @@ -45,8 +46,7 @@ type deferral_position_t =
structural equality except for the case of closures, where it just compares
the id of the closure.
*/

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type any_t =
| Exp(exp_t)
| Pat(pat_t)
Expand Down Expand Up @@ -146,7 +146,9 @@ and rul_term =
| Hole(list(any_t))
| Rules(exp_t, list((pat_t, exp_t)))
and rul_t = IdTagged.t(rul_term)
and environment_t = VarBstMap.Ordered.t_(exp_t)
and environment_t =
[@quickcheck.generator Generator.return(VarBstMap.Ordered.empty)]
VarBstMap.Ordered.t_(exp_t)
and closure_environment_t = (Id.t, environment_t)
and stepper_filter_kind_t =
| FilterStepper(filter)
Expand Down
7 changes: 4 additions & 3 deletions src/haz3lcore/statics/Var.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
type t = string;
open Base_quickcheck;
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
type t =
[@quickcheck.generator Generator.string_of(Generator.char_alpha)] string;

let eq = String.equal;

Expand Down
7 changes: 5 additions & 2 deletions src/haz3lcore/tiles/Id.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Util;

open Base_quickcheck;
/* ID FAQ
WHATS AN ID?
Expand Down Expand Up @@ -34,7 +34,7 @@ open Util;
*/

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, quickcheck)]
let sexp_of_t: Uuidm.t => Sexplib.Sexp.t =
t => Sexplib.Sexp.Atom(Uuidm.to_string(t));

Expand All @@ -59,6 +59,9 @@ let t_of_yojson: Yojson.Safe.t => Uuidm.t =
type t = Uuidm.t;

let mk: unit => t = Uuidm.v4_gen(Random.State.make_self_init());
let quickcheck_generator = Generator.return(mk()); // TODO
let quickcheck_observer = Observer.opaque;
let quickcheck_shrinker = Shrinker.atomic;

let compare: (t, t) => int = Uuidm.compare;
let to_string: (~upper: bool=?, t) => string = Uuidm.to_string;
Expand Down

0 comments on commit 44c715d

Please sign in to comment.