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: Sat, 16 Mar 2019 16:51:13 +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="94108"; 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 Sat Mar 16 17:53:13 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.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5CYZ-000OLP-N6 for geb-bug-gnu-emacs@m.gmane.org; Sat, 16 Mar 2019 17:53:11 +0100 Original-Received: from localhost ([127.0.0.1]:44138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5CYY-0003UO-Hv for geb-bug-gnu-emacs@m.gmane.org; Sat, 16 Mar 2019 12:53:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5CYR-0003UH-NY for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2019 12:53:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5CYQ-0006WH-Kb for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2019 12:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33137) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5CYQ-0006W2-Aw for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2019 12:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h5CYP-0000uL-Vd for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2019 12:53: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: Sat, 16 Mar 2019 16:53:01 +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.15527551213395 (code B ref 34757); Sat, 16 Mar 2019 16:53:01 +0000 Original-Received: (at 34757) by debbugs.gnu.org; 16 Mar 2019 16:52:01 +0000 Original-Received: from localhost ([127.0.0.1]:46681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h5CXQ-0000sd-VW for submit@debbugs.gnu.org; Sat, 16 Mar 2019 12:52:01 -0400 Original-Received: from mail-oi1-f171.google.com ([209.85.167.171]:40262) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h5CXO-0000sQ-QR for 34757@debbugs.gnu.org; Sat, 16 Mar 2019 12:51:59 -0400 Original-Received: by mail-oi1-f171.google.com with SMTP id k11so9836563oic.7 for <34757@debbugs.gnu.org>; Sat, 16 Mar 2019 09:51:58 -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=JJbZUwDdAyc0RGBXgUnl0KyKRUxLKaCxdQimQsQhP5o=; b=q09z6MAGhci9X50N91BljshZAECMRK1j38cg+Y584Lgfjgw3WK8cxEabHu3RGqiRBB R6kXQQgnOvq0uKBnubmQFMqZF3nJ1eUZgyU50b144jRlx/JoAJp012VfljSNbDyn0vlJ oaUmIw2O1B9ePOtZ3JFq6AXY2nEd4wWI5haOiAv3okc9ddoF4Hp+82MK2RYvP8xweJ2q kz4hmISE4lFvtawnV1xwpura6bOboVfsH7Ti/Yl+D4O8ny65IEdr40+IsWOY/xMQlHRf Clzdk9Npd0FRyEsAdqax7TvySUNdUrayeRnjMPxum4xQId+nmaYmlas+ARioGVmpASPZ dVog== 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=JJbZUwDdAyc0RGBXgUnl0KyKRUxLKaCxdQimQsQhP5o=; b=WJrBMHhGQs1crbgx6zQQ9MWPFpqUdee5awRFc7GwSEMmk02kHYyGh+VoitYm+dNQur QPmOyehqPicBm0KzdFnUq5vIjDaMh2woGRAi2ykmFYOZ8kEC3UipzcYNgWIW06UPWOQ3 mw78Mdl7uQZC2t5PLH6I+T+siPRG472Ye7sZJx9zjcVsTID7FxxNRBN8nkc7uUlz5ye4 lggWa7wSmpp6r6Epw/6sslt75qb0zYiLdV1td+fZTfG72whnLOFHc6lpJxsZscLd0342 PqkJ8GBwJxwG0HC8VTmgbRNUT+wVnAqlO171p30WibiADvm0ii2fILijKqp4U1gLkb4+ bIDQ== X-Gm-Message-State: APjAAAWwi9MdRgfjOAcnuvW3Dyk9eWHXAC4g7UWK+T1uKv4KOJ/550z1 w/f7rfidmXPaHFsYDZzMB6l+n05xs5+aGEymrtZf8A== X-Google-Smtp-Source: APXvYqw3HkM1qhw+oCiltPR9k/ilTgTVsnC8qAWKHWyBcF2kVnB2mMivIXpL3YhfMm4i2dTA7D9vADitiNwEKszzk20= X-Received: by 2002:aca:52c2:: with SMTP id g185mr5147063oib.128.1552755111824; Sat, 16 Mar 2019 09:51:51 -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:156411 Archived-At: On Fri, Mar 15, 2019 at 8:30 PM Stefan Monnier w= rote: > > > 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 function > 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 understand > 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 the > 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 error > > 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*..."