Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not report metaprogramming declarations via exact? and rw? #6672

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Lean/Data/Name.lean
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ def anyS (n : Name) (f : String → Bool) : Bool :=
| .num p _ => p.anyS f
| _ => false

/-- Return true if the name is in a namespace associated to metaprogramming.-/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/-- Return true if the name is in a namespace associated to metaprogramming.-/
/-- Return true if the name is in a namespace associated to metaprogramming. -/

def isMetaprogramming (n : Name) : Bool :=
let components := n.components
components.head? == `Lean || (components.any fun n => n == `Tactic || n == `Linter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment linters in Batteries use Batteries.Tactic.Lint as part of their namespace: they get excluded by Tactic, but maybe you could

  • also filter Lint here, or
  • change their namespace to Linter instead of Lint.


end Name
end Lean

Expand Down
6 changes: 4 additions & 2 deletions src/Lean/Meta/Tactic/LibrarySearch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ open LazyDiscrTree (InitEntry findMatches)

private def addImport (name : Name) (constInfo : ConstantInfo) :
MetaM (Array (InitEntry (Name × DeclMod))) :=
-- Don't report lemmas from metaprogramming namespaces.
if name.isMetaprogramming then return #[] else
forallTelescope constInfo.type fun _ type => do
let e ← InitEntry.fromExpr type (name, DeclMod.none)
let a := #[e]
if e.key == .const ``Iff 2 then
let a := a.push (←e.mkSubEntry 0 (name, DeclMod.mp))
let a := a.push (←e.mkSubEntry 1 (name, DeclMod.mpr))
let a := a.push (← e.mkSubEntry 0 (name, DeclMod.mp))
let a := a.push (← e.mkSubEntry 1 (name, DeclMod.mpr))
pure a
else
pure a
Expand Down
6 changes: 3 additions & 3 deletions src/Lean/Meta/Tactic/Rewrites.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ private def addImport (name : Name) (constInfo : ConstantInfo) :
if constInfo.isUnsafe then return #[]
if !allowCompletion (←getEnv) name then return #[]
-- We now remove some injectivity lemmas which are not useful to rewrite by.
if name matches .str _ "injEq" then return #[]
if name matches .str _ "sizeOf_spec" then return #[]
match name with
| .str _ n => if n.endsWith "_inj" ∨ n.endsWith "_inj'" then return #[]
| .str _ n => if n = "injEq" ∨ n = "sizeOf_spec" ∨ n.endsWith "_inj" ∨ n.endsWith "_inj'" then return #[]
| _ => pure ()
-- Don't report lemmas from metaprogramming namespaces.
if name.isMetaprogramming then return #[]
withNewMCtxDepth do withReducible do
forallTelescopeReducing constInfo.type fun _ type => do
match type.getAppFnArgs with
Expand Down
6 changes: 6 additions & 0 deletions tests/lean/librarySearch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,9 @@ error: apply? didn't find any relevant lemmas
-/
#guard_msgs in
example {α : Sort u} (x y : α) : Eq x y := by apply?

-- If this lemmas is added later to the library, please update this `#guard_msgs`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- If this lemmas is added later to the library, please update this `#guard_msgs`.
-- If this lemma is added later to the library, please update this `#guard_msgs`.

-- The point of this test is to ensure that `Lean.Grind.not_eq_prop` is not reported to users.
/-- error: `exact?` could not close the goal. Try `apply?` to see partial suggestions. -/
#guard_msgs in
example (p q : Prop) : (¬ p = q) = (p = ¬ q) := by exact?
Loading