-
Notifications
You must be signed in to change notification settings - Fork 197
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
Change Global instances to #[export] #2239
Conversation
Suggests a different approach to managing typeclass instances now that the "export" locality attribute is available
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.
I'm tentatively in favour of this, but would first like to see that it works in practice, by removing Global
(almost?) everywhere in the library, and checking that only a small number of Imports
need to be added. Maybe the best approach is to try it in a few waves. E.g. try it for one folder first, then another, then more if things are going well?
BTW, based on https://coq.inria.fr/doc/V8.20.0/refman/language/core/sections.html#section-mechanism, I think that instances within a section can not be declared Global
, so we shouldn't have any Global Instance
declarations within a section. If I'm right, that means that when testing this, we can simply change all Global Instance
to Instance
.
We have about 2000 global instances in total, broken up by top-level folder like this:
./Algebra: 461
./Analysis: 0
./Axioms: 0
./Basics: 53
./Categories: 100
./Classes: 406
./Colimits: 22
./Cubical: 3
./Diagrams: 12
./Equiv: 5
./HIT: 8
./Homotopy: 133
./Limits: 4
./Metatheory: 4
./Misc: 1
./Modalities: 110
./Pointed: 57
./PropResizing: 0
./Sets: 21
./Spaces: 165
./Spectra: 0
./Tactics: 20
./Truncations: 17
./Types: 104
./Universes: 59
./WildCat: 250
In this series of commits I remove all the global instances from some of the folders to see how much maintenance is required. I think the documentation you're citing is either incorrect or we are misinterpreting it. There are many The kind of maintenance I had to do was:
To elaborate on (2.), if So you have typeclass searches which were quick before but now take a very long time, or go down a dead end. Most of these can be fixed by setting the typeclass search depth to something lower or annotating terms with more explicit detail. |
@patrick-nicodemus Thanks for tackling this! I haven't looked closely yet, but have a few comments/questions.
Does the library build after each commit? For example, the first new commit removes global instances from Basics, and only two other changes are made. If the library builds with just those two changes, that's great news.
Oh, that's annoying. It's hard to see how to handle that automatically. I guess you could try to do it based on indentation. Replace
That's to be expected. Another possible solution is to change
Couldn't you just change
It would be good if not many such changes were needed. If a quick fix involving the import order (or using But longer-term, we should try to avoid situations where the order of imports affects typeclass search in a meaningful way. I think the real solution is to adjust the priorities of the instances so the more useful ones are tried first. This might be a bit hard to figure out, but is the most robust solution to this issue. So if there are cases in which you can easily tell what instance is being missed, you could give it higher priority. But if it's not easy, a quick fix involving import order (or export) would be fine. |
The library builds after each commit, each one is self contained. Perhaps I should have put the "fixes" in separate commits for readability. |
I have been doing the manual equivalent of this but indenting style is not consistent throughout the library, so this is a very noisy signal for guessing whether you are in a file. |
Yes, it would have been easier to see the fixes if they were in separate commits. (I do like to have the library build after each commit, but that could be achieved by pairwise squashing before merge.) In any case, no need to redo things now. |
I have just skimmed through the commits. Here's my summary of the changes besides removing
(There's also a merge commit, but github seems to just show me the combination of the previous commits, so I'm assuming nothing substantial changed there. I also might have missed one or two things in my skimming, but if so, the diff was small enough to not catch my eye.) So the upshot is that this change affected almost nothing. It's pretty amazing to me that we didn't seem to be relying on the transitive behaviour of The only commit I'm not completely happy with is the WildCat commit, but since only five files were affected, it shouldn't be hard to find a way to get rid of the changes made to those files. We should also check that the build time has not gone up. |
Co-authored-by: Dan Christensen <[email protected]>
@@ -208,12 +208,12 @@ Section MonoidEnriched. | |||
`{!HasMorExt A} `{forall x y, IsHSet (x $-> y)}. | |||
|
|||
Section Monoid. | |||
Context `{!IsMonoidObject _ _ y}. | |||
Context `{!IsMonoidObject (fun a b : A => cat_binprod a b) unit y}. |
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.
I looked into this to see if it could be fixed by rearranging the typeclass database and I would prefer to just be more explicit in some parts. It is an unguided typeclass search where it is looking for a bifunctor structure on an unknown function A -> A -> A
so I think it is better to just supply the underlying function explicitly. (Although granted we at least know the type here, so it is at least partially guided.)
Dan pointed out that the changes in this section are a bit ugly. I have rewritten a lot of this section in the latest commit on the philosophy that more changes to keep things pretty is better than a few ugly changes.
5b2137f
to
0838185
Compare
I have done a timing test and on my machine the time increased by ~1% on this PR. I assume this is considered negligible/within the realm of noise. I was hoping this PR would improve performance somewhat, but mostly I was hoping it would help to debug long loops of |
Yes.
I was hoping for an improvement as well, but like you, I still agree with this PR on principle. |
0838185
to
7459edf
Compare
To me, this is essentially done, except for the minor issue about the |
Can you hardwrap the paragraph in STYLE.md at 70 chars? I had a look through all of the changes and they look good. Thanks for tacking this! This is something we should have done a while back. I have the same comment as Dan on the changes in |
0e9fc1d
to
432410e
Compare
This looks good. I'll merge when the CI is done, unless someone speaks up before then. |
Again @patrick-nicodemus, thanks a lot for tackling this. It's really appreciated. |
@jdchristensen The merged commit removed some 2500 Global Instances. I have gone through and removed the remaining ~1000. There are only two changes:
|
Ah, I misread this commit message: "Removed all 'Global Existing Instances' from the entire library." |
@jdchristensen Yes, that is a silly distinction to make but since I was going by textual search and replace, I removed |
Oh, no worries, the commit message was fine and I just misread it. |
Suggests a different approach to managing typeclass instances now that the "export" locality attribute is available