From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.bugs Subject: bug#34757: Invalid bytecode from byte compiler Date: Thu, 13 Jun 2019 11:44:08 +0000 Message-ID: References: <838sxg1rwz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="41416"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 34757@debbugs.gnu.org, chuntaro@sakura-games.jp To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 13 13:49:05 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hbOE5-000Ae7-2P for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jun 2019 13:49:05 +0200 Original-Received: from localhost ([::1]:38744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOE4-0000V7-3k for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jun 2019 07:49:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50705) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOBN-0006UL-Ab for bug-gnu-emacs@gnu.org; Thu, 13 Jun 2019 07:46:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbOAA-0005xE-Tt for bug-gnu-emacs@gnu.org; Thu, 13 Jun 2019 07:45:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49329) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbOAA-0005w1-Q8 for bug-gnu-emacs@gnu.org; Thu, 13 Jun 2019 07:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hbOAA-0006dV-I6 for bug-gnu-emacs@gnu.org; Thu, 13 Jun 2019 07:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Jun 2019 11:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34757 X-GNU-PR-Package: emacs Original-Received: via spool by 34757-submit@debbugs.gnu.org id=B34757.156042629225474 (code B ref 34757); Thu, 13 Jun 2019 11:45:02 +0000 Original-Received: (at 34757) by debbugs.gnu.org; 13 Jun 2019 11:44:52 +0000 Original-Received: from localhost ([127.0.0.1]:34640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hbO9z-0006cn-ND for submit@debbugs.gnu.org; Thu, 13 Jun 2019 07:44:52 -0400 Original-Received: from mail-oi1-f170.google.com ([209.85.167.170]:40668) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hbO9x-0006ca-VZ for 34757@debbugs.gnu.org; Thu, 13 Jun 2019 07:44:50 -0400 Original-Received: by mail-oi1-f170.google.com with SMTP id w196so14177962oie.7 for <34757@debbugs.gnu.org>; Thu, 13 Jun 2019 04:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=v0jzn4cJO2lALLtB9rDiUbZYPyyHbs+FRHOnzjhTMp4=; b=Q1F2Jo4U89m2cMU7gOrozNECiU56yErzuJHNW0f37B6TuJzL+oj54iKs9q+4gYfbML WdD8VukYvR311jjJI0y4lAQUBf96dKVE+rGdjoj3LWcTNIgxUE+EqiO0qciceYv7yBRs LpAP6Y+XeljFbyFa3xo3NfK9QOpQ9lTwH/UJ/oMK+EB7GA3oIz/2QInKnWQS/AESRyDj O8xli12VvWjcyqAVsgwJ2d0NgndSo2qYqNbodSR4vQwT47Hnwdv2P+8joQ0mOfB/RXWX j1XSQ71eUN5fHdXkG5061wRjLLLLQJNVNXfpJ252Ve/gdFIoMxLHyy0ltZUWTSGjSXAI OhLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=v0jzn4cJO2lALLtB9rDiUbZYPyyHbs+FRHOnzjhTMp4=; b=Jltp6YaUHIfWdVj+5+KPnv7fqlGQ/A0s7H6urCsN7LH7pmmUG2dV9F3/MoZsR0IEN7 p2pqiTctOpLdg1beMZlojeOqFz2hyHII+BwHbEKqlNTlNcddZqq0WvsZ3GWOAt20tKJB 2YJFBHn7CHNZUFULUpz1ZI6xnpxSFdpdkpGL3GCzoB16WSHN+Lbrm8h5gywKxtHm2IS+ 0QUhH7DhuVhgUsE/faI6yd5MUZSNLS+UZZbFb7WUUtyzKO+EZarqLhUeMCrUJfPYEwHH Ht8V4igE+Zzyo4Jz2yRSp0+yQKLO2aDnqdieZhqJvpmqWxAAW13vZf5TAfthG3ahlojy g8PA== X-Gm-Message-State: APjAAAUUr/iCdPoF5dibllePFpX8qAxFC5uTzEI8thC/6H1PlA6yzdIo 5Hc4HLqFbl01KpLR9JmFREhKMWx33nWNwdZA8SI= X-Google-Smtp-Source: APXvYqwzFDUJDIg3jj13b6ZFxHzvAP0FiQE59DrSEhu2Y63gRv/2O+V5XQkTylUI8qw3q68GOA+bgODE2NyhlbZO1lI= X-Received: by 2002:aca:4790:: with SMTP id u138mr2769254oia.44.1560426284297; Thu, 13 Jun 2019 04:44:44 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:160485 Archived-At: This bug still appears to be present. Maybe it's time to apply Stefan's patch and see whether anything breaks? On Sat, Mar 16, 2019 at 4:51 PM Pip Cet wrote: > > On Fri, Mar 15, 2019 at 8:30 PM Stefan Monnier = wrote: > > > > > Just to be sure I understand correctly, you would like to remove the > > > decompilation of trivial function calls entirely? > > > > Yes, tho the main motivation was to try and figure out what the > > decompilation is useful for. > > Thanks for explaining! > > > This only affects "open code" (i.e. not the content of functions, which > > are already never decompiled), so the impact should be minor and it > > removes a rather complicated and brittle chunk of code whose purpose is > > not clear. It was originally introduced when we didn't have > > byte-compiled function objects, so its main purpose was one of > > performance, to avoid pessimizing the code by replacing trivial functio= n > > calls with more costly (byte-code "...") expressions but nowadays such > > (byte-code "...") expressions only occur basically at the top-level of > > .elc files where such pessimization would be unnoticeable in terms > > of performance. > > I agree completely, for what it's worth. > > > It does impact the readability of .elc files, OTOH, so I'm not > > completely happy with the result when considering the few cases where > > I was happy to be able to make sense of a .elc file to better understan= d > > the source of a problem (after all, that's why I wrote the > > elisp-byte-code-mode). > > I can speak only for myself, but I think the byte-compiler "magically" > deciding to turn (rare) top-level non-defuns into plain code rather > than byte code is confusing. It's much better with your patches. > > > > It seems the special case is necessary to avoid compilation errors, > > > > I haven't found it to be really necessary, no. > > Well, you fixed it with the second patch. > > > > and that it's used for (byte-compile 3), so I think the comment could > > > be improved a little. > > > > (byte-compile 3) seems to work correctly here even without the > > special case. It returns (byte-code "\300\207" [3] 1) which is indeed > > a correct expression that evaluates to 3 (just like the argument to > > `byte-compile` was an expression whose evaluation returns 3). > > No argument here. The case branch affects what happens when > (byte-compile 3) is called, but isn't necessary for the result to be > correct, and the comment can be misread to imply it's irrelevant in > this case. > > > Let's not forget that what `byte-compile` tries to do is to preserve th= e > > invariant that > > > > (eval EXP) =E2=89=83 (eval (byte-compile EXP)) > > I think byte-compile does different things for different arguments: > the behavior for symbols and other expressions is simply different. > > > This said, if you remove the special case, you will bump into > > a corner-case bug in `byte-compile` which happens because that function > > incorrectly considers that `byte-compile-top-level` returns a value > > whereas in reality it returns an expression (just like `byte-compile`): > > the decompilation happens to turn expressions that return constant > > values (like byte-compiled functions) into their value (as an > > optimization which relies on the fact that those objects are > > self-evaluating), so if you remove it, you then bump into this bug of > > byte-compile. The patch below would fix this bug. > > I don't think that was a bug, but it was an unfortunate wrinkle in the > (undocumented) API of byte-compile-top-level. > > > But indeed the decompilation of constants is handy since that's what > > people expect from `byte-compile`. When I (byte-compile '(lambda (x) > > (foo))) I expect to receive a byte-compiled function, and not > > a byte-code expression which when evaluated will return that > > byte-compiled function. > > I think it's more than handy: it's how I'd read the current > documentation, and how I'd expect a function called byte-compile to > behave. > > > > I'm not sure this case can actually happen without doing something > > > silly, but (byte-compile '(internal-get-closed-var 0)) throws an erro= r > > > with Stefan's patch, because the byte code is (byte-constant . 0) > > > (byte-return). > > > > This source code is arguably invalid, so it's not a real problem, but > > The source code is invalid, but the LAP code is valid-looking, and I > can't conclude it cannot be generated by valid source code being > passed to `byte-compile' somehow. > > > diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el > > index f46cab2c17..ae17553d0c 100644 > > --- a/lisp/emacs-lisp/bytecomp.el > > +++ b/lisp/emacs-lisp/bytecomp.el > > @@ -2674,7 +2674,11 @@ byte-compile > > (setq fun (byte-compile-top-level fun nil 'eval))) > > (if macro (push 'macro fun)) > > (if (symbolp form) > > - (fset form fun) > > + ;; byte-compile returns an *expression* equivalent to the > > I think this would be clearer if it read "byte-compile-top-level > returns an *expression*..."