Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ _build_playground
node_modules
*.dump
coverage
_coverage/
bisect*.coverage

lib/ocaml
tests/build_tests/*/lib/
Expand Down
18 changes: 2 additions & 16 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
compiler/js_parser/**
compiler/ml/cmt_format.ml
compiler/core/js_name_of_module_id.ml
compiler/core/js_pass_debug.ml
compiler/core/lam_util.ml
compiler/core/lam_compile_main.ml
compiler/ext/bs_hash_stubs.ml
compiler/ext/js_reserved_map.ml
compiler/ext/ext_string.ml
compiler/ext/ext_string.mli
compiler/ext/ext_sys.ml
compiler/ext/hash.cppo.ml
compiler/ext/hash_set.cppo.ml
compiler/ext/map.cppo.ml
compiler/ext/ordered_hash_map.cppo.ml
compiler/ext/set.cppo.ml
compiler/ext/vec.cppo.ml
**/*.cppo.ml
**/*.cppo.mli
compiler/syntax/compiler-libs-406/*
83 changes: 82 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,87 @@ format: | $(YARN_INSTALL_STAMP)
checkformat: | $(YARN_INSTALL_STAMP)
./scripts/format_check.sh

# Coverage (bisect_ppx)
#
# Requires the `bisect_ppx` opam package (>= 2.8.0) in your switch:
# opam install bisect_ppx
# or pull it in via the rescript dev-setup deps:
# opam install . --deps-only --with-dev-setup
#
# Quick start:
# make coverage # run full test suite, generate report
# make clean-coverage # remove coverage artifacts
#
# Outputs (under _coverage/):
# html/index.html — human-browsable line-level report
# coverage.json — Coveralls-format JSON, queryable with jq:
# { source_files: [{ name, coverage: [null|N, ...] }] }
# null = not instrumented, 0 = uncovered, N > 0 = hit count
# e.g. uncovered line numbers in one file:
# jq -r --arg f compiler/ml/typecore.ml \
# '.source_files[] | select(.name==$f) | .coverage
# | to_entries[] | select(.value==0) | (.key+1)' \
# _coverage/coverage.json

COVERAGE_DIR := _coverage
COVERAGE_FILES_DIR := $(COVERAGE_DIR)/files
COVERAGE_HTML_DIR := $(COVERAGE_DIR)/html
COVERAGE_JSON := $(COVERAGE_DIR)/coverage.json
COVERAGE_BISECT_PREFIX := $(abspath $(COVERAGE_FILES_DIR))/bisect

# Re-builds the toolchain with bisect_ppx instrumentation and swaps the
# instrumented binaries into BIN_DIR so any test runner that shells out to
# `bsc` produces .coverage files.
.PHONY: coverage-build
coverage-build: | $(YARN_INSTALL_STAMP)
dune build --instrument-with bisect_ppx
@$(foreach bin,$(COMPILER_DUNE_BINS),touch $(bin);)
@$(foreach bin,$(COMPILER_BIN_NAMES), \
cp $(DUNE_BIN_DIR)/$(bin)$(PLATFORM_EXE_EXT) $(BIN_DIR)/$(bin).exe && \
chmod 755 $(BIN_DIR)/$(bin).exe;)

.PHONY: coverage-prepare
coverage-prepare: clean-coverage coverage-build
mkdir -p $(COVERAGE_FILES_DIR)

# Build the runtime with the instrumented bsc so subsequent test runs have
# a fresh stdlib. Coverage from the runtime build is discarded so reports
# only reflect what the tests exercised.
.PHONY: coverage-lib
coverage-lib: coverage-prepare
BISECT_FILE=$(COVERAGE_BISECT_PREFIX)-discard BISECT_SILENT=YES \
yarn workspace @rescript/runtime build
rm -f $(COVERAGE_BISECT_PREFIX)-discard*.coverage

.PHONY: coverage-run
coverage-run: coverage-lib
BISECT_FILE=$(COVERAGE_BISECT_PREFIX) BISECT_SILENT=YES \
node scripts/test.js -all

.PHONY: coverage-report
coverage-report:
bisect-ppx-report html \
--coverage-path $(COVERAGE_FILES_DIR) \
--ignore-missing-files \
-o $(COVERAGE_HTML_DIR)
bisect-ppx-report coveralls \
--coverage-path $(COVERAGE_FILES_DIR) \
--ignore-missing-files \
$(COVERAGE_JSON)
bisect-ppx-report summary \
--coverage-path $(COVERAGE_FILES_DIR)
@echo ""
@echo "HTML report: $(COVERAGE_HTML_DIR)/index.html"
@echo "JSON data: $(COVERAGE_JSON)"

.PHONY: coverage
coverage: coverage-run coverage-report

.PHONY: clean-coverage
clean-coverage:
rm -rf $(COVERAGE_DIR)
find . -name 'bisect*.coverage' -not -path './_build/*' -delete

# Clean

clean-gentype:
Expand All @@ -225,7 +306,7 @@ clean-gentype:

clean-tests: clean-gentype

clean: clean-lib clean-compiler clean-rewatch
clean: clean-lib clean-compiler clean-rewatch clean-coverage

dev-container:
docker build -t rescript-dev-container docker
Expand Down
2 changes: 2 additions & 0 deletions analysis/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
(package analysis)
(modes byte exe)
(name main)
(instrumentation
(backend bisect_ppx))
(libraries analysis))
2 changes: 2 additions & 0 deletions analysis/src/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(library
(name analysis)
(instrumentation
(backend bisect_ppx))
(flags
(-w "+6+26+27+32+33+39"))
(libraries unix str ext ml jsonlib syntax reanalyze))
2 changes: 2 additions & 0 deletions compiler/bsc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
(name rescript_compiler_main)
(public_name bsc)
(package rescript)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-30-40-41-42-48-70))
(libraries common core depends flow_parser gentype syntax))
5 changes: 2 additions & 3 deletions compiler/common/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(library
(name common)
(wrapped false)
(preprocess
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-9-40-42))
(libraries syntax))
29 changes: 26 additions & 3 deletions compiler/core/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
(library
(name core)
(wrapped false)
(preprocess
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
Comment on lines -4 to -6
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dune was unabled to have both this preprocess stanza and the ppx stanza. There were such few files actually using cppo flags that I just converted them into per file rules.

(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-27-30-40-41-42-48-70))
(libraries depends ext flow_parser frontend gentype))

(rule
(target js_name_of_module_id.ml)
(deps js_name_of_module_id.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target js_pass_debug.ml)
(deps js_pass_debug.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target lam_compile_main.ml)
(deps lam_compile_main.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target lam_util.ml)
(deps lam_util.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions compiler/depends/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name depends)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-40-42))
(libraries common))
File renamed without changes.
47 changes: 39 additions & 8 deletions compiler/ext/dune
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
(library
(name ext)
(wrapped false)
(preprocess
(action
(run
%{bin:cppo}
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{input-file})))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-42-40-9-48-70))
(foreign_stubs
(language c)
(names ext_basic_hash_stubs)))

(rule
(target bs_hash_stubs.ml)
(deps bs_hash_stubs.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target js_reserved_map.ml)
(deps js_reserved_map.cppo.ml)
(action
(run
%{bin:cppo}
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{deps}
-o
%{target})))

(rule
(target ext_sys.ml)
(deps ext_sys.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target ext_string.ml)
(deps ext_string.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target ext_string.mli)
(deps ext_string.cppo.mli)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(targets hash_set_string.ml)
(deps hash_set.cppo.ml)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions compiler/frontend/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name frontend)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-40-42-70))
(libraries common ml))
2 changes: 2 additions & 0 deletions compiler/gentype/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name gentype)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-40-41-42-48-70))
(libraries ml))
File renamed without changes.
11 changes: 8 additions & 3 deletions compiler/ml/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
(library
(name ml)
(wrapped false)
(preprocess
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-42-40-41-44-45-9-48-67-70))
(libraries ext flow_parser))

(rule
(target cmt_format.ml)
(deps cmt_format.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))
2 changes: 2 additions & 0 deletions compiler/syntax/cli/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
(package rescript)
(enabled_if
(<> %{profile} browser))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-42-40-9-48-70))
(libraries syntax))
2 changes: 2 additions & 0 deletions compiler/syntax/src/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name syntax)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-42-40-9-48-70))
(libraries ml))
1 change: 1 addition & 0 deletions rescript.opam
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ depends: [
"ounit2" {with-test & = "2.2.7"}
"odoc" {with-doc}
"ocaml-lsp-server" {with-dev-setup & = "1.22.0"}
"bisect_ppx" {with-dev-setup & >= "2.8.0"}

# Test dependencies that would be broken on Windows runners
"js_of_ocaml" {os != "win32" & with-test & = "6.0.1"}
Expand Down
1 change: 1 addition & 0 deletions rescript.opam.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ depends: [
"ounit2" {with-test & = "2.2.7"}
"odoc" {with-doc}
"ocaml-lsp-server" {with-dev-setup & = "1.22.0"}
"bisect_ppx" {with-dev-setup & >= "2.8.0"}

# Test dependencies that would be broken on Windows runners
"js_of_ocaml" {os != "win32" & with-test & = "6.0.1"}
Expand Down
2 changes: 2 additions & 0 deletions tests/ounit_tests/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
(package rescript)
(enabled_if
(<> %{profile} browser))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-30-40-41-42-48-70))
(libraries core ounit2 analysis))
2 changes: 2 additions & 0 deletions tools/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
; The main module that will become the binary.
(name main)
(libraries tools)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w "+6+26+27+32+33+39")))
2 changes: 2 additions & 0 deletions tools/src/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(library
(name tools)
(instrumentation
(backend bisect_ppx))
(flags
(-w "+6+26+27+32+33+39"))
(libraries analysis cmarkit))
Loading