Support dune instrumentation backend (#50)#102
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a1753ccdf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| vb with | ||
| pvb_expr = strip_expr vb.pvb_expr; | ||
| pvb_pat = strip_pat vb.pvb_pat; | ||
| pvb_constraint = None; | ||
| } |
There was a problem hiding this comment.
Preserve type constraints during auto instrumentation
Dropping pvb_constraint in auto mode changes the user’s typing contract and can make previously valid functions fail to type-check (for example functions relying on locally abstract types, GADT refinements, polymorphic recursion, or coercions). Because --auto is meant to add tracing, not alter type semantics, clearing this field can break builds or silently change inferred types when instrumentation is enabled.
Useful? React with 👍 / 👎.
Register ppx_minidebug as a dune instrumentation backend so users can enable auto-instrumentation of all top-level functions via `(instrumentation (backend ppx_minidebug --auto))` in their dune files. - Add `(instrumentation.backend (ppx ppx_minidebug))` to library stanza - Add `--auto`, `--auto-mode`, `--auto-log-value`, `--auto-db-base-name` CLI args - Implement `auto_instrument_impl` as ppxlib `impl` hook for whole-file transform - Inject `module Debug_runtime = (val Minidebug_db.debug_db_file ...)` when needed - Add `[%%ppx_minidebug_disable]` extension for per-file opt-out - Strip type annotations in auto-mode to avoid unexpandable PPX extensions - Detect already-instrumented bindings to prevent double instrumentation - Add PPX transformation tests, runtime behavior test, and integration fixture Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Restore the original pvb_constraint on the output of debug_binding after stripping it for the input. This preserves locally abstract types, GADT refinements, polymorphic recursion, and coercions while still suppressing value logging (which would generate unexpandable [%show:] extensions in the impl hook). Add test_auto_poly.ml to verify polymorphic type constraints are preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e55e096 to
cd3faad
Compare
Suggested Refactors & Lessons for Next Time1. Extract eligibility predicateThe "is this binding eligible for auto-instrumentation?" check is duplicated in three places: 2. Consider a dedicated
|
Summary
(instrumentation.backend (ppx ppx_minidebug)))--autoflag andauto_instrument_implhook to auto-instrument unannotated top-level functions with entry/exit tracingmodule Debug_runtime = (val Minidebug_db.debug_db_file "debugger_<filename>")automatically when needed[%%ppx_minidebug_disable]extension for per-file opt-outlet%debug_*bindings[%show:]/[%sexp_of:]extensions (impl hook runs after context-free rules)Test plan
test_auto_instrument,test_auto_disable,test_auto_no_functions,test_auto_mixedtest_auto_runtime(generates DB, verified viaminidebug_view)test/instrumentation_fixture/withrun_instrumentation_test.shdune runtestpasses all existing testsCloses #50
🤖 Generated with Claude Code