From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Patch to remove a bit of duplicated code in eval.c Date: Fri, 17 Sep 2021 13:11:48 -0400 Message-ID: References: <87h7ekxkb1.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21327"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Federico Tedin Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 17 19:14:05 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mRHR7-0005JP-FT for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 19:14:05 +0200 Original-Received: from localhost ([::1]:40550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRHR5-0005JR-VA for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 13:14:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRHP2-0002g7-Mb for emacs-devel@gnu.org; Fri, 17 Sep 2021 13:11:57 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:5830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRHOz-0002Wp-Rk for emacs-devel@gnu.org; Fri, 17 Sep 2021 13:11:55 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9C4B6100054; Fri, 17 Sep 2021 13:11:51 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9710F10018B; Fri, 17 Sep 2021 13:11:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1631898709; bh=J7JKJk7HCveMJ4DsEbaOs5t2plbKODYDIFrcHm8O5Bg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=RCG4JGCYDqSfO60whUmTej8yLT3nYmtoA2mm6T59oIJrvbGZnWIKFFdtZNEkQ0S67 trQ5ljdqE5wxpY13cqO+P3jbwhY30nkEi1MOfEsFfXZHuJdKq4Csk+SDYII0SmrVqZ OG0aEW1REyWMvstIXctEYEtya4OvKVrLlkvVBB73q23jbh5dXLQp3eRFn6NUNrOwKC wsNlUikdWpPmR+0blqrFWoTVlKXvD1qKasMG0K8kDRcUd1Xovzoqh0hNNFj+IOysVo YjJs0krsH2Gt560R20iHsEIR6t5u9idh5xLPTGztHSoaa525zRDm2894SGYAeu9nmc yW3QpSinjNoSg== Original-Received: from ceviche (modemcable063.211-21-96.mc.videotron.ca [96.21.211.63]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7B10D12015D; Fri, 17 Sep 2021 13:11:49 -0400 (EDT) In-Reply-To: <87h7ekxkb1.fsf@gmail.com> (Federico Tedin's message of "Thu, 16 Sep 2021 23:49:38 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:274904 Archived-At: > @@ -3081,11 +2978,52 @@ DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, > } > > > +static Lisp_Object > +apply_subr (struct Lisp_Subr *subr, Lisp_Object args, ptrdiff_t count) > +{ I think this definition deserves a comment explaining at least what is `count` (the other two are fairly self-explanatory, but not that one). > + Lisp_Object *arg_vector; > + Lisp_Object tem; > + USE_SAFE_ALLOCA; > + > + ptrdiff_t numargs = list_length (args); > + > + if (subr->max_args != UNEVALLED) > + { > + Lisp_Object args_left = args; > + SAFE_ALLOCA_LISP (arg_vector, numargs); > + > + for (ptrdiff_t i = 0; i < numargs; i++) > + { > + tem = Fcar (args_left); > + args_left = Fcdr(args_left); > + tem = eval_sub(tem); [ Be careful to remember to put a space before the open parens. ] > Lisp_Object > -funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) > +funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args, bool unevalled_ok) > { I'm not very happy with this. Everywhere else in Emacs, the name "funcall" means we're calling a *function* and not a special form. I think we'd be better off keeping `funcall_subr` unchanged and use "something else" when `+apply_subr` needs to handle a special form (aka `UNEVALLED`). That will also make it obvious that the patch does not slow down execution of bytecode at all (which does use `funcall_subr` but not `eval_sub`). > My concerns now are: > 1) Could I have broken anything without realizing it, since this is such > a central function in Lisp code evaluation? Everything seems to be > compiling fine (without warnings) and so far I haven't had any crashes. I haven't looked in enough details to be sure, but in principle it should be OK since it re-uses the well-tested `funcall_subr` code. > 2) I removed a comment that made reference to Bug#21245, but it seems > like it makes sense since the variable it refers to is no longer needed. That removal looks good, thanks. > 3) Have I maybe made Emacs slower by always using SAFE_ALLOCA_LISP for > the subroutine arguments (instead of only for 'max_args=MANY')? It might slightly slow down execution of interpreted code, but interpreted code should not be performance critical (after all, if speed matters, the answer is to byte-compile the code). You can try and measure the slowdown in the following way: rm src/*.pdmp lisp/**/*.elc (cd src; make bootstrap-emacs.pdmp) rm lisp/**/*.elc (cd lisp; time make emacs-lisp/macroexp.elc) The important part is to time the `make emacs-lisp/macroexp.elc`. The three lines before it only serve to get to a state where we have a working Emacs executable with no bytecode at all (so the compilation of `macroexp.el` takes a long while because all the code is interpreted). Stefan