feat: add auxiliary KVMap for storing extra information at Exception.internal
This commit is contained in:
parent
2a769bbd79
commit
5adfd37dfd
8 changed files with 20 additions and 20 deletions
|
|
@ -89,8 +89,8 @@ def mkFreshUserName {m} [MonadLiftT CoreM m] (n : Name) : m Name :=
|
|||
|
||||
@[inline] def CoreM.toIO {α} (x : CoreM α) (ctx : Context) (s : State) : IO (α × State) := do
|
||||
match (← (x.run ctx s).toIO') with
|
||||
| Except.error (Exception.error _ msg) => do let e ← msg.toString; throw $ IO.userError e
|
||||
| Except.error (Exception.internal id) => throw $ IO.userError $ "internal exception #" ++ toString id.idx
|
||||
| Except.error (Exception.error _ msg) => do let e ← msg.toString; throw $ IO.userError e
|
||||
| Except.error (Exception.internal id _) => throw $ IO.userError $ "internal exception #" ++ toString id.idx
|
||||
| Except.ok a => pure a
|
||||
|
||||
instance {α} [MetaEval α] : MetaEval (CoreM α) := {
|
||||
|
|
@ -112,14 +112,14 @@ export Core (CoreM mkFreshUserName)
|
|||
try
|
||||
x
|
||||
catch ex => match ex with
|
||||
| Exception.error _ _ => throw ex
|
||||
| Exception.internal id' => if id == id' then h ex else throw ex
|
||||
| Exception.error _ _ => throw ex
|
||||
| Exception.internal id' _ => if id == id' then h ex else throw ex
|
||||
|
||||
@[inline] def catchInternalIds {α} {m : Type → Type} [Monad m] [MonadExcept Exception m] (ids : List InternalExceptionId) (x : m α) (h : Exception → m α) : m α := do
|
||||
try
|
||||
x
|
||||
catch ex => match ex with
|
||||
| Exception.error _ _ => throw ex
|
||||
| Exception.internal id => if ids.contains id then h ex else throw ex
|
||||
| Exception.error _ _ => throw ex
|
||||
| Exception.internal id _ => if ids.contains id then h ex else throw ex
|
||||
|
||||
end Lean
|
||||
|
|
|
|||
|
|
@ -561,7 +561,7 @@ private partial def resolveLValLoop (lval : LVal) (e eType : Expr) (previousExce
|
|||
| none =>
|
||||
previousExceptions.forM fun ex => logException ex
|
||||
throw ex
|
||||
| ex@(Exception.internal _) => throw ex
|
||||
| ex@(Exception.internal _ _) => throw ex
|
||||
|
||||
private def resolveLVal (e : Expr) (lval : LVal) : TermElabM (Expr × LValResolution) := do
|
||||
let eType ← inferType e
|
||||
|
|
|
|||
|
|
@ -205,8 +205,8 @@ instance : MonadRecDepth CommandElabM := {
|
|||
try
|
||||
x
|
||||
catch ex => match ex with
|
||||
| Exception.error _ _ => logException ex
|
||||
| Exception.internal id =>
|
||||
| Exception.error _ _ => logException ex
|
||||
| Exception.internal id _ =>
|
||||
if id == abortExceptionId then
|
||||
pure ()
|
||||
else
|
||||
|
|
@ -542,7 +542,7 @@ def failIfSucceeds (x : CommandElabM Unit) : CommandElabM Unit := do
|
|||
hasNoErrorMessages
|
||||
catch
|
||||
| ex@(Exception.error _ _) => do logException ex; pure false
|
||||
| Exception.internal id => do logError "internal"; pure false -- TODO: improve `logError "internal"`
|
||||
| Exception.internal id _ => do logError "internal"; pure false -- TODO: improve `logError "internal"`
|
||||
finally
|
||||
restoreMessages prevMessages
|
||||
if succeeded then
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ def logInfo (msgData : MessageData) : m Unit :=
|
|||
def logException [MonadLiftT IO m] (ex : Exception) : m Unit := do
|
||||
match ex with
|
||||
| Exception.error ref msg => logErrorAt ref msg
|
||||
| Exception.internal id =>
|
||||
| Exception.internal id _ =>
|
||||
unless id == abortExceptionId do
|
||||
let name ← id.getName
|
||||
logError ("internal exception: " ++ name)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ private def resumePostponed (macroStack : MacroStack) (declName? : Option Name)
|
|||
assignExprMVar mvarId result
|
||||
pure true
|
||||
catch
|
||||
| ex@(Exception.internal id) =>
|
||||
| ex@(Exception.internal id _) =>
|
||||
if id == postponeExceptionId then
|
||||
set s
|
||||
pure false
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ private def evalTacticUsing (s : SavedState) (stx : Syntax) (tactics : List Tact
|
|||
match evalFns with
|
||||
| [] => throw ex
|
||||
| evalFns => s.restore; loop evalFns
|
||||
| ex@(Exception.internal id) =>
|
||||
| ex@(Exception.internal id _) =>
|
||||
if id == unsupportedSyntaxExceptionId then
|
||||
s.restore; loop evalFns
|
||||
else
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ def getMessageLog : TermElabM MessageLog :=
|
|||
let sNew ← saveAllState
|
||||
s.restore
|
||||
pure (EStateM.Result.error ex sNew)
|
||||
| ex@(Exception.internal id) =>
|
||||
| ex@(Exception.internal id _) =>
|
||||
if id == postponeExceptionId then s.restore
|
||||
throw ex
|
||||
|
||||
|
|
@ -844,7 +844,7 @@ private def elabUsingElabFnsAux (s : SavedState) (stx : Syntax) (expectedType? :
|
|||
exceptionToSorry ex expectedType?
|
||||
else
|
||||
throw ex
|
||||
| Exception.internal id =>
|
||||
| Exception.internal id _ =>
|
||||
if id == unsupportedSyntaxExceptionId then
|
||||
s.restore
|
||||
elabUsingElabFnsAux s stx expectedType? catchExPostpone elabFns
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@ namespace Lean
|
|||
/- Exception type used in most Lean monads -/
|
||||
inductive Exception :=
|
||||
| error (ref : Syntax) (msg : MessageData)
|
||||
| internal (id : InternalExceptionId)
|
||||
| internal (id : InternalExceptionId) (extra : KVMap := {})
|
||||
|
||||
def Exception.toMessageData : Exception → MessageData
|
||||
| Exception.error _ msg => msg
|
||||
| Exception.internal id => id.toString
|
||||
| Exception.error _ msg => msg
|
||||
| Exception.internal id _ => id.toString
|
||||
|
||||
def Exception.getRef : Exception → Syntax
|
||||
| Exception.error ref _ => ref
|
||||
| Exception.internal _ => Syntax.missing
|
||||
| Exception.error ref _ => ref
|
||||
| Exception.internal _ _ => Syntax.missing
|
||||
|
||||
instance : Inhabited Exception := ⟨Exception.error (arbitrary _) (arbitrary _)⟩
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue