Skip to content

Replace the %debugger extension with a debugger() function - #9163

Merged
cknitt merged 2 commits into
masterfrom
debugger-function
Nov 1, 2026
Merged

cknitt merged 2 commits into
masterfrom
debugger-function

Conversation

@cknitt

@cknitt cknitt commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Why

%debugger is a language feature selected by an extension name, one of the items #8624 lists before the parsetree can be stamped as v1. It never needed to be one: the frontend only rewrote it into a call of a local external with the %debugger primitive. The standard library can declare that external, and calls to externals are inlined, so the debugger statement stays in the caller's frame.

What changes

  • Pervasives gets external debugger: unit => unit = "%debugger", next to __LOC__ and the other debugging helpers:

    let add = (a, b) => {
      debugger()
      a + b
    }

    compiles to debugger; return a + b | 0;, as %debugger did.

  • Since debugger is now a function, its argument can be any unit expression. The backend evaluates it before the statement, so debugger(Console.log("before pause")) compiles to console.log("before pause"); debugger;. Before, the Pdebugger case ignored its arguments, which was only safe while %debugger always passed a literal ().

  • %debugger is removed (v13): the frontend's handler is gone, and the parser reports

    The %debugger extension has been removed. Use debugger() instead.
    

    like it does for the removed %re.

%raw is no replacement, because debugger is a statement: %raw("debugger") compiles to return debugger;.

Tests

  • tests/build_tests/super_errors/fixtures/syntaxErrorsRemovedDebuggerExtension.res for the new error.
  • debugger_test.res covers an effectful argument in statement and in value position.
  • The existing %debugger tests (debugger_test, debug_keep_test, lazy_test, the source map test) now use debugger(). Their generated JS is unchanged, and the source map test checks the same positions.
  • The printer fixture that used %debugger as an example of an extension uses %foo.

There is no deprecation in v12 first: %debugger is only used while debugging locally and shouldn't be in production code, so its removal doesn't need a migration period.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Changelog

💥 Breaking Change

  • Replace the %debugger extension with a debugger() function in Pervasives. %debugger is now a syntax error that points to debugger().

Semantic Diff

2 commits · Full page

Replace the %debugger extension with a debugger() function

86101e9 · cknitt + Claude · Nov 01, 2026, 08:28 UTC

Why

%debugger was a language feature selected by an extension name (#8624), but it only ever lowered to an external with the %debugger primitive. The standard library can declare that external, and an external call is inlined, so the statement stays in the caller's frame.

JS modified (debugger())

let add = (a, b) => {
  debugger()
  a + b
}

js · After

function add(a, b) {
  debugger;
  return a + b | 0;
}

Diagnostic added (%debugger)

let f = x => {
  %debugger
  x
}

diagnostic · After

Syntax error!
The %debugger extension has been removed. Use debugger() instead.

⚠️ Breaking: %debugger is a syntax error. Replace it with debugger().

✨ Evaluate the argument of debugger() before the statement

43dc5c5 · cknitt + Claude · Nov 01, 2026, 11:28 UTC · new

Why

debugger() is a function now, so any unit-valued expression can be its argument, but the Pdebugger case of the JS backend ignored its arguments, so effects such as a log call were dropped silently. %debugger always passed a literal unit, which hid this (Codex review on #9163).

JS modified (debugger with an argument)

let f = () => debugger(Console.log("before pause"))

js

 function f() {
+  console.log("before pause");
   debugger;
 }

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.74%. Comparing base (0800cb4) to head (43dc5c5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9163      +/-   ##
==========================================
- Coverage   81.75%   81.74%   -0.01%     
==========================================
  Files         460      460              
  Lines       64948    64946       -2     
==========================================
- Hits        53097    53092       -5     
- Misses      11851    11854       +3     
Files with missing lines Coverage Δ
compiler/core/lam_compile.ml 91.54% <100.00%> (+0.03%) ⬆️
compiler/frontend/ast_exp_extension.ml 93.75% <ø> (-0.70%) ⬇️
compiler/frontend/ast_exp_handle_external.ml 80.48% <ø> (-0.77%) ⬇️
compiler/syntax/src/res_core.ml 92.03% <100.00%> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9163

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9163

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9163

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9163

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9163

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9163

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9163

commit: 43dc5c5

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T11:30:37.259697Z 43dc5c5 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb3c414ec6

ℹ️ 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".

Why:
    %debugger was a language feature selected by an extension name (#8624),
    but it only ever lowered to an external with the %debugger primitive.
    The standard library can declare that external, and an external call
    is inlined, so the statement stays in the caller's frame.

JS modified (debugger()):
Example:
    let add = (a, b) => {
      debugger()
      a + b
    }
After (js):
    function add(a, b) {
      debugger;
      return a + b | 0;
    }

Diagnostic added (%debugger):
Example:
    let f = x => {
      %debugger
      x
    }
After (diagnostic):
    Syntax error!
    The %debugger extension has been removed. Use debugger() instead.

Breaking: `%debugger` is a syntax error. Replace it with `debugger()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the debugger-function branch from cb3c414 to 86101e9 Compare November 1, 2026 11:23
Why:
    debugger() is a function now, so any unit-valued expression can be its
    argument, but the Pdebugger case of the JS backend ignored its
    arguments, so effects such as a log call were dropped silently. %debugger
    always passed a literal unit, which hid this (Codex review on #9163).

JS modified (debugger with an argument):
Example:
    let f = () => debugger(Console.log("before pause"))
Before (js):
    function f() {
      debugger;
    }
After (js):
    function f() {
      console.log("before pause");
      debugger;
    }

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 43dc5c5aca

ℹ️ 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".

@cknitt
cknitt marked this pull request as ready for review November 1, 2026 12:24
@cknitt
cknitt requested a review from cristianoc November 1, 2026 12:24
@cknitt
cknitt merged commit 995be5c into master Nov 1, 2026
26 checks passed
@cknitt
cknitt deleted the debugger-function branch November 1, 2026 14:02
fhammerschmidt added a commit to fhammerschmidt/rescript-lang.org that referenced this pull request Nov 21, 2026
ReScript 13 removed the %debugger extension in favor of the
debugger() function from Pervasives (rescript-lang/rescript#9163).

- Update the Debugger section of Embed Raw JavaScript, drop the stale
  second output block, and explain why %raw("debugger") isn't a
  replacement.
- Move debugger() from the cheatsheet's extension point list to its own
  section.
- Replace the %debugger syntax lookup entry with a debugger() entry
  under special values, and regenerate route types.

Fixes rescript-lang#1487

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fhammerschmidt added a commit to fhammerschmidt/rescript-lang.org that referenced this pull request Nov 22, 2026
ReScript 13 removed the %debugger extension in favor of the
debugger() function from Pervasives (rescript-lang/rescript#9163).

- Update the Debugger section of Embed Raw JavaScript, drop the stale
  second output block, and explain why %raw("debugger") isn't a
  replacement.
- Move debugger() from the cheatsheet's extension point list to its own
  section.
- Replace the %debugger syntax lookup entry with a debugger() entry
  under special values, and regenerate route types.

Fixes rescript-lang#1487

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fhammerschmidt added a commit to rescript-lang/rescript-lang.org that referenced this pull request Nov 24, 2026
* docs: replace removed %debugger with debugger()

ReScript 13 removed the %debugger extension in favor of the
debugger() function from Pervasives (rescript-lang/rescript#9163).

- Update the Debugger section of Embed Raw JavaScript, drop the stale
  second output block, and explain why %raw("debugger") isn't a
  replacement.
- Move debugger() from the cheatsheet's extension point list to its own
  section.
- Replace the %debugger syntax lookup entry with a debugger() entry
  under special values, and regenerate route types.

Fixes #1487

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: open docs examples in the playground with the docs' compiler

Playground links from code examples only passed the code, so the
playground fell back to the latest stable compiler and couldn't compile
v13-only examples such as debugger(). Add the installed compiler
version, which the examples are checked against, as the version
parameter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: redirect the old %debugger syntax lookup URL

Permanently redirect /syntax-lookup/extension_debugger to the renamed
specialvalues_debugger page so existing links keep working, and cover
the rule in the redirect check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: list debugger() under built-in functions in the syntax lookup

debugger() is a function from Pervasives, not a compiler-filled special
value like __LOC__. Move its entry to the existing, previously unused
Built-In Functions category and point the redirect for the old
%debugger URL at the new page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: add throw() to the syntax lookup's built-in functions

throw() is the other user-facing Pervasives function with its own
docstring. Add a syntax lookup entry next to debugger(), based on that
docstring, with the generated JS output and links to the exception
docs. Regenerate route types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants