Documentation

Lean.Environment

Note [Environment Branches] #

The kernel environment type Lean.Kernel.Environment enforces a linear order on the addition of declarations: addDeclCore takes an environment and returns a new one, assuming type checking succeeded. On the other hand, the metaprogramming-level Lean.Environment wrapper must allow for branching environment transformations so that multiple declarations can be elaborated concurrently while still being able to access information about preceding declarations that have also been branched out as soon as they are available.

The basic function to introduce such branches is addConstAsync, which takes an environment and returns a structure containing two environments: one for the "main" branch that can be used in further branching and eventually contains all the declarations of the file and one for the "async" branch that can be used concurrently to the main branch to elaborate and add the declaration for which the branch was introduced. Branches are "joined" back together implicitly via the kernel environment, which as mentioned cannot be changed concurrently: when the main branch first tries to access it, evaluation is blocked until the kernel environment on the async branch is complete. Thus adding two declarations A and B concurrently can be visualized like this:

o addConstAsync A
|\
| \
|  \
o addConstAsync B
|\   \
| \   o elaborate A
|  \  |
|   o elaborate B
|   | |
|   | o addDeclCore A
|   |/
|   o addDeclCore B
|  /
| /
|/
o .olean serialization calls Environment.toKernelEnv

While each edge represents a Lean.Environment that has its own view of the state of the module, the kernel environment really lives only in the right-most path, with all other paths merely holding an unfulfilled Task representing it and where forcing that task leads to the back-edges joining paths back together.

Opaque environment extension state.

Equations
Instances For
    @[reducible, inline]
    Equations
    Instances For
      @[instance_reducible]
      Equations
      @[instance_reducible]
      instance Lean.instGetElemArrayModuleIdxLtNatToNatSize {α : Type u_1} :
      GetElem (Array α) ModuleIdx α fun (a : Array α) (i : ModuleIdx) => i.toNat < a.size
      Equations
      @[instance_reducible]
      instance Lean.instGetElem?ArrayModuleIdxLtNatToNatSize {α : Type u_1} :
      GetElem? (Array α) ModuleIdx α fun (a : Array α) (i : ModuleIdx) => i.toNat < a.size
      Equations
      • One or more equations did not get rendered due to their size.
      @[reducible, inline]
      Equations
      Instances For

        Opaque persistent environment extension entry.

        Content of a .olean file. We use compact.cpp to generate the image of this object in disk.

        Instances For

          Import including information resulting from processing of the entire import DAG.

          Instances For

            Environment fields that are not used often.

            • trustLevel : UInt32

              The trust level used by the kernel. For example, the kernel assumes imported constants are type correct when the trust level is greater than zero.

            • mainModule : Name

              Name of the module being compiled.

            • isModule : Bool

              Participating in the module system?

            • imports : Array Import

              Direct imports

            • Compacted regions for all imported modules. Objects in compacted memory regions do no require any memory management.

            • Direct and transitive imports. Modules are given with their effective import modifiers, not their original ones. Each module is listed at most once. The index of a module in the array equals the ModuleIdx for the same module.

            • moduleNames : Array Name

              Name of all imported modules (directly and indirectly). The index of a module name in the array equals the ModuleIdx for the same module.

            • importAllModules : Array EffectiveImport

              Subset of modules for which importAll is true. This is assumed to be a much smaller set so we precompute it instead of iterating over all of modules multiple times. However, note that in a non-module file, this is identical to modules.

            • moduleData : Array ModuleData

              Module data for all imported modules.

            Instances For
              • unfoldCounter : PHashMap Name Nat

                Number of times each declaration has been unfolded by the kernel.

              • enabled : Bool

                If enabled = true, kernel records declarations that have been unfolded.

              Instances For

                An environment stores declarations provided by the user. The kernel currently supports different kinds of declarations such as definitions, theorems, and inductive families. Each has a unique identifier (i.e., Name), and can be parameterized by a sequence of universe parameters. A constant in Lean is just a reference to a ConstantInfo object. The main task of the kernel is to type check these declarations and refuse type incorrect ones. The kernel does not allow declarations containing metavariables and/or free variables to be added to an environment. Environments are never destructively updated.

                The environment also contains a collection of extensions. For example, the simp theorems declared by users are stored in an environment extension. Users can declare new extensions using meta-programming.

                • constants : ConstMap

                  Mapping from constant name to ConstantInfo. It contains all constants (definitions, theorems, axioms, etc) that have been already type checked by the kernel.

                • quotInit : Bool

                  quotInit = true if the command init_quot has already been executed for the environment, and Quot declarations have been added to the environment. When the flag is set, the type checker can assume that the Quot declarations in the environment have indeed been added by the kernel and not by the user.

                • diagnostics : Diagnostics

                  Diagnostic information collected during kernel execution.

                  Remark: We store kernel diagnostic information in an environment field to simplify the interface with the kernel implemented in C/C++. Thus, we can only track declarations in methods, such as addDecl, which return a new environment. Kernel.isDefEq and Kernel.whnf do not update the statistics. We claim this is ok since these methods are mainly used for debugging.

                • const2ModIdx : Std.HashMap Name ModuleIdx

                  Mapping from constant name to module (index) where constant has been declared. Recall that a Lean file has a header where previously compiled modules can be imported. Each imported module has a unique ModuleIdx. Many extensions use the ModuleIdx to efficiently retrieve information stored in imported modules.

                  Remark: this mapping also contains auxiliary constants, created by the code generator, that are not in the field constants. These auxiliary constants are invisible to the Lean kernel and elaborator. Only the code generator uses them.

                • extGens : Array Nat
                • trackedGen : Nat

                  Counter bumped by every modification of a generation-tracked extension (PersistentEnvExtensionDescrCore.trackGen): while it is unchanged, no such extension has changed. Like the generations, it rolls back with the environment, so after a rollback a different modification can reach a value seen before. Results stored in the environment roll back with it and stay sound. As the counter only grows along one environment branch, a result stored outside the environment stays sound across a rollback only if it was stamped with at most the restored value; later ones must be dropped.

                • The header contains additional information that is set at import time.

                Instances For

                  Exceptions that can be raised by the kernel when type checking new declarations.

                  Instances For
                    @[export lean_environment_find]
                    Equations
                    Instances For
                      @[extern lean_add_decl]
                      opaque Lean.Kernel.Environment.addDeclCore (env : Environment) (maxHeartbeats maxRecDepth : USize) (decl : Declaration) (cancelTk? : Option IO.CancelToken) :

                      Type check given declaration and add it to the environment

                      @[extern lean_add_decl_without_checking]

                      Add declaration to kernel without type checking it.

                      WARNING This function is meant for temporarily working around kernel performance issues. It compromises soundness because, for example, a buggy tactic may produce an invalid proof, and the kernel will not catch it if the new option is set to true.

                      Enables/disables kernel diagnostics.

                      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
                          @[export lean_kernel_record_unfold]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[export lean_kernel_get_diag]
                            Equations
                            Instances For
                              @[export lean_kernel_set_diag]
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                Instances For
                                  Equations
                                  Instances For

                                    ConstantInfo variant that allows for asynchronous filling of components via tasks.

                                    • name : Name

                                      The declaration name, known immediately.

                                    • The kind of the constant, known immediately.

                                    • The "signature" including level params and type, potentially filled asynchronously.

                                    • constInfo : Task ConstantInfo

                                      The final, complete constant info, potentially filled asynchronously.

                                    Instances For

                                      Accessibility levels of declarations in Lean.Environment.

                                      • private : Visibility

                                        Information private to the module.

                                      • public : Visibility

                                        Information to be exported to other modules.

                                      Instances For

                                        The declarations whose declaration-keyed state changed, as recorded in Environment.declChangeLog. A list with the newest entry first, as the log only grows at one end and validation only reads the entries logged since some position: appending then never copies the log, even while older environments share it.

                                        • size : Nat

                                          Number of entries, which positions in the log refer to.

                                        • entries : List Name

                                          The logged declarations, newest first.

                                        Instances For

                                          Appends declName to the log.

                                          Equations
                                          Instances For
                                            def Lean.DeclChangeLog.allSince (log : DeclChangeLog) (fromPos : Nat) (p : Name → Bool) :

                                            Returns whether p holds for all entries logged since position fromPos.

                                            Equations
                                            Instances For

                                              Elaboration-specific extension of Kernel.Environment that adds tracking of asynchronously elaborated declarations.

                                              • serverBaseExts : Array Lean.EnvExtensionState
                                              • Kernel environment task that is fulfilled when all asynchronously elaborated declarations are finished, containing the resulting environment. Also collects the environment extension state of all environment branches that contributed contained declarations.

                                              • asyncConstsMap : VisibilityMap AsyncConsts
                                              • asyncCtx? : Option AsyncContext
                                              • importRealizationCtx? : Option RealizationContext
                                              • localRealizationCtxMap : Lean.NameMap RealizationContext
                                              • allRealizations : Task (Lean.NameMap AsyncConst)
                                              • isExporting : Bool

                                                Indicates whether the environment is being used in an exported context, i.e. whether it should provide access to only the data to be imported by other modules participating in the module system. Apart from controlling access, some operations such as mkAuxDeclName may also change their output based on this flag.

                                                By default, isExporting is set to false when command elaborators are invoked such that they have access to the full local environment. Use with(out)Exporting to modify based on context. For example, elabDeclaration sets it based on (← getScope).isPublic on the top level, then elabMutualDef may switch from public to private when e.g. entering the proof of a theorem.

                                              • isRecordingDeps : Bool

                                                Mirrors Lean.Core.Context.isRecordingDeps for pure extension reads, which cannot see the context: while set, a generation-tracked extension must be read with (genRecorded := true), by which the caller asserts that it recorded the generation (Lean.recordExtGenAccess), and any other extension must have EnvExtension.logWrites; other reads panic.

                                              • synthCacheRaw? : Option NonScalar
                                              • declChangeLog : DeclChangeLog

                                                Log of declaration-keyed state changes some recording computation could have observed (logDeclChange): a write about a declaration is appended when the declaration was added before the latest recording started (recordingConstGen), as writes about younger declarations cannot invalidate a recorded result. A recorded result is validated against the entries appended since it was recorded (checkDeclChangeLog); reducibility changes are the most common source.

                                              • recordingConstGen : Nat

                                                constGen when a recording computation last started on this branch, or a later value carried over a rollback (raiseRecordingConstGen); see declChangeLog.

                                              • constAddedGens : PHashMap Name Nat

                                                For each constant added on this environment branch, the constGen at which it became observable here (synchronous addDecl, asynchronous registration, merged realizations); see constAddedGen.

                                              • constGen : Nat

                                                Counter bumped by every constant added on this environment branch: a consumer capturing it at some point knows that a constant with a larger constAddedGen did not exist then.

                                              Instances For

                                                Counter bumped by every modification of a generation-tracked extension (PersistentEnvExtensionDescrCore.trackGen): while it is unchanged, no such extension has changed. Like the generations, it rolls back with the environment, so after a rollback a different modification can reach a value seen before. Results stored in the environment roll back with it and stay sound. As the counter only grows along one environment branch, a result stored outside the environment stays sound across a rollback only if it was stamped with at most the restored value; later ones must be dropped.

                                                Equations
                                                Instances For
                                                  Equations
                                                  Instances For

                                                    Constructs an elaboration environment from a given kernel environment's constants. All constants are accessible in both the private and public scope. All other data is empty.

                                                    Equations
                                                    Instances For
                                                      @[export lean_elab_environment_to_kernel_env]
                                                      Equations
                                                      Instances For

                                                        Updates env.isExporting. Ignored if env.header.isModule is false.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          Registers n as added now on this environment branch, unless it already was: a constant announced by addConstAsync keeps the generation of its announcement when its asynchronous branch adds it.

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            The constGen at which n was added on this branch. Constants not registered, in particular imported ones, have generation 0, i.e. are treated as older than anything a consumer captured. For caching that is a conservative approximation as lower generation numbers lead to more cache misses.

                                                            Equations
                                                            Instances For

                                                              Records a change of the declaration-keyed state about declName in Environment.declChangeLog, if some recording computation could have observed the previous state. Callers invoke this only for writes that change observable state.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                def Lean.Environment.checkDeclChangeLog (env : Environment) (fromPos baseConstGen : Nat) :

                                                                Returns whether a result recorded at log position fromPos when constGen was baseConstGen is still valid: every change logged since must be about a declaration added after that point.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For

                                                                  Notes that a recording computation starts on this branch; see Environment.declChangeLog.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For

                                                                    Raises recordingConstGen to at least gen. A rollback of the environment restores an earlier recording start, while results recorded since may survive it; carrying the later start over keeps changes to the declarations they could have observed logged.

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      Updates Environment.isRecordingDeps.

                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For

                                                                        The declaration prefix to which the environment is restricted to, if any.

                                                                        Equations
                                                                        Instances For

                                                                          Returns the environment just after importing. none if finalizeImport has never been called on it.

                                                                          Equations
                                                                          Instances For

                                                                            Forgets about the asynchronous context restrictions. Used only for withoutModifyingEnv.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For
                                                                              def Lean.Environment.addDeclCore (env : Environment) (maxHeartbeats maxRecDepth : USize) (decl : Declaration) (cancelTk? : Option IO.CancelToken) (doCheck : Bool := true) :

                                                                              Adds given declaration to the environment, type checking it unless doCheck is false.

                                                                              This is a plumbing function for the implementation of Lean.addDecl, most users should use it instead.

                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For

                                                                                Mapping from constant name to ConstantInfo. It contains all constants (definitions, theorems, axioms, etc) that have been already type checked by the kernel.

                                                                                Equations
                                                                                Instances For

                                                                                  Mapping from constant name to module (index) where constant has been declared. Recall that a Lean file has a header where previously compiled modules can be imported. Each imported module has a unique ModuleIdx. Many extensions use the ModuleIdx to efficiently retrieve information stored in imported modules.

                                                                                  Remark: this mapping also contains auxiliary constants, created by the code generator, that are not in the field constants. These auxiliary constants are invisible to the Lean kernel and elaborator. Only the code generator uses them.

                                                                                  Equations
                                                                                  Instances For

                                                                                    Looks up the given declaration name in the environment, avoiding forcing any in-progress elaboration tasks unless necessary. This can usually be done efficiently because addConstAsync ensures that declarations added in an environment branch have that branch's declaration name as a prefix, so we know exactly what tasks to wait for to find a declaration. However, this is not true for declarations from realizeConst, which are not restricted to the current prefix, and reference to which may escape the branch(es) they have been realized on such as when looking into the type Expr of a declaration found on another branch. Thus when we cannot find the declaration using the fast prefix-based lookup, we fall back to waiting for and looking at the realizations from all branches. To avoid this expensive search for realizations from other branches, skipRealize can be set to ensure negative lookups are as fast as positive ones.

                                                                                    Use findTask instead if any blocking should be avoided.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For

                                                                                      Like findAsync? but returns a task instead of resorting to blocking.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For

                                                                                        Like findAsync but blocks on everything but the constant's body (if any), which is not accessible through the result.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For
                                                                                          def Lean.Environment.find? (env : Environment) (n : Name) (skipRealize : Bool := false) :

                                                                                          Like findAsync?, but blocks until the constant's info is fully available.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For

                                                                                            Checks if, in the public scope (Environment.isExporting), the given name refers to a definition with a visible body, i.e. ConstantInfo.hasValue. Recall that outside the module system, this is any definition.

                                                                                            Equations
                                                                                            Instances For
                                                                                              Equations
                                                                                              Instances For

                                                                                                Allows realizeConst calls for the given declaration in all derived environment branches. Realizations will run using the given environment and options to ensure deterministic results. Note that while we check that the function isn't called before the declaration is actually added to the environment, we cannot automatically check that it isn't otherwise called too early in the sense that helper declarations and environment extension state that may be relevant to realizations may not have been added yet. We do check that we are not calling it from a different branch than c was added on, which would be definitely too late. Thus, this function should generally be called in elaborators calling addDecl (when that declaration is a plausible target for realization) at the latest possible point, i.e. at the very end of the elaborator or just before a first realization may be triggered if any.

                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                Instances For

                                                                                                  Returns debug output about the asynchronous state of the environment.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For

                                                                                                    Returns debug output about the synchronous state of the environment.

                                                                                                    Equations
                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                    Instances For

                                                                                                      Result of Lean.Environment.promiseChecked.

                                                                                                      Instances For

                                                                                                        Starts an asynchronous modification of the kernel environment. The environment is split into a "main" branch that will block on access to the kernel environment until PromiseCheckedResult.commitChecked has been called on the "async" environment branch.

                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        Instances For

                                                                                                          Commits the kernel environment of the given environment back to the main branch.

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For

                                                                                                            Result of Lean.Environment.addConstAsync which is necessary to complete the asynchronous addition.

                                                                                                            Instances For
                                                                                                              def Lean.Environment.addConstAsync (env : Environment) (constName : Name) (kind : ConstantKind) (exportedKind? : Option ConstantKind := some kind) (reportExts checkMayContain : Bool := true) :

                                                                                                              Starts the asynchronous addition of a constant to the environment. The environment is split into a "main" branch that holds a reference to the constant to be added but will block on access until the corresponding information has been added on the "async" environment branch and committed there; see the respective fields of AddConstAsyncResult as well as the [Environment Branches] note for more information.

                                                                                                              exportedKind? must be passed if the eventual kind of the constant in the exported constant map will differ from that of the private version. It must be none if the constant will not be exported.

                                                                                                              Equations
                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                              Instances For

                                                                                                                Commits the signature of the constant to the main environment branch. The declaration name must match the name originally given to addConstAsync. It is optional to call this function but can help in unblocking corresponding accesses to the constant on the main branch.

                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                Instances For

                                                                                                                  Commits the full constant info as well as the current environment extension state and set of nested asynchronous constants to the main environment branch. If info? is none, it is taken from the given environment. The declaration name and kind must match the original values given to addConstAsync. The signature must match the previous commitSignature call, if any.

                                                                                                                  Equations
                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                  Instances For

                                                                                                                    Assuming Lean.addDecl has been run for the constant to be added on the async environment branch, commits the full constant info from that call to the main environment, (asynchronously) waits for the final kernel environment resulting from the addDecl call, and commits it to the main branch as well, unblocking kernel additions there. All commitConst preconditions apply.

                                                                                                                    Equations
                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                    Instances For
                                                                                                                      def Lean.Environment.contains (env : Environment) (n : Name) (skipRealize : Bool := true) :

                                                                                                                      Checks whether findAsync? would return a result.

                                                                                                                      NOTE: Unlike findAsync, this function defaults skipRealize to true to avoid unnecessary blocking on realizations, which should always be brought into scope by running realizeConst, which does its own, optimized existence check.

                                                                                                                      Equations
                                                                                                                      Instances For

                                                                                                                        Checks whether the given declaration is known on the current branch, in which case findAsync? will not block.

                                                                                                                        Equations
                                                                                                                        Instances For

                                                                                                                          Returns whether realizeConst forConst callbacks can access c in the private scope, i.e. whether c is part of the realization environment of forConst. Returns false if realizations for forConst are not enabled on the current environment branch. Like contains, may block on asynchronous elaboration.

                                                                                                                          Use this to choose forConst when a realization depends on two (or more) constants: a correct target is one whose realization environment contains all others.

                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For

                                                                                                                            Returns the constants added in the current module, in elaboration tree pre-order: the top-level declarations in elaboration order, each followed by its asynchronous sub-declarations, recursively. The recursive part can optionally be skipped for theorems for when their sub-decls are unimportant and visiting them would only add latency by having to wait for proof elaboration to finish.

                                                                                                                            Unlike iterating env.constants.map₂, this does not block on env.checked, i.e. kernel checking.

                                                                                                                            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
                                                                                                                                Equations
                                                                                                                                Instances For
                                                                                                                                  Equations
                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                  Instances For
                                                                                                                                    Equations
                                                                                                                                    Instances For
                                                                                                                                      Equations
                                                                                                                                      Instances For

                                                                                                                                        Branch specification for asynchronous environment extension access.

                                                                                                                                        Note: For declarations not created via addConstAsync, including those created via realizeConst, the two specifiers are equivalent.

                                                                                                                                        Instances For

                                                                                                                                          Async access mode for environment extensions used in EnvExtension.get/set/modifyState. When modified in concurrent contexts, extensions may need to switch to a different mode than the default mainOnly, which will panic in such cases. The access mode is set at environment extension registration time but can be overridden when calling the mentioned functions in order to weaken it for specific accesses.

                                                                                                                                          In all modes, the state stored into the .olean file for persistent environment extensions is the result of getState (asyncMode := .sync) called on the main environment branch at the end of the file, i.e. it encompasses all modifications on all branches except for local modifications for which only the main branch is included.

                                                                                                                                          • sync : AsyncMode

                                                                                                                                            Safest access mode, writes and reads the extension state to/from the full checked environment. This mode ensures the observed state is identical independently of whether or how parallel elaboration is used but getState will block on all prior environment branches by waiting for checked. setState and modifyState do not block.

                                                                                                                                            While a safe fallback for when mainOnly is not sufficient, any extension that reasonably could be used in parallel elaboration contexts should opt for a weaker mode to avoid blocking unless there is no way to access the correct state without waiting for all prior environment branches, in which case its data management should be restructured if at all possible.

                                                                                                                                          • local : AsyncMode

                                                                                                                                            Accesses only the state of the current environment branch. Modifications on other branches are not visible and are ultimately discarded except for the main branch. Provides the fastest accessors, will never block.

                                                                                                                                            This mode is particularly suitable for extensions where state does not escape from lexical scopes even without parallelism, e.g. ScopedEnvExtensions when setting local entries.

                                                                                                                                          • mainOnly : AsyncMode

                                                                                                                                            Default access mode. Like local but panics when trying to modify the state on anything but the main environment branch. For extensions that fulfill this requirement, all modes functionally coincide with local but this is the safest and most efficient choice in that case, preventing accidental misuse.

                                                                                                                                            This mode is suitable for extensions that are modified only at the command elaboration level before any environment forks in the command, and in particular for extensions that are modified only at the very beginning of the file.

                                                                                                                                          • async (branch : AsyncBranch) : AsyncMode

                                                                                                                                            Accumulates modifications in the checked environment like sync, but get/modify/setState will panic instead of blocking unless their asyncDecl parameter is specified, which will access the state of the environment branch corresponding to the passed declaration name, if any; see AsyncBranch for a description of the specific state accessed. In other words, at most the environment branch corresponding to that declaration will be blocked on instead of all prior branches. The local state can still be accessed by calling getState with mode local explicitly.

                                                                                                                                            This mode is suitable for extensions with map-like state where the key uniquely identifies the top-level declaration where it could have been set, e.g. because the key on modification is always the surrounding declaration's name. In particular, this mode is closest to how the environment's own constant map works which provides findAsync? for block-avoiding access.

                                                                                                                                          Instances For
                                                                                                                                            @[reducible, inline]
                                                                                                                                            abbrev Lean.ReplayFn (σ : Type) :
                                                                                                                                            Equations
                                                                                                                                            Instances For
                                                                                                                                              @[implemented_by _private.Lean.Environment.0.Lean.takeNewEntriesRevUnsafe]
                                                                                                                                              def Lean.takeNewEntriesRev {α : Type u_1} (newEntries oldEntries : List α) :
                                                                                                                                              List α

                                                                                                                                              Returns the entries newEntries has in front of its suffix oldEntries, oldest first.

                                                                                                                                              This is intended for ReplayFn implementations of extensions that record entries in a list, where newEntries is oldEntries with the entries added in the meantime consed on. The suffix is found by pointer equality, so the cost is proportional to the number of new entries rather than to the number of all entries added in the current file; the latter matters because every realization replays every such extension. If oldEntries is not a physical suffix of newEntries, the leading newEntries.length - oldEntries.length entries are returned instead.

                                                                                                                                              Equations
                                                                                                                                              Instances For
                                                                                                                                                def Lean.takeNewEntries {α : Type u_1} (newEntries oldEntries : List α) :
                                                                                                                                                List α

                                                                                                                                                Like takeNewEntriesRev, but returns the new entries in their order in newEntries.

                                                                                                                                                Equations
                                                                                                                                                Instances For
                                                                                                                                                  structure Lean.EnvExtension (σ : Type) :

                                                                                                                                                  Environment extension, can only be generated by registerEnvExtension that allocates a unique index for this extension into each environment's extension state's array.

                                                                                                                                                  • idx : Nat
                                                                                                                                                  • mkInitial : IO σ
                                                                                                                                                  • asyncMode : AsyncMode
                                                                                                                                                  • replay? : Option (ReplayFn σ)

                                                                                                                                                    Optional function that, given state before and after realization and newly added constants, replays this change onto a state from another (derived) environment. This function is used only when making changes to an extension inside a realizeConst call, in which case it must be present.

                                                                                                                                                  • name : Name

                                                                                                                                                    Name for diagnostics; set automatically for persistent extensions.

                                                                                                                                                  • genIdx? : Option Nat

                                                                                                                                                    For a generation-tracked extension (PersistentEnvExtensionDescrCore.trackGen), the index of its generation in Kernel.Environment.extGens.

                                                                                                                                                  • logWrites : Bool

                                                                                                                                                    Whether writes are logged by declaration in Environment.declChangeLog, so that type class resolution may read the extension without recording the read: every write some recording computation could have observed is appended to the log. Hence each write must name its declaration or be marked unlogged; see EnvExtension.modifyState.

                                                                                                                                                  Instances For

                                                                                                                                                    Whether ext is generation-tracked; see PersistentEnvExtensionDescrCore.trackGen.

                                                                                                                                                    Equations
                                                                                                                                                    Instances For

                                                                                                                                                      User-defined environment extensions are declared using the initialize command. This command is just syntax sugar for the init attribute. When we import lean modules, the vector stored at envExtensionsRef may increase in size because of user-defined environment extensions. When this happens, we must adjust the size of the env.extensions. This method is invoked when processing imports.

                                                                                                                                                      Equations
                                                                                                                                                      Instances For
                                                                                                                                                        def Lean.EnvExtension.asyncMayModify {σ : Type} (ext : EnvExtension σ) (env : Environment) (asyncDecl : Name) (asyncMode : AsyncMode := ext.asyncMode) :

                                                                                                                                                        Checks whether modifyState (asyncDecl := declName) may be called on an async environment extension; see AsyncMode.async for details.

                                                                                                                                                        Equations
                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                        Instances For

                                                                                                                                                          How a write to an extension is logged; see EnvExtension.modifyState.

                                                                                                                                                          Instances For
                                                                                                                                                            @[inline]
                                                                                                                                                            def Lean.EnvExtension.modifyState {σ : Type} (ext : EnvExtension σ) (env : Environment) (f : σ → σ) (asyncMode : AsyncMode := ext.asyncMode) (asyncDecl : Name := Name.anonymous) (bumpGen : Bool := true) (log : WriteLog := WriteLog.missing) :

                                                                                                                                                            Applies the given function to the extension state. See AsyncMode for details on how modifications from different environment branches are reconciled.

                                                                                                                                                            For generation-tracked extensions the modification bumps the generation if bumpGen is set; see PersistentEnvExtensionDescrCore.trackGen. For an extension with logWrites, log must name the declaration the write is about, which logs it, or state .unlogged; otherwise the write panics.

                                                                                                                                                            Note that in modes sync and async, f will be called twice, on the local and on the checked state.

                                                                                                                                                            Equations
                                                                                                                                                            Instances For
                                                                                                                                                              @[inline]
                                                                                                                                                              def Lean.EnvExtension.setState {σ : Type} (ext : EnvExtension σ) (env : Environment) (s : σ) (asyncMode : AsyncMode := ext.asyncMode) (log : WriteLog := WriteLog.missing) :

                                                                                                                                                              Sets the extension state to the given value. See AsyncMode for details on how modifications from different environment branches are reconciled.

                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                @[implemented_by _private.Lean.Environment.0.Lean.EnvExtension.getStateUnsafe]
                                                                                                                                                                opaque Lean.EnvExtension.getState {σ : Type} [Inhabited σ] (ext : EnvExtension σ) (env : Environment) (asyncMode : AsyncMode := ext.asyncMode) (asyncDecl : Name := Name.anonymous) (genRecorded : Bool := false) :
                                                                                                                                                                σ

                                                                                                                                                                Returns the current extension state. See AsyncMode for details on how modifications from different environment branches are reconciled.

                                                                                                                                                                Overriding the extension's default AsyncMode is usually not recommended and should be considered only for important optimizations.

                                                                                                                                                                genRecorded asserts that the caller recorded the extension's generation in the current recording computation (Lean.recordExtGenAccess), which reading a generation-tracked extension while Environment.isRecordingDeps is set requires.

                                                                                                                                                                Generation of the generation-tracked extension with index genIdx (EnvExtension.genIdx?) on the current branch of env.

                                                                                                                                                                Equations
                                                                                                                                                                Instances For

                                                                                                                                                                  Generation of the generation-tracked extension ext on the current branch of env.

                                                                                                                                                                  Equations
                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                  Instances For
                                                                                                                                                                    def Lean.registerEnvExtension {σ : Type} (mkInitial : IO σ) (replay? : Option (ReplayFn σ) := none) (asyncMode : EnvExtension.AsyncMode := EnvExtension.AsyncMode.mainOnly) (name : Name := by exact decl_name%) (trackGen logWrites : Bool := false) :

                                                                                                                                                                    Environment extensions can only be registered during initialization. Reasons: 1- Our implementation assumes the number of extensions does not change after an environment object is created. 2- We do not use any synchronization primitive to access envExtensionsRef.

                                                                                                                                                                    Note that by default, extension state is not stored in .olean files and will not propagate across imports. For that, you need to register a persistent environment extension.

                                                                                                                                                                    trackGen makes the extension generation-tracked; see PersistentEnvExtensionDescrCore.trackGen.

                                                                                                                                                                    Equations
                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                    Instances For
                                                                                                                                                                      def Lean.mkEmptyEnvironment (trustLevel : UInt32 := 0) :
                                                                                                                                                                      Equations
                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                      Instances For
                                                                                                                                                                        Instances For
                                                                                                                                                                          Instances For
                                                                                                                                                                            @[reducible, inline]
                                                                                                                                                                            abbrev Lean.ImportM (α : Type) :
                                                                                                                                                                            Equations
                                                                                                                                                                            Instances For

                                                                                                                                                                              The level of information to save/load. Each level includes all previous ones.

                                                                                                                                                                              • exported : OLeanLevel

                                                                                                                                                                                Information from exported contexts.

                                                                                                                                                                              • server : OLeanLevel

                                                                                                                                                                                Environment extension state for the language server.

                                                                                                                                                                              • private : OLeanLevel

                                                                                                                                                                                Private module data.

                                                                                                                                                                              Instances For
                                                                                                                                                                                @[instance_reducible]
                                                                                                                                                                                Equations
                                                                                                                                                                                structure Lean.OLeanEntries (α : Type) :

                                                                                                                                                                                Data computed once per extension for all three olean levels. Avoids calling the export function three separate times so that expensive computations can be shared.

                                                                                                                                                                                • exported : α
                                                                                                                                                                                • server : α
                                                                                                                                                                                • private : α
                                                                                                                                                                                Instances For

                                                                                                                                                                                  Create OLeanEntries with the same value for all levels.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For

                                                                                                                                                                                    Look up the entry for a given level.

                                                                                                                                                                                    Equations
                                                                                                                                                                                    Instances For
                                                                                                                                                                                      structure Lean.PersistentEnvExtension (α β σ : Type) :

                                                                                                                                                                                      An environment extension with support for storing/retrieving entries from a .olean file.

                                                                                                                                                                                      • α is the type of the entries that are stored in .olean files.
                                                                                                                                                                                      • β is the type of values used to update the state.
                                                                                                                                                                                      • σ is the actual state.

                                                                                                                                                                                      For most extensions, α and β coincide. α and β do not coincide for extensions where the data used to update the state contains elements which cannot be stored in files (for example, closures).

                                                                                                                                                                                      During elaboration of a module, state of type σ can be both read and written. When elaboration is complete, the state of type σ is converted to serialized state of type Array α by exportEntriesFn. To read the current module's state, use PersistentEnvExtension.getState. To modify it, use PersistentEnvExtension.addEntry, with an addEntryFn that performs the appropriate modification.

                                                                                                                                                                                      When a module is loaded, the values saved by all of its dependencies for this PersistentEnvExtension are available as an Array (Array α) via the environment extension, with one array per transitively imported module. The state of type σ used in the current module can be initialized from these imports by specifying a suitable addImportedFn. The addImportedFn runs at the beginning of elaboration for every module, so it's usually better for performance to query the array of imported modules directly, because only a fraction of imported entries is usually queried during elaboration of a module.

                                                                                                                                                                                      The most typical pattern for using PersistentEnvExtension is to set σ to a datatype such as NameMap that efficiently tracks data for the current module. Then, in exportEntriesFn, this type is converted to an array of pairs, sorted by the key. Given ext : PersistentEnvExtension α β σ and env : Environment, the complete array of imported entries sorted by module index can be obtained using (ext.toEnvExtension.getState env).importedEntries. To query the extension for some constant name n, first use env.getModuleIdxFor? n. If it returns none, look up n in the current module's state (the NameMap). If it returns some idx, use ext.getModuleEntries env idx to get the array of entries for n's defining module, and query it using Array.binSearch. This pattern imposes a constraint that the extension can only track metadata that is declared in the same module as the definition to which it applies; relaxing this restriction can make queries slower due to needing to search all modules. If it is necessary to search all modules, it is usually better to initialize the state of type σ once from all imported entries and choose a more efficient search datastructure for it.

                                                                                                                                                                                      Note that addEntryFn is not in IO. This is intentional, and allows us to write simple functions such as

                                                                                                                                                                                      def addAlias (env : Environment) (a : Name) (e : Name) : Environment :=
                                                                                                                                                                                      aliasExtension.addEntry env (a, e)
                                                                                                                                                                                      

                                                                                                                                                                                      without using IO. We have many functions like addAlias.

                                                                                                                                                                                      • toEnvExtension : EnvExtension (PersistentEnvExtensionState α σ)
                                                                                                                                                                                      • name : Name
                                                                                                                                                                                      • addImportedFn : Array (Array α) → ImportM σ
                                                                                                                                                                                      • addEntryFn : σ → β → σ
                                                                                                                                                                                      • exportEntriesFn : Environment → σ → OLeanEntries (Array α)

                                                                                                                                                                                        Function to transform state into data that should be imported into other modules. Returns entries for all three olean levels at once so that expensive computations can be shared. When using the module system without import all, OLeanLevel.exported is imported, else OLeanLevel.private. Additionally, when using the module system in the language server, the OLeanLevel.server data is accessible via getModuleEntries (level := .server). By convention, each level should include all data of previous levels.

                                                                                                                                                                                        This function is run once after elaborating the file and joining all asynchronous threads. For non-module files, only the private field is used.

                                                                                                                                                                                      • statsFn : σ → Format
                                                                                                                                                                                      Instances For
                                                                                                                                                                                        @[instance_reducible]
                                                                                                                                                                                        Equations
                                                                                                                                                                                        @[instance_reducible]
                                                                                                                                                                                        Equations
                                                                                                                                                                                        • One or more equations did not get rendered due to their size.

                                                                                                                                                                                        Returns the data saved by ext.exportEntriesFn when m was elaborated. See docs on the function for details. When using the module system, level can be used to select the level of data to retrieve, but is limited to the maximum level actually imported: exported on the cmdline and server in the language server. Higher levels will return the data of the maximum imported level.

                                                                                                                                                                                        Equations
                                                                                                                                                                                        Instances For

                                                                                                                                                                                          Retrieves additional IR extension state for the interpreter.

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For
                                                                                                                                                                                            @[inline]
                                                                                                                                                                                            Equations
                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                            Instances For
                                                                                                                                                                                              def Lean.PersistentEnvExtension.getState {α β σ : Type} [Inhabited σ] (ext : PersistentEnvExtension α β σ) (env : Environment) (asyncMode : EnvExtension.AsyncMode := ext.toEnvExtension.asyncMode) (asyncDecl : Name := Name.anonymous) (genRecorded : Bool := false) :
                                                                                                                                                                                              σ

                                                                                                                                                                                              Get the current state of the given extension in the given environment. For genRecorded, see EnvExtension.getState.

                                                                                                                                                                                              Equations
                                                                                                                                                                                              Instances For
                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                Set the current state of the given extension in the given environment.

                                                                                                                                                                                                Equations
                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                  Modify the state of the given extension in the given environment by applying the given function.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                    • name : Name
                                                                                                                                                                                                    • mkInitial : IO σ
                                                                                                                                                                                                    • addImportedFn : Array (Array α) → ImportM σ
                                                                                                                                                                                                    • addEntryFn : σ → β → σ
                                                                                                                                                                                                    • exportEntriesFnEx : Environment → σ → OLeanEntries (Array α)

                                                                                                                                                                                                      Function to transform state into data that should be imported into other modules. Returns entries for all three olean levels at once so that expensive computations can be shared. When using the module system without import all, OLeanLevel.exported is imported, else OLeanLevel.private. Additionally, when using the module system in the language server, the OLeanLevel.server data is accessible via getModuleEntries (level := .server). By convention, each level should include all data of previous levels.

                                                                                                                                                                                                      This function is run once after elaborating the file and joining all asynchronous threads. For non-module files, only the private field is used.

                                                                                                                                                                                                    • statsFn : σ → Format
                                                                                                                                                                                                    • replay? : Option (ReplayFn σ)
                                                                                                                                                                                                    • trackGen : Bool

                                                                                                                                                                                                      Whether the extension is generation-tracked: every modification bumps its generation (EnvExtension.getGen), so that a result computed from the state can be validated later by comparing generations. Generation-tracked extensions must use AsyncMode.local or .mainOnly, as generations are branch-local.

                                                                                                                                                                                                      Generations only grow along an environment branch, even when a modification restores an earlier state: returning to an earlier generation would let a later, different modification reach a generation some result was recorded at, validating it against a state it never saw. The environment itself rolling back to an earlier generation is covered at Kernel.Environment.trackedGen.

                                                                                                                                                                                                    • logWrites : Bool
                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                      def Lean.useDefaultIfOtherFieldGiven {α : Sort u_1} {β : Sort u_2} (default : α) (_otherField : β) :
                                                                                                                                                                                                      α

                                                                                                                                                                                                      Auxiliary function to signal to the structure instance elaborator that default should be used as the default value for a field but only if _otherField has been given, which is added as an artificial dependency.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                          Equations
                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                            @[implemented_by Lean.registerPersistentEnvExtensionUnsafe]

                                                                                                                                                                                                            Stores each given module data in the respective file name. Objects shared with prior parts are not duplicated. Thus the data cannot be loaded with individual readModuleData calls but must loaded by passing (a prefix of) the file names to readModuleDataParts. mod is used to determine an arbitrary but deterministic base address for mmap.

                                                                                                                                                                                                            Equations
                                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                              Loads the module data from the given file names. The files must be (a prefix of) the result of a saveModuleDataParts call.

                                                                                                                                                                                                              Equations
                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                def Lean.saveModuleData (fname : System.FilePath) (mod : Name) (data : ModuleData) :
                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                  @[noinline, export lean_environment_free_regions]

                                                                                                                                                                                                                  Free compacted regions of imports. No live references to imported objects may exist at the time of invocation; in particular, env should be the last reference to any Environment derived from these imports.

                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                      def Lean.writeModule (env : Environment) (fname : System.FilePath) (writeIR : Bool := true) :
                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                        def Lean.mkExtNameMap (startingAt : Nat) :

                                                                                                                                                                                                                        Construct a mapping from persistent extension name to extension index at the array of persistent extensions. We only consider extensions starting with index >= startingAt.

                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                          @[extern lean_update_env_attributes]

                                                                                                                                                                                                                          "Forward declaration" needed for updating the attribute table with user-defined attributes. User-defined attributes are declared using the initialize command. The initialize command is just syntax sugar for the init attribute. The init attribute is initialized after the attributeExtension is initialized. We cannot change the order since the init attribute is an attribute, and requires this extension. The attributeExtension initializer uses attributeMapRef to initialize the attribute mapping. When we a new user-defined attribute declaration is imported, attributeMapRef is updated. Later, we set this method with code that adds the user-defined attributes that were imported after we initialized attributeExtension.

                                                                                                                                                                                                                          @[extern lean_get_num_attributes]

                                                                                                                                                                                                                          "Forward declaration" for retrieving the number of builtin attributes.

                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                            Bumps all modules' isExported flag to true, intended for use in shake only.

                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                              def Lean.throwAlreadyImported {α : Type} (s : ImportState) (const2ModIdx : Std.HashMap Name ModuleIdx) (modIdx : Nat) (cname : Name) :
                                                                                                                                                                                                                              IO α
                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                @[reducible, inline]
                                                                                                                                                                                                                                abbrev Lean.ImportStateM (α : Type) :
                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                  @[inline]
                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                    def Lean.importModulesCore (imports : Array Import) (globalLevel : OLeanLevel := OLeanLevel.private) (arts : NameMap ImportArtifacts := ∅) (isExported : Bool := decide (globalLevel < OLeanLevel.private)) (loadIRSig : Bool := false) :
                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                      def Lean.finalizeImport (s : ImportState) (imports : Array Import) (opts : Options) (trustLevel : UInt32 := 0) (leakEnv loadExts : Bool) (level : OLeanLevel := OLeanLevel.private) (isModule : Bool := level != OLeanLevel.private) (loadIRSig : Bool := false) :

                                                                                                                                                                                                                                      Constructs environment from importModulesCore results.

                                                                                                                                                                                                                                      See also importModules for parameter documentation.

                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                        def Lean.importModules (imports : Array Import) (opts : Options) (trustLevel : UInt32 := 0) (plugins : Array Plugin := #[]) (leakEnv loadExts : Bool := false) (level : OLeanLevel := OLeanLevel.private) (arts : NameMap ImportArtifacts := ∅) :

                                                                                                                                                                                                                                        Creates environment object from given imports.

                                                                                                                                                                                                                                        If leakEnv is true, we mark the environment as persistent, which means it will not be freed. We set this when the object would survive until the end of the process anyway. In exchange, RC updates are avoided, which is especially important when they would be atomic because the environment is shared across threads (potentially, storing it in an IO.Ref is sufficient for marking it as such).

                                                                                                                                                                                                                                        If loadExts is true, we initialize the environment extensions using the imported data. Doing so may use the interpreter and thus is only safe to do after calling enableInitializersExecution; see also caveats there. If not set, every extension will have its initial value as its state. While the environment's constant map can be accessed without loadExts, many functions that take Environment or are in a monad carrying it such as CoreM may not function properly without it.

                                                                                                                                                                                                                                        If level is exported, the module to be elaborated is assumed to be participating in the module system and imports will be restricted accordingly. If it is server, the data for getModuleEntries (includeServer := true) is loaded as well. If it is private, all data is loaded as if no module annotations were present in the imports.

                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                          unsafe def Lean.withImportModules {α : Type} (imports : Array Import) (opts : Options) (act : Environment → IO α) (trustLevel : UInt32 := 0) :
                                                                                                                                                                                                                                          IO α

                                                                                                                                                                                                                                          Creates environment object from imports and frees compacted regions after calling act. No live references to the environment object or imported objects may exist after act finishes. As this cannot be ruled out after loading environment extensions, importModules's loadExts is always unset using this function.

                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                                            Enables/disables kernel diagnostics.

                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                @[noinline]
                                                                                                                                                                                                                                                unsafe def Lean.Environment.evalConst (α : Type) (env : Environment) (opts : Options) (constName : Name) (checkMeta : Bool := true) :

                                                                                                                                                                                                                                                Evaluates the given declaration under the given environment to a value of the given type. This function is only safe to use if the type matches the declaration's type in the environment and if enableInitializersExecution has been used before importing any modules.

                                                                                                                                                                                                                                                If checkMeta is true (the default), the function checks that all referenced imported constants are marked or imported as meta or otherwise fails with an error. It should only be set to false in cases where it is acceptable for code to work only in the language server, where more IR is loaded, such as in #eval.

                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                  def Lean.Environment.replayConsts (dest oldEnv newEnv : Environment) (skipExisting : Bool := false) :

                                                                                                                                                                                                                                                  Replays the difference between newEnv and oldEnv onto dest: the set of constants in newEnv but not oldEnv and the environment extension state for extensions defining replay?. If skipExisting is true, constants that are already in dest are not added. If newEnv and dest are not derived from oldEnv, the result is undefined.

                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                    unsafe def Lean.Environment.evalConstCheck (α : Type) (env : Environment) (opts : Options) (typeName constName : Name) :

                                                                                                                                                                                                                                                    Like evalConst, but first check that constName indeed is a declaration of type typeName. Note that this function cannot guarantee that typeName is in fact the name of the type α.

                                                                                                                                                                                                                                                    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
                                                                                                                                                                                                                                                        def Lean.Environment.realizeValue {α : Type u_1} [BEq α] [Hashable α] [TypeName α] (env : Environment) (forConst : Name) (key : α) (realize : Environment → Options → BaseIO Dynamic) :

                                                                                                                                                                                                                                                        Plumbing function for Lean.Meta.realizeValue; see documentation there.

                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                          Plumbing function for Lean.Meta.realizeConst; see documentation there.

                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                                                            Kernel API #

                                                                                                                                                                                                                                                            @[extern lean_kernel_is_def_eq]

                                                                                                                                                                                                                                                            Kernel isDefEq predicate. We use it mainly for debugging purposes. Recall that the kernel type checker does not support metavariables. When implementing automation, consider using the MetaM methods.

                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                              @[extern lean_kernel_whnf]

                                                                                                                                                                                                                                                              Kernel WHNF function. We use it mainly for debugging purposes. Recall that the kernel type checker does not support metavariables. When implementing automation, consider using the MetaM methods.

                                                                                                                                                                                                                                                              @[extern lean_kernel_check]

                                                                                                                                                                                                                                                              Kernel typecheck function. We use it mainly for debugging purposes. Recall that the Kernel type checker does not support metavariables. When implementing automation, consider using the MetaM methods.

                                                                                                                                                                                                                                                              class Lean.MonadEnv (m : Type → Type) :
                                                                                                                                                                                                                                                              Instances
                                                                                                                                                                                                                                                                def Lean.getMainModule {m : Type → Type} [Monad m] [MonadEnv m] :

                                                                                                                                                                                                                                                                Returns the module name of the current file.

                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                  @[instance_reducible, always_inline]
                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                  def Lean.withExporting {m : Type → Type} {α : Type} [Monad m] [MonadEnv m] [MonadFinally m] [MonadOptions m] (x : m α) (isExporting : Bool := true) :
                                                                                                                                                                                                                                                                  m α

                                                                                                                                                                                                                                                                  Sets Environment.isExporting to the given value while executing x. No-op if EnvironmentHeader.isModule is false.

                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                    def Lean.withoutExporting {m : Type → Type} {α : Type} [Monad m] [MonadEnv m] [MonadFinally m] [MonadOptions m] (x : m α) (when : Bool := true) :
                                                                                                                                                                                                                                                                    m α

                                                                                                                                                                                                                                                                    If when is true, sets Environment.isExporting to false while executing x.

                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                      def Lean.mkDefinitionValInferringUnsafe {m : Type → Type} [Monad m] [MonadEnv m] (name : Name) (levelParams : List Name) (type value : Expr) (hints : ReducibilityHints) :

                                                                                                                                                                                                                                                                      Constructs a DefinitionVal, inferring the unsafe field

                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                                                                                        Constructs a declaration from a theorem, resorting to an unsafe def if needed

                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                                          Environment extension for overriding the height that getMaxHeight assigns to a definition. This is consulted for all definitions regardless of their reducibility hints. Currently used by structural recursion to ensure that parent definitions get the correct height even though the _f helper definitions are marked as .abbrev (which getMaxHeight would otherwise ignore).

                                                                                                                                                                                                                                                                          def Lean.setDefHeightOverride (env : Environment) (declName : Name) (height : UInt32) :

                                                                                                                                                                                                                                                                          Register a height override for a definition so that getMaxHeight uses it.

                                                                                                                                                                                                                                                                          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