Zulip Chat Archive

Stream: mathlib4

Topic: Auto-implicits


Yaël Dillies (Dec 05 2022 at 16:16):

Is turning off auto-implicits mathlib-wide on the table? I just had a very confusing error because I used npow_rec, which created an auto-implicit called npow_rec, while had they been disabled I wouldn't have spent 15min to see that I meant npowRec.

Mario Carneiro (Dec 05 2022 at 16:17):

@Kevin Buzzard has mentioned that he has as part of his workflow to put a set_option at the top of the file and then remove it when he is done

Mario Carneiro (Dec 05 2022 at 16:18):

I think it is a useful feature and don't want to remove it for new code, but for porting it's generally better to disable auto-implicits

Yaël Dillies (Dec 05 2022 at 16:20):

I would be happy if I could remove it locally without touching code (I don't think asking people to write set_option AutoImplicit False at the top of each file they edit is a viable solution), because I can see this problem repeating over and over again.

Yaël Dillies (Dec 05 2022 at 16:21):

Better error messages would help too. In my case, the error was a cryptic and uninspectable

invalid default value for field, it contains metavariables
  zsmulRec nsmul

Yaël Dillies (Dec 05 2022 at 16:22):

(or rather inspectable, but didn't give me the crucial info)

Mario Carneiro (Dec 05 2022 at 16:22):

mathport could add the set_option line

Mario Carneiro (Dec 05 2022 at 16:22):

I have no idea what you want to do about the error message

Yaël Dillies (Dec 05 2022 at 16:23):

Sure, but that doesn't help with writing new code.

Mario Carneiro (Dec 05 2022 at 16:23):

for new code the option shouldn't be disabled

Marc Huisinga (Dec 05 2022 at 16:23):

Maybe the error message could point it out if auto-implicits are involved?

Mario Carneiro (Dec 05 2022 at 16:23):

that's what I just said above

Yaël Dillies (Dec 05 2022 at 16:23):

Well, I want it disabled for me :stuck_out_tongue_closed_eyes:

Yaël Dillies (Dec 05 2022 at 16:24):

The error message never told me what the metavariable was.

Mario Carneiro (Dec 05 2022 at 16:24):

You can do that by modifying the lakefile

Mario Carneiro (Dec 05 2022 at 16:24):

you can add set_options that apply globally there

Mario Carneiro (Dec 05 2022 at 16:24):

and if you don't push the lakefile changes then you can work with a different set of options than everyone else

Yaël Dillies (Dec 05 2022 at 16:25):

That doesn't really work with my setup, though. I'm working on fresh gitpods every time.

Mario Carneiro (Dec 05 2022 at 16:26):

okay... if you have no personal configuration then I'm not sure how you expect to persist personal changes

Yaël Dillies (Dec 05 2022 at 16:26):

Those auto-implicits definitely break the principle of least surprise, which I why I would like to consider disabling them mathlib-wise, given that mathlib is mostly targeted towards mathematicians.

Mario Carneiro (Dec 05 2022 at 16:27):

I think you just aren't used to them yet. The syntax highlighting is very good for spotting auto-implicits

Yaël Dillies (Dec 05 2022 at 16:27):

Auto-implicits don't show up in #where either, right?

Mario Carneiro (Dec 05 2022 at 16:27):

that wouldn't make any sense?

Yaël Dillies (Dec 05 2022 at 16:28):

Well, variable {f : α → α} now makes sense, so I sure hope my question does make sense.

Mario Carneiro (Dec 05 2022 at 16:29):

I have found that it is much easier to get the types right with auto implicits instead of long-scoped variable lines

Mario Carneiro (Dec 05 2022 at 16:30):

Often you can just avoid needing variable lines at all, and then you don't need to use #where all the time either

Yaël Dillies (Dec 05 2022 at 16:33):

All the files I've structured use long-scoped variable lines, sorted by increasing typeclass assumptions, and very short lemma statements.

Yaël Dillies (Dec 05 2022 at 16:34):

I'm not sure how you would achieve short statements with auto-implicits in topology or algebra.

Mario Carneiro (Dec 05 2022 at 16:35):

It depends on the theorem, but if the statement already implies the necessary typeclass assumptions then you don't need any variable lines

Mario Carneiro (Dec 05 2022 at 16:36):

you just have the same short statement without the variable line

Moritz Doll (Dec 05 2022 at 23:02):

Yael, the experience is completely different between porting existing code and writing new code. At first I thought it was nonsense as well (I have coe being a type), but it is so nice, when you remove all the boilerplate that is just defining types.

Kevin Buzzard (Dec 05 2022 at 23:12):

Yes this autoImplicit thing is very much a porting only technique. It's brilliant not to have to define various variables because the system just guesses them correctly.

Siddhartha Gadgil (Dec 06 2022 at 03:32):

Mario Carneiro said:

You can do that by modifying the lakefile

I did not realise this. I get bitten by auto_implicit often enough that it is probably worth doing this for my code, and even more so for code on which students depend.

Jon Eugster (Dec 06 2022 at 09:39):

Mario Carneiro said:

you can add set_options that apply globally there

I didn't quite get this to work, I just added some lines

set_option autoImplicit false
set_option ...... false

anywhere in the lakefile.lean, but it does not seem like they're globally set. Is there a documentation of that feature?

Alex J. Best (Dec 06 2022 at 10:07):

You can add -D autoImplicit=false as an extra Lean 4 server arg in your vscode settings, this should persist acrosss instances of gitpod if set up properly

Sebastian Ullrich (Dec 06 2022 at 11:44):

We could also (optionally) display auto implicits as LSP inlay hints (specially highlighted text that is not actually part of the editor) as in ... {α} .... Except that as usual the API is not really made for the incremental processing of a theorem prover.

Gabriel Ebner (Jun 19 2023 at 22:11):

FYI, inlay hint requests support ranges and the LSP server can request inlays to be refreshed, so we could send partial results and then update them as the file is process: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#workspace_inlayHint_refresh All of this seems to be implemented in VS Code.

Sebastian Ullrich (Jun 20 2023 at 14:31):

The part that made me hesitate to use the analogous request for semantic highlighting is that it is an unconditional workspace-wide refresh. But I don't think we will know whether that is a performance issue in editors without trying.

Patrick Massot (Jun 20 2023 at 14:32):

Note that semantic highlighting is already brittle in VSCode. Sometimes VScode gets tired of highlighting stuff and needs to be reloaded.


Last updated: Dec 20 2023 at 11:08 UTC