Configurable caches for classpaths, files, sources, and file bytes #24780
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.
The main goal of this PR is to enable caching of file contents across compiler runs. Importantly, this PR is careful not to change any of the existing caching strategies (except for compilation tests). It only enables users of the compiler to customize them.
This PR follows a series of experiments (#24630, #24644, #24737, #24777) in which I tried caching at different levels.
This PR addresses the problem by introducing two new concepts:
CacheStore: a configurable set of caches that can potentially be shared across runs. ACacheStoreis associated with each context.Cache: the interface for individual caches, together with a collection of composable implementations: thread-safe and thread-unsafe variants; a file-based implementation that invalidates entries when files on disk change (refactored from the existingFileBasedCache); and a filter cache that allows caching only a subset of keys.This PR deliberately sidesteps the question of how these caches should be used by other tools, such as Zinc. Addressing that will require further work on API boundaries. However, the proposed changes are self-contained and already allow speeding up compilation tests (by ~11% on my machine), as well as running benchmarks without measuring I/O, which was the initial motivation.
Commits:
CacheStore, which provides caches for classpaths, abstract files (by name), and source files. The defaultDefaultCacheStorepreserves the current behavior: a singleton global cache forClassPathinstances, and no-op caches for files and sources (which are still cached per run viaContextBase).CacheStorefor compilation tests that cachesSourceFileandAbstractFileinstances across runs, avoiding repeated reads of the standard library from disk.wrong-ownertest to list context owners instead of all outer contexts. This is needed becausectx.freshadds an outer context that would otherwise introduce an extra<none>.CacheStorefor class file bytes. The default is to not cache them. The test cache is updated to cache class bytes globally.CacheStorefor TASTy file bytes, analogous to the class-file cache.