all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: "João Távora" <joaotavora@gmail.com>
Cc: Richard Stallman <rms@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: How to cause a compiler warning?
Date: Wed, 17 Jan 2024 12:25:22 +0000	[thread overview]
Message-ID: <ZafHMgcbQBVoJaPD@ACM> (raw)
In-Reply-To: <87v87ve9i5.fsf@gmail.com>

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).



  reply	other threads:[~2024-01-17 12:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-14  3:09 How to cause a compiler warning? Richard Stallman
2024-01-14  3:20 ` João Távora
2024-01-14 13:01   ` Alan Mackenzie
2024-01-14 15:43     ` João Távora
2024-01-14 16:21       ` Alan Mackenzie
2024-01-15  0:16         ` João Távora
2024-01-17 12:25           ` Alan Mackenzie [this message]
2024-01-17 13:40             ` João Távora
2024-01-18 12:05               ` Alan Mackenzie
2024-01-18 12:26                 ` João Távora
2024-01-14 15:54     ` Ihor Radchenko
2024-01-14 16:26       ` Alan Mackenzie
2024-01-17  3:29         ` Richard Stallman
2024-01-17 11:59           ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZafHMgcbQBVoJaPD@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.