From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Aymeric Agon-Rambosson Newsgroups: gmane.emacs.devel Subject: Re: Finalizing 'inhibit-automatic-native-compilation' Date: Mon, 06 Feb 2023 11:57:41 +0100 Message-ID: <87cz6nxdqy.fsf@X570GP> References: <837cx8cey0.fsf@gnu.org> <83357vauh5.fsf@gnu.org> <837cx6a8me.fsf@gnu.org> <83357ua6ja.fsf@gnu.org> <83zga28ra8.fsf@gnu.org> <83r0vd97s0.fsf@gnu.org> <83lell73yv.fsf@gnu.org> <87sffo3as7.fsf@melete.silentflame.com> <83v8kkxzzx.fsf@gnu.org> <87r0v811pm.fsf@melete.silentflame.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37896"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.10; emacs 28.1 Cc: Eli Zaretskii , monnier@iro.umontreal.ca, emacs-devel@gnu.org, akrl@sdf.org, larsi@gnus.org, rlb@defaultvalue.org To: Sean Whitton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Feb 06 13:13:32 2023 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 1pP0NH-0009bk-JK for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Feb 2023 13:13:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pP0MU-0004bF-HV; Mon, 06 Feb 2023 07:12:42 -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 1pOzC6-0007Om-Gp for emacs-devel@gnu.org; Mon, 06 Feb 2023 05:57:54 -0500 Original-Received: from forward501c.mail.yandex.net ([178.154.239.209]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pOzC3-0007YV-M4; Mon, 06 Feb 2023 05:57:54 -0500 Original-Received: from myt5-f3d0b203e46f.qloud-c.yandex.net (myt5-f3d0b203e46f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3b2d:0:640:f3d0:b203]) by forward501c.mail.yandex.net (Yandex) with ESMTP id A40BA5E6FA; Mon, 6 Feb 2023 13:57:44 +0300 (MSK) Original-Received: by myt5-f3d0b203e46f.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id gvYOIn0ZKOs1-64ftEcNv; Mon, 06 Feb 2023 13:57:43 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.com; s=mail; t=1675681064; bh=I0jS+4aib8eT4U6LPxNMPAPlB7y4QisQN4f7wPVzFyc=; h=Cc:Message-ID:References:Date:Subject:In-reply-to:To:From; b=Ra1C0Zy+9WD3gGFxgL26gnpg8iLsf/yMCaArToRxee+owSyxypqfET01olfMgXxN9 TzkyhfGSXPTlfTr9v+fcFF1maf0i39IUhIINaXK0+wTO7SpG8HUUqxBTqE6Lk6TbCR x7xXJbssRLOeiIs56xOb7jLk80X2vbtGcT0dE/f0= Authentication-Results: myt5-f3d0b203e46f.qloud-c.yandex.net; dkim=pass header.i=@yandex.com In-reply-to: <87r0v811pm.fsf@melete.silentflame.com> Received-SPF: pass client-ip=178.154.239.209; envelope-from=aymeric.agon@yandex.com; helo=forward501c.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 06 Feb 2023 07:12:41 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:303018 Archived-At: Hello everyone, and sorry for my being late. Le jeudi 2 f=C3=A9vrier 2023 =C3=A0 09:17, Sean Whitton=20 a =C3=A9crit : > Aymeric, you investigated one of these cases in details. Would=20 > you be > able to summarise the situation we had in Debian for Eli,=20 > please? The case Sean refers to is probably the packaging of projectile=20 (https://github.com/bbatsov/projectile). In the testbed of this package, the buttercup library=20 (https://github.com/jorgenschaefer/emacs-buttercup) is used to=20 advise some primitives, like `file-exists-p',=20 `insert-file-contents', `file-directory-p' and probably=20 others. These primitives can be advised so as to be replaced by a=20 function that does nothing, or that always returns a specific=20 value, etc... The following test was interesting : (describe "projectile-parse-dirconfig-file" (it "parses dirconfig and returns directories to ignore and=20 keep" (spy-on 'file-exists-p :and-return-value t) (spy-on 'file-truename :and-call-fake (lambda (filename)=20 filename)) (spy-on 'insert-file-contents :and-call-fake (lambda (filename) (save-excursion (insert=20 "\n-exclude\n+include\n#may-be-a-comment\nno-prefix\n=20 left-wspace\nright-wspace\t\n")))) (expect (projectile-parse-dirconfig-file) :to-equal=20 '(("include/") ("exclude" "#may-be-a-comment" "no-prefix" "left-wspace" "right-wspace") nil)) ;; same test - but with comment lines enabled using prefix '#' (let ((projectile-dirconfig-comment-prefix ?#)) (expect (projectile-parse-dirconfig-file) :to-equal=20 '(("include/") ("exclude" "no-prefix" "left-wspace" "right-wspace") nil))) )) The primitive `file-exists-p' is advised as to always return t,=20 whether the argument corresponds to an existing file or not. If we=20 assume the trampoline is not already there (and that is the case=20 in our build environment), a trampoline compilation is triggered,=20 and exits without error. The advice is effective only after that. Then `file-truename' is advised, but it is not a primitive. Then `insert-file-contents' is advised as well, it is a=20 primitive. We enter the function `comp-subr-trampoline-install',=20 and we begin by checking whether the corresponding trampoline=20 already exists by entering the function=20 `comp-trampoline-search'. This function relies on `file-exists-p',=20 which answers that the file corresponding to the compiled=20 trampoline exists, even if it doesn't. Hence we enter=20 `native-elisp-load' with a filename that doesn't exist as=20 argument, and we error out : comp-subr-trampoline-install(insert-file-contents) comp-trampoline-search(insert-file-contents) native-elisp-load("/tmp/buttercupKuLmvD/28.2-4001e2a9/subr--trampoline-696.= .. error: (native-lisp-load-failed "file does not exists"=20 "/tmp/buttercupKuLmvD/28.2-4001e2a9/subr--trampoline-696e736572742d66696c65= 2d636f6e74656e7473_insert_file_contents_0.eln") We always get the error because the trampoline is never there=20 beforehand, and upstream did not get it precisely because it was=20 lucky to always have it before running the test. If we have to=20 load *any* trampoline after the advice of `file-exists-p' is=20 effective, and we're not lucky enough to already have the=20 trampoline, then we reach the error. In that case, we worked around the problem by adding the primitive=20 `insert-file-contents' to the variable=20 `native-comp-never-optimize-functions'. >> . where and under what circumstances will those advised=20 >> functions be >> called, as part of your preparation of the packages? (if=20 >> the >> advised functions are only called when the end-user uses=20 >> the >> package, that is not relevant to the present discussion) As far as we can tell, this advising of primitives happens mostly=20 in tests, that is in our build environment on our build machines. >> . if we provide a way to specify, via=20 >> comp-enable-subr-trampolines, >> the directory to which the trampolines will be written,=20 >> will that >> satisfy your uses? if not, why not (details, please)? >> . why cannot you use native-comp-eln-load-path to force the >> trampolines go to a directory of your choice? In this case, this is not pertinent. We need to : - either not to have to install a trampoline - or, if we have to, be certain to find it in the *first*=20 directory returned by `comp-eln-load-path-eff'. If neither condition are met, we reach the error. The only=20 variables that are of help here are=20 `native-comp-never-optimize-functions' or=20 `comp-enable-subr-trampolines'. Since EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION acts on neither=20 of these, we have to manually add (with-eval-after-load 'comp (push 'insert-file-contents=20 native-comp-never-optimize-functions)) At the beginning of the test file. For this reason, it would be nice, if possible, that=20 EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION also disables=20 trampoline compilation, for instance by setting=20 `comp-enable-subr-trampolines'. The name of the environment=20 variable would be changed accordingly, of course. The performance penalty wouldn't be a problem, since this would=20 only be for the duration of the test. If Andrea prefers, we could=20 also have two different environment variables, one for trampoline=20 and the other for deferred async compilation. But I don't see why=20 only one knob doesn't work : if we had an environment variable=20 that acted on both `inhibit-automatic-native-compilation' and=20 `comp-enable-subr-trampolines', like what happens when=20 `native-comp-available-p' evaluates to nil, wouldn't that exactly=20 "really disable native compilation", or am I missing something ? >> I dislike having environment variables that alter Emacs=20 >> behavior, >> because environment variables are inherited by sub-processes. This is precisely why I like it. Our build mechanism can have=20 emacs instances nested deep in layers of wrapper scripts. Because=20 of this, we can simply export the variable in the environment of=20 the ancestor process, and not worry about adding --eval arguments=20 in various places in the middle of our scripts. But only the=20 descendants of this ancestor process are concerned by this=20 environment variable, and they live only as long as the building=20 mechanism runs, so I don't see the reason for worry. Then, if=20 users want to use this variable in normal use, and they decide on=20 top of that to have multiple nested emacsen, then I agree that=20 they have to be careful, but that situation seems a bit=20 far-fetched. I hope everything was clear. Best, Aymeric Agon-Rambosson P.S. We have a couple of packages for which we have deactivated=20 some trampoline compilation in order to pass tests or avoid an=20 error. I haven't been able to find out why like I did with=20 projectile, but I guess these cases can be of interest to you : https://github.com/joaotavora/yasnippet/pull/1158 https://github.com/DamienCassou/beginend/pull/75 P.P.S. The new mechanism consisting in having all the trampolines=20 compiled as part of the building process would probably solve=20 these two problems, but not the one from projectile. I assume=20 these trampolines would be put in the system eln cache, which is=20 not returned as the first directory by=20 `comp-eln-load-path-eff'. We would therefore reach the error=20 anyway. But this is very good in my opinion, as are all efforts to=20 increase the amount of stuff native compiled eagerly (like=20 NATIVE_FULL_AOT).