From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67005: 30.0.50; improve nadivce/comp/trampoline handling Date: Wed, 15 Nov 2023 22:47:21 +0100 Message-ID: <87ttpmwuxi.fsf@sappc2.fritz.box> References: <874jhv9921.fsf@sappc2.fritz.box> <875y24zrt1.fsf@sappc2.fritz.box> Reply-To: Jens Schmidt Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18853"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: andrea corallo , 67005@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 15 22:48:39 2023 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 1r3NkU-0004eE-Q6 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Nov 2023 22:48:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3Njx-0000yk-CF; Wed, 15 Nov 2023 16:48:05 -0500 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 1r3Njv-0000xi-D0 for bug-gnu-emacs@gnu.org; Wed, 15 Nov 2023 16:48:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r3Njv-00030w-4H for bug-gnu-emacs@gnu.org; Wed, 15 Nov 2023 16:48:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r3Nju-0005Tc-Br for bug-gnu-emacs@gnu.org; Wed, 15 Nov 2023 16:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jens Schmidt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Nov 2023 21:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67005 X-GNU-PR-Package: emacs Original-Received: via spool by 67005-submit@debbugs.gnu.org id=B67005.170008486620934 (code B ref 67005); Wed, 15 Nov 2023 21:48:02 +0000 Original-Received: (at 67005) by debbugs.gnu.org; 15 Nov 2023 21:47:46 +0000 Original-Received: from localhost ([127.0.0.1]:54028 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3Njd-0005RW-NI for submit@debbugs.gnu.org; Wed, 15 Nov 2023 16:47:46 -0500 Original-Received: from mr5.vodafonemail.de ([145.253.228.165]:49710) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3NjZ-0005QN-Mm for 67005@debbugs.gnu.org; Wed, 15 Nov 2023 16:47:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-23sep; t=1700084856; bh=Ownvwx0F/KxZULhYmyG0MEZV8almHb7t+N893Ay8ywQ=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=tGrNeCkzc3540Szzy8xprDTsrKvTGKsC5PnMdHpdpb+xuu++sxrS+sMVfacTx10TX EqW/6zxS0eu3qiSt1PusAU8ff2ylytJ6ZxHjqR+aShWEIwMuJa6jEO9Fm4upDIjlMj xx5ehIZ5EoLbTTmXMsqsRh4SFFz8acjW/mSNSHXk= Original-Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr5.vodafonemail.de (Postfix) with ESMTPS id 4SVxbX0YQyz1yJ3; Wed, 15 Nov 2023 21:47:35 +0000 (UTC) Original-Received: from sappc2 (port-83-236-15-179.dynamic.as20676.net [83.236.15.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4SVxbK1X6Sz9s0R; Wed, 15 Nov 2023 21:47:22 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Tue, 14 Nov 2023 19:06:38 -0500") X-purgate-type: clean X-purgate: clean X-purgate-size: 2916 X-purgate-ID: 155817::1700084851-C27FF816-0B1F90E4/0/0 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274421 Archived-At: Stefan Monnier writes: > [...] "Yes, I think you're right" to all your previous statements. > This seems OK: if there's an advice when the code is compiled, there's > a good chance that the advice will also be present when the code is > executed, in which case it's more efficient to use a straight `funcall` > than a "direct" call that gets redirected to `funcall`. Interesting point. I thought a native trampoline would be somehow more efficient than a straight `funcall'. I agree now to your "-1". >> ------------------------- snip ------------------------- >> (defun bar () nil) >> (advice-add 'bar :before 'ignore) >> (native-compile 'bar) >> >> => >> >> comp--native-compile: Native compiler error: bar, "can't native >> compile an already byte-compiled function" >> ------------------------- snip ------------------------- > We could tweak `native-compile` and `byte-compile` so they look through > pieces of advice to try and find the underlying not-yet-compiled > functions, compile them and re-install them where they were found, but > obviously, noone asked for that until now and hence noone bothered to do > that work, most likely because things like (native-compile 'bar) and > (byte-compile 'bar) are operations used extremely rarely. TBH, I think it would be sufficient and nice to throw at least a more meaningful error message along the lines of "(native|byte) compilation of advised functions not supported". Subject to a different bug? >> Another suspectible spot is the following from function `Ffset': >> >> if (!NILP (Vnative_comp_enable_subr_trampolines) >> && SUBRP (function) >> && !SUBR_NATIVE_COMPILEDP (function)) >> CALLN (Ffuncall, Qcomp_subr_trampoline_install, symbol); > > Actually, I don't understand this code now that I re-(re-)*read it. > Why do we negate the SUBR_NATIVE_COMPILEDP (function)? Do you mean "why do we negate it" or "why do we have it at all"? As for the negation, we have SUBR_NATIVE_COMPILEDP (Lisp_Object a) { return SUBRP (a) && !NILP (XSUBR (a)->native_comp_u); } so a condition !NILP (Vnative_comp_enable_subr_trampolines) && SUBRP (function) && SUBR_NATIVE_COMPILEDP (function)) does not make much sense. As for the existence of "!SUBR_NATIVE_COMPILEDP" I'll try an answer, but this is of course again Andrea's domain ... I guess it mirrors the condition (cond ((and subrp (not (subr-native-elisp-p f))) ;; Trampoline removal. from `comp-call-optim-form-call'. But probably your question was why we distinguish in *both* these places between primitives and native compiled Elisp? FWIW, I tried removing both conditions and got errors when making bootstrap: Error: native-ice ("../lisp/emacs-lisp/macroexp.el" "missing function declaration" byte-compile-constant)