Minimize imports via lake shake and add import lint/stats#1020
Conversation
9b9a9c1 to
f67eff0
Compare
e3e4344 to
4ed3706
Compare
4ed3706 to
cc03084
Compare
cc03084 to
f72b880
Compare
f72b880 to
21e2490
Compare
8bc777a to
c980740
Compare
cf887ad to
9e18fc7
Compare
## Summary Run `lake shake` on DDM modules to minimize their import graph. This is the DDM-only subset of #1020, split out to reduce merge conflict surface. ## Changes - **DDM import minimization**: Applied `lake shake --fix` across 30 `Strata/DDM/` files, removing unnecessary imports and demoting `public import` to `import` where re-export was not needed by downstream consumers. - **`HashCommands.lean` visibility fixes**: Reorganized `meta section` / `public section` boundaries and removed unnecessary `private` qualifiers to maintain correct elaboration-time visibility after import changes. - **Downstream import fixes**: 13 non-DDM files that lost transitive access to DDM symbols received explicit imports (`Strata.DDM.Format`, `Strata.DDM.Util.Ion`, `Lean.Parser.Types`, `Lean.Parser.Extension`). Two unnecessary `public import Lean.Expr` / `public import Lean.ToExpr` were removed from `Translate.lean`. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
9e18fc7 to
af9c4db
Compare
fb44527 to
3c62e63
Compare
3c62e63 to
2f17390
Compare
MikaelMayer
left a comment
There was a problem hiding this comment.
🤖🔍 Overall this is a solid mechanical import-minimization PR with clear metrics. A few concerns:
-
Internal Std imports: Several files now import
Std.Data.DTreeMap.Internal.Operations,Std.Tactic.BVDecide.Normalize.Prop,Std.Tactic.BVDecide.Normalize.BitVec,Std.Tactic.BVDecide.Normalize.Bool, andStd.Do.Triple.SpecLemmas. These look like internal implementation modules that may not be part of Std's stable API. If they get reorganized upstream, this will break. Consider whether these are truly the minimal necessary imports or if there's a more stable public entry point. -
Emptied aggregator modules:
Imperative.lean,SMT.lean, andLExprType.leanare now emptymodulefiles with no imports. If they're truly dead, they should be deleted rather than left as empty shells. If they're kept for the-- shake: keepaggregator pattern, they need the annotation. -
MetaVerifier.lean workaround: The comment "For some reason shake wants to meta import the following while lake itself only requires imports" suggests shake may be producing incorrect suggestions here. The pattern of duplicating imports as both
meta importandimport -- shake: keepis unusual and warrants investigation. -
Deletion candidates list: The 23
-- noimport:modules inStrata.leanis a significant number of orphaned modules. Is there a plan to either delete them or re-integrate them?
MikaelMayer
left a comment
There was a problem hiding this comment.
🤖🔍 All previous comments appear addressed — reviewer sign-off still needed.
- Internal Std imports (
Std.Data.DTreeMap.Internal.Operations,Std.Do.Triple.SpecLemmas,Std.Tactic.BVDecide.Normalize.Prop) replaced with stable public entry points (Std.Data.DTreeMap,Std.Do,Std.Tactic.BVDecide) - Empty aggregator shells deleted and replaced with proper
-- shake: keep-allaggregator modules at the parent level - Orphaned
-- noimport:modules now properly imported inStrata.lean - MetaVerifier pattern acknowledged as a shake bug to file (acceptable)
public sectionin Boole/Grammar.lean confirmed intentional by author
MikaelMayer
left a comment
There was a problem hiding this comment.
🤖🔍 All previous comments appear addressed — reviewer sign-off still needed.
New commit 046c7bf adds Strata.Languages.Laurel.Grammar import and fixes ReflectTests.lean imports — both look correct.
Minor note: Std.Tactic.BVDecide.Normalize.Prop remains in MetaVerifier.lean (an internal module), but given the acknowledged shake bugs in that file, this is acceptable for now.
MikaelMayer
left a comment
There was a problem hiding this comment.
🤖🔍 All previous inline comments appear addressed:
- Internal Std imports in LTy.lean and Tactics.lean replaced with stable entry points ✅
- Empty aggregator modules (Imperative, SMT, LExprType) properly fixed or deleted ✅
- Orphaned modules now properly imported in Strata.lean ✅
- MetaVerifier shake bug acknowledged ✅
- public section in Boole/Grammar confirmed intentional ✅
One new concern: DDMAxiomsExtraction.lean had a #guard_msgs in #eval examplePgm.commands test removed (commit f381871). This test exists and passes on main. Was this removal intentional, or did the import change break the .commands output? If the output changed due to import minimization, the expected output should be updated rather than the test deleted.
Also minor: Std.Tactic.BVDecide.Normalize.BitVec remains in Verifier.lean (an internal module), while the same pattern was fixed to Std.Tactic.BVDecide in LTy.lean. Not blocking but worth noting for consistency.
Reviewer sign-off still needed.
Summary
Run
lake shaketo minimize the import graph across all 293 Strata modules,reducing average transitive Strata imports by 32% (56 → 38) and total transitive
imports (including Lean/Std) by 40% (1379 → 831). Add CI linting to ensure
Strata.leantransitively imports every module, and add an import statisticsscript for ongoing measurement.
Changes
Import lint driver (
Scripts/CheckImports.lean): Verifies that all.leanfiles under
Strata/are transitively imported byStrata.lean. Registered aslintDriverinlakefile.tomlsolake lintruns it automatically. Supports-- noimport: Strata.Foocomments inStrata.leanto allowlist intentionallyexcluded modules.
Import statistics script (
Scripts/ImportStats.lean): Computes per-moduletransitive import counts (both total and Strata-only), reporting average,
median, min, max, top/bottom lists, and histograms. Run via
lake exe ImportStats.lake shake Strata --fix: Applied shake's suggestions to remove unnecessaryimports across 225 files (net -185 lines). This is the bulk of the change.
Aggregator modules use
-- shake: keep: Pure aggregator modules(
CBMC.lean,GOTO.lean,B3.lean,Dyn.lean,Python.lean,Imperative.lean,Lambda.lean,DDM.lean,LExprType.lean,B3/Verifier.lean) intentionally re-export their submodules and are annotatedwith
-- shake: keepsolake shake --fixwon't strip them.DDM elaboration imports use
-- shake: keep: Files using#dialect,#strata,#strata_gen, and related macros have elaboration-time importdependencies that shake cannot detect. These are annotated with
-- shake: keepto prevent breakage.Renamed aggregator files:
Dyn/Dyn.lean→Dyn.lean,Python/Python.lean→Python.lean,Imperative/Imperative.lean→Imperative.lean— theFoo/Foo.leanpattern is unnecessary now that theseare proper
modulefiles.Orphaned modules added to
Strata.lean: When shake stripped re-exportsfrom real code files (e.g.
ProgramWF.leanno longer re-exportsStatementWF),the orphaned modules were added directly to
Strata.leanto maintain fullcoverage.
Results
By submitting this pull request, I confirm that you can use, modify, copy, and
redistribute this contribution, under the terms of your choice.