Skip to content

DEMO: verify a ReScript React Todo app and @tscert.noMutation reducer with TScert - #9430

Draft
cristianoc wants to merge 3 commits into
exp/emit-ts-2from
exp/emit-ts-react-todo
Draft

cristianoc wants to merge 3 commits into
exp/emit-ts-2from
exp/emit-ts-react-todo

Conversation

@cristianoc

@cristianoc cristianoc commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Draft demo stacked on #9211 (exp/emit-ts-2). TScert is still evolving and not stable yet, and source-level error reporting is not wired up here.

Verifying a ReScript React App with TScert

1. Verifying a React app

tests/build_tests/emit_ts_react is a ReScript React Todo app behind a 27-line trusted host (TodoHost.ts). TScert verifies all 4 app modules (29/29 units) against jsx-runtime.d.ts and rejects the negative controls (ForgedElement, InvalidProps, ImpureReducer), while Biome checks hook placement.

ReScript React Todo app
yarn install
yarn todo:check   # build, snapshot + boundary check, TScert (app + controls), Biome
yarn todo:dev     # run the app locally

2. @tscert.noMutation + the React reducer

React requires reducers passed to useReducer not to mutate state, which ReScript's type system alone does not prevent (arrays, refs, mutable fields in helpers). Annotating reduce in TodoModel.res:

@tscert.noMutation
let reduce = (state: state, action: action): state => ...

emits:

/// <reference types="@cristianoc/tscert/effects" />
export function reduce(state: state, action: action): Modifies<{}, state>

TypeScript still reads Modifies<{}, state> as state, while TScert checks the empty write footprint transitively across modules: Forwarding.res passes, and ForwardingMutation.res fails because Forwarded.bumpInPlace mutates a record field in another module:

reject: source effect refusal at [329,360): the footprint claimed for 'incrementInPlace' is not established by its body

3. Open questions

Ideas like checked no-mutation make sense directly at the ReScript source level (reducers, pure selectors, library boundaries), beyond TS emission.

  • Does a checked no-mutation annotation feel valuable for ReScript users?
  • What should real integration and error reporting look like (mapping refusals like [329,360) back to .res locations/call chains, editor UX, attribute vs. type syntax)?

Why:
    TScert verification of React components and reducers under `-bs-emit-ts`
    needs explicit parameter types on local/callback functions and JSX
    wrappers, a mapping for `JsxEvent.Mouse.t`, and a way to emit an empty
    write-footprint claim (`Modifies<{}, T>`) on functions marked
    `@tscert.noMutation` without eta-reducing forwarding wrappers.

JS modified (@tscert.noMutation):
Example:
    @tscert.noMutation
    let increment = n => Forwarded.increment(n)
Before (js):
    export const increment = Forwarded.increment;
After (js):
    /// <reference types="@cristianoc/tscert/effects" />
    …
    export function increment(n: number): Modifies<{}, number> {
      return Forwarded.increment(n);
    }

JS modified (callback parameters):
Example:
    let squares = xs => Array.map(xs, x => x * x)
Before (js):
    export function squares(xs: number[]): number[] {
      return xs.map(x => x * x | 0);
    }
After (js):
    export function squares(xs: number[]): number[] {
      return xs.map((x: number) => x * x | 0);
    }

Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Add `tests/build_tests/emit_ts_react`, a multi-module ReScript React Todo
app (`TodoModel`, `TodoReact`, `TodoRow`, `TodoLabel`) mounted by a thin
trusted React host (`src/trusted/TodoHost.ts`) with `@tscert.noMutation`
on `TodoModel.reduce`. The test suite verifies the emitted app modules and
cross-module forwarding cases (`Forwarding` / `ForwardingMutation`) with
TScert against `contracts/jsx-runtime.d.ts`, checks negative controls
(`ForgedElement`, `InvalidProps`, `ImpureReducer`, `ConditionalHook`), and
checks hook placement with Biome.

Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Changelog

🚀 New Feature

  • Support @tscert.noMutation on functions with experimental TypeScript emission.
    The emitted return type states an empty write footprint for TScert to check
    and the generated file references the TScert package's effect declarations.
    Annotated forwarding functions keep their signatures in the emitted code.

Semantic Diff

3 commits · Full page

Support @tscert.noMutation and callback/JSX types under -bs-emit-ts

9ea68c0 · cristianoc · Nov 26, 2026, 03:28 UTC

Why

TScert verification of React components and reducers under -bs-emit-ts needs explicit parameter types on local/callback functions and JSX wrappers, a mapping for JsxEvent.Mouse.t, and a way to emit an empty write-footprint claim (Modifies<{}, T>) on functions marked @tscert.noMutation without eta-reducing forwarding wrappers.

JS modified (@tscert.noMutation)

@tscert.noMutation
let increment = n => Forwarded.increment(n)

js

-export const increment = Forwarded.increment;
+/// <reference types="@cristianoc/tscert/effects" />
+…
+export function increment(n: number): Modifies<{}, number> {
+  return Forwarded.increment(n);
+}

JS modified (callback parameters)

let squares = xs => Array.map(xs, x => x * x)

js

 export function squares(xs: number[]): number[] {
-  return xs.map(x => x * x | 0);
+  return xs.map((x: number) => x * x | 0);
 }
Add TScert-verified React Todo app build test

3bbb51f · cristianoc · Nov 26, 2026, 03:28 UTC

Add tests/build_tests/emit_ts_react, a multi-module ReScript React Todo app (TodoModel, TodoReact, TodoRow, TodoLabel) mounted by a thin trusted React host (src/trusted/TodoHost.ts) with @tscert.noMutation on TodoModel.reduce. The test suite verifies the emitted app modules and cross-module forwarding cases (Forwarding / ForwardingMutation) with TScert against contracts/jsx-runtime.d.ts, checks negative controls (ForgedElement, InvalidProps, ImpureReducer, ConditionalHook), and checks hook placement with Biome.

✨ Polish React Todo app UI and keyboard ergonomics

998c71e · cristianoc · Nov 26, 2026, 03:46 UTC · new

Upgrade tests/build_tests/emit_ts_react to a clean, usable Todo UI: add Enter-to-submit, placeholder and aria-label support on TodoInput, live task counts (TodoModel.countTodos) in the header, segmented filter tabs, and footer, circular completion toggles, color-coded clickable priority pills, an empty state, and refined card styling while keeping all 4 app modules (29/29 units) verified by TScert.

@cristianoc
cristianoc added this pull request to stack #9431 November 26, 2026 03:38
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 638,971,114 → 639,049,077 (+0.01%).

Generated projects: 630,398,528 → 630,510,437 (+0.02%).

Benchmark Base Head Change
build/Namespace/clean 85,223,866 85,316,033 +0.11%

Instructions

In total: 9,225,046,825 → 9,225,122,296 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 26,008,229 → 26,008,861 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request 998c71e compared with base 005b7ac in this run.

Upgrade `tests/build_tests/emit_ts_react` to a clean, usable Todo UI:
add Enter-to-submit, placeholder and aria-label support on `TodoInput`,
live task counts (`TodoModel.countTodos`) in the header, segmented filter
tabs, and footer, circular completion toggles, color-coded clickable
priority pills, an empty state, and refined card styling while keeping all
4 app modules (`29/29` units) verified by TScert.

Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
@cristianoc
cristianoc requested a review from cknitt November 26, 2026 03:59

This branch has not been deployed

No deployments
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