lean4-htt/src/Lean/Elab/Exception.lean
Sebastian Ullrich f97a7d4234
feat: incremental elaboration of definition headers, bodies, and tactics (#3940)
Extends Lean's incremental reporting and reuse between commands into
various steps inside declarations:
* headers and bodies of each (mutual) definition/theorem
* `theorem ... := by` for each contained tactic step, including
recursively inside supported combinators currently consisting of
  * `·` (cdot), `case`, `next`
  * `induction`, `cases`
  * macros such as `next` unfolding to the above

![Recording 2024-05-10 at 11 07
32](https://github.com/leanprover/lean4/assets/109126/c9d67b6f-c131-4bc3-a0de-7d63eaf1bfc9)

*Incremental reuse* means not recomputing any such steps if they are not
affected by a document change. *Incremental reporting* includes the
parts seen in the recording above: the progress bar and messages. Other
language server features such as hover etc. are *not yet* supported
incrementally, i.e. they are shown only when the declaration has been
fully processed as before.

---------

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
2024-05-22 13:23:30 +00:00

68 lines
3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Lean.InternalExceptionId
import Lean.Exception
namespace Lean.Elab
builtin_initialize postponeExceptionId : InternalExceptionId ← registerInternalExceptionId `postpone
builtin_initialize unsupportedSyntaxExceptionId : InternalExceptionId ← registerInternalExceptionId `unsupportedSyntax
builtin_initialize abortCommandExceptionId : InternalExceptionId ← registerInternalExceptionId `abortCommandElab
builtin_initialize abortTermExceptionId : InternalExceptionId ← registerInternalExceptionId `abortTermElab
builtin_initialize abortTacticExceptionId : InternalExceptionId ← registerInternalExceptionId `abortTactic
builtin_initialize autoBoundImplicitExceptionId : InternalExceptionId ← registerInternalExceptionId `autoBoundImplicit
def throwPostpone [MonadExceptOf Exception m] : m α :=
throw $ Exception.internal postponeExceptionId
def throwUnsupportedSyntax [MonadExceptOf Exception m] : m α :=
throw $ Exception.internal unsupportedSyntaxExceptionId
def throwIllFormedSyntax [Monad m] [MonadError m] : m α :=
throwError "ill-formed syntax"
def throwAutoBoundImplicitLocal [MonadExceptOf Exception m] (n : Name) : m α :=
throw $ Exception.internal autoBoundImplicitExceptionId <| KVMap.empty.insert `localId n
def isAutoBoundImplicitLocalException? (ex : Exception) : Option Name :=
match ex with
| Exception.internal id k =>
if id == autoBoundImplicitExceptionId then
some <| k.getName `localId `x
else
none
| _ => none
def throwAlreadyDeclaredUniverseLevel [Monad m] [MonadError m] (u : Name) : m α :=
throwError "a universe level named '{u}' has already been declared"
-- Throw exception to abort elaboration of the current command without producing any error message
def throwAbortCommand {α m} [MonadExcept Exception m] : m α :=
throw <| Exception.internal abortCommandExceptionId
-- Throw exception to abort elaboration of the current term without producing any error message
def throwAbortTerm {α m} [MonadExcept Exception m] : m α :=
throw <| Exception.internal abortTermExceptionId
-- Throw exception to abort evaluation of the current tactic without producing any error message
def throwAbortTactic {α m} [MonadExcept Exception m] : m α :=
throw <| Exception.internal abortTacticExceptionId
def isAbortTacticException (ex : Exception) : Bool :=
match ex with
| Exception.internal id .. => id == abortTacticExceptionId
| _ => false
def isAbortExceptionId (id : InternalExceptionId) : Bool :=
id == abortCommandExceptionId || id == abortTermExceptionId || id == abortTacticExceptionId
def mkMessageCore (fileName : String) (fileMap : FileMap) (data : MessageData) (severity : MessageSeverity) (pos : String.Pos) (endPos : String.Pos) : Message :=
let pos := fileMap.toPosition pos
let endPos := fileMap.toPosition endPos
{ fileName, pos, endPos, data, severity }
end Lean.Elab