Documentation

ImportGraph.WorkspaceModel.Model

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 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.

@[reducible, inline]

A Bitset whose bit positions are indices for a WorkspaceModel's indexed datatypes (e.g. WorkspaceModel.packages). These indices are PkgIdxs.

Instances For
    @[reducible, inline]

    A Bitset whose bit positions are indices for a WorkspaceModel's indexed datatypes (e.g. WorkspaceModel.libs). These indices are LibIdxs.

    Instances For
      @[reducible, inline]

      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
        @[reducible, inline]

        The index of a lean_lib in a WorkspaceModel's Bitsets and Arrays. Caution: simply an abbrev for Nat.

        Instances For
          @[reducible, inline]

          The index of a lake package in a WorkspaceModel's Bitsets and Arrays.

          Instances For
            @[reducible, inline]

            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.

            Instances For

              One package of the model: a Lake package, or the toolchain pseudo-package (last; see the module docstring). All paths are absolute.

              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.)

                • 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

                  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 prelude keyword (and hence no implicit Init imports).

                  • 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.

                  • depthsPerLib : Array Nat

                    Dependency statistic: Per library, the longest chain of modules from that library that must be built before building this modules, including this module. 0 indicates non-dependence on the library. The Array index is the library's LibIdx.

                  • depthsPerPkg : Array Nat

                    Dependency statistic: Per package, the longest chain of modules from a given package that must be built before building this modules, including this module. 0 indicates non-dependence on the package. The Array index is the package's PkgIdx.

                  • 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

                    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

                      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.

                      Instances For
                        @[inline]

                        Whether errors have been produced when creating the WorkspaceModel.

                        Instances For
                          @[inline]

                          Whether the WorkspaceModel contains the given module.

                          Instances For

                            Lookups #

                            The index of the toolchain pseudo-package (the last package).

                            Instances For
                              @[inline]

                              The index of the module named mod, if it is in the model.

                              Instances For
                                @[inline]

                                The index of the package with original name name, if any.

                                Instances For
                                  @[inline]

                                  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.)

                                  Instances For
                                    @[inline]
                                    Instances For
                                      @[inline]
                                      Instances For
                                        @[inline]
                                        Instances For
                                          @[inline]
                                          Instances For
                                            @[inline]
                                            Instances For

                                              Lake lifts #

                                              This section contains lifts of basic lake functions (usually of the same name) to WorkspaceModel.