Repository navigation
DEMO: verify a ReScript React Todo app and @tscert.noMutation reducer with TScert - #9430
cristianoc wants to merge 3 commits into
Conversation
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>
Changelog🚀 New Feature
Semantic Diff3 commits · Full page Support
|
✅ Compiler benchmarksAllocated wordsIn total: 638,971,114 → 639,049,077 (+0.01%). Generated projects: 630,398,528 → 630,510,437 (+0.02%).
InstructionsIn total: 9,225,046,825 → 9,225,122,296 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn 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>
1. Verifying a React app
tests/build_tests/emit_ts_reactis a ReScript React Todo app behind a 27-line trusted host (TodoHost.ts). TScert verifies all 4 app modules (29/29units) againstjsx-runtime.d.tsand rejects the negative controls (ForgedElement,InvalidProps,ImpureReducer), while Biome checks hook placement.2.
@tscert.noMutation+ the React reducerReact requires reducers passed to
useReducernot to mutate state, which ReScript's type system alone does not prevent (arrays,refs, mutable fields in helpers). AnnotatingreduceinTodoModel.res:emits:
TypeScript still reads
Modifies<{}, state>asstate, while TScert checks the empty write footprint transitively across modules:Forwarding.respasses, andForwardingMutation.resfails becauseForwarded.bumpInPlacemutates a record field in another module:3. Open questions
Ideas like checked no-mutation make sense directly at the ReScript source level (reducers, pure selectors, library boundaries), beyond TS emission.
[329,360)back to.reslocations/call chains, editor UX, attribute vs. type syntax)?