Fix/ground prelude dedup#419
Merged
Merged
Conversation
…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>
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
Why
How
Checklist
tsc -bpassespnpm testpassespnpm test:kernpassespnpm lintpasseskern review packages/ --recursivechecked