Zulip Chat Archive

Stream: mathlib4

Topic: Alphabetical listing of imports


Damiano Testa (Aug 23 2023 at 15:14):

Is it something desired/expected that imports be in alphabetical order? I think that this is required for Mathlib.lean and Tactic.lean.

Anne Baanen (Aug 23 2023 at 16:08):

I certainly check for this in my reviews, mostly because I find it neater. More importantly, it makes merge conflicts easier to spot / resolve: if two PRs change the imports then they will agree on the order, so the only different lines are actual changes in the imports, and not reorderings.

Eric Wieser (Aug 23 2023 at 21:05):

Note that changing import order can change behavior

Damiano Testa (Aug 23 2023 at 21:17):

I was giving this a try on branch#adomani/alpha. There is an error in Tactic.Positivity.Core and I wonder if this is what Eric points out or just my script having messed up somewhere.

I'll look into it tomorrow, but the dependence on the order maybe is a signal that alphabetising imports should not be a requirement.

Damiano Testa (Aug 23 2023 at 21:19):

Also, has someone consciously ordered their imports, so as to simplify a proof?

Damiano Testa (Aug 23 2023 at 21:20):

This could be next level golfing: find the global permutation of imports that allows you to shorten the most proofs...

Damiano Testa (Aug 24 2023 at 05:09):

Here is what happens in #6763 for building master (now linting):

  • in Mathlib.Tactic.Positivity.Core I left Mathlib.Tactic.NormNum.Core first, to avoid a timeout;
  • in Mathlib.LinearAlgebra.Charpoly.ToMatrix I bumped a little the heartbeats (the file has 2 direct imports and swapping them did not fix the timeout);
  • in Mathlib.NumberTheory.NumberField.Norm declaration isUnit_norm now builds with
set_option maxHeartbeats 6400000 in  -- via count_heartbeat in
set_option synthInstance.maxHeartbeats 10000000 in -- by hand: timeout with one fewer 0

The sorting of the imports was very crude, so I may have missed sorting "disconnected" imports, but the bulk of the sorting should be done.

As I mentioned, maybe this is not wanted, but, if it is, then the next step would probably be enforcing that new PRs sort their imports and check that the current ones are really all sorted.

Mario Carneiro (Aug 24 2023 at 05:16):

Damiano Testa said:

Also, has someone consciously ordered their imports, so as to simplify a proof?

To simplify a proof? I doubt it, but to avoid something failing I can definitely imagine

Matthew Ballard (Aug 24 2023 at 12:52):

That crazy bump is almost completely due to Subalgebra.toX’s

Damiano Testa (Aug 24 2023 at 12:56):

A different perspective is that it is entirely due to import orders... :upside_down:

Matthew Ballard (Aug 24 2023 at 12:57):

:) but it can’t just be a problem here

Damiano Testa (Aug 24 2023 at 12:58):

Agreed! Anyway, I saw that Alex just ibenched the branch, so we'll get some data!

Matthew Ballard (Aug 24 2023 at 12:59):

I can imagine a fuzzing import order tool ;)

Matthew Ballard (Aug 24 2023 at 13:04):

At quick glance it wants to pull apart the algebra instance on the algebraic closure

Damiano Testa (Aug 24 2023 at 13:47):

The results are in. They look... random to me. If anyone who understands what they really say wants to comment, I'd be happy to learn!

Damiano Testa (Aug 24 2023 at 13:48):

The results are in. They look... random to me. If anyone who understands what they really say wants to comment, I'd be happy to learn!

Alex J. Best (Aug 24 2023 at 14:02):

I think we should expect them to look random. But it would be good to understand

- ~Mathlib.NumberTheory.NumberField.Norm instructions 1423.4%

at least!

Matthew Ballard (Aug 24 2023 at 14:11):

Do we have a linter or anything that reports all uses of a particular instance in a build?

Damiano Testa (Aug 27 2023 at 12:17):

I just re-updated #6763, but maybe there is no interest in doing this.

I personally think that it might be informative to understand

I will stop maintining up to date the PR, but I have a script that alphabetizes the imports, so can recreate it whenever there is interest!


Last updated: Dec 20 2023 at 11:08 UTC