-
Notifications
You must be signed in to change notification settings - Fork 460
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
fix: make name unresolution consistent and avoid auxiliary names #6938
base: master
Are you sure you want to change the base?
Conversation
Mathlib CI status (docs):
|
bb08e43
to
8466d5a
Compare
# Conflicts: # src/Lean/Elab/Tactic/Try.lean
8466d5a
to
7a8df53
Compare
This would be a breaking change if integrated as-is (it changes both the type and namespace of As far as I can tell, the change in the type of the local-avoiding variant is unavoidable if we want to truly guarantee that it avoids all locals: as I note in the PR description, there are situations where it is impossible to determine the full set of locally shadowed names outside It's not immediately clear to me what the best path forward is. Given that the unresolution errors caused by the current implementation of |
Fixing this while staying in So I wonder about these alternatives way to address this:
|
Yes, if we simply assume that an auxiliary decl named I've tried your suggestion (1), and it does resolve the issue of avoiding conflicts with auxiliary declarations. I worried a little bit that Unfortunately, option (1), on its own, does not address the other issue of correctly resolving fully-qualified names of auxiliary declarations when resuming postponed elaboration; we may (and presumably do) call If option (1) is a preferable route, I can either open a separate PR with those changes or revert this PR's changes and push them here (if it's easier to keep things in one place). |
I am somewhat out of my depth here, with postponed elaboratation etc. Maybe @Kha can advise? Would it help if the aux declarations would be added to the context with the fully qualified name, so the map isn't even needed, and with name resolution adjusted to heed the currently opened namespaces also when looking up local variables? Or would that break other things? (Separate PRs of competing options might be useful to compare and for later reference.) |
I agree, and with |
This would be addressed if every |
This particular issue did not arise in practice—I noticed it while trying to resolve the originally reported issue (where we were resolving local names properly but not detecting them during unresolution). I suppose the issue here could arise if a proof were split into lemmas using |
Let’s not worry too much about name resolution or even unresolution in corner cases for which we have no evidence that they occur in practice. So if the code stays significantly simpler by not worrying, that’s probably the better trade off for now. Leaving a comment in the code and/or a low-priority issue to keep track might pay off. |
This PR ensures that names suggested by
simp?
are not shadowed by auxiliary declarations in the local context.This PR moves
unresolveNameGlobalAvoidingLocals
into theTerm
namespace and restricts it toTermElabM
, since it is impossible to correctly resolve some auxiliary declarations (e.g., in amutual
block) without access to theauxDeclToFullName
map in theTermElabM
context. It also addsauxDeclToFullName
to theSavedContext
for postponed expressions, which ensures that (un)resolution of auxiliary-declaration names is consistent between terms and tactic blocks (previously, it was not possible to refer to certain auxiliary declarations by suffixes in a tactic block).Closes #6706.