-
Notifications
You must be signed in to change notification settings - Fork 59
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
Port to MathComp 2 #560
Port to MathComp 2 #560
Conversation
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.
Thank a lot for this PR, I have the impression that a lot of boilerplate are simplified.
I have added some small remarks.
Also what is the level of maturity of mathcomp2 ?
I notice that our code is simplified but except that did you gain other things with this change ? I notice that we need a much recent version of Coq, did we loose something else ?
proofs/arch/arch_extra.v
Outdated
@@ -273,7 +274,7 @@ Variant extended_op := | |||
|
|||
Definition extended_op_beq o1 o2 := | |||
match o1, o2 with | |||
| BaseOp o1, BaseOp o2 => eq_op (T:= prod_eqType _ ceqT_eqType) o1 o2 | |||
| BaseOp o1, BaseOp o2 => @eq_op (_ * ceqT_eqType)%type o1 o2 |
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.
The name T is no longer available, or it is a question of style ?
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.
It's now called s
(for sort
I guess) for all structures, we should maybe change that but this will require some hacking into hierarchy-builder, not sure it's worth it. Anyway, Enrico's solution is much better here:
| BaseOp o1, BaseOp o2 => o1 == o2 :> _ * ceqT_eqType
Definition wpblendw (m : u8) (w1 w2 : word U128) := | ||
let v1 := split_vec U16 w1 in | ||
let v2 := split_vec U16 w2 in | ||
let b := split_vec 1 m in | ||
let r := map3 (λ (b0 : word.word_ringType 0) (v3 v4 : mathcomp.word.word.word U16), if b0 == 1%R then v4 else v3) b v1 v2 in | ||
let r := map3 (λ (b0 : (mathcomp.word.word.word 1 : ringType)) (v3 v4 : mathcomp.word.word.word U16), if b0 == 1%R then v4 else v3) b v1 v2 in |
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.
word.word_ringType 0 is the same than
mathcomp.word.word.word 1 ?
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.
Yes, word.word_ringType 0
was a ring structure on word 0.+1
(which is moral since ring requires 0 != 1
which doesn't hold on empty words), at least this is now much clearer.
@@ -534,7 +527,7 @@ Variant saved_stack := | |||
Definition saved_stack_beq (x y : saved_stack) := | |||
match x, y with | |||
| SavedStackNone, SavedStackNone => true | |||
| SavedStackReg v1, SavedStackReg v2 => v1 == v2 | |||
| (SavedStackReg v1), SavedStackReg v2 => v1 == v2 |
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.
Why parenthesis here?
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.
A nasty parsing error on v1
:
Error: Syntax error: '|' or '=>' expected (in [eqn])
no idea where it comes from.
proofs/lang/memory_model.v
Outdated
@@ -722,7 +722,8 @@ Proof. | |||
have [hle hlt] := wunsigned_range (p - wrepr Uptr sz). | |||
have := Z.mod_le _ _ hle (wsize_size_pos ws). | |||
have := Z_mod_lt (wunsigned (p - wrepr Uptr sz)) (wsize_size ws) ltac:(done). | |||
by Psatz.lia. | |||
move=> [? ?] ?; split; first exact: Zle_minus_le_0. |
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.
Psatz.lia does not work anymore with the change? Or it was very slow ?
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.
lia
was no longer working because we had for some reason both GRing_Zmodule__to__GRing_Nmodule (GRing_ComRing__to__GRing_Zmodule (word Uptr))
and GRing_ComRing__to__GRing_Nmodule (word Uptr)
which are convertible but not syntactically equal, hence not the same variable for lia. Maybe using https://github.com/math-comp/mczify/ would help but not sure since there is a mix of stdlib and mathcomp in those arithmetic expressions.
I pushed a (slightly) better fix for now.
proofs/lang/word.v
Outdated
@@ -2136,6 +2136,7 @@ Proof. | |||
|
|||
rewrite Z.shiftl_mul_pow2; last done. | |||
split; first Psatz.lia. | |||
rewrite /wbase (modulusD 64 64) modulusE -expZE /=. | |||
exact: Zmult_lt_compat_r. | |||
rewrite /wbase (modulusD 64 64) modulusE -expZE. |
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.
This seem much more complicated. What is the motivation for the change ?
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.
The apply: Zmult_lt_compat_r
was no longer working (or terribly slow) I didn't really investigate why. There might be a simpler fix.
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.
Some comments from the coffee room
proofs/lang/memory_model.v
Outdated
by Psatz.lia. | ||
move=> [? ?] ?; split; first exact: Zle_minus_le_0. | ||
by apply: Z.le_lt_trans hlt; apply: (Z.le_sub_nonneg _ _).1. |
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.
Can you explain why this lia does not work anymore?
Do we need algebra-tactics for this to work?
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.
C.f. above #560 (comment)
proofs/arch/arch_extra.v
Outdated
| BaseOp o1, BaseOp o2 => eq_op (T:= prod_eqType _ ceqT_eqType) o1 o2 | ||
| BaseOp o1, BaseOp o2 => @eq_op (_ * ceqT_eqType)%type o1 o2 |
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.
Maybe we could have an Arguments
directive to name the implicit T
(either here or in MC2).
Also putting the argument in type_scope should make the %type unneeded.
But I also wonder if o1 == o2 :> (_ * ceqT_eqType)
would just do it.
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.
We could indeed fix that in MC2, not sure it's worth the effort though.
Your solution here is much better anyway, I kept it.
A number of major reverse dependencies have already been successfully ported: abel, analysis, comp-dec-modal, coqeal, coquelicot, finmap, fourcolor, gaia, graph-theory, interval, mczify, multinomials, odd-order, real-closed, reglang, tarjan and others work with both MC1 and MC2 (basically devs that don't instantiate any structure).
Not much. There are new structures for semirings and semigroups (useful for instance for bigop with min and max when they don't have a neutral element and hence cannot be equipped with a monoid structure) that you may benefit. But honestly, my main motivation was that Jasmin is now among the main unported dev both in nixpkgs and Coq CI so if we want MC2 to be made the default there, this will have to be ported at some point.
Coq >= 8.16, that's indeed one year more recent than 8.14 currently required by Jasmin.
MC2 requires hierarchy-builder, itself requiring coq-elpi to build so the dependency chain is a bit longer. But that's more mathcomp developers' problem than yours. Compilation time and memory use might also be a bit larger: on mathcomp itself and mathcomp Analysis, compilation typically requires 30 to 40% more memory and takes a bit less than 3 times longer, but those are heavy users of elaborate structures, for you use case the impact is probably much less. |
@vbgl please ping me whenever you plan to merge this so that we can avoid breaking Coq's CI too much. |
Sure. Thanks for your help. I’ve just rebased and launched CI. |
The CI machine ran out of memory. Is this just bad luck or the sign of a real regression? |
I think we need to look into it in order to know what happens in this specific case. Sometimes the new layout of structures/classes (that is flat) is a bit worse in terms of term comparison performance. The issue popped up a couple of times in MC. On the good side in MC2 we have a very handy locking mechanism which helps to hide "large terms" behind opaque symbols. |
Coq 8.17.0 is known to have a dramatic memory issue, could you try with another version? |
I did not spot that. If you are with that combo of coq, coq-elpi and HB the perfs are very bad. |
Indeed, apparently it's much better. |
In order to be able to merge jasmin-lang/jasmin#560 without breaking Coq's CI.
How do you know? What’s a good way to measure time & memory consumption of |
Well, it's working whereas it wasn't but I don't know more.
When using coq_makefile, doing |
@vbgl with coq/coq#18402 merged, merging the current PR won't break Coq's CI. |
What’s the meaning of all these new warnings? Should we pay attention to them or just silence them? |
Which one? |
All of them. Here is one, for instance:
|
I was asking because I no longer see any CI result here.
I see, the fact that those warnings are displayed is a bug of HB, they should be ignored, for the record, here is what we have in our _CoqProject for mathcomp:
|
Looks like a Nix issue, you should ask @vbgl I guess. |
The fix is to wait for latest mathcomp to be available in CI. This might take a couple of weeks and require to address #803. |
Sorry, I don't get it, what is the link between the latest mathcomp and this Jasmin bug? |
Updating the CI environment might bring in recent binutils. |
I did look at the other PR, and left a comment. Can we consider this PR unblocked? I mean, it has to wait for CI, but other than that, is it sufficient? Should we put more energy in making it faster before the merge? Knowing that HB.instance will get faster, eventually. |
Rebased and run the measurements again. Total run time: before 11mn, after 14mn. I can no longer find any file with a dramatic increase in cost. |
Ouch:
Why is this so different from Pierre's numbers? I noticed you rolled back to mathcomp 2.1. Does this mean that we really need 2.2? |
I think you are comparing the time to build math-comp 2 vs the time to download math-comp 1. This does not look fair. |
I will, but there is no hurry. |
Rebased on top of recent |
coq-master fails for whatever reason, but the other results are good.
(I'm not sure that I didn't miss some external factor like I did previously, such as caching) |
Note that this very week we are having a sprint to optimize HB.instance, see https://coq.zulipchat.com/#narrow/stream/237868-Hierarchy-Builder-devs-.26-users/topic/Hierarchy.20Builder.20optimization.20sprint I guess we will make a release of HB soon, although I don't know how much you will gain now that the imports are minimized. For sure you won't lose anything ;-) |
Thanks everyone involved for your time on this PR! |
Now that jasmin-lang/jasmin#560 is merged
Now that jasmin-lang/jasmin#560 is merged
Requires jasmin-lang/coqword#22