chore: simplify isExprDefEqStuck and isLevelDefEqStuck

This commit is contained in:
Leonardo de Moura 2020-08-21 12:03:51 -07:00
parent 32a55d5b9c
commit ae5b4defb1
5 changed files with 9 additions and 18 deletions

View file

@ -113,7 +113,7 @@ def isTypeCorrect (e : Expr) : MetaM Bool :=
catch
(traceCtx `Meta.check $ do checkAux e; pure true)
(fun ex => do
trace! `Meta.typeError ex.toTraceMessageData;
trace! `Meta.typeError ex.toMessageData;
pure false)
@[init] private def regTraceClasses : IO Unit := do

View file

@ -15,9 +15,8 @@ namespace Meta
abbrev ExceptionContext := MessageDataContext
inductive Exception
| isLevelDefEqStuck (u v : Level) (ctx : ExceptionContext)
| isExprDefEqStuck (t s : Expr) (ctx : ExceptionContext)
| core (ex : Core.Exception)
| isDefEqStuck
| core (ex : Core.Exception)
namespace Exception
instance : Inhabited Exception := ⟨core $ arbitrary _⟩
@ -29,16 +28,9 @@ def getRef : Exception → Syntax
def mkCtx (ctx : ExceptionContext) (m : MessageData) : MessageData :=
MessageData.withContext ctx m
/-- Generate trace message that is suitable for tracing crawlers -/
def toTraceMessageData : Exception → MessageData
| isLevelDefEqStuck u v ctx => mkCtx ctx $ `isLevelDefEqStuck ++ " " ++ u ++ " =?= " ++ v
| isExprDefEqStuck t s ctx => mkCtx ctx $ `isExprDefEqStuck ++ " " ++ t ++ " =?= " ++ s
| core ex => ex.toMessageData
def toMessageData : Exception → MessageData
| isLevelDefEqStuck u v ctx => mkCtx ctx $ `isLevelDefEqStuck ++ " " ++ u ++ " =?= " ++ v
| isExprDefEqStuck t s ctx => mkCtx ctx $ `isExprDefEqStuck ++ " " ++ t ++ " =?= " ++ s
| core ex => ex.toMessageData
| isDefEqStuck => "<isDefEqStuck>"
| core ex => ex.toMessageData
end Exception

View file

@ -966,7 +966,7 @@ private partial def isDefEqQuick : Expr → Expr → MetaM LBool
ctx ← read;
if ctx.config.isDefEqStuckEx then do
trace! `Meta.isDefEq.stuck (t ++ " =?= " ++ s);
throwEx $ Exception.isExprDefEqStuck t s
throw Exception.isDefEqStuck
else pure LBool.false
else pure LBool.undef) $ do
-- Both `t` and `s` are terms of the form `?m ...`

View file

@ -109,7 +109,7 @@ partial def isLevelDefEqAux : Level → Level → MetaM Bool
ctx ← read;
if ctx.config.isDefEqStuckEx && (lhs.isMVar || rhs.isMVar) then do
trace! `Meta.isLevelDefEq.stuck (lhs ++ " =?= " ++ rhs);
throwEx $ Exception.isLevelDefEqStuck lhs rhs
throw Exception.isDefEqStuck
else
pure false
else do

View file

@ -583,9 +583,8 @@ adaptReader (fun (ctx : Context) => { ctx with config := { ctx.config with isDef
catch
(toLOptionM $ synthInstance? type)
(fun ex => match ex with
| Exception.isExprDefEqStuck _ _ _ => pure LOption.undef
| Exception.isLevelDefEqStuck _ _ _ => pure LOption.undef
| _ => throw ex)
| Exception.isDefEqStuck => pure LOption.undef
| _ => throw ex)
def synthInstance (type : Expr) : MetaM Expr := do
result? ← synthInstance? type;