@@ -4,6 +4,7 @@ import Egg.Tactic.Config.Option
44import Egg.Tactic.Config.Modifier
55import Egg.Tactic.Goal
66import Egg.Tactic.Guides
7+ import Egg.Tactic.Blocks
78import Egg.Tactic.Rewrite.Rules.Gen.Basic
89import Egg.Core.Gen.Guides
910import Egg.Tactic.Trace
@@ -41,8 +42,8 @@ open Config.Modifier (egg_cfg_mod)
4142syntax egg_baskets := ("+" noWs ident)*
4243
4344protected partial def eval
44- (mod : TSyntax ``egg_cfg_mod) (args : TSyntax `egg_args)
45- (guides : Option (TSyntax `egg_guides )) (baskets : TSyntax `Egg.egg_baskets)
45+ (mod : TSyntax ``egg_cfg_mod) (args : TSyntax `egg_args) (guides : Option (TSyntax `egg_guides))
46+ (blocks : Option (TSyntax `egg_blocks )) (baskets : TSyntax `Egg.egg_baskets)
4647 (calcifyTk? : Option Syntax := none) : TacticM Unit := do
4748 let save ← saveState
4849 try core catch err => restoreState save; throw err
5758 let goal ← Goal.gen goal
5859 goal.id.withContext do
5960 let guides := (← guides.mapM Guides.parseGuides).getD #[]
61+ let blocks ← getBlocks blocks cfg
6062 -- We increase the mvar context depth, so that ambient mvars aren't unified during rewrite
6163 -- generation proof and reconstruction. Note that this also means that we can't assign the
6264 -- `goal` mvar inside of this `do`-block .
6769 let rws := rules.entries.map (·.rw)
6870 guides := guides ++ (← genDerivedGuides goal.toCongr rws)
6971 withTraceNode `egg.guides (fun _ => return "Guides" ) do guides.trace `egg.guides
70- runEqSat goal rules guides cfg
72+ runEqSat goal rules guides blocks cfg
7173 match res with
7274 | some (proof, proofTime, result) =>
7375 if cfg.reporting then
7981 if let some tk := calcifyTk? then calcify tk proof goal.intros.unzip.snd
8082 | none => goal.id.admit
8183 runEqSat
82- (goal : Goal) (rules : Rewrite.Rules) (guides : Guides) (cfg : Config) :
84+ (goal : Goal) (rules : Rewrite.Rules) (guides : Guides) (blocks : Blocks) ( cfg : Config) :
8385 TacticM <| Option (AbstractMVarsResult × Nat × Request.Result) := do
84- let req ← Request.encoding goal.toCongr rules guides #[] cfg
86+ let req ← Request.encoding goal.toCongr rules guides blocks cfg
8587 withTraceNode `egg.encoded (fun _ => return "Encoded" ) do req.trace `egg.encoded
8688 if let .beforeEqSat := cfg.exitPoint then return none
8789 let result ← req.run cfg.explLengthLimit (onEqSatFailure cfg)
9294 | .proof prf =>
9395 let proofTime := (← IO.monoMsNow) - beforeProof
9496 return some (prf, proofTime, result)
95- | .retryWithShapes => runEqSat goal rules guides { cfg with shapes := true }
97+ | .retryWithShapes => runEqSat goal rules guides blocks { cfg with shapes := true }
9698 onEqSatFailure (cfg : Config) (report : Request.Result.Report) : Request.Failure → MetaM MessageData
9799 | .backend msg? => do
98100 let mut msg := msg?
@@ -105,17 +107,21 @@ where
105107 let msg := s! "egg found an explanation exceeding the length limit ({ len} vs { cfg.explLengthLimit} )\n You can increase this limit using 'set_option egg.explLengthLimit <num>'.\n "
106108 unless cfg.reporting do return msg
107109 return msg ++ formatReport cfg.flattenReports report
110+ getBlocks (stx? : Option <| TSyntax `egg_blocks) (cfg : Config) : TacticM Blocks := do
111+ let some stx := stx? | return #[]
112+ unless cfg.subgoals do logWarningAt stx "conditions are only blocked when `egg.subgoals` is `true`"
113+ Blocks.parseBlocks cfg.toNormalization stx
108114
109- elab "egg " baskets:egg_baskets mod:egg_cfg_mod args:egg_args guides:(egg_guides)? : tactic =>
110- Egg.eval mod args guides baskets
115+ elab "egg " baskets:egg_baskets mod:egg_cfg_mod args:egg_args guides:(egg_guides)? blocks:(egg_blocks)? : tactic =>
116+ Egg.eval mod args guides blocks baskets
111117
112118-- WORKAROUND: This fixes `Tests/EndOfInput *`.
113119macro "egg " baskets:egg_baskets mod:egg_cfg_mod : tactic =>
114120 `(tactic| egg $baskets $mod:egg_cfg_mod)
115121
116122-- The syntax `egg?` calls calcify after running egg.
117- elab tk:"egg? " baskets:egg_baskets mod:egg_cfg_mod args:egg_args guides:(egg_guides)? : tactic =>
118- Egg.eval mod args guides baskets (calcifyTk? := tk)
123+ elab tk:"egg? " baskets:egg_baskets mod:egg_cfg_mod args:egg_args guides:(egg_guides)? blocks:(egg_blocks)? : tactic =>
124+ Egg.eval mod args guides blocks baskets (calcifyTk? := tk)
119125
120126-- WORKAROUND: This fixes a problem analogous to `Tests/EndOfInput *` for `egg?`.
121127macro "egg? " baskets:egg_baskets mod:egg_cfg_mod : tactic =>
0 commit comments