GNU bug report logs - #24122
Fix byte-compile of interactive closures

Previous Next

Package: emacs;

Reported by: npostavs <at> users.sourceforge.net

Date: Mon, 1 Aug 2016 02:24:01 UTC

Severity: minor

Tags: patch

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

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 24122 in the body.
You can then email your comments to 24122 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#24122; Package emacs. (Mon, 01 Aug 2016 02:24:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to npostavs <at> users.sourceforge.net:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 01 Aug 2016 02:24:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: bug-gnu-emacs <at> gnu.org
Subject: Fix byte-compile of interactive closures
Date: Sun, 31 Jul 2016 22:23:08 -0400
[Message part 1 (text/plain, inline)]
Severity: minor
tags: patch
found: 24.3
found: 25.1

Running

    emacs -Q -l bug-byte-compile.el

gives

    bug-byte-compile.el:Warning: misplaced interactive spec: ‘(interactive)’

where bug-byte-compile.el is

[bug-byte-compile.el (text/plain, inline)]
;;; -*- lexical-binding: t -*-

(let ((foo--var nil))
  (defun foo ()
    (interactive)
    foo--var))

(byte-compile 'foo)
[Message part 3 (text/plain, inline)]
The problem is that byte-compile--reify-function which puts the bindings
inside the closure bindings inside the function body as an optimization,
puts them in front of the docstring and (interactive ...) form.  Here is
a fix:

[v1-0001-Fix-byte-compile-of-interactive-closures.patch (text/plain, inline)]
From 46cf05f447a7c834789c5ce8805cb5997c685c43 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sun, 31 Jul 2016 20:46:37 -0400
Subject: [PATCH v1] Fix byte-compile of interactive closures

* lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Put
bindings after docstring and `interactive' form, if any.
---
 lisp/emacs-lisp/bytecomp.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index dc7574e..175690a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2582,7 +2582,13 @@ byte-compile--reify-function
   (pcase-let* (((or (and `(lambda ,args . ,body) (let env nil))
                     `(closure ,env ,args . ,body))
                 fun)
+               (preamble nil)
                (renv ()))
+    ;; Split docstring and `interactive' form from body.
+    (when (stringp (car body))
+      (push (pop body) preamble))
+    (when (eq (car-safe (car body)) 'interactive)
+      (push (pop body) preamble))
     ;; Turn the function's closed vars (if any) into local let bindings.
     (dolist (binding env)
       (cond
@@ -2595,8 +2601,8 @@ byte-compile--reify-function
        ((eq binding t))
        (t (push `(defvar ,binding) body))))
     (if (null renv)
-        `(lambda ,args ,@body)
-      `(lambda ,args (let ,(nreverse renv) ,@body)))))
+        `(lambda ,args ,@preamble ,@body)
+      `(lambda ,args ,@preamble (let ,(nreverse renv) ,@body)))))
 
 ;;;###autoload
 (defun byte-compile (form)
-- 
2.8.0


bug marked as fixed in version 25.2, send any further explanations to 24122 <at> debbugs.gnu.org and npostavs <at> users.sourceforge.net Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 06 Aug 2016 20:17:03 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. (Sun, 04 Sep 2016 11:24:03 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:12 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 26.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:12 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 25.2. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:12 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. (Sun, 01 Jan 2017 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 172 days ago.

Previous Next


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