Skip to content

fix(compiler): protect AST cache and reject invalid affine/vector configurations (#736 #665 #666) - #1402

Merged
godofecht merged 12 commits into
mainfrom
fix/issue-736-665-666-compiler-guards
Oct 8, 2026
Merged

godofecht merged 12 commits into
mainfrom
fix/issue-736-665-666-compiler-guards

Conversation

@godofecht

@godofecht godofecht commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Narrow compiler guards for #665, #666 and the part of #736 that #1345 left open. Part of #665, #666 and #736.

#736 (parse cache, inside the #1345 trust boundary)

  • flowc_parse_cached: when the cache root leaves no room in the 512-byte key buffer for / + 16 hex bytes + .ast + NUL, compile without the cache. Before, the suffix was written past the buffer.

  • A record whose header root is outside [0, ast_len) is a miss and is re-parsed. Before, any root that passed the magic/schema/size checks was returned as the parse result.

  • tools/flow_cli/sys.flow: write_bytes (raw bytes with NUL) so the test can corrupt a record.

  • Records carry a u64 payload checksum after the header (record schema 2) and a cap of 4194304 nodes. A payload that does not match its checksum, or a record with trailing bytes, is a miss. This follows the resolved question in docs/project/Questions.md: the cache directory stays trusted as perf: schema-salted non-executable parse cache (#736) #1345 set it, with no ownership checks and no O_EXCL writes.

#665 (affine tiling): a malformed FLOWC_MLIR_TILE or FLOWC_MLIR_TILE_L2, an L2 without an inner tile, or an L2 smaller than the inner tile is refused with a diagnostic. Before, each one silently fell back to a different schedule.

#666 (register tiles): FLOWC_MLIR_REGISTER_TILES must be exactly 1 (10 no longer enables it). Nested lane products are overflow-checked, an overflowing vector-width token is rejected before type registration, and non-positive operand lane counts are refused before the nested result type is registered.

Evidence

New regressions fail on the old code. With main's resolve.flow and this branch's tests, incremental_cache gives 4 passed, 2 failed (long_cache_root and out_of_range_root: emit fails, rc -1). Without the checksum commit, corrupt_payload fails the same way. With the fixes: 7 passed.

Local gates on this head (macOS arm64):

  • selftest flowc: PASS; bootstrap regen fixed point at gen2; --verify ALL PASS
  • tests/scripts: incremental_cache 7/0, mlir_pipeline 35/0, mlir_register_tiles 12/0
  • test-lang 285/0, tests/cgen 142/0, parity_mlir PASS, roundtrip ALL PASS, self_host_full ALL PASS, tests/tools pass
  • tests/cli: only the known local jit_hello and test_mlir drift

Generated state: compiler/bootstrap/flowc_stage_a.c and the binary regenerated in the last commit.

Risk

A malformed tiling env var that used to be ignored now fails the MLIR emit. FLOWC_MLIR_REGISTER_TILES values other than 1 no longer enable register tiles. Cache behaviour only changes for over-long cache roots and corrupt records.

@godofecht
godofecht force-pushed the fix/issue-736-665-666-compiler-guards branch from 9661c96 to 582b070 Compare October 8, 2026 00:20
@godofecht
godofecht marked this pull request as ready for review October 8, 2026 00:20
@godofecht
godofecht force-pushed the fix/issue-736-665-666-compiler-guards branch from 582b070 to 30f97df Compare October 8, 2026 03:33
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 force-pushed the fix/issue-736-665-666-compiler-guards branch from 30f97df to 5a103e3 Compare October 8, 2026 07:57
@godofecht
godofecht enabled auto-merge October 8, 2026 07:57
@godofecht
godofecht added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit a9bba59 Oct 8, 2026
34 checks passed
@godofecht
godofecht deleted the fix/issue-736-665-666-compiler-guards branch October 12, 2026 23:03
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