Skip to content

fix: warn that filterInit removes Init.* when replacing findImportsFromSource - #179

Open
josaum wants to merge 1 commit into
leanprover-community:mainfrom
josaum:fix/filterinit-deprecation-warning
Open

josaum wants to merge 1 commit into
leanprover-community:mainfrom
josaum:fix/filterinit-deprecation-warning

Conversation

@josaum

@josaum josaum commented Oct 15, 2026

Copy link
Copy Markdown

Fixes #149.

findImportsFromSource filtered only exactly Init, but its deprecation message recommends parseImports' + ModuleHeader.filterInit, which removes the whole Init namespace. Anyone following the deprecation message on a file with an explicit Init.* import (e.g. a prelude file importing Init.Data.Nat.Basic, like Mathlib's Mathlib/Data/Fin/Init.lean) gets a silent change in import analysis.

Of the two options in the issue, this PR implements the second: the broad behavior of filterInit is intended — its docstring has explicitly documented "removes every import in the Init namespace (Init itself and Init.*)" since #154 — so the remaining gap is that the deprecation path did not warn that the replacement is not behavior-preserving.

Changes

  • The @[deprecated] message on findImportsFromSource now warns that the suggested replacement is not behavior-preserving, and shows how to keep Init.* imports: header.imports.filter (·.module != Init)`.
  • The docstrings of filterInit and findImportsFromSource now document the difference explicitly.
  • New regression tests in ImportGraphTest/FilterInit.lean pin down both behaviors:
    • filterInit drops an explicit Init.* import from a prelude file;
    • filterInit drops Init itself, including the duplicated implicit Init imports that module-system files can produce, and the implicit Init of a plain header;
    • filtering on ·.module != Init(the deprecated function's behavior) keeps explicitInit.*` imports.

Verification

Locally, both against the branch's pinned toolchain (leanprover/lean4:v4.35.0) and current main's (v4.36.0-rc1): lake build passes, lake exe graph --help works, and lake build ImportGraphTest passes for every target except the pre-existing ImportGraphTest.AnotherFileWithTransitiveImports, which exceeds my sandbox's memory limit (OOM-kill, exit 137) identically on unmodified main, so it is unrelated to this change. The deprecation warning renders as expected. No sorry/admit anywhere.

…rtsFromSource`

`findImportsFromSource` only removed `Init` itself, but its deprecation
message recommends `parseImports'` + `ModuleHeader.filterInit`, which
removes the whole `Init` namespace. Anyone following the deprecation
message on a file with an explicit `Init.*` import (e.g. a `prelude`
file importing `Init.Data.Nat.Basic`) gets a silent change in import
analysis.

Since the broad filtering is the intended behavior of `filterInit` (its
docstring documents it as removing every import in the `Init`
namespace), this change:

- extends the deprecation message to warn that the replacement is not
  behavior-preserving, and shows how to keep `Init.*` imports with
  `header.imports.filter (·.module != `Init)`;
- documents the difference in the docstrings of `filterInit` and
  `findImportsFromSource`;
- adds regression tests pinning both behaviors (`ImportGraphTest/FilterInit.lean`).

Fixes leanprover-community#149
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.

ModuleHeader.filterInit removes the whole Init namespace, but is documented and recommended as removing Init

1 participant