Skip to content

docs(res-to-affine): corpus run + regex precision fixes (Refs #57)#319

Merged
hyperpolymath merged 1 commit into
mainfrom
corpus-run-57
May 21, 2026
Merged

docs(res-to-affine): corpus run + regex precision fixes (Refs #57)#319
hyperpolymath merged 1 commit into
mainfrom
corpus-run-57

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

First end-to-end run of the Phase-1 scanner (#314) against the estate's
real .res surface — 491 deduplicated files across idaptik (475) and
gitbot-fleet (16). The run surfaced two high-impact false-positive
sources, which this PR fixes alongside the corpus report.

  • side-effect-import was flagging in-function let _ = X.f(...)
    — ReScript's normal "discard chained-call return value" idiom — not
    just the LESSONS.md "module-load side effect" anti-pattern. 1,181
    hits in the corpus, vast majority indented.
  • mutable-global was flagging any :=, including
    intra-function local-ref mutation. 653 hits in the corpus, none at
    column 0.

Both regexes now anchor at column 0. re_untyped_exn also picks up
column-0 raise / try via a (^|...) alternation.

Impact

Before After Δ
Total markers 2,146 348 −84%
Files with markers 216 94 −122
side-effect-import 1,181 36 −1,145
mutable-global 653 0 −653
raw-js 198 198 unchanged
untyped-exception 114 114 unchanged

Spot-checked the new top hotspots — every remaining side-effect-import
hit is genuinely column-0 (e.g. idaptik/src/Main.res:5:let _ = PixiSound.sound);
every raw-js and untyped-exception hit corresponds to a real %raw(…)
block or try/Js.Exn/Promise.catch occurrence.

What's added

  • tools/res-to-affine/CORPUS-RUN.md — human report (corpus stats,
    regex change-log, top hot-spots, Phase-2 follow-ups, reproducer).
  • tools/res-to-affine/CORPUS-RUN.json — machine-readable sidecar.
  • tools/res-to-affine/README.md — link to both.
  • tools/res-to-affine/scanner.ml — three regex tightenings with
    an inline comment naming the column-0 vs in-function trade-off.

Trade-off

We no longer flag:

  • module-load side effects nested inside module X = { ... } blocks
  • top-level let x = ref(...) declarations (we still flag the :=
    that follows, if column-0)

Both are scoped to Phase 2's AST walker and listed in
CORPUS-RUN.md as follow-ups (item 2 + item 3).

Refs #57 (the issue is multi-phase, this is a precision pass on
Phase 1, not a phase close).

Test plan

  • dune build tools/res-to-affine — clean.
  • dune test tools/res-to-affine/ — 3/3 OK (snapshot byte-identical
    because the synthetic fixture covers column-0 cases only).
  • Re-ran scanner over the 491-file corpus, verified the per-kind
    tally matches the table above and spot-checked remaining hits.
  • CI on this PR.

🤖 Generated with Claude Code

First end-to-end run of the Phase-1 scanner against the estate's 491
deduplicated .res files (idaptik + gitbot-fleet) surfaced two
high-impact false-positive sources in the top-level regexes:

- `side-effect-import` fired on in-function `let _ = X.foo(...)`,
  ReScript's normal "discard a chained call's return value" idiom
  (1,181 hits, vast majority indented; LESSONS.md's anti-pattern is
  the top-level form only).
- `mutable-global` fired on any `:=`, including local ref mutation
  inside function bodies (653 hits, none at column 0 in the corpus).

Both regexes are now anchored at column 0, matching the LESSONS.md
anti-pattern shape (module-load side effect, module-scoped mutable).
`re_untyped_exn` also gains a `(^|...)` alternation so `raise` / `try`
at column 0 is no longer missed.

Total markers across the corpus: 2,146 → 348 (−84%).
Files with any marker: 216 → 94. The 3-test snapshot suite is
unchanged — the synthetic fixture covers column-0 cases only.

Adds `tools/res-to-affine/CORPUS-RUN.md` (human report with corpus
stats, regex change-log, top-hotspots table, and Phase-2 follow-ups)
plus `CORPUS-RUN.json` (machine-readable sidecar). README links both.

The trade-off: we no longer flag module-load side effects nested
inside `module X = { ... }` blocks, nor `let x = ref(...)` top-level
declarations paired with their later `:=`. Those are scoped to
Phase 2's AST walker and listed in CORPUS-RUN.md as follow-ups.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hyperpolymath hyperpolymath merged commit 65fa5ef into main May 21, 2026
0 of 14 checks passed
@hyperpolymath hyperpolymath deleted the corpus-run-57 branch May 21, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant