-
Notifications
You must be signed in to change notification settings - Fork 462
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: reserved names #3675
feat: reserved names #3675
Conversation
Mathlib CI status (docs):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current design, one would globally reserve every name that ends with, say, .induct
, and register an action that tries its best whenever someone accesses foo.induct
, no matter what foo
is - so even Prop.induct
is reserved, is it?
This is different from adding a ”thunked declaration” to the environment at precisely the time when, from the users point of view, the name did come into existence, in which case there is no squatting in every namespace.
A thunk could also store extra information to be used by the lazy action.
But I see the problems: One does not know the number of equation lemmas ahead of times, and maybe it's tricky to serialize a CoreM ()
thunk, so maybe this isn't an option.
Could the behavior of not being able to declare definitions with names like |
If it wouldn't be for the
This way the user experience is much closer to what it would be if the definitions were simply created eagerly, and it avoids squatting useful names like I just don’t have a great idea how to extend that to |
@nomeata I considered this option. It will dramatically increase the number of symbols in the |
@nomeata Yes, this is another issue with the thunk approach. |
It is possible as a backward compatibility option.
It seems only the |
We can do it.
Yes, we can run the extra check at declaration time. |
Ah, I didn’t quite catch the first time that If we really want to avoid And maybe it’s actually good to squat the |
@nomeata Please take a look at |
Thanks, I think that's a nice approach now. What is your plan for error reporting? Can the delayed action log messages and/or throw exceptions, and will they be passes to the user in a helpful way? Is it the responsibility of the action to prepend the message with something like “Failed to create |
@nomeata Right now it is marked as a TODO in the code. I still need to try a few experiments. |
I was struggling with this in Aesop, so I love this PR! Once it lands, will there be an expectation that tactics may realise declarations with reserved names, but may not otherwise add new declarations? And will there be a way to efficiently determine which declarations were realised by a tactic? |
It sounds reasonable, but we are not enforcing this expectation.
We are currently not tracking this information, but we could track all names realized so far in an environment extension. |
And all other related functions.
TODO: check whether reserved names are available at declaration time.
5a5680f
to
5adf19c
Compare
Okay. I'll require that Aesop rules satisfy this expectation and that's going to be fine in practice.
This would be useful. To check whether an Aesop rule modified the environment, I currently have to compare the environment's |
Would |
That doesn't really help in this case since the theorem in question matches the naming convention (it is a theorem). That's not a bad thing insofar as we want the things lean generates to not be too different, but we also don't want to name-squat things the user wants to use or is already using. |
@digama0 Agreed. The idea was that a single world reserved identifier like |
See next test for examples.