Skip to content
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

Cleanup phantom types #1046

Merged
merged 5 commits into from
Nov 30, 2023
Merged

Cleanup phantom types #1046

merged 5 commits into from
Nov 30, 2023

Conversation

proux01
Copy link
Contributor

@proux01 proux01 commented Jul 4, 2023

Motivation for this change

Cleanup phantom types now that reverse coercions make them useless.

We probably want to wait for 8.18 to be out before merging this, in order to get a better interactive experience with nicer printing.

Things done/to do
  • added corresponding entries in CHANGELOG_UNRELEASED.md
  • added corresponding documentation in the headers
  • tried to abide by the contribution guide
Compatibility with MathComp 1.X
  • I added the label TODO: MC-1 port to make sure someone ports this PR to
    the mathcomp-1 branch or I already opened an issue or PR (please cross reference).
    (while this would be possible, I'm not sure we want to backport that)
Automatic note to reviewers

Read this Checklist and put a milestone if possible.

Overlays (to be merged before the current PR)

@proux01 proux01 added kind: clean-up This issure/PR is about cleaning up obsolete code, removing hacks, etc needs: coq 8.18 labels Jul 4, 2023
@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch from 37390a3 to 498bb9f Compare July 4, 2023 23:18
@CohenCyril
Copy link
Member

I agree for merging this only with 8.18...
Maybe we want to keep the old notations with a deprecation as well?

@proux01
Copy link
Contributor Author

proux01 commented Jul 5, 2023

I agree for merging this only with 8.18...

Note that we should also remove phantoms in HB itself.
I should also benchmarks this to check there is no performance regression (but I'd rather wait for the situation to have stabilized on the Elpi/HB front here).

Maybe we want to keep the old notations with a deprecation as well?

That's what the current PR does, the notations remain as parsing only and are deprecated.

@proux01
Copy link
Contributor Author

proux01 commented Jul 9, 2023

Some benchmarks:

  • Coq without improved printing of reverse coercions (V8.19+alpha aaaf8994b0), mathcomp master (1e6f7e5): 25:43
  • Coq with improved printing of reverse coercions (aaaf8994b0), mathcomp master (1e6f7e5): 27:28
  • Coq with improved printing of reverse coercions (aaaf8994b0), mathcomp this branch (498bb9f): 26:24

(common to all three: coq-elpi coq-master + merge master (8be42fa), HB coq-master + batch-accumulation (6d81cdf))

So there doesn't seem to be any dramatic slowdown.

@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch from 498bb9f to c37f71f Compare July 18, 2023 14:37
@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch from 094f9ca to 91379dd Compare October 3, 2023 09:11
proux01 added a commit to proux01/multinomials that referenced this pull request Oct 5, 2023
This should be backward compatible
@pi8027
Copy link
Member

pi8027 commented Nov 14, 2023

Do you have any blockers in merging this PR? (Just asking because I wanted to do the same for multinomials.)

@proux01
Copy link
Contributor Author

proux01 commented Nov 14, 2023

We were waiting for 8.18 to be out (because printing is only reasonnable since 8.18) but it should be good now, I guess it's just a matter of rebasing and merging, let's discuss this during the next meeting.

proux01 added a commit to coq-community/reglang that referenced this pull request Nov 22, 2023
palmskog pushed a commit to coq-community/reglang that referenced this pull request Nov 22, 2023
proux01 added a commit to proux01/multinomials that referenced this pull request Nov 24, 2023
This should be backward compatible
@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch 2 times, most recently from 9962404 to b51c39c Compare November 27, 2023 13:09
@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch 2 times, most recently from 1e903ad to ddea82e Compare November 28, 2023 09:13
proux01 added a commit to math-comp/odd-order that referenced this pull request Nov 29, 2023
proux01 added a commit to math-comp/odd-order that referenced this pull request Nov 29, 2023
proux01 added a commit to math-comp/odd-order that referenced this pull request Nov 29, 2023
pi8027 added a commit to math-comp/multinomials that referenced this pull request Nov 29, 2023
mathcomp/fingroup/perm.v Outdated Show resolved Hide resolved
@proux01 proux01 force-pushed the hierarchy-builder-rev_coerce branch 2 times, most recently from 365f200 to e4718ec Compare November 29, 2023 14:24
@pi8027
Copy link
Member

pi8027 commented Nov 29, 2023

@proux01 Do you think this PR is ready for review modulo CI? If so, I will try to review it (since I need this PR to be merged before starting #1128).

@proux01
Copy link
Contributor Author

proux01 commented Nov 29, 2023

@pi8027 yes, I'm just fixing the changelog (and waiting for CI) before clicking on Ready for review but it can already be reviewed.

@@ -324,12 +322,13 @@ End UnitsGroup.

Module Import UnitsGroupExports.
Bind Scope group_scope with unit_of.
Arguments unit_of R%type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the presence of reverse coercions, I think it makes sense to do

Bind Scope type_scope with finUnitRingType.

(and the same for every structure whose carrier is a Type).

Then we can get rid of this kind of Arguments declarations (but it can be done in a separate PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, let's do that in another PR.
In fact, we should probably implement this in HB rather than putting Bind Scope manually everywhere. Cc @CohenCyril

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this systematically, the rule of thumb would be that a structure should inherit the Bind Scope declaration from the carrier. For example, a morphism structure should inherit it from its carrier _ -> _ (whose scope is fun(ction)_scope).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are already three cases in HB depending on coercion class of the key (SortClass, FunClass and globref), this should guide the binding (to type_scope, fun_scope and ? respectively).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm taking care of doing this by hand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if the interface for binding scopes exists in coq-elpi, it's probably just as easy to improve HB.

mathcomp/algebra/fraction.v Outdated Show resolved Hide resolved
mathcomp/algebra/poly.v Outdated Show resolved Hide resolved
mathcomp/algebra/qpoly.v Outdated Show resolved Hide resolved
mathcomp/algebra/ssralg.v Outdated Show resolved Hide resolved
mathcomp/algebra/vector.v Outdated Show resolved Hide resolved
mathcomp/solvable/alt.v Outdated Show resolved Hide resolved
mathcomp/ssreflect/finset.v Outdated Show resolved Hide resolved
@proux01 proux01 marked this pull request as ready for review November 29, 2023 15:37
mathcomp/algebra/qpoly.v Outdated Show resolved Hide resolved
mathcomp/algebra/vector.v Show resolved Hide resolved
@@ -1580,7 +1580,7 @@ Definition cfIsom :=
locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)).
Canonical cfIsom_unlockable := [unlockable of cfIsom].

Lemma cfIsomE phi x : x \in G -> cfIsom phi (f x) = phi x.
Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need : finType here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the details but it's needed to keep the type of the lemma unchanged (otherwise, we get x : aT whereas it was x : finGroupType_to_finType aT before removing the phantoms).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange that finGroupType_to_finType is displayed ... we should investigate (we can merge first and investigate later)

mathcomp/field/falgebra.v Outdated Show resolved Hide resolved
mathcomp/field/fieldext.v Outdated Show resolved Hide resolved
mathcomp/algebra/qpoly.v Outdated Show resolved Hide resolved
mathcomp/algebra/ring_quotient.v Outdated Show resolved Hide resolved
mathcomp/ssreflect/order.v Outdated Show resolved Hide resolved
mathcomp/ssreflect/generic_quotient.v Outdated Show resolved Hide resolved
mathcomp/ssreflect/generic_quotient.v Outdated Show resolved Hide resolved
Copy link
Member

@pi8027 pi8027 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions are left (see my review comments above), but any of them can be addressed in a separate PR. So, this PR seems good enough to merge.

@pi8027
Copy link
Member

pi8027 commented Nov 30, 2023

@proux01 @CohenCyril Shall we merge this one?

Copy link
Member

@CohenCyril CohenCyril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@proux01 amazing work, thank you.

@pi8027 pi8027 merged commit 28837b1 into master Nov 30, 2023
149 checks passed
@proux01 proux01 deleted the hierarchy-builder-rev_coerce branch November 30, 2023 15:35
@proux01
Copy link
Contributor Author

proux01 commented Nov 30, 2023

Thanks @pi8027 for the careful review!

@proux01
Copy link
Contributor Author

proux01 commented Nov 30, 2023

Note about the odd-order overlay: math-comp/odd-order#52 it required the addition of a few rewrite patterns, They looked like the usual issue with rewrite not selecting the first occurence, as already encountered when porting MC to HB (for instance with associativity lemmas).

@proux01
Copy link
Contributor Author

proux01 commented Nov 30, 2023

About the CoqEAL overlay: there was some strange exploit of the duplicated phantom canonical instances, this seems to hint to the fact that the dvdRing structure there should be included in the main MC algebraic hierarchy, which would hopefully avoid that terrible hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: clean-up This issure/PR is about cleaning up obsolete code, removing hacks, etc needs: coq 8.18
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants