lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

feat: accept user-defined options on the cmdline

Open Kha opened this issue 1 year ago • 11 comments

Initial options are now re-parsed and validated after importing. Cmdline option assignments prefixed with weak. are silently discarded if the option name without the prefix does not exist.

Fixes #3403

Kha avatar Jul 14 '24 15:07 Kha

Mathlib CI status (docs):

Should this also adjust LeanOptions?

mhuisi avatar Jul 18 '24 07:07 mhuisi

I think it would be useful to be able to set options that are ignored if not declared in the imports. For example, suppose we want to set an option project-wide which is defined in the project itself (e.g. a mathlib linter which is supposed to only take effect in mathlib itself). In this case the file which defines the option and any files that don't import this file will have to be special cased by lake in order to avoid passing the option to these files and getting the unknown option error. This also mimics the behavior of -D flags in C or environment variables - just let the options pass if you don't recognize them.

Alternatively, this could be another type of "weak" option flag, which could be used when this is specifically the intent, and leave the default to check options eagerly.

digama0 avatar Jul 20 '24 05:07 digama0

@digama0 We do believe that moving Mathlib's linters into a separate library (in the same repo) is achievable and independently valuable (for downstream users as well). This is likely true for other projects as well, though I don't want to exclude the possibility of adding some weak option support further down the road if the benefit is clear.

Kha avatar Jul 25 '24 09:07 Kha

Should this also adjust LeanOptions?

@mhuisi We do not currently check the existence of options from setup-file at all, is that correct? Then making the server consistent with the cmdline sounds like a good follow-up change to me. This PR as is at least should not be able to break anything, so I'd like to see it in the next RC.

Kha avatar Jul 25 '24 10:07 Kha

Should this also adjust LeanOptions?

@mhuisi We do not currently check the existence of options from setup-file at all, is that correct? Then making the server consistent with the cmdline sounds like a good follow-up change to me. This PR as is at least should not be able to break anything, so I'd like to see it in the next RC.

Yes, I think you are correct.

mhuisi avatar Jul 25 '24 10:07 mhuisi

@digama0 We do believe that moving Mathlib's linters into a separate library (in the same repo) is achievable and independently valuable (for downstream users as well). This is likely true for other projects as well, though I don't want to exclude the possibility of adding some weak option support further down the road if the benefit is clear.

Even if we did move all mathlib linters into a separate lean_lib (which I agree can be justified by other means than having to work around lean limitations), it wouldn't solve the problem unless we imported the entirety of this lib in every mathlib file, which is a technique we are trying to move away from because it leads to import bloat. This is especially true if some linter involves a reference to some nontrivial part of mathlib, so I think it would end up just limiting our ability to build and deploy these linters.

digama0 avatar Jul 25 '24 13:07 digama0

Would it work to have a very small library mathlib_flags with possibly just a single file that just declares the options? Not the most elegant of setups, but maybe a good compromise – after being told that you misspelt an options is a worthwhile feature?

nomeata avatar Jul 26 '24 06:07 nomeata

That sounds like an okay compromise but at least it doesn't make additional support for weak options appear unreasonable. Added.

Kha avatar Jul 26 '24 08:07 Kha

@Kha While I very much like the notion of "weak" options here, I am worried about having two different notions of weakness between Lake and Lean. "weak" in Lake means not included in the trace. Since since options are part of the trace, that notion of weakness could applied here. Therefore, could I bike-shed for perhaps using "try" instead of "weak" as the prefix for these options? (Alternatively we could come up with another word for Lake's notion, but it seems easier to change this than that.)

tydeu avatar Jul 26 '24 16:07 tydeu

local. maybe, as in “locally in this package defined option”?

nomeata avatar Jul 26 '24 17:07 nomeata

Or perhaps checked vs unchecked options?

david-christiansen avatar Jul 29 '24 05:07 david-christiansen

Collecting possible prefixes as an alternative to weak:

  • user
  • local
  • unchecked
  • deferred
  • flex
  • lazy

Maybe in the end weak is the best of these, because validation is only done weakly. It's not user or local since it can be applied to builtin options, it's not completely unchecked since if the option exists its value does get checked, and it's not deferred or lazy since using weak turns off existence checking. The only remaining alternative is flex, as a synonym for "lenient" or "relaxed".

kmill avatar Jul 31 '24 18:07 kmill

@kmill A rather verbose alternatively would be an unrequired option (or, funnily, an optional option ).

tydeu avatar Jul 31 '24 23:07 tydeu