fix(tokenizer): invalidate cached ASTs after source edits by jinchuntan · Pull Request #1082 · 8f4e/8f4e · GitHub
Skip to content

fix(tokenizer): invalidate cached ASTs after source edits - #1082

Merged
irimias57 merged 1 commit into
8f4e:mainfrom
jinchuntan:fix/in-place-ast-cache
Oct 17, 2026
Merged

irimias57 merged 1 commit into
8f4e:mainfrom
jinchuntan:fix/in-place-ast-cache

Conversation

@jinchuntan

Copy link
Copy Markdown
Contributor

The AST cache now keeps a copy of the source lines used to parse each block. Editing the caller's array no longer makes stale code look unchanged.

Added a tokenizer regression that checks the edited source is a cache miss and the next unchanged compile is a hit. A compiler regression also runs the exported WebAssembly function and checks that it returns 2 after the edit.

Both regressions failed before the fix and pass with it. All 748 tokenizer and compiler tests pass. All affected lint checks and type checks and tests also pass.

npx nx run-many --target=test --projects=@8f4e/tokenizer,@8f4e/compiler --parallel=1 --output-style=static
npx nx affected --target=lint --base=59354c60 --output-style=static
npx nx affected --target=typecheck --base=59354c60 --output-style=static
npx nx affected --target=test --base=59354c60 --parallel=2 --output-style=static

Fixes #1057

Prepared with Codex assistance.

Keep a snapshot of source lines for deferred cache hashing so caller
mutations cannot make a stale AST appear current.

Cover the tokenizer cache miss and subsequent hit after an edit and
verify the public compiler exports the updated function value.

Fixes 8f4e#1057

Prepared with Codex assistance.

@irimias57 irimias57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, Nigel! This is a clean, focused fix for the cache invalidation bug, and the tokenizer-level plus public compiler regressions cover the behavior very well. Nicely done!

@andorthehood

Copy link
Copy Markdown
Member

@irimias57
irimias57 merged commit c0c50fe into 8f4e:main Oct 17, 2026
2 checks passed
@andorthehood andorthehood added compiler Compiler, tokenizer, codegen, and language-semantics work contributor labels Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler Compiler, tokenizer, codegen, and language-semantics work contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalidate cached ASTs after an in-place source edit

3 participants