GNU bug report logs - #12299
24.1; no byte compiler warning for inline function call with too few arguments

Previous Next

Package: emacs;

Reported by: "Roland Winkler" <winkler <at> gnu.org>

Date: Wed, 29 Aug 2012 02:16:02 UTC

Severity: normal

Tags: confirmed

Found in version 24.1

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12299 in the body.
You can then email your comments to 12299 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Wed, 29 Aug 2012 02:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Roland Winkler" <winkler <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 29 Aug 2012 02:16:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Roland Winkler" <winkler <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1; no byte compiler warning for inline function call with too few
	arguments
Date: Tue, 28 Aug 2012 21:14:06 -0500
cat > foo.el << EOF
(defsubst foo (a b))
(foo t)
EOF

Byte-compile the above file. The Emacs 24.1 byte compiler does not
complain that the inline function foo is called with too few arguments.
Emacs 23.1 complains

  foo.el:2:1:Warning: attempt to open-code `anonymous lambda' with
    too few arguments

till it aborts with

  foo.el:2:1:Error: Variable binding depth exceeds max-specpdl-size

which I do not find very appropriate either.


In GNU Emacs 24.1.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
 of 2012-06-10 on regnitz
Windowing system distributor `The X.Org Foundation', version 11.0.10706000




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 16 Aug 2019 22:48:01 GMT) Full text and rfc822 format available.

Message #8 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: "Roland Winkler" <winkler <at> gnu.org>
Cc: 12299 <at> debbugs.gnu.org
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments
Date: Fri, 16 Aug 2019 15:46:52 -0700
"Roland Winkler" <winkler <at> gnu.org> writes:

> cat > foo.el << EOF
> (defsubst foo (a b))
> (foo t)
> EOF
>
> Byte-compile the above file. The Emacs 24.1 byte compiler does not
> complain that the inline function foo is called with too few arguments.

I can confirm that this bug is still present in Emacs 27, but it's weird
that this hasn't come up more often.  I mean, defsubsts are commonly
used, and not having byte compilation warnings about the wrong number of
arguments is something you'd expect to come up more often.

> Emacs 23.1 complains
>
>   foo.el:2:1:Warning: attempt to open-code `anonymous lambda' with
>     too few arguments
>
> till it aborts with
>
>   foo.el:2:1:Error: Variable binding depth exceeds max-specpdl-size
>
> which I do not find very appropriate either.

Nope.

I tried briefly to follow the logic in the stuff that'd give a "attempt
to open-code", but it doesn't seem to be triggered at all in this case.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) confirmed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 16 Aug 2019 22:48:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Thu, 15 Jul 2021 20:31:02 GMT) Full text and rfc822 format available.

Message #13 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: "Roland Winkler" <winkler <at> gnu.org>
Cc: 12299 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments
Date: Thu, 15 Jul 2021 22:29:51 +0200
"Roland Winkler" <winkler <at> gnu.org> writes:

> cat > foo.el << EOF
> (defsubst foo (a b))
> (foo t)
> EOF
>
> Byte-compile the above file. The Emacs 24.1 byte compiler does not
> complain that the inline function foo is called with too few arguments.

This is still the case in Emacs 28, which is pretty surprising.  (Both
when doing dynamic and lexical compilation.)

I've added Stefan to the CCs -- perhaps he has some comments here.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 16 Jul 2021 15:41:02 GMT) Full text and rfc822 format available.

Message #16 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 12299 <at> debbugs.gnu.org, Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments
Date: Fri, 16 Jul 2021 11:39:46 -0400
Lars Ingebrigtsen [2021-07-15 22:29:51] wrote:
> "Roland Winkler" <winkler <at> gnu.org> writes:
>> cat > foo.el << EOF
>> (defsubst foo (a b))
>> (foo t)
>> EOF
>>
>> Byte-compile the above file. The Emacs 24.1 byte compiler does not
>> complain that the inline function foo is called with too few arguments.
> This is still the case in Emacs 28, which is pretty surprising.  (Both
> when doing dynamic and lexical compilation.)
> I've added Stefan to the CCs -- perhaps he has some comments here.

No particular comments, no.  IIRC this part of the byte compiler is just
not making efforts to detect such errors, indeed.
It's probably not hard to fix.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Sat, 17 Jul 2021 14:05:02 GMT) Full text and rfc822 format available.

Message #19 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 12299 <at> debbugs.gnu.org, Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments
Date: Sat, 17 Jul 2021 16:04:49 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> No particular comments, no.  IIRC this part of the byte compiler is just
> not making efforts to detect such errors, indeed.
> It's probably not hard to fix.

Right.  Well, let's hope that somebody feels up to poking at this
problem.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Thu, 22 Jul 2021 13:16:02 GMT) Full text and rfc822 format available.

Message #22 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Roland Winkler <winkler <at> gnu.org>, 12299 <at> debbugs.gnu.org
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Thu, 22 Jul 2021 15:14:55 +0200
[Message part 1 (text/plain, inline)]
Would this patch do?
For some reason that I haven't investigated, the usual warning-suppression mechanisms seem ineffective for these warnings. I'm probably doing something wrong. Even so, it's better to have arity checks that cannot be disabled than none at all.

[0001-Warn-about-arity-errors-in-inlining-calls-bug-12299.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 23 Jul 2021 11:10:01 GMT) Full text and rfc822 format available.

Message #25 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 12299 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Fri, 23 Jul 2021 13:09:46 +0200
Mattias Engdegård <mattiase <at> acm.org> writes:

> Would this patch do?
> For some reason that I haven't investigated, the usual
> warning-suppression mechanisms seem ineffective for these
> warnings. I'm probably doing something wrong. Even so, it's better to
> have arity checks that cannot be disabled than none at all.

Yes, we can fix up suppression afterwards...

> From cb9d873871eb445ad18b2a89f3c4ba7e6a4d3ef3 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase <at> acm.org>
> Date: Thu, 22 Jul 2021 15:00:17 +0200
> Subject: [PATCH] Warn about arity errors in inlining calls (bug#12299)

This leads to warnings like:

Warning: Eager macro-expansion skipped due to cycle:
  … => (load "byte-opt.el") => (macroexpand-all (defalias 'byte-decompile-bytecode-1 …)) => (macroexpand (cl-symbol-macrolet …)) => (load "byte-opt.el")

At least initially?  A "make bootstrap" made it go away.

It otherwise seems to work fine for the test example.

I wondered whether this added warning would find errors in the Emacs
tree, so I did a "make bootstrap" after applying the patch, but we
apparently have none of those, which surprised me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 23 Jul 2021 13:19:01 GMT) Full text and rfc822 format available.

Message #28 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 12299 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Fri, 23 Jul 2021 15:18:28 +0200
23 juli 2021 kl. 13.09 skrev Lars Ingebrigtsen <larsi <at> gnus.org>:

> Yes, we can fix up suppression afterwards...

It's not a new problem -- there are plenty of warnings that can be generated during the source-level optimisation and suppressions don't work there right now.

> This leads to warnings like:
> 
> Warning: Eager macro-expansion skipped due to cycle:
>  … => (load "byte-opt.el") => (macroexpand-all (defalias 'byte-decompile-bytecode-1 …)) => (macroexpand (cl-symbol-macrolet …)) => (load "byte-opt.el")

Strange. I never saw anything like that. But if bootstrapping helped you, then I suppose it's fine.

> I wondered whether this added warning would find errors in the Emacs
> tree, so I did a "make bootstrap" after applying the patch, but we
> apparently have none of those, which surprised me.

Yes, I'm disappointed as well. Had hoped for some juicy pay-off, but no.

Thanks for testing it -- pushed to master, slightly simplified (somehow I completely missed the existence of `func-arity`)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 23 Jul 2021 15:03:02 GMT) Full text and rfc822 format available.

Message #31 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 12299 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>,
 Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Fri, 23 Jul 2021 11:02:37 -0400
> diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
> index 341643c7d1..ad9f827171 100644
> --- a/lisp/emacs-lisp/byte-opt.el
> +++ b/lisp/emacs-lisp/byte-opt.el
> @@ -274,6 +274,7 @@ byte-compile-inline-expand
>        ((pred byte-code-function-p)
>         ;; (message "Inlining byte-code for %S!" name)
>         ;; The byte-code will be really inlined in byte-compile-unfold-bcf.
> +       (byte-compile--check-arity-bytecode form fn)
>         `(,fn ,@(cdr form)))

Hmm... wouldn't we want the warning to be emitted if the source code was itself
of the form constructed by `(,fn ,@(cdr form))?
IOW I think we want that `byte-compile--check-arity-bytecode` call to be
elsewhere (in the code that actually compiles the code constructed by
`(,fn ,@(cdr form))).

Also, as a general rule I think we should try and refrain from emitting
warnings from the code in byte-opt.el (warnings should be independent
from optimizations).

> -         `(,(symbol-function name) ,@(cdr form))))
> +         (let ((bc (symbol-function name)))
> +           (byte-compile--check-arity-bytecode form bc)
> +           `(,bc ,@(cdr form)))))

I think the same holds here.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 23 Jul 2021 15:53:01 GMT) Full text and rfc822 format available.

Message #34 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 12299 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>,
 Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Fri, 23 Jul 2021 17:52:41 +0200
23 juli 2021 kl. 17.02 skrev Stefan Monnier <monnier <at> iro.umontreal.ca>:

> Hmm... wouldn't we want the warning to be emitted if the source code was itself
> of the form constructed by `(,fn ,@(cdr form))?

You mean when FN is a bytecode object? Sure, we can do that too. (We currently report an error when there are too many arguments but not too few.) However, it doesn't replace the newly inserted checks, because:

> IOW I think we want that `byte-compile--check-arity-bytecode` call to be
> elsewhere (in the code that actually compiles the code constructed by
> `(,fn ,@(cdr form))).

Tried that first, but then we no longer have the function name so the user sees

 Warning: ‹bytecode gibberish› called with 1 argument but requires 2

> Also, as a general rule I think we should try and refrain from emitting
> warnings from the code in byte-opt.el (warnings should be independent
> from optimizations).

Agree in general but for non-inlined calls we do the arity checks in the codegen, after optimising, and that's too late for inlined calls. We could do it in cconv, but then (a) we may not know the signature or (b) the call could be in dead code.

But this is good to have in mind -- we have a growing list of things to deal with in a compiler reorganisation. There is a lot of history in this code.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12299; Package emacs. (Fri, 23 Jul 2021 16:22:02 GMT) Full text and rfc822 format available.

Message #37 received at 12299 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 12299 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>,
 Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments [PATCH]
Date: Fri, 23 Jul 2021 12:21:28 -0400
>> IOW I think we want that `byte-compile--check-arity-bytecode` call to be
>> elsewhere (in the code that actually compiles the code constructed by
>> `(,fn ,@(cdr form))).
> Tried that first, but then we no longer have the function name so the user sees
>  Warning: ‹bytecode gibberish› called with 1 argument but requires 2

Ah, right, makes sense, thanks,


        Stefan





Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Mon, 06 Dec 2021 23:37:02 GMT) Full text and rfc822 format available.

Notification sent to "Roland Winkler" <winkler <at> gnu.org>:
bug acknowledged by developer. (Mon, 06 Dec 2021 23:37:02 GMT) Full text and rfc822 format available.

Message #42 received at 12299-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 12299-done <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Roland Winkler <winkler <at> gnu.org>
Subject: Re: bug#12299: 24.1; no byte compiler warning for inline function
 call with too few arguments
Date: Tue, 7 Dec 2021 00:36:36 +0100
Mattias Engdegård <mattiase <at> acm.org> writes:

> Thanks for testing it -- pushed to master, slightly simplified
> (somehow I completely missed the existence of `func-arity`)

It seems like this bug was fixed, so I'm closing it now.

commit 109ca1bd00b56ba66b123b505d8c2187fded0ef7
Author: Mattias Engdegård <mattiase <at> acm.org>
Date:   Thu Jul 22 15:00:17 2021 +0200

    Warn about arity errors in inlining calls (bug#12299)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Jan 2022 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 74 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.