-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add mnemonics for warnings #9657
Conversation
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.
Thanks! I would love to have real names for warnings, especially in local attributes. I can cope with arcane build scripts, but it feels really bad to commit [@@warning "-4"]
in a source file.
High-level remarks:
-
I like your systematic approach to naming, but I noticed a fair amount of typos in the actual strings. We have to be careful here. In particular, if a release goes out with the bad name, it could be fairly annoying for compatibility.
-
I was surprised to see that you introduced new flags. I am fine with the new flags, but maybe there could be also an approach for people using
-w
as before? For example, maybe we could single-quote or parenthesize warning names in this context. (I suppose that not using any form of quoting is problematic as-
is ambiguous, but then a longest-match rule would also deal with this just fine.) -
I have long thought about turning warnings into a sigma-type, with one GADT for the warning name (indexed over the payload type), so that we could manipulate warning names in a more convenient way. Would you be interested in a preparatory PR doing this?
utils/warnings.ml
Outdated
| Assignment_to_non_mutable_value -> "assignment-to-non-mutable-value" | ||
| Unused_module _ -> "unused-module" | ||
| Unboxable_type_in_prim_decl _ -> "unboxable-type-in-prim-decl" | ||
| Constraint_on_gadt -> "constarint-on-gadt" |
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.
typo here
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.
Thanks, fixed.
utils/warnings.ml
Outdated
| Implicit_public_methods _ -> "implicit-public-methods" | ||
| Unerasable_optional_argument -> "unerasable-optional-argument" | ||
| Undeclared_virtual_method _ -> "undeclared-virtual-method" | ||
| Not_principal _ -> "non-principal" |
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.
the two names are different here
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.
Thanks, fixed.
utils/warnings.ml
Outdated
| All_clauses_guarded -> "all-clauses-guarded" | ||
| Unused_var _ -> "unused-var" | ||
| Unused_var_strict _ -> "unused-var-strict" | ||
| Wildcard_arg_to_constant_constr -> "wildcard-arg-to-constact-constr" |
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.
Typo here
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.
Thanks, fixed.
utils/warnings.ml
Outdated
| Wildcard_arg_to_constant_constr -> "wildcard-arg-to-constact-constr" | ||
| Eol_in_string -> "eol-in-string" | ||
| Duplicate_definitions _ -> "duplicate-definitions" | ||
| Multiple_definition _ -> "multiple-definition" |
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.
This should probably be renamed into definitions
(but in fact the name could be changed completely, maybe Module_name_conflict
or something; for another PR).
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 agree. I hold off to changing this one until the general discussion settles down to avoid polluting the diff.
utils/warnings.ml
Outdated
| Open_shadow_label_constructor _ -> "open-shadow-label-constructor" | ||
| Bad_env_variable _ -> "bad-env-variable" | ||
| Attribute_payload _ -> "attribute-payload" | ||
| Eliminated_optional_arguments _ -> "eliminated-optional-argument" |
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.
arguments
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.
Thanks, fixed.
Indeed. I fixed the ones you pointed out. We could also imagine putting the warning definitions in their own file and generating the names with a script. Is it worth it?
Using names with
I thought about this briefly. If I understand correctly, what we would gain is not having to use dummy values to instantiate warnings, like it is done for |
One important point that I forgot in the issue description: the interaction with alerts. In my view we could use the same flags ( |
After sleeping on it, I changed tack and got rid of the new flags, and simply adapted the existing flag |
BTW, a consequence of the above is that the following now works:
|
Thanks! I didn't dislike your new flags (they are arguably a better interface that could be proposed independently), but I like the idea that we can extend the previous flag with the new feature, and the side-effect that attributes work is particularly nice. |
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 have reviewed the code and I believe it is correct (modulo the bug, see comments). One thing that is remarkable is how non-invasive the patch is; it's really simple.
I am morally approving this PR, because I want to have the feature, but I'm not formally Approving because this deserves a broader discussion with other maintainers¹ and I don't want us to get tempted into merging before.
¹: it's not obvious, but when I have mentioned this feature to other maintainers in the past, I got the feeling that they considered it as a minefield that deserved careful discussion.
utils/warnings.ml
Outdated
| Some n, '-' -> clear n | ||
| Some n, '@' -> set_all n | ||
| _ -> loop 0 | ||
end |
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 believe that this is subtly wrong if we have warnings named foo
and also oo
. You should check s
before rest
.
(Nitpick: I would match on s.[0], name_to_number rest
rather than in the other order, so that source order follows input order.)
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.
Good catch! Fixed.
utils/warnings.ml
Outdated
Unsafe_without_parsing; | ||
Redefining_unit ""; | ||
Unused_open_bang ""; | ||
Unused_functor_parameter "" ] |
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 think that it would be better to use the Objectively Right indentation style here, which is to use a terminator for the last item and the enclosing bracket on the next line, because we are going to keep adding new stuff to this list.
(What happens when we forget ? Could there maybe be a check somewhere that the last warning number is also the last known warning?)
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.
Fixed indentation. To make sure that we are not forgetting anything, one possibility could generate the list all
and the function name
with a script.
Thanks! I also hope other developers will chime in. Do you think it would be too intrusive to cc the |
Let's try! Yo @ocaml/caml-devel, do you have an opinion about adding names for warnings (systematically derived from the constructor name in Warnings.ml)? This is proposed by @nojb, and the implementation is surprisingly simple.
|
I think it's a great idea, and I like the UI. |
@nojb: I foresee changes in warning names in the future, and then we will really want to also keep supporting the older names for compatibility. The current implementation makes it hard to map several names to the same warning number. Do you have an idea? |
Yes, it was possible. I switched to using functions to try to exploit exhaustivity of pattern matching to make sure we have defined description, names, etc. for every warning. But of course I just pushed the problem over to the definition of No problem from me to switch back to keeping a list of triples @Armael @gasche do you agree to switch to a list of triples |
Yes, I'm also happy with this proposed approach. |
I pushed a commit with this change. One downside of it is that we lose the proximity in the program text between the warning name and the constructor, so it becomes harder to check that the warning name corresponds to the constructor (keeping this proximity was one of the reasons for my initial approach in fact). |
My only issue is that the current constructor names (assuming you haven't changed them) are not good names. For example, I bet anyone writing |
This sounds reasonable indeed! |
No, I haven't changed them. I will happily do the adaptation of the code if someone is willing to the assessment (I don't feel like I would do a very good job at it myself). |
Nicolás Ojeda Bär (2020/06/11 22:04 -0700):
> @Armael @gasche do you agree to switch to a list of triples `(warning number, warning names, warning description) : int * string list * string`? If yes, I will update the PR.
I pushed a commit with this change. One downside of it is that we lose
the proximity in the program text between the warning name and the
constructor, so it becomes harder to check that the warning name
corresponds to the constructor (keeping this proximity was one of the
reasons for my initial approach in fact).
I'm wondering about deprecation. Among the warning names, do we want to
have a way to distinguish the deprecated ones, which might trigger a
deprecation message, from the other ones?
If each warning has only one official name, then the convention could be
that this official name is the head of the list and that the deprecated
equivalents are in the tail of the list.
|
To help the task, I generated this table with the current names. Those interested may edit this issue directly (please do not delete the previous constructor name, but rather use
|
Note: with a list of names for each warning, we have the option to not offer names for some warnings if we don't agree on a good name. So we could keep @nojb's implementation work, but start with only a handful of names that people like, and keep numbers-only for some warnings. (I'm not sure I like the idea myself. The general point is that there is a risk we diverge in complete bike-shedding land rather soon, and ways to make incremental progress before we like all the names could be helpful.) |
Gabriel Scherer (2020/06/12 02:19 -0700):
Note: with a list of names for each warning, we have the option to *not* offer names for some warnings if we don't agree on a good name. So we could keep @nojb's implementation work, but start with only a handful of names that people like, and keep numbers-only for some warnings.
(I'm not sure I like the idea myself. The general point is that there
is a risk we diverge in complete bike-shedding land rather soon, and
ways to make incremental progress *before* we like all the names could
be helpful.)
Well it feels odd to me too in terms of user experience to provide names
for some warnings and not for otehrs, although I also understand very
well the risk there is in waiting that we never agree.
… |
Personnally, I think that this an excellent idea. I will try to make few name suggestion later today. |
One thing one might consider when adding names to warnings is to add a logic similar to the one of gcc concerning unknown warnings:
|
Where are we for this PR? The discussion seems to have died without falling in endless bikeshedding. Does this mean that all names are consensual enough, even |
Good question. My feeling is that the systematic assessment that @lpw25 suggested (and @fpottier seconded) has not taken place yet. @gasche had suggested starting with only naming a subset of warnings, but I don't think that is a good idea: users will then resist using names for warnings that were not in the initial set in order to be as compatible as possible, which will defeat the purpose of the patch. I am not really sure how to proceed here... |
My systematic assessment is that the proposed names are serviceable. I can write down my evaluation if it would help. |
Meetings? Yuck. I propose to go ahead based on the systematic review of @Octachron. If @nojb is willing to update the warning constructor names to follow the current proposal, that part of the PR is good to go. We pinged all maintainers already, and interested people had more than enough time to voice concerns if they have some. The part that needs review is the overall implementation (I remember looking at it and being fine with it, but I don't remember the details), and especially ensuring that we have enough mechanisms to evolve gracefully when we (1) add new warnings (maybe we should implement @bschommer's suggestion for example) and (2) rename an existing warning (the old name should still be recognized for compatibility reasons). |
I rebased the PR on |
I believe that the two proposals are mostly identical, except that (1) alert payload don't currently allow spaces, they probably should for readability for the same reasons and (2) you propose to forbid Extra remarks:
|
Do I understand correctly that this is another new feature in 4.12 that was merged 6 months ago and is being redesigned at the last minute and will therefore have to be pulled out the 4.12 beta urgently? What does this says about our design process? |
To clarify: most of the feature is fine, the problem is with the current support in |
We have an user interface that is lacking a natural extension due to backward compatibility constraints. It is far too late to add any extension to the user interface at this point of the release cycle, without even mentioning breaking backward compatibility. If the attribute warning cannot support list of named warnings, would it not be simpler to add a |
For me the problem is not so much that passing several warnings is not supported, it is that Also, I am not convinced by the "this is too late in the release cycle" argument. If we don't fix the issue now, users are going to get confused by it down the line, and they will open issues and ask us to fix it. "After the release" is actually later than today in the release cycle, and it will be orders-of-magnitude more costly in terms of total work. (I don't want to be sensationalist, this is an issue about warning attributes; but note that giving an easy way to mistakenly disable all warnings is a believable bug-inclusion vector). We should fix it now. As to "why wasn't it caught before?", I suppose that it is the kind of issues that is hard to catch without dogfooding. |
Another way to say things is: I am a user of 4.12~alpha and I am reporting a problematic usability bug. I don't believe that "it is too late in the release cycle to fix this issue" is an appropriate response. |
It does not make sense to not open an issue indeed. And if we can find a fix that alleviates the issue, does not break backward compatibility, and is consensual; then it makes sense to integrate it. The issue merely does not seem acute enough to break backward compatibility in a hurry or to block the release if a satisfying design seems out of reach. |
I was not only suggesting to use the same syntax, but even the same command-line options and attributes (only for warning mnemonics). The -w/-warn-error options and corresponding attributes would be for (legacy) numeric/single-letter; and the alert-related options/attributes would be for named warnings. |
The core of my proposal is to deprecate just-a-letter warning specifiers. This does not break backward-compatibility. If you write |
@alainfrisch so you propose to un-support |
Alerts and warnings have a quite different semantic nowadays. Mixing the two seems confusing since the reader needs to guess which alerts in Deprecation is very much a backward compatibility issue right now with dune default settings. And the issue might be even more problematic if we mix meta-level deprecation alerts with the usual deprecation alerts. For instance, how do I disable globally on a project these warning deprecation alerts? |
We could get a sense of whether anyone is actually affected (uses just-a-letter warning specifiers) by implementing the warning and checking the opam-repository. Should we?
In an imaginary world where this feature is implemented, you would need to disable warning 3, so either you change your build system to pass |
But then I am disabling all the useful deprecation warnings when I only wanted to remove the warning for [@@@warning "@imported-from-the-future"] |
Yes, but you only need to do this as a stopgap measure until you fix your just-a-letter warning specifiers to use a |
Which semantics difference do you see between alerts and warnings? It's already the case that warning 3 is actually mapped to an alert.
That's right, but this also applies to alerts that could be added to the stdlib (or to specific language features). |
Since alerts are currently a quite specific kind of warnings (compiler messages?), after seeing |
I can't belive this conversation died without reaching a conclusion. I agree with @gasche that the long-term solution is to deprecate the single-letter syntax, but we can't rush such a change and repeat the As a stop-gap measure, I propose that we warn when the single-letter syntax seems to be used, but the set of letters contains either a repeated letter or 'a' along with some other letter(s). Since these combinations are redundant, they are unlikely to be used in the wild. On the other hand, all the new warning names (and probably most of their misspellings) are caught by it. |
Alerting on redundant warning letters does seem like a good starting point since it matches the current interpretation. |
Apologies (I'm sure you didn't mean it as criticism but I wondered about how this happened as well); I think I grow a bit discouraged by the impression of being alone in caring about the issue. I agree with your proposal to warn on redundant warnings as a first step; but I think that our user-interface will not be pleasant until we decide to stop considering only-a-letter specifications as things user should write. But: I think that deprecating only-a-letter specifiers is not a Pervasives-deprecation-like situation. The big difference is that there is a backward-compatible fix to silence the warning, which is to use |
You're right. But I'm still worried about annoying every dune user out there. |
Does dune use just-a-letter specifications in its default warnings? |
I think therefore Dune users would be affected the same as any other - manually-specified warnings flags would be caught by any deprecation. |
Rereading the issue, I am perfectly fine with deprecating single-letter with a specific alert ( On the issue of having multiple named warning by arguments, I think it would clearer to have a distinct separator (space or comma?) rather than a longest-match specification with the aim to make parsing independent from the list of known warnings. |
Let's start by implementing the |
Ok, let me do that. |
continued in #10207 |
This PR proposes to add easier-to-remember names for warnings as an alternative to numeric IDs.
I derived the names mechanically from the warning constructor name; for simplicity I would suggest this always be the case, so that if a name needs to be tweaked, then the constructor name should be changed accordingly. (NB: what follows is the description of the final design, the original description can be found further below).
For the CLI, the
-w
flag is extended to take a single name in the form:respectively to enable, disable, or enable as fatal error the given named warning. For example,
enables
unused-value-declaration
(warning 32) and disablesunused-open
(warning 33). The names for each warning are can be found in the output of-warn-help
, in the manual, and when a warning is displayed by the compiler, eg:or, in the case of fatal warnings:
Using a name to specify a single warning can be used anywhere where a warning specification list is expected, eg:
Old description (so that the discussion below makes sense)
For the CLI, I used two new flags,
-W <name>
(to enable a warning by name) and-Wno <name>
(to disable a warning by name). For example,enables
unused-value-declaration
(warning 32) and disablesunused-open
(warning 33). The names for each warning are displayed when using-warn-help
.Similarly, the flags
-Werror <name>
and-Wno-error <name>
can be used to toggle warning<name>
into an error.Next step is to allow its use when using the
[@@ocaml.warning ...]
attribute, but wanted to put this out there in order to make sure there is agreement on the approach.Another possible follow-up is to introduce names for sets of warnings, like
-W all
(similar to-w A
), etc.Closes: #7823