getStarLemmas lists the current module's star-indexed lemmas once more after each library search

Open
#16,415 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Read createModuleTreeRef in src/Lean/Meta/LazyDiscrTree.lean and libSearchFindDecls in src/Lean/Meta/Tactic/LibrarySearch.lean, then run the supplied Star.lean reproduction. Trace how current-module dropped entries are added to starLemmasExt across repeated searches; done when my_star_lemma appears once after three searches and the regression is covered.

Written by the indexing model from the issue text.

Description

Prerequisites
  • Check that your issue is not already filed:
    https://github.com/leanprover/lean4/issues
  • Reduce the issue to a minimal, self-contained, reproducible test case.
    Avoid dependencies to Mathlib or Batteries.
  • Test your test case against the latest nightly release. I tested 4.34.1 and 4.35.0. The code involved is unchanged on master (createModuleTreeRef in src/Lean/Meta/LazyDiscrTree.lean, and libSearchFindDecls in src/Lean/Meta/Tactic/LibrarySearch.lean).
  • When reporting a perceived soundness bug: not a soundness bug.
Description

getStarLemmas lists each of the current module's star-indexed lemmas once more after every library search in the same process. After three searches, a lemma of the current module is listed three times, so the last-resort pass of exact? and apply? tries it three times.

libSearchFindDecls passes the process-wide starLemmasExt to findMatches as droppedEntriesRef. findMatches builds a new tree of the current module on every call (createModuleTreeRef). Each time, createModuleTreeRef appends that module's dropped entries to the ref, after what's already there. The imported part is appended only once, when the imported tree is first made, so only the current module's part repeats.

Context

Found while comparing a program's own use of LazyDiscrTree with libSearchFindDecls and getStarLemmas, on goals in one file.

Steps to Reproduce
  1. Save this as Star.lean:
import Lean
open Lean Meta LibrarySearch
theorem my_star_lemma {α : Prop} (h : α) : α := h
#eval show MetaM Unit from do
  let _ ← libSearchFindDecls (mkConst ``True)
  let a ← getStarLemmas
  let _ ← libSearchFindDecls (mkConst ``True)
  let _ ← libSearchFindDecls (mkConst ``True)
  let b ← getStarLemmas
  let count (xs : Array (Name × DeclMod)) := (xs.filter (·.1 == ``my_star_lemma)).size
  IO.println s!"after 1 search: {a.size} star lemmas, my_star_lemma {count a} times"
  IO.println s!"after 3 searches: {b.size} star lemmas, my_star_lemma {count b} times"
  1. Run lean Star.lean.

Expected behavior: my_star_lemma is listed once, however many searches ran before.

Actual behavior:

after 1 search: 1660 star lemmas, my_star_lemma 1 times
after 3 searches: 1662 star lemmas, my_star_lemma 3 times

On 4.35.0, the counts are 1673 and 1675, again with my_star_lemma listed 1 and 3 times.

Versions
  • Lean (version 4.34.1, aarch64-unknown-linux-gnu, commit 5045d0056413266e57c625dcd7c365b10e377c52, Release)
  • Lean (version 4.35.0, aarch64-unknown-linux-gnu, commit eb6cafb7290e8bd5f2937522d8d804f58f02bafc, Release)
  • Linux, aarch64
Additional Information

starLemmasExt lives as long as the process, so the list grows with every search the process makes: each exact? or apply? in one file adds that file's star-indexed lemmas again.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.