From 63d88e87733bfee0fedfcf585f6ee4d26ae6ac73 Mon Sep 17 00:00:00 2001
From: Alexander Bandukwala <7h3kk1d@gmail.com>
Date: Sat, 10 Aug 2024 12:58:11 -0400
Subject: [PATCH 1/5] [IN-PROGRESS] Working on adding code coverage

---
 .gitignore         | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 dune-project       |  3 ++-
 hazel.opam         |  3 ++-
 hazel.opam.locked  | 20 ++++++++--------
 src/haz3lcore/dune |  2 ++
 src/haz3lweb/dune  |  4 ++++
 src/pretty/dune    |  2 ++
 src/util/dune      |  2 ++
 test/dune          |  4 ++--
 test/haz3ltest.re  |  1 +
 10 files changed, 87 insertions(+), 14 deletions(-)

diff --git a/.gitignore b/.gitignore
index ec464113b6..ccfcb18745 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,63 @@ setup.log
 
 # Backup of opam lock file
 hazel.opam.locked.old
+_coverage/coverage.css
+_coverage/coverage.js
+_coverage/highlight.pack.js
+_coverage/index.html
+_coverage/src/haz3lcore/StructureShareSexp.re.html
+_coverage/src/haz3lcore/VarMap.re.html
+_coverage/src/haz3lcore/dynamics/Builtins.re.html
+_coverage/src/haz3lcore/dynamics/Casts.re.html
+_coverage/src/haz3lcore/dynamics/Constraint.re.html
+_coverage/src/haz3lcore/dynamics/Delta.re.html
+_coverage/src/haz3lcore/dynamics/DHExp.re.html
+_coverage/src/haz3lcore/dynamics/DHPat.re.html
+_coverage/src/haz3lcore/dynamics/Elaborator.re.html
+_coverage/src/haz3lcore/dynamics/Environment.re.html
+_coverage/src/haz3lcore/dynamics/EvaluatorError.re.html
+_coverage/src/haz3lcore/dynamics/FilterAction.re.html
+_coverage/src/haz3lcore/dynamics/Incon.re.html
+_coverage/src/haz3lcore/dynamics/InvalidOperationError.re.html
+_coverage/src/haz3lcore/dynamics/Sets.re.html
+_coverage/src/haz3lcore/dynamics/VarBstMap.re.html
+_coverage/src/haz3lcore/lang/Form.re.html
+_coverage/src/haz3lcore/lang/Operators.re.html
+_coverage/src/haz3lcore/lang/Precedence.re.html
+_coverage/src/haz3lcore/lang/Sort.re.html
+_coverage/src/haz3lcore/lang/term/Any.re.html
+_coverage/src/haz3lcore/lang/term/Cls.re.html
+_coverage/src/haz3lcore/lang/term/Exp.re.html
+_coverage/src/haz3lcore/lang/term/IdTagged.re.html
+_coverage/src/haz3lcore/lang/term/Pat.re.html
+_coverage/src/haz3lcore/lang/term/Rul.re.html
+_coverage/src/haz3lcore/lang/term/TPat.re.html
+_coverage/src/haz3lcore/lang/term/Typ.re.html
+_coverage/src/haz3lcore/prog/CoreSettings.re.html
+_coverage/src/haz3lcore/statics/CoCtx.re.html
+_coverage/src/haz3lcore/statics/Constructor.re.html
+_coverage/src/haz3lcore/statics/ConstructorMap.re.html
+_coverage/src/haz3lcore/statics/Ctx.re.html
+_coverage/src/haz3lcore/statics/Info.re.html
+_coverage/src/haz3lcore/statics/Mode.re.html
+_coverage/src/haz3lcore/statics/Self.re.html
+_coverage/src/haz3lcore/statics/Statics.re.html
+_coverage/src/haz3lcore/statics/Term.re.html
+_coverage/src/haz3lcore/statics/TermBase.re.html
+_coverage/src/haz3lcore/statics/Var.re.html
+_coverage/src/haz3lcore/statics/uterm/UExp.re.html
+_coverage/src/haz3lcore/statics/uterm/UPat.re.html
+_coverage/src/haz3lcore/statics/uterm/UTyp.re.html
+_coverage/src/haz3lcore/tiles/Id.re.html
+_coverage/src/haz3lcore/tiles/Mold.re.html
+_coverage/src/haz3lcore/tiles/Nib.re.html
+_coverage/src/haz3lcore/tiles/Nibs.re.html
+_coverage/src/haz3lcore/tiles/Secondary.re.html
+_coverage/src/haz3lcore/tiles/Token.re.html
+_coverage/src/util/Direction.re.html
+_coverage/src/util/IntMap.re.html
+_coverage/src/util/ListUtil.re.html
+_coverage/src/util/OptUtil.re.html
+_coverage/src/util/StringUtil.re.html
+_coverage/src/util/TupleUtil.re.html
+_coverage/src/util/Util.re.html
diff --git a/dune-project b/dune-project
index 5e71bc4ee5..4e17ae067c 100644
--- a/dune-project
+++ b/dune-project
@@ -25,10 +25,11 @@
   (menhir
    (>= 2.0))
   yojson
-  reason
+  (reason (>= 3.12.0))
   ppx_yojson_conv_lib
   ppx_yojson_conv
   incr_dom
+  bisect_ppx
   (omd (>= 2.0.0~alpha4))
   ezjs_idb
   virtual_dom
diff --git a/hazel.opam b/hazel.opam
index 36a81b933a..ad9af541a1 100644
--- a/hazel.opam
+++ b/hazel.opam
@@ -11,10 +11,11 @@ depends: [
   "ocaml" {>= "5.2.0"}
   "menhir" {>= "2.0"}
   "yojson"
-  "reason"
+  "reason" {>= "3.12.0"}
   "ppx_yojson_conv_lib"
   "ppx_yojson_conv"
   "incr_dom"
+  "bisect_ppx"
   "omd" {>= "2.0.0~alpha4"}
   "ezjs_idb"
   "virtual_dom"
diff --git a/hazel.opam.locked b/hazel.opam.locked
index 8672b0816a..8c7a594892 100644
--- a/hazel.opam.locked
+++ b/hazel.opam.locked
@@ -27,14 +27,14 @@ depends: [
   "base_bigstring" {= "v0.16.0"}
   "base_quickcheck" {= "v0.16.0"}
   "bignum" {= "v0.16.0"}
-  "bigstringaf" {= "0.10.0"}
+  "bigstringaf" {= "0.9.1"}
   "bin_prot" {= "v0.16.0"}
+  "bisect_ppx" {= "2.8.3"}
   "camlp-streams" {= "5.0.1"}
   "chrome-trace" {= "3.16.0"}
   "cmdliner" {= "1.3.0"}
   "conf-bash" {= "1"}
   "conf-gmp" {= "4"}
-  "conf-pkg-config" {= "3"}
   "core" {= "v0.16.2"}
   "core_kernel" {= "v0.16.0"}
   "cppo" {= "1.6.9"}
@@ -74,13 +74,13 @@ depends: [
   "lsp" {= "1.19.0"}
   "lwt" {= "5.7.0"}
   "markup" {= "1.0.3"}
-  "menhir" {= "20240715"}
-  "menhirCST" {= "20240715"}
-  "menhirLib" {= "20240715"}
-  "menhirSdk" {= "20240715"}
+  "menhir" {= "20231231"}
+  "menhirCST" {= "20231231"}
+  "menhirLib" {= "20231231"}
+  "menhirSdk" {= "20231231"}
   "merlin-extend" {= "0.6.1"}
   "merlin-lib" {= "5.1-502"}
-  "num" {= "1.5-1"}
+  "num" {= "1.5"}
   "ocaml" {= "5.2.0"}
   "ocaml-base-compiler" {= "5.2.0"}
   "ocaml-compiler-libs" {= "v0.17.0"}
@@ -90,7 +90,7 @@ depends: [
   "ocaml-options-vanilla" {= "1"}
   "ocaml-syntax-shims" {= "1.0.0"}
   "ocaml-version" {= "3.6.7"}
-  "ocamlbuild" {= "0.15.0"}
+  "ocamlbuild" {= "0.14.3"}
   "ocamlc-loc" {= "3.16.0"}
   "ocamlfind" {= "1.9.6"}
   "ocamlformat" {= "0.26.2"}
@@ -143,7 +143,7 @@ depends: [
   "ppx_variants_conv" {= "v0.16.0"}
   "ppx_yojson_conv" {= "v0.16.0"}
   "ppx_yojson_conv_lib" {= "v0.16.0"}
-  "ppxlib" {= "0.33.0"}
+  "ppxlib" {= "0.32.1"}
   "protocol_version_header" {= "v0.16.0"}
   "ptime" {= "1.1.0" & with-test}
   "ptmap" {= "2.0.5"}
@@ -179,7 +179,7 @@ depends: [
   "virtual_dom" {= "v0.16.0"}
   "xdg" {= "3.16.0"}
   "yojson" {= "2.2.2"}
-  "zarith" {= "1.14"}
+  "zarith" {= "1.13"}
   "zarith_stubs_js" {= "v0.16.1"}
 ]
 build: [
diff --git a/src/haz3lcore/dune b/src/haz3lcore/dune
index 77e2ca3fe1..a0d9770816 100644
--- a/src/haz3lcore/dune
+++ b/src/haz3lcore/dune
@@ -4,6 +4,8 @@
  (name haz3lcore)
  (libraries util sexplib unionFind uuidm virtual_dom yojson core)
  (js_of_ocaml)
+ (instrumentation
+  (backend bisect_ppx))
  (preprocess
   (pps
    ppx_yojson_conv
diff --git a/src/haz3lweb/dune b/src/haz3lweb/dune
index 8d25155dc5..84023f76a5 100644
--- a/src/haz3lweb/dune
+++ b/src/haz3lweb/dune
@@ -8,6 +8,8 @@
 (library
  (name workerServer)
  (modules WorkerServer)
+ (instrumentation
+  (backend bisect_ppx))
  (libraries
   incr_dom
   virtual_dom.input_widgets
@@ -28,6 +30,8 @@
 
 (library
  (name haz3lweb)
+ (instrumentation
+  (backend bisect_ppx))
  (modules
   (:standard \ Main)
   \
diff --git a/src/pretty/dune b/src/pretty/dune
index 868d03defc..c131965aff 100644
--- a/src/pretty/dune
+++ b/src/pretty/dune
@@ -3,6 +3,8 @@
 (library
  (name pretty)
  (libraries util sexplib)
+ (instrumentation
+  (backend bisect_ppx))
  (preprocess
   (pps ppx_let ppx_sexp_conv)))
 
diff --git a/src/util/dune b/src/util/dune
index 889c95bd2c..8fbebea70b 100644
--- a/src/util/dune
+++ b/src/util/dune
@@ -2,6 +2,8 @@
  (name util)
  (libraries re base ptmap incr_dom virtual_dom yojson)
  (js_of_ocaml)
+ (instrumentation
+  (backend bisect_ppx))
  (preprocess
   (pps
    ppx_yojson_conv
diff --git a/test/dune b/test/dune
index 832c9689f2..3b9dc8bb2e 100644
--- a/test/dune
+++ b/test/dune
@@ -2,7 +2,7 @@
 
 (test
  (name haz3ltest)
- (libraries haz3lcore alcotest junit junit_alcotest)
+ (libraries haz3lcore alcotest junit junit_alcotest bisect_ppx.runtime)
  (modes js)
  (preprocess
-  (pps js_of_ocaml-ppx)))
+  (pps js_of_ocaml-ppx ppx_deriving.show)))
diff --git a/test/haz3ltest.re b/test/haz3ltest.re
index e405fba7b8..e346e20556 100644
--- a/test/haz3ltest.re
+++ b/test/haz3ltest.re
@@ -7,3 +7,4 @@ let (suite, _) =
     [("Elaboration", Test_Elaboration.elaboration_tests)],
   );
 Junit.to_file(Junit.make([suite]), "junit_tests.xml");
+Bisect.Runtime.write_coverage_data();
\ No newline at end of file

From 484e3f07521d22cfc3824e4a44b1990c98fe264b Mon Sep 17 00:00:00 2001
From: Alexander Bandukwala <7h3kk1d@gmail.com>
Date: Sat, 10 Aug 2024 13:00:00 -0400
Subject: [PATCH 2/5] Fix git ignore

---
 .gitignore | 63 +++---------------------------------------------------
 1 file changed, 3 insertions(+), 60 deletions(-)

diff --git a/.gitignore b/.gitignore
index ccfcb18745..87b0876181 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,63 +56,6 @@ setup.log
 
 # Backup of opam lock file
 hazel.opam.locked.old
-_coverage/coverage.css
-_coverage/coverage.js
-_coverage/highlight.pack.js
-_coverage/index.html
-_coverage/src/haz3lcore/StructureShareSexp.re.html
-_coverage/src/haz3lcore/VarMap.re.html
-_coverage/src/haz3lcore/dynamics/Builtins.re.html
-_coverage/src/haz3lcore/dynamics/Casts.re.html
-_coverage/src/haz3lcore/dynamics/Constraint.re.html
-_coverage/src/haz3lcore/dynamics/Delta.re.html
-_coverage/src/haz3lcore/dynamics/DHExp.re.html
-_coverage/src/haz3lcore/dynamics/DHPat.re.html
-_coverage/src/haz3lcore/dynamics/Elaborator.re.html
-_coverage/src/haz3lcore/dynamics/Environment.re.html
-_coverage/src/haz3lcore/dynamics/EvaluatorError.re.html
-_coverage/src/haz3lcore/dynamics/FilterAction.re.html
-_coverage/src/haz3lcore/dynamics/Incon.re.html
-_coverage/src/haz3lcore/dynamics/InvalidOperationError.re.html
-_coverage/src/haz3lcore/dynamics/Sets.re.html
-_coverage/src/haz3lcore/dynamics/VarBstMap.re.html
-_coverage/src/haz3lcore/lang/Form.re.html
-_coverage/src/haz3lcore/lang/Operators.re.html
-_coverage/src/haz3lcore/lang/Precedence.re.html
-_coverage/src/haz3lcore/lang/Sort.re.html
-_coverage/src/haz3lcore/lang/term/Any.re.html
-_coverage/src/haz3lcore/lang/term/Cls.re.html
-_coverage/src/haz3lcore/lang/term/Exp.re.html
-_coverage/src/haz3lcore/lang/term/IdTagged.re.html
-_coverage/src/haz3lcore/lang/term/Pat.re.html
-_coverage/src/haz3lcore/lang/term/Rul.re.html
-_coverage/src/haz3lcore/lang/term/TPat.re.html
-_coverage/src/haz3lcore/lang/term/Typ.re.html
-_coverage/src/haz3lcore/prog/CoreSettings.re.html
-_coverage/src/haz3lcore/statics/CoCtx.re.html
-_coverage/src/haz3lcore/statics/Constructor.re.html
-_coverage/src/haz3lcore/statics/ConstructorMap.re.html
-_coverage/src/haz3lcore/statics/Ctx.re.html
-_coverage/src/haz3lcore/statics/Info.re.html
-_coverage/src/haz3lcore/statics/Mode.re.html
-_coverage/src/haz3lcore/statics/Self.re.html
-_coverage/src/haz3lcore/statics/Statics.re.html
-_coverage/src/haz3lcore/statics/Term.re.html
-_coverage/src/haz3lcore/statics/TermBase.re.html
-_coverage/src/haz3lcore/statics/Var.re.html
-_coverage/src/haz3lcore/statics/uterm/UExp.re.html
-_coverage/src/haz3lcore/statics/uterm/UPat.re.html
-_coverage/src/haz3lcore/statics/uterm/UTyp.re.html
-_coverage/src/haz3lcore/tiles/Id.re.html
-_coverage/src/haz3lcore/tiles/Mold.re.html
-_coverage/src/haz3lcore/tiles/Nib.re.html
-_coverage/src/haz3lcore/tiles/Nibs.re.html
-_coverage/src/haz3lcore/tiles/Secondary.re.html
-_coverage/src/haz3lcore/tiles/Token.re.html
-_coverage/src/util/Direction.re.html
-_coverage/src/util/IntMap.re.html
-_coverage/src/util/ListUtil.re.html
-_coverage/src/util/OptUtil.re.html
-_coverage/src/util/StringUtil.re.html
-_coverage/src/util/TupleUtil.re.html
-_coverage/src/util/Util.re.html
+
+# Code coverage
+_coverage/

From 39f6d594cd1fe7e8744ec05b8a417b3bd520ead4 Mon Sep 17 00:00:00 2001
From: Alexander Bandukwala <7h3kk1d@gmail.com>
Date: Mon, 12 Aug 2024 16:10:15 -0400
Subject: [PATCH 3/5] formatting

---
 test/haz3ltest.re | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/haz3ltest.re b/test/haz3ltest.re
index e346e20556..6e152b2fe8 100644
--- a/test/haz3ltest.re
+++ b/test/haz3ltest.re
@@ -7,4 +7,4 @@ let (suite, _) =
     [("Elaboration", Test_Elaboration.elaboration_tests)],
   );
 Junit.to_file(Junit.make([suite]), "junit_tests.xml");
-Bisect.Runtime.write_coverage_data();
\ No newline at end of file
+Bisect.Runtime.write_coverage_data();

From 8c38c1bc22b4281d8b19d6400ba2fb4ca8e46aea Mon Sep 17 00:00:00 2001
From: Alexander Bandukwala <7h3kk1d@gmail.com>
Date: Fri, 16 Aug 2024 11:18:05 -0400
Subject: [PATCH 4/5] Add coverage command to makefile

---
 Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Makefile b/Makefile
index 455ff6e441..e5851f1ecf 100644
--- a/Makefile
+++ b/Makefile
@@ -61,5 +61,13 @@ test:
 	dune build @src/fmt @test/fmt --auto-promote src test --profile dev
 	node $(TEST_DIR)/haz3ltest.bc.js
 
+coverage:
+	dune build @src/fmt @test/fmt --auto-promote src test --profile dev
+	dune runtest --instrument-with bisect_ppx --force
+	bisect-ppx-report summary
+
+generate-coverage-html:
+	bisect-ppx-report html
+
 clean:
 	dune clean

From a85fb7e83717c373ef6e2294f61ad3bb0c44a4d2 Mon Sep 17 00:00:00 2001
From: Alexander Bandukwala <7h3kk1d@gmail.com>
Date: Fri, 16 Aug 2024 11:21:34 -0400
Subject: [PATCH 5/5] Add coverage to Readme

---
 README.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/README.md b/README.md
index a15bdd424e..15caf27308 100644
--- a/README.md
+++ b/README.md
@@ -197,6 +197,9 @@ You can run all of the unit tests located in `test` by running `make test`.
 
 Unit tests are written using the [Alcotest framework](https://github.com/mirage/alcotest).
 
+#### Coverage
+Code coverage is provided by [bisect_ppx](https://github.com/aantron/bisect_ppx). To collect coverage statistics from tests run `make coverage`. After coverage statistics are generated, running `make generate-coverage-html` will generate a local webpage at `_coverage/index.html` that can be viewed to see line coverage per module.
+
 ### Continuous Integration
 
 When you push your branch to the main `hazelgrove/hazel` repository, we