RFC: Introduce the guard/unguard attributes for Fixpoint - #12539
Conversation
|
I'm in favor of this PR (and generally in favor of adding attributes every time it is convenient to locally enable an option). Of course, the usual nitpicking regarding the name of the attribute applies. I'd personally prefer if there was a generic way of specifying boolean attributes such as |
Zimmi48
left a comment
There was a problem hiding this comment.
On a technical note, there is no reason why the attribute should be defined in a central place. Please put the definition in the file where you use it.
|
Thanks for your feedback, @Zimmi48.
Your comment suggests this approach does not yet exist, at least not in the form you’d like it to exist. Do you think this PR is a good occasion to introduce it? Another possibility is for me to implement your naming proposition, but in a more ad-hoc way.
Will do. Thanks! |
Yes, that would make sense. One possible API would be for |
|
I was wondering: maybe What do you think? |
|
Sure, that sounds reasonable. But if we want to mimic the flags as much as possible, it could be |
|
You’re right. My focus was the Will try to implement this this afternoon. Do you think it can find its way to a 8.12 beta, or it will be postponed to 8.13? (it would make a lot of sense if so) |
|
This is definitely 8.13 material. (The beta has already been tagged BTW.) |
Even for the general case, we could consider having a function that declares at the same time, a flag and the corresponding attribute, following standard conventions regarding casing and the replacement of spaces by underscores. |
Zimmi48
left a comment
There was a problem hiding this comment.
Another remark is that your current implementation that sets the flag locally through side-effects is too naive as witnessed by this failing example:
#[ unguard ] Fixpoint tada (x : nat) : nat.
exact (tada (S x)).
Defined.
(*
Error:
Recursive definition of tada is ill-formed.
In environment
tada : nat -> nat
x : nat
Recursive call to tada has principal argument equal to
"S x" instead of a subterm of "x".
Recursive definition is: "fun x : nat => tada (S x)".
*)Instead, you should probably have the attribute passed to the functions constructing the fixpoints, and end up with setting the right typing flags in the environment. But as witnessed by the initial attempt of @SimonBoulier in #9004, it is far from trivial.
I think it is not very hard, we have the infrastructure for it in |
|
Should I wait until #12372 is merged, then? |
I think it is not necessary, tho we may get some small conflicts, but the main strategy can be carried out. So it seems that More generally [@Zimmi48 you did follow the discussion more closely] , what kind of parameters should |
In fact all the ones in #9004 can be added, but indeed it would be more easy to base this PR on top of #12372 , adding a |
|
Since this change would be part of 8.13 rather than 8.12, I think I will subscribe to #12372, wait until it is merged, then start working on this again. Thanks for the feedback, @Zimmi48 and @ejgallego. |
|
Sounds good @lthms , if you wait for that PR most of the changes that will be needed will be in the parsing front, I'm going to add a typing_flags field to the record. |
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
|
It looks like the awaited PR has been merged. (: Congrats @ejgallego! I will take the time to study it and understand how to use the API it introduces/refactors. Do you have any good example of how to do that in mind that I could read? |
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
|
Superseded by #12586 |
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes.
We use the new `Declare.Info` structure to uniformly add properties to the handling of constants. In this case, per-constant typing flags. The internal code may want to see some further refactoring, including pushing the flags down to `Safe_typing.add_constant` , but the changes in the interface should be definitive. This will allow rocq-prover#12539 and rocq-prover#9004 using attributes. (cherry picked from commit b531ef3)
I occasionally run into situation where I am okay with relying on the
Unset Guard Checkingrecent feature of Coq (for utility functions, mostly), but I found the current way of using it cumbersome.This patch adds new attributes to more easily control the feature.
It is a work in progress, in particular I believe the code can be refactor to be made more idiomatic wrt. the rest of the code base.
Overall, this is a RFC. Do you think we can move forward, from this draft to a complete PR?
And, finally, the obligatory snippet to demonstrate the feature.