Zulip Chat Archive

Stream: general

Topic: Stop compiler at first error?


David Loeffler (May 02 2023 at 00:46):

Is there a way to compile a single file (like "lean --make") but stopping at the first sign of an error, rather than continuing with the compilation through to the end of the file?

Scott Morrison (May 02 2023 at 00:49):

I don't think so. Perhaps it might be possible to read stderr and abort if you can read anything from it??

Eric Wieser (May 02 2023 at 00:55):

I think we do this in CI?

Eric Wieser (May 02 2023 at 00:56):

https://github.com/leanprover-community/mathlib/blob/master/scripts/detect_errors.py#L40

Adam Topaz (May 02 2023 at 00:56):

Indeed env LEAN_ABORT_ON_PANIC=1 lake build

Adam Topaz (May 02 2023 at 00:58):

(For lean4, that is)

David Loeffler (May 02 2023 at 00:59):

Adam Topaz said:

Indeed env LEAN_ABORT_ON_PANIC=1 lake build

Good to know this exists in lean4. The context is that I'm hacking together a script to detect unnecessary import statements, because flattening the import hierarchy will make life easier during the porting process. So applying it to mathlib4 is not useful (yet).

David Loeffler (May 02 2023 at 01:01):

(We already have leanproject reduce-imports but that only detects import statements in the transitive closure of other imports. I want to detect imports that do actually have an effect, but where the stuff that's ipmorted doesn't get used.)

Adam Topaz (May 02 2023 at 01:06):

For lean3 it seems you have to do what Scott suggests using the script Eric mentioned. You can take a look at how mathlib3 CI does this.

Eric Wieser (May 02 2023 at 01:09):

David Loeffler said:

I want to detect imports that do actually have an effect, but where the stuff that's ipmorted doesn't get used.

I assume you're aware that the graphs in #mathlib4 > port progress (but not the ones on #port-dashboard) already do this?

Eric Wieser (May 02 2023 at 01:11):

because flattening the import hierarchy will make life easier during the porting process.

I'm not sure how true this is; while it might mean some files can be ported sooner, it won't have much effect on the overall speed of porting all of mathlib, as we're far beyond the bottleneck now

Eric Wieser (May 02 2023 at 01:11):

Where it might help is that fewer imports mean faster simp calls due to fewer available lemmas

Eric Wieser (May 02 2023 at 01:12):

But I think most of our timeout problems are caused by unreasonably nasty unification problems related to typeclasses, not large simp lemma sets

Eric Wieser (May 02 2023 at 01:13):

That said, the tool you're describing does still sound useful to have in the long run :)

Mario Carneiro (May 02 2023 at 01:13):

is that actually observed in lean 4? The way discrimination tree indexing works means that it is almost completely indifferent to having more lemmas in the simp set

Mario Carneiro (May 02 2023 at 01:13):

although a larger simp set does mean more initialization time at import

David Loeffler (May 02 2023 at 01:14):

Eric Wieser said:

David Loeffler said:

I want to detect imports that do actually have an effect, but where the stuff that's imported doesn't get used.

I assume you're aware that the graphs in #mathlib4 > port progress (but not the ones on #port-dashboard) already do this?

Do they really? I wasn't aware of that. How exactly is this detection done?

Mario Carneiro (May 02 2023 at 01:16):

it checks the declarations in the file to see whether they use any declarations in the target file

David Loeffler (May 02 2023 at 01:21):

Mario Carneiro said:

it checks the declarations in the file to see whether they use any declarations in the target file

I wonder if it might be useful to extract that check and run it as part of the CI test cycle (at some point in the future)

Mario Carneiro (May 02 2023 at 01:25):

It is expensive

Mario Carneiro (May 02 2023 at 01:26):

plus the results are not so easily interpretable as to be usable in a CI check

Adam Topaz (May 02 2023 at 01:30):

Mario, this isn’t really related, but how can I make lean4 emit errors in json?

Eric Wieser (May 02 2023 at 01:30):

Mario Carneiro said:

It is expensive

This is also the reason that #port-dashboard does not attempt this

Adam Topaz (May 02 2023 at 01:30):

The json flag doesn’t exist in lean4 as far as I know

Mario Carneiro (May 02 2023 at 01:32):

that's an open issue IIRC

Mario Carneiro (May 02 2023 at 01:32):

there is no such flag

Eric Wieser (May 02 2023 at 01:32):

Does the flag belong in lake or lean?

Mario Carneiro (May 02 2023 at 01:33):

both?

Eric Wieser (May 02 2023 at 01:33):

Does lake invoke lean as a subprocess, or hook into it directly somehow?

Mario Carneiro (May 02 2023 at 01:33):

lake definitely wants lean to emit json

Mario Carneiro (May 02 2023 at 01:33):

it calls it as a subprocess

Eric Wieser (May 02 2023 at 01:33):

I made a thread about the --json argument, but I don't know if I've seen an issue

Eric Wieser (May 02 2023 at 01:34):

It might be worth tagging that mathport-high-priority, since it means we can get better CI feedback on mathlib4 PRs


Last updated: Dec 20 2023 at 11:08 UTC