Skip to content

feat: t27_check -- parse and typecheck .t27 source, with a fix hint for foreign syntax - #5

Closed
gHashTag wants to merge 1 commit into
t27f-deckfrom
t27-check
Closed

gHashTag wants to merge 1 commit into
t27f-deckfrom
t27-check

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Closes gHashTag/t27#10073

Part of the epic gHashTag/t27#10066 (learnability: parser hints for foreign syntax). Stacked on #4 (t27f-deck), which carries wasm/BUILD; the rule table is gHashTag/t27#10080.

What

A new tool, t27_check: give it .t27 source, get back whether it parses and typechecks and, for each
diagnostic, the line, the source line and a short "write this instead" hint for foreign syntax. It runs offline.

t27_check({source: "module M;\npub fn f(a: u8) -> u8 {\n    return (a as u3);\n}\n"})
{ ok: false, errors: 1, warnings: 0, diagnostics: [{ severity: "error", line: 3,
  message: "parse error in fn 'f' near line 3: unknown cast target type `u3`; ...",
  hint: "Casts reach only bool u8 ... usize f32 f64: there is no `as u3`. Keep a wider type and mask the value, e.g. `x & 7`.",
  source: "    return (a as u3);" }] }
  • wasm/explorer.wasm: the bootstrap parser and typechecker (gHashTag/t27 bindings/wasm-explorer), copied
    unchanged, 774 KB. It decides ok or not; the server adds no verdict.
  • wasm/check_hints.wasm + wasm/check_hints.mjs: generated from specs/t27mcp/check_hints.t27 by
    t27c gen-c + zig cc and t27c gen-js (the string parameters of the spec arrive as const char*, so no
    hand export glue is needed). Built on the Railway lab; commands and sha256 in wasm/BUILD.
  • check.mjs (26 lines) is glue: it moves bytes between the two wasm modules. A message the spec does not know
    gets no hint, and the compiler's words stand alone.

Hand-written JavaScript added: check.mjs 26, server.mjs 11, smoke.mjs 11 = 48 lines (cap: 40 per file, 80
per PR).

Evidence

  • npm run smoke: the four new t27_check checks pass (clean source, as u3 with its line and source, in as a
    name, and a negative control: an arity error gets no hint). The run's one failure,
    backendFailures tally matches the specs blaming a backend (737 counted vs 113 blaming), is in the live atlas
    data and in code this PR does not touch; it is the kind of tally logic the epic's last item moves into .t27.
  • 200 checks of a failing source take 58 ms in total.
  • Spec side: 13 of 13 tests, 0 vacuous, negative control fails as it should (spec(t27mcp): check_hints -- compiler message to a short fix hint for foreign syntax t27#10080).

🤖 Generated with Claude Code

…or foreign syntax

The compiler front end runs as wasm (explorer.wasm, gHashTag/t27
bindings/wasm-explorer, unchanged); each message gets a hint code and a line
number from wasm/check_hints.wasm, generated from
gHashTag/t27 specs/t27mcp/check_hints.t27 (PR gHashTag/t27#10080). check.mjs is
26 lines of glue and holds no rule.

Closes gHashTag/t27#10073
Refs gHashTag/t27#10066

Co-Authored-By: Claude Sonnet 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.

1 participant