-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25bddeb
commit 8130010
Showing
3 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,58 @@ | ||
import Egg.Core.Request | ||
import Lean | ||
open Lean Elab Tactic | ||
open Lean Meta Elab Tactic Std Format | ||
|
||
initialize registerTraceClass `egg | ||
initialize registerTraceClass `egg.rewrites (inherited := true) | ||
initialize registerTraceClass `egg.frontend (inherited := true) | ||
initialize registerTraceClass `egg.reconstruction (inherited := true) | ||
|
||
namespace Egg | ||
|
||
-- TODO: Replace this with a `MessageData` instance. | ||
#check MessageData | ||
|
||
nonrec def MVars.format (mvars : MVars) : MetaM Format := do | ||
let expr := format <| ← mvars.expr.toList.mapM (ppExpr <| Expr.mvar ·) | ||
let tc := format <| ← mvars.tc.toList.mapM (ppExpr <| Expr.mvar ·) | ||
let lvl := format <| mvars.lvl.toList.map (Level.mvar ·) | ||
return "expr: " ++ expr ++ "\n" ++ "class: " ++ tc ++ "\n" ++ "level: " ++ lvl | ||
|
||
def Directions.format : Directions → Format | ||
| .none => "∅" | ||
| .forward => "⇒" | ||
| .backward => "⇐" | ||
| .both => "⇔" | ||
|
||
def Congr.Rel.format : Congr.Rel → Format | ||
| .eq => "=" | ||
| .iff => "↔" | ||
|
||
def Congr.format (cgr : Congr) : MetaM Format := | ||
return (← ppExpr cgr.lhs) ++ " " ++ cgr.rel.format ++ " " ++ (← ppExpr cgr.rhs) | ||
|
||
def Rewrite.trace (rw : Rewrite) (stx? : Option Syntax) (cls : Name) : TacticM Unit := do | ||
let mut header := m!"{rw.src.description}({rw.validDirs.format})" | ||
if let some stx := stx? then header := m!"{header}: {stx}" | ||
withTraceNode cls (fun _ => return header) do | ||
Lean.traceM cls fun _ => return m!"{← rw.toCongr.format}" | ||
Lean.traceM cls fun _ => return m!"LHS MVars\n{← rw.lhsMVars.format}" | ||
Lean.traceM cls fun _ => return m!"RHS MVars\n{← rw.rhsMVars.format}" | ||
|
||
def Rewrites.trace (rws : Rewrites) (stx : Array Syntax) (cls : Name) : TacticM Unit := do | ||
for rw in rws, idx in [:rws.size] do rw.trace stx[idx]? cls | ||
|
||
def Rewrite.Encoded.trace (rw : Rewrite.Encoded) (cls : Name) : TacticM Unit := do | ||
let header := m!"{rw.name}({rw.dirs.format})" | ||
withTraceNode cls (fun _ => return header) do | ||
Lean.trace cls fun _ => m!"LHS: {rw.lhs}" | ||
Lean.trace cls fun _ => m!"RHS: {rw.rhs}" | ||
|
||
def Request.trace (req : Request) : TacticM Unit := do | ||
withTraceNode `egg.frontend (fun _ => return "Request") do | ||
withTraceNode `egg.frontend (fun _ => return "Goal") (collapsed := false) do | ||
withTraceNode `egg.frontend (fun _ => return "LHS") do trace[egg.frontend] req.lhs | ||
withTraceNode `egg.frontend (fun _ => return "RHS") do trace[egg.frontend] req.rhs | ||
let rwsTitle := (if req.rws.isEmpty && !req.cfg.genNatLitRws then "No " else "") ++ "Rewrites" | ||
withTraceNode `egg.frontend (fun _ => return rwsTitle) (collapsed := false) do | ||
for rw in req.rws do | ||
withTraceNode `egg.frontend (fun _ => return m!"{rw.name}") do | ||
trace[egg.frontend] "Directions: {rw.dirs}" | ||
withTraceNode `egg.frontend (fun _ => return "LHS") (collapsed := false) do trace[egg.frontend] rw.lhs | ||
withTraceNode `egg.frontend (fun _ => return "RHS") (collapsed := false) do trace[egg.frontend] rw.rhs | ||
for rw in req.rws do rw.trace `egg.frontend | ||
if req.cfg.genNatLitRws then trace[egg.frontend] "Nat Literal Conversions" |