Skip to content

perf: schema-salted non-executable parse cache (#736) - #1345

Merged
godofecht merged 10 commits into
mainfrom
cursor/ast-cache-schema-salt-1e07
Oct 6, 2026
Merged

godofecht merged 10 commits into
mainfrom
cursor/ast-cache-schema-salt-1e07

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Linked issue: #736 (first slice only).

The parsed-declaration cache that landed in #1302 hashed source plus a version mix and wrote raw AST words under ~/.cache/flow/ast. This slice closes the two blockers named on the issue:

  1. Cache key now mixes an explicit schema id, compiler version, AstNode size, parse-affecting config (bundle expand-all stages and MLIR parse mode), optional FLOW_CACHE_SALT, and the source bytes. A salt mutation test proves a new key is allocated when the salt changes and the source does not.
  2. Trust boundary writes a non-executable FCAC integer record (magic, schema, node size, length, root, then AstNode words) only under $XDG_CACHE_HOME/flow/ast or $HOME/.cache/flow/ast. A checkout .flow_cache/ is never opened. Load is a memcpy of integers; pickle is not used.

This is not typecheck, monomorphize, or codegen caching, and it is not a full import-dependency graph. Those remain open on #736.

Overlap check

  • I searched open pull requests and recent commits for overlapping work.
  • This does not duplicate another active implementation, or the relationship is explained below.

Open PRs #1332 #1331 #1330 #1329 #1328 #1326 #1325 #1268 #1267 #1265 are unrelated (MLIR flags and benchmarks). #1302 already merged a first AST cache; this PR hardens that cache rather than starting a second one.

Evidence

Baseline before this change: on 9a278876 the cache key omitted parse-affecting config and an explicit schema constant; the on-disk header was a bare 736 magic; there was no salt-only mutation test and no untrusted-checkout proof.

Targeted proof: ./flow tool tests/scripts/incremental_cache.flow

PASS incremental_cache/salt_mutation
PASS incremental_cache/source_edit
PASS incremental_cache/untrusted_checkout
PASS incremental_cache/format_not_pickle
incremental_cache: 4 passed, 0 failed, 0 skipped
  • salt_mutation — same source, FLOW_CACHE_SALT=frontend-v1 then frontend-v2; a new .ast file appears only after the salt change.
  • source_edit — edited helper return value is observed.
  • untrusted_checkout — protocol-0 pickle under project .flow_cache/ that would touch a sentinel if loaded does not run.
  • format_not_pickle — user-cache records begin with FCAC.

Why that proof would detect the old failure: a key that ignored salt would keep a single record across the salt change; a pickle loader would create the sentinel.

Repository gate(s) run:

  • ./flow tool tests/scripts/incremental_cache.flow — 4 passed
  • env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)" — flowc: PASS
  • ./compiler/scripts/bootstrap_from_c.sh --regen — fixed point at gen2
  • ./compiler/scripts/bootstrap_from_c.sh --verify — PASS bootstrap C matches compiler/src
  • no hosted workflows added, enabled, or used

Generated/bootstrap state: compiler/bootstrap/flowc_stage_a.c regenerated in a separate commit after the compiler/src/ edits.

Risk

Internal compiler cache only. Existing ~/.cache/flow/ast records with the old header miss and reparse. Cold builds are unchanged when the cache directory cannot be created.

  • No unresolved language/API design decision is being implemented implicitly.
  • No unrelated generated artifacts or local state are included.
  • Docs changed when user-visible behaviour or syntax changed.
  • docs/project/Questions.md updated if this needs a language-design decision.

Compatibility

  • No user-visible compatibility change.
  • Compatibility change is documented in docs/project/CHANGELOG.md.

Agent handoff

Remaining #736 gaps, still on the issue: dependency-aware invalidation, typecheck/monomorphize/codegen caches, cache hit/miss diagnostics, stale-executable prevention.

Open in Web Open in Cursor 

cursoragent and others added 2 commits October 5, 2026 02:02
Key parsed-declaration records by cache schema, compiler version, node
size, parse-affecting config, and FLOW_CACHE_SALT. Persist integer FCAC
records under the user cache so an untrusted checkout cannot execute
crafted project-local cache data.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht marked this pull request as ready for review October 5, 2026 02:09
Keep main's FLOWC_PROF_CACHE span around the cache probe. Regenerate
bootstrap C and Linux x86-64 flowc_stage_a ELF.
Resolve bootstrap binary by taking main then regenerating.
Regenerated bootstrap on Mac (fixed point gen2) and rebuilt the
checked-in ELF on Linux for CI self-host.
Record 28 corpus programs whose MLIR changed after the main merge.
Bootstrap binary and corpus digests taken from main; will regen and re-record.
Rebuild Linux ELF and refresh corpus digests for the schema-salt
parse-cache branch on current main.
@godofecht
godofecht merged commit 4609f80 into main Oct 6, 2026
39 checks passed
godofecht added a commit that referenced this pull request Oct 6, 2026
godofecht added a commit that referenced this pull request Oct 6, 2026
Brings in #1345, which salts the parse-cache key with a schema, node size and
parse-affecting config and re-records the MLIR corpus goldens it affects.
That is what the previous merge could not fix: before #1345 the parse cache
was not schema validated, so a program's emitted MLIR depended on which files
the corpus run had already parsed, and this branch's new fixtures changed that
state on CI.

With the cache now transparent (measured: identical MLIR with and without
FLOW_CACHE_SALT), main's flowc and the merged flowc emit byte-identical MLIR
for tests/lang/test_typecheck_overload_integration.flow, so the merged
compiler matches main's recorded digest 81533a1e.

Conflict: compiler/bootstrap/flowc_stage_a (binary) was taken from main. The
generated .c was reset to main's copy because it auto-merged, then
regenerated from the merged compiler/src with bootstrap_from_c.sh --regen
(fixed point at gen2); --verify reports it as self-reproducing.

Generated with Codebuff (https://codebuff.com)
Co-Authored-By: Codebuff <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Records gain a u64 payload checksum after the header (schema 2) and are
neither written nor read above 4194304 nodes. A record whose payload does
not match, or that has trailing bytes, is a miss and is re-parsed. The
directory trust model from #1345 is unchanged, per the resolved question
in docs/project/Questions.md.
godofecht added a commit that referenced this pull request Oct 8, 2026
Records gain a u64 payload checksum after the header (schema 2) and are
neither written nor read above 4194304 nodes. A record whose payload does
not match, or that has trailing bytes, is a miss and is re-parsed. The
directory trust model from #1345 is unchanged, per the resolved question
in docs/project/Questions.md.
@godofecht
godofecht deleted the cursor/ast-cache-schema-salt-1e07 branch October 12, 2026 23:02
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.

2 participants