@@ -22,9 +22,9 @@ namespace Lean.Elab.Tactic
2222open Lean Elab Parser Tactic Meta Simp Tactic.TryThis
2323
2424/-- Filter out `+suggestions` from the config syntax -/
25- def filterSuggestionsFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig) : MetaM (TSyntax ``Lean.Parser.Tactic.optConfig) := do
25+ def filterSuggestionsFromConfig (cfg : TSyntax ``Lean.Parser.Tactic.optConfig) : MetaM (TSyntax ``Lean.Parser.Tactic.optConfig) := do
2626 -- The config has one arg: a null node containing configItem nodes
27- let nullNode := config .raw.getArg 0
27+ let nullNode := cfg .raw.getArg 0
2828 let configItems := nullNode.getArgs
2929
3030 -- Filter out configItem nodes that contain +suggestions
@@ -38,7 +38,7 @@ def filterSuggestionsFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig
3838
3939 -- Reconstruct the config with filtered items
4040 let newNullNode := nullNode.setArgs filteredItems
41- return ⟨config .raw.setArg 0 newNullNode⟩
41+ return ⟨cfg .raw.setArg 0 newNullNode⟩
4242
4343open TSyntax.Compat in
4444/-- Constructs the syntax for a simp call, for use with `simp?`. -/
@@ -85,18 +85,50 @@ def mkSimpCallStx (stx : Syntax) (usedSimps : UsedSimps) : MetaM (TSyntax `tacti
8585@[builtin_tactic simpAllTrace] def evalSimpAllTrace : Tactic := fun stx => withMainContext do withSimpDiagnostics do
8686 match stx with
8787 | `(tactic| simp_all?%$tk $[!%$bang]? $cfg:optConfig $(discharger)? $[only%$o]? $[[$args,*]]?) =>
88- let stx ← if bang.isSome then
89- `(tactic| simp_all!%$tk $cfg:optConfig $(discharger)? $[only%$o]? $[[$args,*]]?)
90- else
91- `(tactic| simp_all%$tk $cfg:optConfig $(discharger)? $[only%$o]? $[[$args,*]]?)
92- let { ctx, simprocs, .. } ← mkSimpContext stx (eraseLocal := true )
88+ -- Check if premise selection is enabled
89+ let config ← elabSimpConfig cfg (kind := .simpAll)
90+ let mut argsArray : TSyntaxArray [`Lean.Parser.Tactic.simpErase, `Lean.Parser.Tactic.simpLemma] :=
91+ if let some a := args then a.getElems else #[]
92+ if config.suggestions then
93+ -- Get premise suggestions from the premise selector
94+ let suggestions ← Lean.PremiseSelection.select (← getMainGoal)
95+ -- Convert suggestions to simp argument syntax and add them to the args
96+ for sugg in suggestions do
97+ let arg ← `(Parser.Tactic.simpLemma| $(mkIdent sugg.name):term)
98+ argsArray := argsArray.push arg
99+ -- Build the simp_all syntax with the updated arguments
100+ let stxForExecution ←
101+ if argsArray.isEmpty then
102+ if bang.isSome then
103+ `(tactic| simp_all!%$tk $cfg:optConfig $[$discharger]? $[only%$o]?)
104+ else
105+ `(tactic| simp_all%$tk $cfg:optConfig $[$discharger]? $[only%$o]?)
106+ else
107+ if bang.isSome then
108+ `(tactic| simp_all!%$tk $cfg:optConfig $[$discharger]? $[only%$o]? [$argsArray,*])
109+ else
110+ `(tactic| simp_all%$tk $cfg:optConfig $[$discharger]? $[only%$o]? [$argsArray,*])
111+ -- Build syntax for suggestion (without +suggestions config)
112+ let filteredCfg ← filterSuggestionsFromConfig cfg
113+ let stxForSuggestion ←
114+ if argsArray.isEmpty then
115+ if bang.isSome then
116+ `(tactic| simp_all!%$tk $filteredCfg:optConfig $[$discharger]? $[only%$o]?)
117+ else
118+ `(tactic| simp_all%$tk $filteredCfg:optConfig $[$discharger]? $[only%$o]?)
119+ else
120+ if bang.isSome then
121+ `(tactic| simp_all!%$tk $filteredCfg:optConfig $[$discharger]? $[only%$o]? [$argsArray,*])
122+ else
123+ `(tactic| simp_all%$tk $filteredCfg:optConfig $[$discharger]? $[only%$o]? [$argsArray,*])
124+ let { ctx, simprocs, .. } ← mkSimpContext stxForExecution (eraseLocal := true )
93125 (kind := .simpAll) (ignoreStarArg := true )
94126 let ctx := if bang.isSome then ctx.setAutoUnfold else ctx
95127 let (result?, stats) ← simpAll (← getMainGoal) ctx (simprocs := simprocs)
96128 match result? with
97129 | none => replaceMainGoal []
98130 | some mvarId => replaceMainGoal [mvarId]
99- let stx ← mkSimpCallStx stx stats.usedTheorems
131+ let stx ← mkSimpCallStx stxForSuggestion stats.usedTheorems
100132 addSuggestion tk stx (origSpan? := ← getRef)
101133 return stats.diag
102134 | _ => throwUnsupportedSyntax
0 commit comments