import_diff: comparing different import states #
import_diff compares statistics for two import states in the module system.
Future work #
- More statistics, possibly:
oleansizes,prevsanddepthsspecific to the current package? - Better table rendering
- Ability to inspect which imports they are?
- Tooling for the non-diff case, i.e. to view statistics on the current import state in isolation?
Lean.Parser.Module.import, but with all parsed as a non-reserved symbol.
The syntax kind produced is the same as Lean.Parser.Module.import, so
Lean.Parser.Module.import can be used in antiquotations when matching against this syntax.
This is addressed by lean4#16650, and should
be deprecated in favor of Lean.Parser.Module.import when it lands.
A syntax declaration adds every token of the parsers it mentions to the token table, and
Lean.Parser.Module.import can parse all. Mentioning it in syntax would therefore reserve
all as a keyword in every module downstream, where it is an ordinary identifier
(theorem Commute.all, let all := ...). Parsing it as a non-reserved symbol prevents this.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Removes one of the current imports to this file.
Equations
- ImportGraph.importMinus = Lean.ParserDescr.nodeWithAntiquot "importMinus" `ImportGraph.importMinus (Lean.ParserDescr.nonReservedSymbol "-" false)
Instances For
Adds an import to the current imports of this file.
Equations
- ImportGraph.importPlus = Lean.ParserDescr.nodeWithAntiquot "importPlus" `ImportGraph.importPlus (Lean.ParserDescr.nonReservedSymbol "+" false)
Instances For
An import added to (+) or removed from (-) the imports of the current file to form the
final import state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ImportGraph.diffCurrent = Lean.ParserDescr.nodeWithAntiquot "diffCurrent" `ImportGraph.diffCurrent (Lean.ParserDescr.unary `sepByIndentSemicolon ImportGraph.diffCurrentItem)
Instances For
#import_diff compares two import states with respect to the import hierarchy, and reports
statistics on the difference. (The compared imports do not need to be present in the current file.)
There are two ways to use import_diff:
Relative to the current file's imports, using + and -:
#import_diff
+public import Foo
-meta import Bar.Baz
+import Bar
This will take the current file's imports as the initial import state, and diff against the final import state constructed by adding in the + imports and removing the - imports.
Absolute, using to and optionally from. The from imports are the initial import state, and the to imports the final one. If from is omitted, the current file's imports are used as the initial import state.
#import_diff
from
public import Foo
meta import Bar
import Baz
to
public import Foo
meta import Bar.Baz
import Bar
import Baz
Note: in both cases, imports may be separated by ; instead of newlines, if desired.
The output is a table of the form
Δ + - ∩
modules imported • • • •
public • • • •
private • • • •
public meta • • • •
private meta • • • •
previous modules • • • •
ir loaded • • • •
Δ new old
build depth • • •
(Changes due to import all are shown only if nonzero.)
Columns:
Δ: the net changes (collapsing+and-)+: the size of the final state not present in the initial state-: the size of the initial state not present in the final state∩: the size of the overlap between the initial and final states
Rows:
modules imported: The comparison ofmodules importedis module-system aware, and only includes modules that actually make it to the environment (i.e. whose*.oleans are actually loaded).public/private/...: The count of changes to phase and visibility. Note that this might exceed modules imported, as the availability of a module might change between the initial and final state while it is imported in both. E.g., a module may have been upgraded from a private import to a public import, or a module might now be imported as both meta and non-meta, while its imported status remained unchanged.previous modulescompares the total number of prior modules in the build graph, ignoring module system annotations.ir loaded: compares the number of modules whose IR is loaded.metaimports cause more IR to be loaded, as the IR for every module above them is loaded, ignoring module system annotations. (Note: this is only accurate forlake build, as the server loads much more IR.)build depth: compares the old and new depth of the build graph (counting the current module), ignoring module system annotations.
Notes #
- Lean prepends
public import Initandpublic meta import Initto each file behind the scenes (assuming you have not writtenprelude, which suppresses this behavior). However, the shared column (∩) deliberately ignores all contributions from theseInitimports to provide a more useful sense of what two import states have in common. (build depthis the only statistic which does include contributions fromInit.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
An Import with a ModIdx in some WorkspaceModel.
Note that as a matter of implementation this extends NeedsKind (which provides a proof of
well-formedness of the underlying VisibilityKind) instead of Import (but provides exactly the
same data), and may be converted to and from an Import via .toImport and .ofImport.
- module : Lean.Name
The
Nameof the imported module. - modIdx : ModIdx
The module index of the import in an ambient
WorkspaceModel.
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bundle an Import and its module index in an ambient WorkspaceModel together in an
ImportWithIdx.
Equations
- ImportGraph.WorkspaceModel.ImportWithIdx.ofImport imp modIdx = have __NeedsKind := ImportGraph.Shake.NeedsKind.ofImport imp; { kind := __NeedsKind, module := imp.module, modIdx := modIdx }
Instances For
Instances For
Bundle an Import together with its module index in the given WorkspaceModel, if it can be
found.
Equations
Instances For
Converts syntax for an import into a NeedsKind, Name, and ModIdx in the given workspace
model representing that import, throwing if the module name cannot be found.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Various transitions between two import states.
- directImportsTransition : Diff.Transition (Array WorkspaceModel.ImportWithIdx)
The initial and final direct imports being compared.
- importedTransition : Diff.Transition ModuleBitset
The initial and final sets of all modules imported (at any phase and visibility).
- providesTransition : Diff.Transition Shake.Provides
The initial and final transitive dependencies (module-system aware).
- prevsTransition : Diff.Transition ModuleBitset
The initial and final modules prior to the importing module (ignoring module system annotations).
- irLoadedTransition : Diff.Transition ModuleBitset
The initial and final sets of modules whose IR is loaded. (Note that
metaimport annotations cause IR to be loaded from all modules prior, ignoring module system annotations.) This is only accurate forlake build, as the server loads extra IR. - depthTransition : Diff.Transition Nat
The initial and final depths of the build graph.
Instances For
A Venn diagram of what was added, lost, and shared between the initial and final import
states. Derived from ImportTransition, but also removes the
public import Init / public meta import Init implicitly added to every non-prelude file from the
shared field (and thus requires that information from the WorkspaceModel).
- importedVenn : Diff.Venn ModuleBitset
Venn diagram comparing the initial and final full sets of imported modules. Drops the imports provided by the implicit init import (even if dragged in by other imports).
- providesVenn : Diff.Venn Shake.Provides
Venn diagram comparing the initial and final transitive dependencies (module-system aware). Drops the transitive dependencies provided by the implicit
Initimport. - prevsVenn : Diff.Venn ModuleBitset
Venn diagram comparing the initial and final prior modules, ignoring module system annotations. Drops the modules provided by the implicit
Initimport. - irLoadedVenn : Diff.Venn ModuleBitset
Venn diagram comparing the initial and final loaded IR. Note that
metaannotations load IR for every module prior to them, ignoring module system annotations. Drops the IR provided by the implicitInitimport.
Instances For
Captures statistics on the initial and final states (.transitions) as well as derived
information on what was added and lost.
Instances For
Given direct imports in ImportWithIdxs, compute their transitive dependencies (what they
provide to the importing module).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given direct imports in ImportWithIdxs, compute all modules prior to the module importing
them. Includes Init by default.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given direct imports in ImportWithIdxs, compute the depth of the build graph of the importing
module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a WorkspaceModel and a transition between an initial and final sets of direct
imports, compute the transitions and Venn diagrams in ImportDiff.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Renders an ImportVenn as a table.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Renders an ImportDiff as a table. This is the table for the ImportVenn part plus the build
depth transition reported below. Other transitions are not reported.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Non-module #import_diff #
#import_diff foo bar ... computes the new transitive imports that are added to a given file when
modules foo, bar, ... are added to the set of imports of the file. More precisely, it computes the
import diff between when foo, bar, ... are added to the imports and when foo, bar, ... are removed
from the imports.
Note: the command also works when some of the modules passed as arguments are already present in the file's imports.
Equations
- One or more equations did not get rendered due to their size.