Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lean/Elab/Tactic/Grind/BuiltinTactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def logAnchor (numDigits : Nat) (anchorPrefix : UInt64) (e : Expr) : TermElabM U
-/
Term.addTermInfo' stx e
logAt (severity := .information) (isSilent := true) stx
m!"#{anchorToString numDigits anchorPrefix} := {e}"
m!"#{anchorPrefixToString numDigits anchorPrefix} := {e}"

@[builtin_grind_tactic cases] def evalCases : GrindTactic := fun stx => do
let `(grind| cases #$anchor:hexnum) := stx | throwUnsupportedSyntax
Expand Down
2 changes: 1 addition & 1 deletion src/Lean/Meta/Tactic/Grind/Action.lean
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ If `s?` is `none` just returns `true`.
-/
def checkSeqAt (s? : Option SavedState) (goal : Goal) (seq : List TGrind) : GrindM Bool := do
let some s := s? | return true
let tac ← mkGrindParen seq
Lean.withoutModifyingState do
s.restore
let tac ← mkGrindParen seq
-- **Note**: Ensure tracing is disabled.
withTheReader Grind.Context (fun ctx => { ctx with config.trace := false }) do
try
Expand Down
15 changes: 10 additions & 5 deletions src/Lean/Meta/Tactic/Grind/Anchor.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ def hashName (n : Name) : UInt64 :=
else if isPrivateName n then
hash (privateToUserName n)
else if n.isInternal then
match n with
| .str p _ | .num p _ => hashName p
| _ => 0
/-
**Note** We consider hashing the prefix, but it was not good enough.
For example, an internal name may depend on the name of theorem being defined.
Moreover, changing a `theorem` to an `example` would break anchors.
-/
0
else
hash n

Expand All @@ -45,8 +48,10 @@ public partial def getAnchor (e : Expr) : GrindM UInt64 := do
"instability". Recall that `match` auxiliary declarations are reused.
-/
if (← isMatcher declName) then pure 0
else pure <| hash declName
| .fvar fvarId => pure <| hashName (← fvarId.getDecl).userName
else pure <| hashName declName
| .fvar fvarId =>
let userName := (← fvarId.getDecl).userName
pure <| hashName userName
| .mdata _ b => getAnchor b
| .letE n v t b _ =>
pure <| mix (hashName n) <| mix (← getAnchor t) <| mix (← getAnchor v) (← getAnchor b)
Expand Down
7 changes: 6 additions & 1 deletion src/Lean/Meta/Tactic/Grind/EMatch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,12 @@ where
let mut proof := proof
let mut prop := prop
if (← getConfig).trace then
let uniqueId ← mkFreshId
/-
**Note**: It is incorrect to use `mkFreshId` here because we use `withFreshNGen` at
`instantiateTheorem`. So, we generate an unique id by using the number of instances generated so far.
The code relies on the fact that `addTheoremInstance` bumps this counter.
-/
let uniqueId := Name.num `_grind_inst (← getNumTheoremInstances)
proof := markTheoremInstanceProof proof uniqueId
modify fun s => { s with instanceMap := s.instanceMap.insert uniqueId thm }
if (← isMatchEqLikeDeclName thm.origin.key) then
Expand Down
4 changes: 2 additions & 2 deletions src/Lean/Meta/Tactic/Grind/EMatchAction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def getAllTheorems (map : EMatch.InstanceMap) : Array EMatchTheorem :=
map.toArray.map (·.2)

public def instantiate' : Action := fun goal kna kp => do
let s ← saveStateIfTracing
let saved? ← saveStateIfTracing
let ((progress, map), goal') ← GoalM.run goal ematch'
if progress then
match (← kp goal') with
Expand All @@ -95,7 +95,7 @@ public def instantiate' : Action := fun goal kna kp => do
let proof ← instantiateMVars (mkMVar goal.mvarId)
let usedThms := collect proof map
let newSeq ← mkNewSeq goal usedThms seq (approx := false)
if (← checkSeqAt s goal newSeq) then
if (← checkSeqAt saved? goal newSeq) then
return .closed newSeq
else
let allThms := getAllTheorems map
Expand Down
4 changes: 4 additions & 0 deletions src/Lean/Meta/Tactic/Grind/Types.lean
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ def addNewRawFact (proof : Expr) (prop : Expr) (generation : Nat) (splitSource :
which is not definitionally equal with `reducible` transparency setting}"
modify fun s => { s with newRawFacts := s.newRawFacts.enqueue { proof, prop, generation, splitSource } }

/-- Returns the number of theorem instances generated so far. -/
def getNumTheoremInstances : GoalM Nat := do
return (← get).ematch.numInstances

/-- Adds a new theorem instance produced using E-matching. -/
def addTheoremInstance (thm : EMatchTheorem) (proof : Expr) (prop : Expr) (generation : Nat) : GoalM Unit := do
saveEMatchTheorem thm
Expand Down
Loading
Loading