Skip to content

Fix/ground prelude dedup#419

Merged
cukas merged 3 commits into
mainfrom
fix/ground-prelude-dedup
Jun 12, 2026
Merged

Fix/ground prelude dedup#419
cukas merged 3 commits into
mainfrom
fix/ground-prelude-dedup

Conversation

@cukas

@cukas cukas commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What

Why

How

Checklist

  • tsc -b passes
  • pnpm test passes
  • pnpm test:kern passes
  • pnpm lint passes
  • kern review packages/ --recursive checked

cukas and others added 3 commits June 12, 2026 08:26
…module

Two ground statements in one emitted module that both need the same runtime
helper block (def _kern_js_fill) currently emit the helper twice, because
groundExpressionPrelude is inlined per-statement and the module assembler
concatenates the per-statement arrays verbatim.

Co-Authored-By: kern-agon <kern-agon@users.noreply.github.com>
groundExpressionPrelude inlines each ground statement's helper/import prelude
ahead of that statement, so a standalone generator call still emits the helper
it needs. When the module assembler concatenates several ground statements that
share a helper block (e.g. def _kern_js_fill), the per-statement inlining
repeated the whole block once per statement.

Add dedupeGroundPrelude: a module-assembly pass keyed on the closed registry of
known helper blocks (block granularity, since distinct helpers share boilerplate
lines) plus the `import X as __k_X` import-line pattern. It keeps the FIRST
occurrence of each unique block/import — preserving first-need order so the
helper still precedes its first use — and drops later repeats, leaving all
non-prelude statement lines untouched. Wired into generateModule (module
children) and emitModels (top-level siblings).

No existing fixture's emitted bytes change (no snapshot/conformance churn); the
only difference is that duplicate helper text is removed in multi-statement
modules.

Co-Authored-By: kern-agon <kern-agon@users.noreply.github.com>
…t-first

Review-fix batch from the 6-engine agon review of this slice:
- import-dedup path now covered (regex ground expressions, __k_re)
- helper-block matching sorts longest-first so a future prefix-colliding
  helper cannot shadow a longer block at a match site

Co-Authored-By: kern-agon <kern-agon@users.noreply.github.com>
@cukas cukas merged commit d74f717 into main Jun 12, 2026
4 checks passed
@cukas cukas deleted the fix/ground-prelude-dedup branch June 12, 2026 08:19
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