A model of the Lake workspace #
This file introduces WorkspaceModel, which carries all of the packages, lean_libs, and modules
of the lake workspace, together with dependency arrows extracted from imports.
We use Bitsets when possible for efficiency. Note that every module lives in a flat Array, as
does every library, regardless of what package or library it comes from. Relationships between
modules, libraries, and packages are stored in each, \using the (unique, global) index of a given
module/library/package as a proxy wherever possible.
The toolchain is recorded as a "pseudo-package" with four libraries (Std, Init, Lean, and
Lake).
Future work #
- We currently ignore
lean_libs which are not default lake targets. We should instead simply record whether a given library is default or not, and handle that in downstream logic. - There is likely room for performance improvement by e.g. not eagerly computing certain data.
- We currently ignore targets that are not
lean_libs entirely. - We could make the indexing system more typesafe. Currently
ModIdx/LibIdx/PkgIdxare justabbrev's forNat.
We build a WorkspaceModel from a WorkspaceSummary using getWorkspaceModel in
ImportGraph.WorkspaceModel.Build. The WorkspaceSummary itself is extracted from an external call to a lake process which loads the workspace, then cached in the build folder.
A Bitset whose bit positions are indices for a WorkspaceModel's indexed datatypes (e.g.
WorkspaceModel.packages). These indices are PkgIdxs.
Instances For
A Bitset whose bit positions are indices for a WorkspaceModel's indexed datatypes (e.g.
WorkspaceModel.libs). These indices are LibIdxs.
Instances For
A Bitset whose bit positions are indices for a WorkspaceModel's indexed datatypes (e.g.
WorkspaceModel.mods). These indices are ModIdxs (not to be confused with ModuleIdxs).
Instances For
The index of a lean_lib in a WorkspaceModel's Bitsets and Arrays. Caution: simply an
abbrev for Nat.
Equations
Instances For
The index of a lake package in a WorkspaceModel's Bitsets and Arrays.
Equations
Instances For
The index of a module in a WorkspaceModel's Bitsets and Arrays.
Note that this is not the same as a ModuleIdx in a given environment. However, both are
presently defs for Nats, so use caution to avoid using one in place of the other.
Equations
Instances For
One package of the model: a Lake package, or the toolchain pseudo-package (last; see the module docstring). All paths are absolute.
- deps : PackageBitset
Dependency arrows: the package's direct dependencies, as resolved by Lake (plus the toolchain pseudo-package).
- libs : LibraryBitset
Workspace relation: the libraries belonging to the package.
- mods : ModuleBitset
Workspace relation: the modules belonging to the package (the union over
libs).
Instances For
Equations
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.
- ImportGraph.WorkspaceModel.instBEqPackage.beq x✝¹ x✝ = false
Instances For
One Lean library of the model, including the pseudo-libraries Init/Std/Lean/Lake
of the toolchain pseudo-package.
- revealedDeps : LibraryBitset
The libraries transitively imported by modules in this library. (May not contain its own index if no module in the library imports something from the library.)
- mods : ModuleBitset
Relational: the enumerated modules contained in the library (found on disk under its
roots/globs). Not necessarily everything that gets built when the library is built. - pkgIdx : PkgIdx
Relational: the package the library belongs to.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
- ImportGraph.WorkspaceModel.instBEqLibrary.beq x✝¹ x✝ = false
Instances For
One module of the model. Modules enter the model by enumerating the source trees of a
chosen set of libraries (see ImportGraph.WorkspaceModel.Build); imports of modules
outside that enumeration remain visible in imports but have no bits anywhere.
- name : Lean.Name
The module's name.
- srcFile : System.FilePath
The module's source filepath (absolute).
- isPrelude : Bool
Whether the module has the
preludekeyword (and hence no implicitInitimports). - transDeps : Shake.Provides
Dependency arrows: Transitive dependencies in the module system.
- transLibDeps : LibraryBitset
Dependency arrows: The transitively reachable libraries this module depends on. Does not necessarily include its own library.
- transPkgDeps : PackageBitset
Dependency arrows: The transitively reachable packages this module depends on. Does not necessarily include its own package.
- prevs : ModuleBitset
Dependency arrows: Every module that must be built before the current module.
- libIdx : LibIdx
Workspace relation: The library this module belongs to.
- pkgIdx : PkgIdx
Workspace relation: the package the module belongs to. Redundant, but we store it here for convenience.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Errors that may be produced when creating the WorkspaceModel.
- readImportsFailure
(mod : Lean.Name)
(modPath : System.FilePath)
(ioError : IO.Error)
: Error
Failed to read the imports from a given file (possibly because we failed to locate the file).
- noLibOfModule
(mod : Lean.Name)
: Error
The given module does not participate in a
lean_lib.
Instances For
Equations
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.
- ImportGraph.WorkspaceModel.instToJsonError.toJson (ImportGraph.WorkspaceModel.Error.noLibOfModule a) = Lean.Json.mkObj [("noLibOfModule", Lean.Json.mkObj [("mod", Lean.toJson a)])]
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
A model of the lake workspace, containing all packages, libraries, and modules and their relationships, as well as dependency arrows between them extracted from parsed source imports.
The packages: Lake packages in Lake's order, with the toolchain "package" last. The index in this array is a
PkgIdxand matches the index used in other packageArrays andPackageBitsets.The libraries of all packages in package order (toolchain libraries last). The index of the library in this array is a
LibIdxand matches its index in other libraryArrays andLibraryBitsets.The modules of all packages and libraries in some topological order, with imported modules coming first and the modules that import them afterwards. The index of a module in this array is a
ModIdxand matches the index in other moduleArrays andModuleBitsets.- idxOfMod : Std.HashMap Lean.Name ModIdx
Module name → module index.
Errors collected when creating the workspace model.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Whether the WorkspaceModel contains the given module.
Equations
- ImportGraph.WorkspaceModel.hasModule mod w = w.idxOfMod.contains mod
Instances For
Lookups #
The index of the toolchain pseudo-package (the last package).
Equations
- m.toolchainPkgIdx = m.packages.size - 1
Instances For
The index of the module named mod, if it is in the model.
Instances For
The index of the package with original name name, if any.
Equations
- m.getPkgIdx? origName = Array.findIdx? (fun (x : ImportGraph.WorkspaceModel.Package) => x.origName == origName) m.packages
Instances For
The index of the library named name, if any. (Library names are not necessarily
unique across packages, so we ask for the package index as well.)
Equations
- m.getLibIdx? pkgIdx libName = Array.findIdx? (fun (lib : ImportGraph.WorkspaceModel.Library) => lib.pkgIdx == pkgIdx && lib.name == libName) m.libs
Instances For
Instances For
Instances For
Instances For
Instances For
Instances For
Lake lifts #
This section contains lifts of basic lake functions (usually of the same name) to WorkspaceModel.
LeanLib.isLocalModule, but lifted to WorkspaceModel.Library.
Equations
- l.isLocalModule mod = ((l.roots.any fun (x : Lean.Name) => x.isPrefixOf mod) || l.globs.any fun (x : Lake.Glob) => Lake.Glob.matches mod x)
Instances For
Equations
- ImportGraph.WorkspaceModel.rawLibIdxOfMod? libs mod = Array.findIdx? (fun (x : ImportGraph.WorkspaceModel.Library) => x.isLocalModule mod) libs
Instances For
Equations
- m.libIdxOfMod? mod = Array.findIdx? (fun (x : ImportGraph.WorkspaceModel.Library) => x.isLocalModule mod) m.libs
Instances For
Like Lake.Module.leanLibFile, but for WorkspaceModel.Module.
Equations
- ImportGraph.WorkspaceModel.Module.leanLibFile m mod ext = Lean.modToFilePath (m.pkgOfMod! mod).leanLibDir mod.name ext
Instances For
Equations
- lib.srcPathOfMod mod = Lean.modToFilePath lib.srcDir mod "lean"
Instances For
Equations
- m.srcPathOfMod? mod = Option.map (fun (x : ImportGraph.LibIdx) => Lean.modToFilePath m.libs[x]!.srcDir mod "lean") (m.libIdxOfMod? mod)
Instances For
Equations
- ImportGraph.WorkspaceModel.Module.srcPath m mod = Lean.modToFilePath (m.libOfMod! mod).srcDir mod.name "lean"