Lake silently accepts import of built-and-then-removed library

Open
#16,591 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Domain
build-system

Research direction

Start by reading src/lake/Lake/Build/Module.lean, especially fetchImportInfo and its handling of findModules results. Trace how workspace import artifacts, ModuleSetup.importArts, and build-time LEAN_PATH interact for the missing-library case, then check the relevant Lake build tests. Done means rebuilding Foo fails after Bar is removed, while toolchain imports such as Init still work.

Written by the indexing model from the issue text.

Description

bug
Description

Lake detects when a module of an existing library is missing even if its .olean file exists but does not do so if the library itself is missing.

Steps to Reproduce

lakefile.toml:

name = "repro"
[[lean_lib]]
name = "Foo"
[[lean_lib]]
name = "Bar"

Bar.lean:

def bar := 1

Foo.lean:

import Bar
def foo := bar
  1. lake build Foo Bar
  2. Remove the Bar library from lakefile.toml and delete Bar.lean.
  3. Change Foo.lean (for example, add a comment) and run lake build Foo.

Expected behavior: The build fails, because no library provides Bar.

Actual behavior: Foo is rebuilt against the stale .lake/build/lib/lean/Bar.olean and the build succeeds. After rm -rf .lake, the same build fails:

error: Foo.lean:1:0: unknown module prefix 'Bar'

No directory 'Bar' or file 'Bar.olean' in the search path entries:
Versions

Lean (version 4.37.0-pre, x86_64-unknown-linux-gnu, commit a9678c19851a8209310ed748045bae7425d5d60e, Release)

Additional Information

fetchImportInfo in src/lake/Lake/Build/Module.lean skips an import when findModules returns no module, which is also the path taken for toolchain modules such as Init. Lake already passes the artifacts of every workspace import to Lean through ModuleSetup.importArts, so the workspace entries in the build-time LEAN_PATH only serve this fallback. The stale file is also not part of the build trace.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More Build System issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.