Skip to content

TSFC: cache the kernel by the repo state, not just the form signature - #5346

Open
pbrubeck wants to merge 8 commits into
mainfrom
pbrubeck/tsfc-codegen-key
Open

TSFC: cache the kernel by the repo state, not just the form signature#5346
pbrubeck wants to merge 8 commits into
mainfrom
pbrubeck/tsfc-codegen-key

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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 point setup_cache_dirs() at sys.prefix instead of $VIRTUAL_ENV, so an activated shell and a bare venv/bin/python share one cache.

Description

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
pbrubeck force-pushed the pbrubeck/tsfc-codegen-key branch 2 times, most recently from 2e6b92f to 43f2801 Compare August 11, 2026 21:28
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
pbrubeck force-pushed the pbrubeck/tsfc-codegen-key branch from 43f2801 to 500f681 Compare August 11, 2026 21:30
"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.
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