From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#58739: Lack of error message about number of args (?native compilation?) Date: Tue, 25 Oct 2022 20:15:38 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5598"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 58739@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 25 22:16:44 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1onQLr-0001Ep-LW for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 Oct 2022 22:16:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onQLL-0001GD-A3; Tue, 25 Oct 2022 16:16:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onQLC-0000Ru-RK for bug-gnu-emacs@gnu.org; Tue, 25 Oct 2022 16:16:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onQLC-0003jL-Ip for bug-gnu-emacs@gnu.org; Tue, 25 Oct 2022 16:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1onQLC-0005MV-4a for bug-gnu-emacs@gnu.org; Tue, 25 Oct 2022 16:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Oct 2022 20:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58739 X-GNU-PR-Package: emacs Original-Received: via spool by 58739-submit@debbugs.gnu.org id=B58739.166672894420584 (code B ref 58739); Tue, 25 Oct 2022 20:16:02 +0000 Original-Received: (at 58739) by debbugs.gnu.org; 25 Oct 2022 20:15:44 +0000 Original-Received: from localhost ([127.0.0.1]:52483 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1onQKt-0005Lw-Hf for submit@debbugs.gnu.org; Tue, 25 Oct 2022 16:15:43 -0400 Original-Received: from mx.sdf.org ([205.166.94.24]:56426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1onQKr-0005Lm-3O for 58739@debbugs.gnu.org; Tue, 25 Oct 2022 16:15:41 -0400 Original-Received: from ma.sdf.org (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 29PKFcWI019884 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Tue, 25 Oct 2022 20:15:38 GMT In-Reply-To: (Alan Mackenzie's message of "Mon, 24 Oct 2022 16:41:25 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246174 Archived-At: Alan Mackenzie writes: > Hello, Andrea. > > On Sun, Oct 23, 2022 at 12:12:49 +0000, Alan Mackenzie wrote: >> Hello, Emacs. > >> Firstly, note that the function desktop-buffer has exactly 12 >> parameters. > >> With an up to date Emacs 29: > >> (i) emacs -Q >> (ii) M-x load-library RET desktop RET. >> (iii) M-x disassemble RET desktop-buffer. > >> Note that this is native code. > >> (iv) M-: (desktop-buffer 1 2 3 4 5 6 7 8 9 10 11 12 13) RET > >> This gives an error message about 4 not being a list. What it ought to >> do is instead throw an error about the number of arguments. This is a >> bug. > >> (v) M-x load-file RET /path/to/emacs/lisp/desktop.elc. >> (vi) M-x disassemble RET desktop-buffer. > >> Note that we now have byte compiled code. > >> (vii) M-: (desktop-buffer 1 2 3 4 5 6 7 8 9 10 11 12 13) RET > >> We now get a correct error message about the numbere of arguments. > >> As a matter of interest, I noticed this bug while byte-compiling >> desktop.el inside Emacs. It gave a warning message about the number of >> parameters to desktop-buffer having changed from 12+ to 12. > >> Here, I suspect there's a bug in the native compilation of >> desktop-buffer. > > The problem here is that (func-arity 'desktop-buffer) returns (12 . 12) on a > byte compiled desktop.elc, but (12 . many) on the corresponding .eln file. > This (12 . many) must be regarded as a bug, since there are no &rest > parameters in desktop-buffer. > > I propose a minor amendment to the definition of MANY, such that it will > mean "there are &rest parameters", rather than "the calling convention > is with nargs + *args". I have implemented this, and my patch is below. > > What I want to ask you to check is that in the native compiler, when > declare_imported_func encounters a function with, say, exactly 12 > arguments, it will throw an error. I think this is actually correct, > since the compiler cannot know whether this function uses the subr > calling convention of nargs + *args, or the byte coded convention of > pushing the 12 arguments individually onto the stack. Is throwing this > error a good idea? Hi Alan, to me this fix looks like a good idea (assuming changing the definition of MANY is acceptable). I think also that throwing the error in 'declare_imported_func' is okay at this point. Just two small nits (forgive me please :) : > Thanks! > > Here's my proposed patch: [...] > } > + else if (nargs > 8) > + /* The calling convention for a function with a fixed number of > + arguments greater than eight is different between a native ^^^ I think this should be aligned with the initial 'The' > + compiled function and a byte compiled function. Thus we > + cannot safely compile it with the native compiler. */ > + signal_error ("Imported function has too many arguments safely to compile natively", I think we should break this string to stay within 78 characters (see CONTRIBUTE). > + subr_sym); > else if (!types) > { > types = SAFE_ALLOCA (nargs * sizeof (* types)); > diff --git a/src/eval.c b/src/eval.c > index 8810136c04..495dbb53b5 100644 > --- a/src/eval.c > +++ b/src/eval.c > @@ -2433,7 +2433,9 @@ eval_sub (Lisp_Object form) > > else if (XSUBR (fun)->max_args == UNEVALLED) > val = (XSUBR (fun)->function.aUNEVALLED) (args_left); > - else if (XSUBR (fun)->max_args == MANY) > + else if (XSUBR (fun)->max_args == MANY > + || XSUBR (fun)->max_args > 8) > + > { > /* Pass a vector of evaluated arguments. */ > Lisp_Object *vals; > @@ -2996,7 +2998,8 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) Likewise > if (numargs >= subr->min_args) > { > /* Conforming call to finite-arity subr. */ > - if (numargs <= subr->max_args) > + if (numargs <= subr->max_args > + && subr->max_args <= 8) > { > Lisp_Object argbuf[8]; > Lisp_Object *a; > @@ -3032,15 +3035,13 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) Likewise > return subr->function.a8 (a[0], a[1], a[2], a[3], a[4], a[5], > a[6], a[7]); [...] Thanks for the patch! Andrea