Documentation

Lean.CoreM

If the diagnostics option is not already set, gives a message explaining this option. Begins with a \n, so an error message can look like m!"some error occurred{useDiagnosticMsg}".

Instances For
    @[reducible, inline]
    Instances For

      Cache for the CoreM monad

      Instances For

        State for the CoreM monad.

        • Current environment.

        • nextMacroScope : Lean.MacroScope

          Next macro scope. We use macro scopes to avoid accidental name capture.

        • Name generator for producing unique FVarIds, MVarIds, and LMVarIds

        • traceState : Lean.TraceState

          Trace messages

        • Cache for instantiating universe polymorphic declarations.

        • messages : Lean.MessageLog

          Message log.

        • Info tree. We have the info tree here because we want to update it while adding attributes.

        • Snapshot trees of asynchronous subtasks. As these are untyped and reported only at the end of the command's main elaboration thread, they are only useful for basic message log reporting; for incremental reporting and reuse within a long-running elaboration thread, types rooted in CommandParsedSnapshot need to be adjusted.

        Instances For

          Context for the CoreM monad.

          • fileName : String

            Name of the file being compiled.

          • fileMap : Lean.FileMap

            Auxiliary datastructure for converting String.Pos into Line/Column number.

          • options : Lean.Options
          • currRecDepth : Nat
          • maxRecDepth : Nat
          • currNamespace : Lean.Name
          • openDecls : List Lean.OpenDecl
          • initHeartbeats : Nat
          • maxHeartbeats : Nat
          • currMacroScope : Lean.MacroScope
          • diag : Bool

            If diag := true, different parts of the system collect diagnostics. Use the set_option diag true to set it to true.

          • If set, used to cancel elaboration from outside when results are not needed anymore.

          • suppressElabErrors : Bool

            If set (when showPartialSyntaxErrors is not set and parsing failed), suppresses most elaboration errors; see also logMessage below.

          Instances For
            @[reducible, inline]
            abbrev Lean.Core.CoreM (α : Type) :

            CoreM is a monad for manipulating the Lean environment. It is the base monad for MetaM. The main features it provides are:

            • name generator state
            • environment state
            • Lean options context
            • the current open namespace
            Instances For
              @[always_inline]
              Equations
              Equations
              • One or more equations did not get rendered due to their size.
              Equations
              Equations
              • One or more equations did not get rendered due to their size.
              Equations
              Equations
              • One or more equations did not get rendered due to their size.
              Equations
              • One or more equations did not get rendered due to their size.
              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.
                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
                    @[inline]
                    def Lean.Core.liftIOCore {α : Type} (x : IO α) :
                    Instances For
                      Equations
                      @[specialize #[]]

                      Incremental reuse primitive: if reusableResult? is none, runs act and returns its result together with the saved monadic state after act including the heartbeats used by it. If reusableResult? on the other hand is some (a, state), restores full state including heartbeats used and returns (a, state).

                      The intention is for steps that support incremental reuse to initially pass none as reusableResult? and store the result and state in a snapshot. In a further run, if reuse is possible, reusableResult? should be set to the previous result and state, ensuring that the state after running withRestoreOrSaveFull is identical in both runs. Note however that necessarily this is only an approximation in the case of heartbeats as heartbeats used by withRestoreOrSaveFull itself after calling act as well as by reuse-handling code such as the one supplying reusableResult? are not accounted for.

                      Instances For

                        Restore backtrackable parts of the state.

                        Instances For
                          @[inline]
                          Instances For
                            @[inline]
                            Equations
                            • x.run' ctx s = Prod.fst <$> x.run ctx s
                            Instances For
                              @[inline]
                              Instances For
                                def Lean.Core.withIncRecDepth {m : TypeType u_1} {α : Type} [Monad m] [MonadControlT Lean.CoreM m] (x : m α) :
                                m α
                                Instances For
                                  @[inline]

                                  Throws an internal interrupt exception if cancellation has been requested. The exception is not caught by try catch but is intended to be caught by Command.withLoggingExceptions at the top level of elaboration. In particular, we want to skip producing further incremental snapshots after the exception has been thrown.

                                  Instances For
                                    def Lean.Core.throwMaxHeartbeat (moduleName optionName : Lean.Name) (max : Nat) :
                                    Instances For
                                      def Lean.Core.checkMaxHeartbeatsCore (moduleName : String) (optionName : Lean.Name) (max : Nat) :
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        Equations
                                        Instances For
                                          def Lean.Core.withCurrHeartbeats {m : TypeType u_1} {α : Type} [Monad m] [MonadControlT Lean.CoreM m] (x : m α) :
                                          m α
                                          Instances For
                                            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

                                                  Returns the current log and then resets its messages while adjusting MessageLog.hadErrors. Used for incremental reporting during elaboration of a single command.

                                                  Instances For

                                                    Includes a given task (such as from wrapAsyncAsSnapshot) in the overall snapshot tree for this command's elaboration, making its result available to reporting and the language server. The reporter will not know about this snapshot tree node until the main elaboration thread for this command has finished so this function is not useful for incremental reporting within a longer elaboration thread but only for tasks that outlive it such as background kernel checking or proof elaboration.

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

                                                      Wraps the given action for use in EIO.asTask etc., discarding its final monadic state.

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

                                                        Option for capturing output to stderr during elaboration.

                                                        def Lean.Core.wrapAsyncAsSnapshot (act : UnitLean.CoreM Unit) (desc : String := by exact decl_name%.toString) :

                                                        Wraps the given action for use in BaseIO.asTask etc., discarding its final state except for logSnapshotTask tasks, which are reported as part of the returned tree.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          @[inline]
                                                          def Lean.withAtLeastMaxRecDepth {m : TypeType u_1} {α : Type} [MonadFunctorT Lean.CoreM m] (max : Nat) :
                                                          m αm α
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            @[inline]
                                                            def Lean.catchInternalId {m : Type u_1 → Type u_2} {α : Type u_1} [Monad m] [MonadExcept Lean.Exception m] (id : Lean.InternalExceptionId) (x : m α) (h : Lean.Exceptionm α) :
                                                            m α
                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              @[inline]
                                                              def Lean.catchInternalIds {m : Type u_1 → Type u_2} {α : Type u_1} [Monad m] [MonadExcept Lean.Exception m] (ids : List Lean.InternalExceptionId) (x : m α) (h : Lean.Exceptionm α) :
                                                              m α
                                                              Instances For

                                                                Return true if ex was generated by throwMaxHeartbeat. This function is a bit hackish. The heartbeat exception should probably be an internal exception. We used a similar hack at Exception.isMaxRecDepth

                                                                Equations
                                                                Instances For

                                                                  Creates the expression d → b

                                                                  Instances For

                                                                    Iterated mkArrow, creates the expression a₁ → a₂ → … → aₙ → b. Also see arrowDomainsN.

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

                                                                        Return true if diagnostic information collection is enabled.

                                                                        Instances For
                                                                          Instances For

                                                                            Return true if the exception was generated by one of our resource limits.

                                                                            Equations
                                                                            • ex.isRuntime = (ex.isMaxHeartbeat || ex.isMaxRecDepth)
                                                                            Instances For

                                                                              Returns true if the exception is an interrupt generated by checkInterrupted.

                                                                              Instances For
                                                                                @[inline]

                                                                                Custom try-catch for all monads based on CoreM. We usually don't want to catch "runtime exceptions" these monads, but on CommandElabM or, in specific cases, using tryCatchRuntimeEx. See issues #2775 and #2744 as well as MonadAlwaysExcept. Also, we never want to catch interrupt exceptions inside the elaborator.

                                                                                Instances For
                                                                                  @[inline]

                                                                                  A variant of tryCatch that also catches runtime exception (see also tryCatch documentation). Like tryCatch, this function does not catch interrupt exceptions, which are not considered runtime exceptions.

                                                                                  Instances For
                                                                                    Equations
                                                                                    Instances
                                                                                      @[inline]
                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      @[inline]
                                                                                      def Lean.mapCoreM {m : TypeType u_1} [MonadControlT Lean.CoreM m] [Monad m] (f : {α : Type} → Lean.CoreM αLean.CoreM α) {α : Type} (x : m α) :
                                                                                      m α
                                                                                      Instances For

                                                                                        Returns true if the given message kind has not been reported in the message log, and then mark it as reported. Otherwise, returns false. We use this API to ensure we don't report the same kind of warning multiple times.

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