[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to cause a compiler warning?
From: |
Alan Mackenzie |
Subject: |
Re: How to cause a compiler warning? |
Date: |
Wed, 17 Jan 2024 12:25:22 +0000 |
Hello, João.
On Mon, Jan 15, 2024 at 00:16:34 +0000, João Távora wrote:
> Alan Mackenzie <acm@muc.de> writes:
> >> Most assuredly not. This may give an incorrect file position for
> >> the
> >> warning.
> > ...
> >> Since 29.1, the correct function for a warning has been
> >> byte-compile-warn-x.
> >> Self-evidently so, of course, the 'x' standing for "correct".
> > Something like that, yes.
> I've had a better look at the 'byte-compile-warn-x' helper. I think I
> understand what it does, but the docstring leaves to be desired, it says
> the first argument a "source element, likely a symbol with position",
> which is vague and curious nomenclature I've not seen in other Lisps.
ARG can be any Lisp form at all. How would you reformulate the doc
string to make it less vague and curious?
> More importantly, is there always a "source element" to give to
> byte-compile-warn-x? Doesn't it depend on the case?
In practice, there is almost always such a source element, yes. In
those rare cases (I can't think of any at the moment) where there is
not, putting in a nil would work, the source code position then being
taken from byte-compile-form-stack.
> Many macros operate on Lisp forms and sometimes there is some obvious
> good form to hook onto and presumably this form is either is a
> sym-with-pos or has some such symbols inside it. Like this:
> (defmacro fooing (a &rest body)
> (when (eq (car-safe a) 'quote)
> (byte-compile-warn-x a "don't quote me, silly"))
> ...)
> Here, I do agree 'byte-compile-warn-x' is much better than
> 'byte-compile-warn', as Flymake highlights exactly the symbol in that
> position. Great.
> But macros are also just functions and sometimes they need to warn
> because... it's Wednesday or something.
> (defmacro define-foos (howmanyfoos)
> (when (its-wednesday)
> (byte-compile-warn "Beware code compiled on wednesdays!"))
> ...)
Really? Can you point out any such existing macro in the source files
of the byte compiler? You must be aware that warning messages without
source code locations are annoying in the extreme.
> Here, 'byte-compile-warn', which makes the whole 'define-foos'
> highlighted by Flymake is not only perfectly valid but also the only
> viable option.
> So I don't think byte-compiler-warn-x is "most assuredly" the only util
> you should use. If it were, byte-compiler-warn might as well be
> deprecated.
Yes, deprecating byte-compile-warn would be a good thing to do, thanks.
> >> Anyway, what about <29 compatible code?
> > What about it? Richard isn't working on < 29 code at the moment.
> Alright, but since you were so assertive in overriding my suggestion
> with a fairly new util, maybe you could comment on what to do in code
> intended to work in those versions, for the benefit of others.
byte-compile-warn-x is intended for use in the byte compiler. Anybody
doing work there should be sophisticated enough to understand what to
do. In macros which extend the Lisp language, there is
macroexp-warn-and-return, for anybody who can understand it. Do people
actually write such language extensions and expect them to work on old
Emacs versions? There may be, but I'm not aware of any.
> João
--
Alan Mackenzie (Nuremberg, Germany).
- How to cause a compiler warning?, Richard Stallman, 2024/01/13
- Re: How to cause a compiler warning?, João Távora, 2024/01/13
- Re: How to cause a compiler warning?, Alan Mackenzie, 2024/01/14
- Re: How to cause a compiler warning?, João Távora, 2024/01/14
- Re: How to cause a compiler warning?, Alan Mackenzie, 2024/01/14
- Re: How to cause a compiler warning?, João Távora, 2024/01/14
- Re: How to cause a compiler warning?,
Alan Mackenzie <=
- Re: How to cause a compiler warning?, João Távora, 2024/01/17
- Re: How to cause a compiler warning?, Alan Mackenzie, 2024/01/18
- Re: How to cause a compiler warning?, João Távora, 2024/01/18
- Re: How to cause a compiler warning?, Ihor Radchenko, 2024/01/14
- Re: How to cause a compiler warning?, Alan Mackenzie, 2024/01/14
- Re: How to cause a compiler warning?, Richard Stallman, 2024/01/16
- Re: How to cause a compiler warning?, Alan Mackenzie, 2024/01/17