Skip to content

fix(playground): repair stale/broken examples + faithful example verifier#1

Merged
natescode merged 2 commits into
mainfrom
fix/playground-examples
Jun 15, 2026
Merged

fix(playground): repair stale/broken examples + faithful example verifier#1
natescode merged 2 commits into
mainfrom
fix/playground-examples

Conversation

@natescode

Copy link
Copy Markdown
Owner

What & why

The deployed playground's examples had drifted from current Silicon syntax, and several "examples" didn't actually do what they claimed. This repairs them so every dropdown example compiles and behaves as advertised.

Examples fixed

Example Before After
Snake A counter that never drew anything A real, playable snake — growing tail + self-collision + food, drawn on the canvas each tick. Arrow keys steer, Space restarts.
HTML list Only console_log'd Builds an HTML <ul> and renders it into the panel via web::set_html.
Option (wasm-gc) Removed pattern => body @match arm Flat @match(o, $Some v, { v }, $None, { dflt }).
Default editor doc (INITIAL_SOURCE) Dropped & call sigil + @local Mirrors hello_world's paren-call syntax.
Cheatsheet Documented the removed => @match form Flat form.
Vec[Int] (gc_vec) Configured for --target=wasm-gc, but @use 'vec' is the linear-memory impl (alloc/realloc, rejected under wasm-gc) → never compiled in the deployed playground Relabeled to the host target (compiles + runs → 55).

Snake internals

The snake body lives in raw linear memory (WASM::i32_store/i32_load at a fixed base; tick() never allocates, so it can't collide with the bump allocator). Two robustness fixes from review:

  • Input is latched into a per-tick pend turn, applied once at the top of tick() — so two fast key presses can't fold the head 180° into the neck.
  • Food is placed only after the body is fully advanced, so it never lands on the snake (incl. the new head) and never reads an unwritten segment slot.

Tooling

  • web/verify-examples.ts now extracts EXAMPLE_FEATURES / EXAMPLE_TARGETS and compiles each example with the exact features + target the UI uses. The old harness compiled everything with features: [] and no target, which is what masked the gc_vec break.
  • server.ts (local dev server) now calls inlineStdlibUses() before parse, mirroring the browser build — previously the five @use-based examples failed at /compile on the dev server.

Verification

  • bun run --cwd playground verify → example verifier: 19/19 compile with their real features/targets.
  • bun run --cwd playground smoke → headless Chromium: 19/19 compile and run in the real UI (game loop, set_html, wasm-gc), zero page errors.
  • Snake driven directly: growth (len 3→4, score +10), wall/self death, restart, 3000-step fuzz with no OOB/crash, and the 180°-reversal exploit no longer kills the snake.
  • Visually confirmed the snake renders (body + food) and the HTML list renders a styled checklist.

Deploy

Vercel builds this directory's static client-side bundle (bun run builddist/). Merging to main ships the fix to production.

Follow-up (not in this PR)

playground/playground/*-plan.html (design/plan pages served statically) still contain pre-ADR-0020 snippets (& sigil, @local). They're illustrative design docs, not interactive examples — worth a separate cleanup pass or an "archived" banner.

🤖 Generated with Claude Code

natescode and others added 2 commits June 14, 2026 16:03
…fier faithful

The deployed playground examples had drifted from current Silicon syntax, and
several "examples" didn't actually do what they claimed:

- Snake: was a counter that never drew anything — now a real, playable snake
  (growing tail + self-collision + food) drawn on the canvas each tick. The body
  lives in raw linear memory (WASM::i32_store/load); arrow keys steer, Space
  restarts. Input is latched into a per-tick `pend` turn so two fast key presses
  can't fold the head 180° into the neck, and food is placed only after the body
  is fully advanced so it never lands on the snake or reads an unwritten slot.
- HTML list: only console-logged — now builds an HTML <ul> and renders it into
  the render panel via web::set_html.
- wasm_gc (Option): used the removed `pattern => body` @match arm — now the flat
  @match(o, $Some v, { v }, $None, { dflt }) form.
- INITIAL_SOURCE (default editor doc): used the dropped `&` call sigil + @Local —
  now mirrors hello_world's paren-call syntax.
- Cheatsheet: documented the removed `=>` @match form — fixed to the flat form.
- gc_vec: was configured for --target=wasm-gc, but `@use 'vec'` is the
  linear-memory impl (alloc/realloc, rejected under wasm-gc), so it never
  compiled in the deployed playground. Relabeled to the host target.
- server.ts (local dev server): never inlined `@use`, so the five stdlib/vec
  examples failed at /compile. Now calls inlineStdlibUses() before parse,
  mirroring the browser build (web/entry.ts).

verify-examples.ts now extracts EXAMPLE_FEATURES/EXAMPLE_TARGETS and compiles
each example with the exact features + target the UI uses (it previously used
features:[] with no target, which masked the gc_vec break). All 19 examples pass
verify-examples and the headless-Chromium smoke test (compile + run-in-UI).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ntax

The static design/roadmap pages served alongside the playground
(plan.html, features-plan.html, modules-plan.html) still showed
pre-ADR-0020 Silicon that the current compiler rejects. Modernized every
Silicon snippet (code blocks, inline <code> refs, and diff illustrations)
while preserving the HTML, syntax-highlight markup, and prose:

- dropped the retired `&` call sigil → parenthesised calls (foo(a, b))
- @let@fn (functions) or bare `name := v` (consts); @var@mut;
  @Local → bare locals
- inline `name:Type` param annotations → bare params (inference)
- old `@extern name arg:Type;` / `@extern name (a:T) -> R;`
  → `\\ @extern name (Types) -> Ret;`
- `;`-style comments in Silicon blocks → `#` (Silicon's comment char)
- `A && B` (no && operator) → nested @if; retired `@stratum_operator`
  example → current `@stratum { Compiler::register::operator(...) }` form;
  grammar note now cites `ExprEnd = Primary { CallSuffix }`

Verified: each modernized <pre> Silicon block parses under the current
grammar (typecheck failures on fragments that reference undefined modules
are expected), HTML tags stay balanced, and the pages render correctly.
platforms-plan.html is unchanged — its `@platform` snippets are proposed
(not yet implemented) syntax, not retired forms.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
silicon-website Ready Ready Preview, Comment Jun 14, 2026 9:43pm

@natescode natescode merged commit 743e832 into main Jun 15, 2026
3 of 4 checks passed
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