refactor: move MonadLog

This commit is contained in:
Leonardo de Moura 2022-05-31 16:50:48 -07:00
parent be69d04af4
commit caa79ca04f
9 changed files with 28 additions and 25 deletions

View file

@ -32,3 +32,4 @@ import Lean.DeclarationRange
import Lean.LazyInitExtension
import Lean.LoadDynlib
import Lean.Widget
import Lean.Log

View file

@ -3,10 +3,10 @@ Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Log
import Lean.Parser.Command
import Lean.ResolveName
import Lean.Meta.Reduce
import Lean.Elab.Log
import Lean.Elab.Term
import Lean.Elab.Tactic.Cache
import Lean.Elab.Binders

View file

@ -3,8 +3,9 @@ Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Log
import Lean.Parser.Command
import Lean.DeclarationRange
import Lean.Elab.Log
import Lean.Data.Lsp.Utf16
namespace Lean.Elab

View file

@ -3,8 +3,9 @@ Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Log
import Lean.Parser.Level
import Lean.Elab.Exception
import Lean.Elab.Log
import Lean.Elab.AutoBound
namespace Lean.Elab.Level

View file

@ -3,7 +3,8 @@ Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Log
import Lean.Log
import Lean.Elab.Util
namespace Lean.Elab
namespace OpenDecl

View file

@ -3,7 +3,7 @@ Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Log
import Lean.Log
import Lean.Elab.InfoTree
namespace Lean.Elab

View file

@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.ResolveName
import Lean.Log
import Lean.Util.Sorry
import Lean.Util.ReplaceExpr
import Lean.Structure
@ -13,7 +14,6 @@ import Lean.Meta.Coe
import Lean.Hygiene
import Lean.Util.RecDepth
import Lean.Elab.Log
import Lean.Elab.Config
import Lean.Elab.Level
import Lean.Elab.Attributes

View file

@ -11,6 +11,7 @@ import Lean.Elab.Exception
import Lean.DocString
import Lean.DeclarationRange
import Lean.Compiler.InitAttr
import Lean.Log
namespace Lean
@ -195,6 +196,21 @@ partial def mkUnusedBaseName (baseName : Name) : MacroM Name := do
else
return baseName
def logException [Monad m] [MonadLog m] [AddMessageContext m] [MonadLiftT IO m] (ex : Exception) : m Unit := do
match ex with
| Exception.error ref msg => logErrorAt ref msg
| Exception.internal id _ =>
unless isAbortExceptionId id do
let name ← id.getName
logError m!"internal exception: {name}"
@[inline] def trace [Monad m] [MonadLog m] [AddMessageContext m] [MonadOptions m] (cls : Name) (msg : Unit → MessageData) : m Unit := do
if checkTraceOption (← getOptions) cls then
logTrace cls (msg ())
def logDbgTrace [Monad m] [MonadLog m] [AddMessageContext m] [MonadOptions m] (msg : MessageData) : m Unit := do
trace `Elab.debug fun _ => msg
builtin_initialize
registerTraceClass `Elab
registerTraceClass `Elab.step

View file

@ -3,11 +3,9 @@ Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Util
import Lean.Util.Sorry
import Lean.Elab.Exception
namespace Lean.Elab
namespace Lean
class MonadLog (m : Type → Type) extends MonadFileMap m where
getRef : m Syntax
@ -63,25 +61,10 @@ def logWarning (msgData : MessageData) : m Unit :=
def logInfo (msgData : MessageData) : m Unit :=
log msgData MessageSeverity.information
def logException [MonadLiftT IO m] (ex : Exception) : m Unit := do
match ex with
| Exception.error ref msg => logErrorAt ref msg
| Exception.internal id _ =>
unless isAbortExceptionId id do
let name ← id.getName
logError m!"internal exception: {name}"
def logTrace (cls : Name) (msgData : MessageData) : m Unit := do
logInfo (MessageData.tagged cls m!"[{cls}] {msgData}")
@[inline] def trace [MonadOptions m] (cls : Name) (msg : Unit → MessageData) : m Unit := do
if checkTraceOption (← getOptions) cls then
logTrace cls (msg ())
def logDbgTrace [MonadOptions m] (msg : MessageData) : m Unit := do
trace `Elab.debug fun _ => msg
def logUnknownDecl (declName : Name) : m Unit :=
logError m!"unknown declaration '{declName}'"
end Lean.Elab
end Lean