Repository navigation
Conversation
…sFromSource` (leanprover-community#150) `findTransitiveImportsFromSource` built paths with `modToRelFilePath`, relative to the process working directory, and silently skipped modules whose source was not found there, returning an incomplete closure with no indication that anything was missed. This made imports from Lake dependency packages (under `.lake/packages/...`) unresolvable, as well as any invocation from a directory other than the package root. Module sources are now located via a new helper `findModuleSource?`, which tries the source search path (`LEAN_SRC_PATH` — under `lake exe` / `lake env` this contains the source directories of every workspace package, including dependencies — plus the toolchain's own `src/lean`), then the `LEAN_PATH` search path, and finally the working-directory- relative path as before. Modules that still cannot be resolved are collected and reported by throwing an `IO.userError`, rather than being silently treated as leaves. The docstring now also documents that `rootFilter` prunes the traversal itself rather than filtering the final result, so a `root` module only reachable via non-`root` modules is not found. Regression tests cover search-path resolution of toolchain modules, closure extending beyond direct imports, and the error raised for unresolvable modules. Fixes leanprover-community#150
Restore `/--` doc-comments that were written as plain `/-` comments, so the documentation is attached to the declarations again.
Restore `/--` on the two new `#guard_msgs` expectations that were written as plain `/-` comments, so the guards actually check output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #150.
findTransitiveImportsFromSourceresolved each module to a working-directory-relative path viamodToRelFilePathand silently skipped it if no file existed there, so the returnedNameSetcould be an incomplete closure with no indication that anything was missed. This bit in the two situations described in the issue: imports from Lake dependency packages (whose sources live under.lake/packages/...), and invocations from a directory other than the package root — e.g. running it onImportGraph/Imports/FromSource.leanfrom a package root used to return justLean.Elab.ParseImportsFastwith none of that module's own transitive imports.Changes
findModuleSource? (mod : Name) : IO (Option FilePath), which locates a module's source by trying, in order:Lean.getSrcSearchPath) —LEAN_SRC_PATH, which underlake exe/lake envcontains the source directories of every workspace package (including dependencies), plus the toolchain's ownsrc/leandirectory, so core modules resolve too;.oleansearch path (LEAN_PATH);findTransitiveImportsFromSourceuses it for traversal; modules whose source still cannot be found are collected and reported by throwing anIO.userErrorlisting them, instead of being silently treated as leaves. The function signature is unchanged, and callers whose modules all resolve see no behavioural change (Mathlib'slint-styleuse, run from the repo root withrootFilter := some \Mathlib`, is unaffected: every traversed module resolves).rootFilterprunes the traversal itself rather than filtering the final result, as suggested in the issue.ImportGraphTest/FromSource.lean: source-search-path resolution of a toolchain module, closure extending beyond a file's direct imports,nonefor an unresolvable module, and the error raised when traversal hits an unresolvable module.Verification
Locally against the pinned toolchain (
leanprover/lean4:v4.35.0):lake buildpasses,lake exe graph --helpworks, andlake build ImportGraphTestpasses for every target except the pre-existingImportGraphTest.AnotherFileWithTransitiveImports, which exceeds my sandbox's memory limit (OOM-kill, exit 137) identically on unmodifiedmain, so it is unrelated to this change. A probe underlake envconfirmsCli.Basicresolves to.lake/packages/Cli/Cli/Basic.leanandLean.Parser.Moduleto the toolchain'ssrc/lean. Nosorry/admitanywhere.