TSFC: cache the kernel by the repo state, not just the form signature - #5346
Open
pbrubeck wants to merge 8 commits into
Open
TSFC: cache the kernel by the repo state, not just the form signature#5346pbrubeck wants to merge 8 commits into
pbrubeck wants to merge 8 commits into
Conversation
TSFC indexes its kernel caches by the form being compiled, not by the compiler that lowered it, so an editable install serves a stale kernel after tsfc/, finat/FIAT/gem, ufl or loopy changes -- silently, as a wrong answer rather than a cache miss. Add tsfc.caching.codegen_key(), fixed at import, and fold it into the three cache keys that index a kernel by its form (tsfc_interface, interpolation) plus Slate's own (which also stamps firedrake/slate/slac/, the generator that it owns outside TSFC). Also point setup_cache_dirs() at sys.prefix instead of $VIRTUAL_ENV, so an activated shell and a bare venv/bin/python share one cache. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
pbrubeck
force-pushed
the
pbrubeck/tsfc-codegen-key
branch
2 times, most recently
from
August 11, 2026 21:28
2e6b92f to
43f2801
Compare
Neither is obvious from the code alone: why stat a file instead of reading it, and why a value with no cache of its own still lets a kernel cache on disk survive across separate runs.
pbrubeck
force-pushed
the
pbrubeck/tsfc-codegen-key
branch
from
August 11, 2026 21:30
43f2801 to
500f681
Compare
"Keyed" is this codebase's own term for this (see hashkey, tsfc_compile_form_hashkey); "indexed" was a synonym substituted in without checking, not the vocabulary the caches actually use.
"On" is the codebase's own preposition for this ("TSFC's kernel cache
keys on the form..."); "by" was substituted in with the previous fix
and changed the idiom without needing to.
The opening sentence described the pre-codegen_key() behavior ("an
edit... leaves a stale kernel in place") without a past-tense marker,
so it read as still true. That is the "Documenting Code That Is Not
There" anti-pattern this same file's own AGENTS.md entry warns
against. The bug belongs in the commit message and PR description,
not in a docstring for code that fixes it.
…key in "Caller" described the code that uses codegen_key() in the abstract instead of naming it: Firedrake's kernel caches.
Lead with what this module does, then why it matters, then the mechanism -- instead of opening on a bare noun phrase that named the output without naming the action.
"Fold" names a functional-programming operation this module does not perform; the caches append codegen_key() as one more tuple element in their own hashkey, which "add" says plainly.
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.
TSFC originally indexed its kernel caches by the form being compiled, not by the compiler that lowered it, so an editable was retrieving a stale kernel after tsfc, finat/FIAT/gem, ufl or loopy changes -- silently, as a wrong answer rather than a cache miss.
Add
tsfc.caching.codegen_key(), fixed at import, and fold it into the three cache keys that index a kernel by its form signature (tsfc_interface, interpolation) plus Slate's own (which also stamps firedrake/slate/slac/, the generator that it owns outside TSFC). Also pointsetup_cache_dirs()atsys.prefixinstead of$VIRTUAL_ENV, so an activated shell and a barevenv/bin/pythonshare one cache.Description