Skip to content

Cache persistence off by default, rename mccode-antlr cache ir-build to ... build - #402

Merged
g5t merged 3 commits into
mainfrom
cache-build
Oct 21, 2026
Merged

g5t merged 3 commits into
mainfrom
cache-build

Conversation

@g5t

@g5t g5t commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Since .comp file parsing was improved drastically, the on-disk Comp IR cache causes more problems than it seems to be worth for most cases.

This PR turns off on-disk caching by default, and adds C typedef caching to the, now renamed, mccode-antlr cache build command. Both the Comp IR cache and C typedef cache are kept in memory to ensure they continue to help with repeated translations in a single process, e.g., live parsing of a .instr file by a language server.

One case where the cache build step makes sense is a read-only pre-baked container image which contains all of McStas' component files, and the new confuse configuration key is provided to ensure this use case is still accessible.

g5t added 3 commits October 21, 2026 04:45
The component cache was keyed on a .comp file's own mtime only, so editing
the parent of `DEFINE COMPONENT b INHERIT a` left b's cached IR -- in memory
and in its sidecar -- reporting a's old contents until b itself was touched.

Each cache entry now records the mtime of every source file it was built
from: itself plus every component resolved through Reader.get_component
while it was parsed, transitively. A hit requires all of them to match
exactly, which also rejects a .comp whose mtime moved backwards (rsync -a
of an older file over a newer sidecar). Sidecars store these sources
relative to their own directory, so a tree copied with mtimes preserved
keeps its cache. The sidecar layout changes, so the cache format is now 5.
`cache ir-build` and `ir-clean --stale` use the same freshness check.
Translation parses every component's SHARE, DECLARE and USERVARS blocks,
and each runtime library they %include, to find C typedefs and declarations.
That parse is cached by content hash, but nothing pre-built the cache, so a
read-only image (stacktainer-splitrun) re-parsed them in every process:
1.3 s for ILL_H142 and 2.5 s for cryostat_example, against 0.34 s warm.

ir-build now constructs the C translator for a one-instance instrument of
each component it builds or finds up to date, which parses exactly the
blocks a real translation would. Only an instrument's own USERVARS are left
for translation time. A component that cannot be translated (e.g. a missing
%include file) is reported separately and does not count as an IR error.
`cache build` pre-builds both translation caches, so the IR-specific name
no longer fits. `cache ir-build` remains as a deprecated spelling that warns
and then runs `cache build`.

Component IR sidecars are now written and read only when the new
`cache.component_ir` configuration value is true (e.g.
MCCODEANTLR_CACHE__COMPONENT_IR=true); it defaults to false. Re-parsing a
component costs ~0.3 s per translation process, while sidecars written into
source trees have repeatedly served stale IR and leaked into published
registries. They remain worthwhile for a prebuilt, read-only cache such as a
container image, which can opt in. The in-memory level is unchanged, so
long-lived processes lose nothing. String values, as stored by
`mccode-antlr config set`, are parsed rather than taken as truthy.

With sidecars disabled, `cache build` says so and only warms the C typedef
cache. The CLI docs also drop a nonexistent `--download` option and list
`--tag` and `--flavor none`.
@g5t g5t mentioned this pull request Oct 21, 2026
@g5t
g5t merged commit 82e5730 into main Oct 21, 2026
14 checks passed
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