Repository navigation
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, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
(Strictly speaking, this is just about autoParam helper decls coming from variable.)
When a variable has an autoParam, the associated autoParam helper declaration is private even if the declaration it is elaborated for is public.
Because Lean assumes that any errors produced by re-elaboration of variables during declaration elaboration are duplicates of errors at the original variable command, Lean resets the message log and erases the logged error, meaning that the declaration fails only with "depends on sorry".
module
public section
variable (h : True := by trivial)
/-- warning: declaration uses `sorry` -/
#guard_msgs in
theorem foo : h = h := rfl
/-- info: foo (h : autoParam True sorry) : h = h -/
#guard_msgs in #check foo
open Lean Meta Elab Command in
/--
info: without exporting := _private.external:file:///lean-nightly/lean-nightly.lean.0._auto_7
---
info: with exporting := sorry
-/
#guard_msgs in
run_cmd do
withoutExporting do runTermElabM fun vars => do
logInfo m!"without exporting := \
{format (← inferType vars[0]!).getAutoParamTactic?.get!}"
withExporting do runTermElabM fun vars => do
logInfo m!"with exporting := \
{(← inferType vars[0]!).getAutoParamTactic?.get!}"Context
This is responsible for a few backward.privateInPublics in Mathlib.
Steps to Reproduce
- Make a
variablewith anautoParam. - Make a declaration with visibility
vthat uses that variable in its type.
Expected behavior: The autoParam helper declaration in that declaration's type lives at visibility v, or fails at the declaration if parts of that type cannot be used at this visibility.
Actual behavior: The autoParam helper declaration is provided as sorry. (The elaboration of the private constant fails under withExporting, and runTermElabM eats the error.)
Versions
4.34.0, commit f2bcf2e
Additional Information
- If variable elaboration is ultimately declaration-specific, perhaps the presence of errors at each original
variablebinder should be recorded in theScopesomewhere along with the corresponding variable syntax. Later, inrunTermElabM, if we encounter new errors despite the original binder elaboration being error-free, do not reset the message log. (If there were originally errors, do reset the message log.) Currently we just always reset the message log. mkUniqueNameshould perhaps respectisExporting, and deprivatize the name underwithExporting. But this encounters the issue that the private name prefix in the default state of the name generator fromCommandElabMis also used to make names module-specific. So, would care need to be taken to have a non-private module-specific header, and also check the environment for branches corresponding to those declarations? Or maybeelabMutualDefshould just set the name generator name to something appropriate beforerunTermElabM:)
(I'm not sure if it's okay for these declarations to be private somehow, and they merely need to be elaborated correctly, but it would surprise me to have a private constant anywhere in a public type!)
Aside: I previously opened #11569, which unintentionally led to the current state of affairs! 🙃 Strictly speaking this issue's title should mention variable, but then we'd lose the symmetry. :)
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Activity