python-compiler-incremental-macro-hygiene
Done. The verified solution is written to ~/SOLUTION.md, with the runnable implementation in ~/incremental_macro_cache.py and tests in ~/test_incremental_macro_cache.py.
Root cause: A cache keyed only on source bytes is wrong for this language. Generated output also depends on (1) transitively-imported macro definitions, (2) the deterministic hygiene salt, (3) the conditional-config environment, and (4) compiler/parser/hygiene versions. Diagnostics and source maps must be cached atomically with the generated bytes, or they drift on reuse.
Fix — Merkle-style invalidation keys + dependency propagation:
H(module, versions, source_hash, used_flags+values, used_macros+fingerprints, module name). Only flags/macros actually referenced are included, so unrelated edits/config stays cached.call_path + macro fingerprint, so cached output is byte-identical across runs.origin spans: template-introduced nodes point at the macro call site; substituted user arguments keep their own spans.Verification:
python3 -m unittest -v test_incremental_macro_cache # 10 passed
All 10 tests pass and cover: unrelated-edit reuse, direct/transitive macro invalidation, used-vs-unused config flags, call-site diagnostic attribution, hygiene renaming, deterministic reuse, graph propagation, and arity diagnostics. The end-to-end demo confirms noise edit → only noise misses (6 hits), root-macro edit → dirty ['base','mid','top'] with noise still cached, and the macro-body error reports at user:2:16 (the call site). The embedded code in SOLUTION.md also compiles cleanly.
# Evidence - Problem class: python-compiler-incremental-macro-hygiene - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-10-05T04:03:42.325Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Design an incremental compiler cache for a language with hygienic macros, conditional compilation, and source maps, where edits can alter macro expansion dependencies across modules. Specify invalidation keys and implement dependency propagation so unaffected artifacts remain reusable while generated diagnostics and source locations stay exact.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-compiler-incremental-macro-hygiene", "provider": "openrouter", "solved_at": "2026-10-05T04:03:42.325Z", "version": "3.11"}