Petrinaut HIR: compile user code to buffer-native programs, remove Babel#8973
Draft
kube wants to merge 12 commits into
Draft
Petrinaut HIR: compile user code to buffer-native programs, remove Babel#8973kube wants to merge 12 commits into
kube wants to merge 12 commits into
Conversation
Introduce a typed, source-spanned, JSON-serializable HIR as the single compiler for dynamics/lambda/kernel user code: - TS->HIR lowering (const destructuring, guard if/early-return, .map comprehensions, first-class distributions) with positioned diagnostics - Schema-checked typing against Color/parameter definitions; analyses for dependency sets, distribution DAGs (nodes/edges/sinks/shared draws), binding usage and constant folding - Buffer-ABI emitters: lambdas read token attributes at statically resolved offsets (tokenValues[slotBases[slot] + attr]); kernels write place-major staging floats with deferred distribution sampling ordered by output index (exact legacy RNG-stream parity); dynamics compile to allocation-free Float64Array loops - Engine hot loops (single-run + Monte Carlo) prefer buffer programs and fall back to object-convention HIR programs per item - HirArtifacts v2 compiled in the LSP worker (sdcpn/compileHirArtifacts request) and threaded through simulation/experiment configs; the engine no longer bundles any compiler (simulation workers: ~3MB -> ~40kB) - HIR semantic lints in the LSP checker (source "hir", codes 99001+); out-of-subset code is an error and Play gates on error severity only - Remove @babel/standalone and compile-user-code.ts; fix H-6519 violations in the supply-chain example; shipped examples are the buffer-ABI coverage gate Design docs: src/hir/README.md (architecture) and src/hir/dsl-sketch.md (planned OCaml-flavoured DSL lowering to the same HIR). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Interactive playground for the HIR pipeline: type dynamics/lambda/kernel TypeScript on the left, and inspect everything it compiles to on the right — the spanned HIR tree, diagnostics with exact ranges, the inferred return type, dependency sets, the distribution DAG (derivation edges, output sinks, shared draws), and both emitted programs (buffer-ABI fast path and object-convention fallback). The model schema (parameters, places, attribute types) is editable JSON and re-checks live. Exposes the compiler via new `@hashintel/petrinaut-core/hir` and `/hir-runtime` entries (typescript declared as an optional peer — only the ./hir entry needs it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… the HIR Rebase onto the FE-769 stack (token format v2, UUID + interned strings) and extend the compiler: - New HIR nodes: string literals, string predicates (startsWith/endsWith/includes), Uuid.generate()/Uuid.from(...) sentinels - Typecheck: uuid/string attribute types; kernel outputs accept strings for string attributes and uuid/string for uuid attributes (omitted uuid = auto-generated); string .length; uuid helpers are kernel-only - Buffer-ABI v2: lambdas and dynamics compile to packed-struct byte reads through the frame's shared f64/u64/u8 views (integers rounded, booleans u8, strings resolved via the per-run pool, uuids assembled from two u64 lanes); slotBases now carry byte offsets. Kernel buffer emission is deferred (needs an RNG-ordinal sink design to preserve the stream) — the object program runs per firing meanwhile - Object programs emit uuid sentinels/string literals; analyses track generatesUuids; string-equality constant folding - Replace the deleted Babel compiler in the dev token playground with a local evaluator Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Remove the object-convention path entirely: the engine no longer decodes token records for user code, and every dynamics/lambda/kernel runs a buffer program with all dimension offsets and strides resolved at compile time and baked into the emitted code as literal constants. - Kernel buffer emitter: static writes into per-transition staging bytes at compile-time-constant offsets; RNG-consuming slots (distributions, generated/converted UUIDs) defer through sink calls emitted in (arc, token, element-declaration) order, preserving the seeded RNG stream; strings intern through the per-run pool inline - Lambda programs now receive (placeBases, indices) with strides baked in — the per-slot offset loop is gone; token layouts are computed once per arc slot at emit time - CompiledTransition carries only buffer programs + reusable scratch (placeBases/indices/staging views); encode-kernel-token.ts and the record-decode adapters are deleted - Artifacts v3 are buffer-only; shapes that don't scalarize fail compilation with hir:not-compilable (all example models compile fully, kernels included — enforced by the coverage gate) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Metrics become the fourth HIR surface and lose their new Function path: - New arrayReduce/arrayConcat HIR nodes (.reduce/.concat lowering); metric code lowers as a function body with spans mapped back to the raw text - Metric buffer programs read frames directly with statically-resolved offsets: attribute offsets/strides baked as literals, place ordinals resolved once at instantiation, reductions emitted as loops over the packed token region (no per-frame MetricState decoding) - compileHirArtifacts covers sdcpn.metrics; expression metric specs carry the compiled artifact; single-run timeline and actual-mode metric paths migrated to the same evaluator via SimulationFrameReader.getRawView() - Delete compile-metric.ts and frames/metric-state.ts; LSP metric sessions get HIR lint incl. hir:not-compilable as blocking errors - All 18 example metrics compile (reduce/concat/guards/strings) — enforced by the coverage gate Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
15 tasks
| case "let": | ||
| // `let` only appears as a function/callback body; those emit blocks. | ||
| // eslint-disable-next-line no-use-before-define -- mutual recursion | ||
| return `(() => ${emitBody(expr, scope)})()`; |
| "__dist", | ||
| "__params", | ||
| "__pool", | ||
| `"use strict"; return (${source});`, |
| "__params", | ||
| "__pool", | ||
| "__places", | ||
| `"use strict"; return (${source});`, |
Comment on lines
+54
to
+60
| const create = new Function( | ||
| `"use strict"; | ||
| const Token = (fn) => fn; | ||
| let __default; | ||
| ${code.replace(/export\s+default\s+/, "__default = ")} | ||
| return __default;`, | ||
| )() as () => unknown; |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Runs scenarios (dynamics, lambda combinations, kernel firings, Monte-Carlo experiment with expression metrics) through the public in-process createMonteCarloSimulator API. Feature-detects the HIR entry so the same script runs on pre-HIR baselines; emits per-scenario build/run medians, heap growth, and a work checksum that must match across variants. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
--no-warmup/--samples/--only for fresh-process cold runs; --compile isolates user-code compilation (HIR pipeline vs Babel per-item). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🌟 What is the purpose of this PR?
🔗 Related links
🚫 Blocked by
🔍 What does this change?
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
turbo.json's have been updated to reflect this🐾 Next steps
🛡 What tests cover this?
❓ How to test this?
📹 Demo