refactor[next]: name the cache layout and give the translation caches one home - #2769
Conversation
4df0e9c to
5813e34
Compare
5813e34 to
25611b6
Compare
edopao
left a comment
There was a problem hiding this comment.
LGTM, just a minor comment.
| @@ -47,8 +47,9 @@ class Params: | |||
| input_fingerprinter=stages.compilable_program_fingerprinter, | |||
| cache=filecache.FileCache( | |||
| str( | |||
There was a problem hiding this comment.
The FileCache constructor accepts path: str | os.PathLike, so it should be possible to avoid the str conversion.
There was a problem hiding this comment.
Done — dropped the str() in factory.py; FileCache resolves the Path itself. It also removes the extra nesting this diff had introduced.
| input_fingerprinter=stages.compilable_program_fingerprinter, | ||
| cache=filecache.FileCache( | ||
| str(cache.get_cache_base_path(config.BUILD_CACHE_LIFETIME) / "gtfn_cache") | ||
| str( |
There was a problem hiding this comment.
Done — dropped the str() in gtfn.py; FileCache resolves the Path itself. It also removes the extra nesting this diff had introduced.
25611b6 to
a752914
Compare
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Refactors cache directory naming by centralizing previously inlined literals, and consolidates translation caches into a single parent directory with per-backend subfolders.
Changes:
- Introduces named constants for cache layout (bindings suffix, translation cache dir name, translation backends, compiledb prototype prefix).
- Adds
get_translation_cache_folder(cache_base, backend)and updates DaCe/gtfn runners to use it. - Updates tests to assert the new cache naming/layout behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/next_tests/unit_tests/otf_tests/compilation_tests/test_cache.py | Updates assertions to use named constants and adds coverage for shared translation cache parent dir. |
| src/gt4py/next/program_processors/runners/gtfn.py | Switches gtfn translation cache path construction to get_translation_cache_folder(...). |
| src/gt4py/next/program_processors/runners/dace/workflow/factory.py | Switches DaCe translation cache path construction to get_translation_cache_folder(...). |
| src/gt4py/next/otf/compilation/cache.py | Adds constants and get_translation_cache_folder(...); updates bindings suffix usage in build cache folder naming. |
| src/gt4py/next/otf/compilation/build_systems/compiledb.py | Names the compiledb synthetic cache folder prefix constant and uses it in name generation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| cache.get_translation_cache_folder( | ||
| cache.get_cache_base_path(config.BUILD_CACHE_LIFETIME), "gtfn" | ||
| ) | ||
| ), |
| def get_translation_cache_folder(cache_base: pathlib.Path, backend: str) -> pathlib.Path: | ||
| """Return the folder under `cache_base` where `backend` caches its translations.""" | ||
| return cache_base / TRANSLATION_CACHE_DIR_NAME / backend |
| def get_translation_cache_folder(cache_base: pathlib.Path, backend: str) -> pathlib.Path: | ||
| """Return the folder under `cache_base` where `backend` caches its translations.""" | ||
| return cache_base / TRANSLATION_CACHE_DIR_NAME / backend |
| #: Suffix appended by `get_cache_folder` to the program name when the cached | ||
| #: artifact includes bindings. It is part of the pattern's `name` group, so | ||
| #: recovering the plain program name means stripping this suffix. | ||
| BINDINGS_NAME_SUFFIX: Final[str] = "_pyext" |
| slug = ext_source.program_source.entry_point.name | ||
| if ext_source.binding_source: | ||
| slug = f"{slug}_pyext" | ||
| slug = f"{slug}{BINDINGS_NAME_SUFFIX}" |
… one home The layout of the generated-code cache was spelled out as string literals at the places that happen to write it: the translation cache directory in each backend's workflow factory, the bindings suffix in `get_cache_folder`, the compile-complete marker in the DaCe compile step, the compiledb prototype name in the compiledb build system. Nothing named these, so reading a cache directory meant recognizing conventions rather than looking them up, and anything outside the writer had to re-spell them. Name each in the module that owns it, and fix the one that was inconsistent while doing so. The two caches holding translation-step output were called `translation_cache/` for DaCe -- a name for the stage, but holding one backend's entries -- and `gtfn_cache/` for gtfn, a name for the backend that says nothing about the stage. Neither holds build artifacts; those sit in sibling `<program>_pyext_<fingerprint>_<version>` folders. They now share one parent, `translation_cache/<backend>/`, reached through `get_translation_cache_folder`, so both read stage first and backend second, the pair is visible as a pair, and clearing every translation cache is one directory rather than a list that grows with each backend. Entries under the previous names are not migrated. They are already discarded on any change of the build-cache version, so leaving them to be recomputed matches what this cache does routinely; the stale directories can simply be removed.
a752914 to
16d6c20
Compare
|
Thanks — going through the Copilot comments, one of them earned a change and the
def __init__(self, path: str | os.PathLike):
self.path = pathlib.Path(path).resolve()Verified
Unlike `get_cache_folder`, this only computes a path. The folder is created by
the cache that writes into it, so that asking where a cache would be does not
create it — which tools that only inspect a cache rely on.Path traversal if Derive the |
|
I did not merge yet, because I want to do it after the release. Also together with possibly moving the build cache directory as well. |
The layout of the generated-code cache was spelled out as string literals at the
places that happen to write it:
"translation_cache"/"gtfn_cache""_pyext"cache.get_cache_folder"compile_commands_cache"Nothing named these, so reading a cache directory meant recognizing conventions
rather than looking them up, and anything outside the writer had to re-spell
them.
Each literal becomes a name in the module that owns it:
BINDINGS_NAME_SUFFIX,TRANSLATION_CACHE_DIR_NAMEandTRANSLATION_CACHE_BACKENDSinotf/compilation/cache.py, andCOMPILEDB_PROTOTYPE_NAME_PREFIXin thecompiledb build system.
The inconsistent pair gets one home, stage first and backend second, reached
through
get_translation_cache_folder(cache_base, backend)so callers no longerassemble the path: