`simp` fails when it tries to apply a private lemma in the public scope

Aperta
#16,660 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
compilers

Direzione di ricerca

Start from the minimal reproduction in the issue: a public section with a private @[simp] theorem x_eq used by simp -failIfUnchanged at h inside an @[expose] definition. The failure is an "Unknown constant" error for the private name, so look at how simp collects and resolves candidate lemmas when run in the public scope. Done means the reproduction no longer errors and simp leaves h unchanged, with private lemmas skipped or handled correctly in that scope.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
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, for example on
    https://live.lean-lang.org/#project=lean-nightly
    (You can also use the settings there to switch to “Lean nightly”)
  • When reporting a perceived soundness bug: Does it affect lake check --paranoid?
    If in doubt, please reach out on [email protected] for responsible disclosure.
Description

When simp is run in the public scope and it tries to apply a private (or privately imported) lemma, it fails with an "Unknown constant" error, even if in the end, that lemma wouldn't have been applied (for example, due to typeclass assumptions). Ideally, simp would apply only public lemmas when run in the public scope.

Context

Mathlib's simps attribute has an option to call simp on the generated lemmas, which is currently run in the public scope. This caused an error in an existing definition in a PR which added a private import to a file, even though the lemma simp tried applying wouldn't have been used because of its typeclass assumptions. See the discussion of https://github.com/leanprover-community/mathlib4/pull/46130 for details. However, this issue can be reproduced without any metaprogramming by constructing a definition using tactics.

Steps to Reproduce
module

public section

def x := 0

@[simp]
private theorem x_eq (_ : False) : x = 0 := rfl

@[expose]
def a (h : x = 0) : Nat := by
  simp -failIfUnchanged at h
  exact 0

Expected behavior: simp does nothing.

Actual behavior: simp fails with "Unknown constant _private.«external:file:///lean-nightly/lean-nightly.lean».0.x_eq".

Versions

Lean 4.38.0-nightly-2026-11-20

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

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

Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
19h 8m
PR unite (30g)
421

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.