GNU bug report logs - #41065
Result of byte-compilation can be nil even if the compiled file contains no errors

Previous Next

Package: emacs;

Reported by: Paul Pogonyshev <pogonyshev <at> gmail.com>

Date: Sun, 3 May 2020 22:22:02 UTC

Severity: minor

Tags: fixed

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 41065 in the body.
You can then email your comments to 41065 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#41065; Package emacs. (Sun, 03 May 2020 22:22:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Pogonyshev <pogonyshev <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 03 May 2020 22:22:02 GMT) Full text and rfc822 format available.

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

From: Paul Pogonyshev <pogonyshev <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Result of byte-compilation can be nil even if the compiled file
 contains no errors
Date: Mon, 4 May 2020 00:21:02 +0200
[Message part 1 (text/plain, inline)]
To reproduce, save this as file `main.el':

    (eval-when-compile
      (let ((default-directory (expand-file-name "/tmp/myprivatelib/")))
        (make-directory default-directory t)
        (with-temp-file "thelib.el"
          (insert "(defun im-a-library-function ()\n"
                  "  (trigger-a-warning-here-1))\n"
                  "(provide 'thelib\n"))  ; <- intentionally erroneous
syntax
        (byte-compile-file "thelib.el")))

    (defun blabla ()
      (trigger-a-warning-here-2))

and execute:

    $ emacs --batch --eval "(print (byte-compile-file \"main.el\"))"

Result is:

    In toplevel form:
    thelib.el:3:1: Error: End of file during parsing

    In end of data:
    ~/test/nested-compilation/main.el:12:1: Warning: the function
        ‘trigger-a-warning-here-2’ is not known to be defined.

    nil

The last line is the result of the call to `byte-compile-file'
from the command line and it is nil.  But this is wrong, because
`main.el' is syntactically correct and never triggers an error:
you can verify this by evaluating `let' form manually.  What
failed is the "inner" compilation, but it must not affect the
result of the "main" compilation process.

A smaller problem is that the path to `main.el' is written fully,
because it is apparently found from `/tmp/myprivatelib', which
further corroborates my guess that the two byte-compilation
processes are improperly lumped together.

If you fix generated `thelib.el' by adding the missing paren,
"outer" compilation will succeed.

I emailed this to to `emacs-devel' quite a while ago:

    https://lists.gnu.org/archive/html/emacs-devel/2020-02/msg00227.html

and the answer from Stefan Monnier confirmed that this should be
qualified as a bug.  I have forgotten to resubmit this to
`bug-gnu-emacs' until now.

Paul
[Message part 2 (text/html, inline)]

Severity set to 'minor' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 20 May 2020 15:49:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41065; Package emacs. (Tue, 27 Oct 2020 00:12:01 GMT) Full text and rfc822 format available.

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

From: Paul Pogonyshev <pogonyshev <at> gmail.com>
To: 41065 <at> debbugs.gnu.org
Subject: PATCH
Date: Tue, 27 Oct 2020 01:10:58 +0100
[Message part 1 (text/plain, inline)]
Trivial patch attached.
[Message part 2 (text/html, inline)]
[0001-Don-t-leak-result-of-nested-byte-compilation-to-oute.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41065; Package emacs. (Tue, 27 Oct 2020 08:48:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Paul Pogonyshev <pogonyshev <at> gmail.com>
Cc: 41065 <at> debbugs.gnu.org
Date: Tue, 27 Oct 2020 09:47:07 +0100
Paul Pogonyshev <pogonyshev <at> gmail.com> writes:

> Subject: [PATCH] Don't leak result of nested byte-compilation to outer level
>  (bug#41065)

[...]

> +	byte-compile-dest-file byte-compiler-error-flag)
>      (setq target-file (byte-compile-dest-file filename))
>      (setq byte-compile-dest-file target-file)
>      (with-current-buffer
> @@ -2000,7 +2000,6 @@ byte-compile-file
>  	  'no-byte-compile)
>        (when byte-compile-verbose
>  	(message "Compiling %s..." filename))
> -      (setq byte-compiler-error-flag nil)

Thanks; applied to Emacs 28.  I tried to follow the code paths where
this variable is used, and as far as I can tell, this should be safe.

The old code was rather odd, because there's just a

(defvar byte-compiler-error-flag)

in the file -- it's not actually defined, but after compiling something,
that `setq' would define it globally.  So your patch fixes that problem,
too.

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




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 27 Oct 2020 08:48:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 41065 <at> debbugs.gnu.org and Paul Pogonyshev <pogonyshev <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 27 Oct 2020 08:48:02 GMT) Full text and rfc822 format available.

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

This bug report was last modified 3 years and 151 days ago.

Previous Next


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