Skip to content

Represent %todo with a Pexp_todo parsetree node - #9161

Merged
cknitt merged 1 commit into
todo-stdlib-jserrorfrom
todo-node
Nov 1, 2026
Merged

cknitt merged 1 commit into
todo-stdlib-jserrorfrom
todo-node

Conversation

@cknitt

@cknitt cknitt commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Why

%todo is a language feature selected by an extension name, one of the items #8624 lists before the parsetree can be stamped as v1.

What changes

%todo and %todo("message") parse to a new node:

| Pexp_todo of {name_loc: Location.t; message: expression option}
  • The parser builds it when the payload is empty, a string literal, or a template without interpolations, with no attributes (Ast_todo.of_payload). Any other payload, such as %todo(1) or %todo({"braced"}), stays a Pexp_extension "todo" and is lowered as before.
  • The message stays an expression, so the printer keeps its spelling (quotes or backquotes, escapes) and the comments inside the payload.
  • The built-in PPX lowers the node with the same code as the extension, now Ast_exp_extension.todo. The generated JS and warning 110 are unchanged.
  • PPXs still see the extension: ast_mapper_to0 writes the node as %todo(...), and ast_mapper_from0 turns a %todo extension with a fitting payload back into the node, the same way the parser does.
  • The printers, comment table, parenthesization, iterator, mapper, depend, printast and editor completion handle the node like Pexp_raw.

Tests

  • tests/syntax_tests/data/ast-mapping/TodoExpressions.res: the v0 round trip.
  • tests/syntax_tests/data/printer/expr/todo.res: printing, comments around and inside the payload, and parentheses in pipes, field access and unary minus.
  • tests/syntax_tests/data/parsing/grammar/expressions/todo.res.
  • todo_roundtrips_through_ast0 in ounit_ast_mapper0_tests.ml: which payloads become a node (none, a string, a template, but not 1), the v0 wire shape, the exact tree (locations included) after a round trip, and a PPX-built %todo("x") arriving as the node.

Stacked on #9160.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub

@cknitt
cknitt added this pull request to stack #9162 November 1, 2026 09:24
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Represent %todo with a Pexp_todo parsetree node. PPXs still see the extension.

Semantic Diff

1 commit · Full page

Represent %todo with a Pexp_todo parsetree node

3c96010 · cknitt + Claude · Nov 01, 2026, 08:23 UTC

Why

%todo is a language feature selected by an extension name, one of the items #8624 lists before the parsetree can be stamped as v1. The node holds the message as written; PPXs still see the extension.

AST modified (%todo)

let f = () => %todo("later")

parse

 expression
-  Pexp_extension "todo"
-    structure_item
-      Pstr_eval
-      expression
-        Pexp_constant PConst_string (source="later", semantic="later")
+  Pexp_todo
+  Some
+    expression
+      Pexp_constant PConst_string (source="later", semantic="later")

Review

  • Which payloads become a node? None, a string literal, or a template without interpolations, without attributes. Any other payload, such as %todo(1), stays an extension and is lowered as before, ignoring it.
  • Why an expression for the message rather than a string? It keeps the spelling (quotes or backquotes, escapes) and the comments inside the payload for the printer, as the extension did.

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.24691% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.67%. Comparing base (0c2890f) to head (3c96010).

Files with missing lines Patch % Lines
tests/ounit_tests/ounit_ast_mapper0_tests.ml 81.81% 4 Missing ⚠️
compiler/ml/typecore.ml 0.00% 3 Missing ⚠️
compiler/syntax/src/res_parens.ml 0.00% 3 Missing ⚠️
compiler/ml/printast.ml 0.00% 2 Missing ⚠️
analysis/src/completion_front_end.ml 0.00% 1 Missing ⚠️
analysis/src/utils.ml 0.00% 1 Missing ⚠️
compiler/frontend/ast_exp_extension.ml 90.90% 1 Missing ⚠️
compiler/ml/depend.ml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           todo-stdlib-jserror    #9161      +/-   ##
=======================================================
- Coverage                81.67%   81.67%   -0.01%     
=======================================================
  Files                      455      456       +1     
  Lines                    64859    64922      +63     
=======================================================
+ Hits                     52974    53024      +50     
- Misses                   11885    11898      +13     
Files with missing lines Coverage Δ
compiler/frontend/bs_builtin_ppx.ml 90.39% <100.00%> (+0.06%) ⬆️
compiler/ml/ast_helper.ml 87.97% <100.00%> (+0.03%) ⬆️
compiler/ml/ast_iterator.ml 94.61% <100.00%> (+0.03%) ⬆️
compiler/ml/ast_mapper.ml 98.48% <100.00%> (+0.01%) ⬆️
compiler/ml/ast_mapper_from0.ml 79.46% <100.00%> (+0.09%) ⬆️
compiler/ml/ast_mapper_to0.ml 80.07% <100.00%> (+0.07%) ⬆️
compiler/ml/ast_todo.ml 100.00% <100.00%> (ø)
compiler/ml/pprintast.ml 91.72% <100.00%> (+0.01%) ⬆️
compiler/syntax/src/res_comments_table.ml 91.24% <100.00%> (+0.01%) ⬆️
compiler/syntax/src/res_core.ml 92.04% <100.00%> (+<0.01%) ⬆️
... and 9 more
🚀 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@9161

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 3c96010

@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-01T16:03:25.549313Z afd0792 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: afd0792a1c

ℹ️ 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:
    %todo is a language feature selected by an extension name, one of the
    items #8624 lists before the parsetree can be stamped as v1. The node
    holds the message as written; PPXs still see the extension.

AST modified (%todo):
Example:
    let f = () => %todo("later")
Before (parse):
    expression
      Pexp_extension "todo"
      [
        structure_item
          Pstr_eval
          expression
            Pexp_constant PConst_string (source="later", semantic="later")
      ]
After (parse):
    expression
      Pexp_todo
      Some
        expression
          Pexp_constant PConst_string (source="later", semantic="later")

Review: Which payloads become a node? None, a string literal, or a template
    without interpolations, without attributes. Any other payload, such as
    `%todo(1)`, stays an extension and is lowered as before, ignoring it.
Review: Why an expression for the message rather than a string? It keeps the
    spelling (quotes or backquotes, escapes) and the comments inside the
    payload for the printer, as the extension did.

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 marked this pull request as ready for review November 1, 2026 16:24
@cknitt
cknitt requested a review from cristianoc November 1, 2026 16:24
@cknitt
cknitt merged commit cc827cd into master Nov 1, 2026
26 checks passed
@cknitt
cknitt deleted the todo-node branch November 1, 2026 19:42
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