Repository navigation
feat(Cache): accept downstream modules as cache get arguments for partial fetching - #45905
marcelolynch wants to merge 13 commits into
Conversation
`lake exe cache get MyProject.Basic` in a downstream project gets the olean cache for the Mathlib cache modules that `MyProject.Basic` imports, also through other modules of the downstream project. A downstream module gets no hash, so the cache never asks for files of its own. Without arguments, `cache get` gets the cache for `Mathlib` only. Co-authored-by: Jon Eugster <[email protected]>
PR summary 5c0fcd8d0eImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
…`get` end to end `getHash` visits every module the same way: it records the imports that `cache` follows in `depsMap`, and only a module in the Mathlib cache gets a hash. `filterByRootModules` collects the hashes reachable from the roots. This replaces the separate walk for downstream modules, the `cache` memo, and `insertDeps`. `Cache/test/downstream.sh` runs `cache get` in a downstream project that requires the checkout, and checks that `lake build` then builds only the downstream modules. The `cache-get-downstream` job runs it on Linux and Windows. Co-authored-by: Jon Eugster <[email protected]>
`findWithExtBase` returns the first entry of the search path that has the module's file, and only falls back to a directory when no entry has the file. Dependencies come first in the search path, so a top-level directory of a dependency (such as Mathlib's `DownstreamTest/`) no longer hides a downstream package with the same name. All lookups of a module's source use `findLeanSource`. An import of a downstream module that no package in the search path has is skipped with a warning, and does not stop `cache get`.
… with a git dependency The test copies `DownstreamTest/` and requires Mathlib by git from a one-commit copy of HEAD, so Mathlib is in `.lake/packages/mathlib`, as in a real downstream project. Lake cannot clone the shallow CI checkout itself. The downstream `cache get` starts from an empty cache directory, and must download as many files as `cache get- Mathlib.Data.Nat.Basic`. A second `cache get` must download and unpack nothing. The `cache-get` job runs it.
…hange The docstring of `getFileImports` states what happens to an unknown import and which messages name `fileName`. The `cache-get` job comment covers the downstream test. The messages for a downstream argument and an unknown import name `cache` as the agent. The Lean core case of the unit test checks that `cache` does not visit the imports of a Lean core module.
…streamTest/` `Cache/test/downstream.sh SCENARIO` sets up `DownstreamTest/`, which requires the checkout by path, and runs a scenario: - `full` is the check of the main CI: `cache get`, then `lake build --no-build Mathlib`. - `partial` checks `cache get DownstreamTest.Partial` against the reference `cache get- Mathlib.Data.Nat.Basic` in the checkout, then checks that `lake build` builds only the downstream modules and that a second `get` does nothing. The main CI runs the script from `workflow-actions/`, so that a fork PR branch gets the script of the workflow revision. The `cache-get` job runs `partial` before any step unpacks Mathlib oleans.
…`Mathlib` imports CI uploads the cache for the closure of `Mathlib`. A downstream module can import other modules of the dependencies, and the server has no files for them. `getHash` resolves the imports itself, `lookup` names a module without a cache file, and the help text documents MATHLIB_NO_CACHE_ON_UPDATE.
…load in one cache directory
Inline the single-use helpers in `Cache/Hashing.lean`, shorten the docs and the help text, and keep one unit test assertion per case that the `partial` scenario does not check. The `partial` scenario drops the second `cache get`.
cache get arguments
cache get argumentscache get arguments for partial fetching
| cache := stt.cache.insert mod (some fileHash) | ||
| depsMap := stt.depsMap.insert mod (fileImports.map (·.1)) }) | ||
| let stt ← get | ||
| if stt.depsMap.contains mod then return stt.hashMap[mod]? |
There was a problem hiding this comment.
the imports get recorded before the hash check now. Before, depsMap was only written on the success path, so a downstream module importing another downstream module never got its imports recorded and get MyProject.Basic would have selected nothing. With depsMap as the visited marker the cache field was redundant, so we drop
joneugster
left a comment
There was a problem hiding this comment.
I've tested this now with a new repo pointing at this branch and it was working as expected!
The changes look reasonable to me (I did only skim over the changes to tests though). Please mark this as non-draft when you don't intent to make further changes :)
|
Thanks! maintainer merge disclosure: As mentioned above, I did originally write a version of this about 2 years ago (originally this was #21238). While said PR was the inspiration for this PR, I do not remember or recognise much of that code, so I thought it adequate to review and test Marcelo's implementation. |
|
🚀 Pull request has been placed on the maintainer queue by joneugster. |
This PR lets
lake exe cache get MyProject.Basicwork in a downstream project. It builds on #35415 by Jon Eugster. Without arguments,cache getgets the cache forMathlib.Changes to the lookup:
getselects the cache modules that it imports, also through other downstream modules, and thatMathlibalso imports. CI uploads the cache only for the closure ofMathlib, and Lake builds the other modules.getHashrecords the imports of each visited module, so the walk continues through downstream modules. From a downstream module, it follows all imports outside Lean core. An unknown import gets a warning, andcacheskips the cache modules that import it..leanfile. Dependencies come first in the search path, and Mathlib has a directoryDownstreamTest/. The file check resolvesDownstreamTest.Partialto the downstream package.A downstream project runs
MATHLIB_NO_CACHE_ON_UPDATE=1 lake updatefor a partialget, because Mathlib'spost_updatehook gets the whole cache.Cache/test/downstream.sh partialruns on Linux and Windows. It checks thatcache get DownstreamTest.Partialdownloads only the files ofcache get- Mathlib.Data.Nat.Basic, and thatlake buildthen builds only the two downstream modules. The main CI runs the existing downstream check through the same script.🤖