Skip to content

Commit 9249ecc

Browse files
committed
index under fvars
1 parent 6740a1c commit 9249ecc

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

src/Lean/Meta/LazyDiscrTree.lean

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,13 @@ def pushArgs (root : Bool) (todo : Array Expr) (e : Expr) :
368368
let nargs := e.getAppNumArgs
369369
push (.proj s i nargs) nargs (todo.push a)
370370
| .fvar _fvarId =>
371-
return (.star, todo)
371+
let nargs := e.getAppNumArgs
372+
if nargs == 0 then
373+
return (.star, todo)
374+
else
375+
let info ← getFunInfoNArgs fn nargs
376+
let todo ← MatchClone.pushArgsAux info.paramInfo (nargs-1) e todo
377+
return (.star, todo)
372378
| .mvar mvarId =>
373379
if mvarId == MatchClone.tmpMVarId then
374380
-- We use `tmp to mark implicit arguments and proofs
@@ -678,18 +684,12 @@ def getMatchCore (root : Std.HashMap Key TrieIndex) (e : Expr) :
678684
let cases ← match k with
679685
| .star =>
680686
pure #[]
681-
/- When goal has fvar head like `p (ite c t e)`, also search by first argument's key.
687+
/- When goal has fvar head like `p (ite c t e)`, follow the star edge with the fvar's arguments.
682688
This finds "eliminator-style" theorems indexed by argument structure. -/
683689
| .fvar _ _ =>
684-
if h : 0 < args.size then
685-
let firstArg := args[args.size - 1] -- args are reversed
686-
let (argK, argArgs) ← MatchClone.getMatchKeyArgs firstArg (root := true) (← read)
687-
if argK != .star && argK != .other then
688-
pure (#[] |> pushRootCase root argK argArgs)
689-
else
690-
pure #[]
691-
else
692-
pure #[]
690+
match root[Key.star]? with
691+
| some c => pure #[{ todo := args, score := 0, c }]
692+
| none => pure #[]
693693
/- See note about "dep-arrow vs arrow" at `getMatchLoop` -/
694694
| .arrow =>
695695
pure (#[] |> pushRootCase root .other #[]

src/Lean/Meta/Tactic/LibrarySearch.lean

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,37 +137,16 @@ to find candidate lemmas.
137137

138138
open LazyDiscrTree (InitEntry findMatches)
139139

140-
/-- When conclusion is fvar-headed, create an entry keyed by the first concrete argument.
141-
For `motive (ite c t e)`, creates entry with key `.const ite 4`.
142-
This enables `exact?` to find "eliminator-style" theorems like `iteInduction`. -/
143-
private def getFirstArgEntry (type : Expr) (value : Name × DeclMod) :
144-
MetaM (Option (InitEntry (Name × DeclMod))) := do
145-
let type ← DiscrTree.reduceDT type true
146-
let fn := type.getAppFn
147-
if !fn.isFVar then return none
148-
let args := type.getAppArgs
149-
if args.isEmpty then return none
150-
let firstArg := args[0]!
151-
let firstArg ← DiscrTree.reduceDT firstArg false
152-
let argFn := firstArg.getAppFn
153-
if !argFn.isConst then return none
154-
some <$> InitEntry.fromExpr firstArg value
155-
156140
private def addImport (name : Name) (constInfo : ConstantInfo) :
157141
MetaM (Array (InitEntry (Name × DeclMod))) :=
158142
-- Don't report lemmas from metaprogramming namespaces.
159143
if name.isMetaprogramming then return #[] else
160144
forallTelescope constInfo.type fun _ type => do
161145
let e ← InitEntry.fromExpr type (name, DeclMod.none)
162-
let mut a := #[e]
163-
-- If root key is star (fvar-headed), also index by argument structure
164-
if e.key == .star then
165-
if let some argEntry ← getFirstArgEntry type (name, DeclMod.none) then
166-
a := a.push argEntry
167146
if e.key == .const ``Iff 2 then
168-
a := a.push (← e.mkSubEntry 0 (name, DeclMod.mp))
169-
a := a.push (← e.mkSubEntry 1 (name, DeclMod.mpr))
170-
pure a
147+
return #[e, ← e.mkSubEntry 0 (name, DeclMod.mp), ← e.mkSubEntry 1 (name, DeclMod.mpr)]
148+
else
149+
return #[e]
171150

172151
/-- Stores import discrimination tree. -/
173152
private def LibSearchState := IO.Ref (Option (LazyDiscrTree (Name × DeclMod)))

0 commit comments

Comments
 (0)