GNU bug report logs - #25088
25.1; feature-unload and reload of cl-defstruct fails

Previous Next

Package: emacs;

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

Date: Fri, 2 Dec 2016 05:24:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 25.1

Fixed in version 25.2

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


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: 25.1; feature-unload and reload of cl-defstruct fails
Date: Fri, 02 Dec 2016 00:24:04 -0500
[Message part 1 (text/plain, inline)]
tags: patch

Running

    emacs -Q -l bug-struct-reload.el --eval "(unload-feature 'bug-struct-reload)" -l bug-struct-reload.el

Where bug-struct-reload.el contains

    (eval-when-compile (require 'cl-lib))
    (cl-defstruct foo f1)
    (provide 'bug-struct-reload)

Shows in *Messages* the following error

    Unexpected element (define-type . foo) in load-history
    Compiler-macro error for foo-p: (void-function foo-p--cmacro) [2 times]

This is because cl-defstruct defines the field accessors before the
predicate.  After calling `feature-unload', the `macro-compiler' symbol
property remains on the predicate even though the function itself is
undefined.  Then when reloading, the compiler tries to call the
predicate's compiler-macro to inline it in the accessor function, and
fails to find the definition.

Since this is a regression in 25.1, I'd like to apply the following
patch to emacs-25, which simply puts the predicate definition before the
accessor functions.

[v1-0001-Define-struct-predicate-before-acccesors.patch (text/plain, inline)]
From d6285c44150fc9f6d0d3d6dadcd272bae3c498e5 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Fri, 2 Dec 2016 00:03:57 -0500
Subject: [PATCH v1] Define struct predicate before acccesors

The accessor functions use the predicate function, which causes problems
when reloading after unload-feature: the compiler-macro property is
still present on the predicate symbol, and the compiler fails to find
the definition when trying to inline it into the accessor function.

* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Move predicate definition
before field accessor definitions.
---
 lisp/emacs-lisp/cl-macs.el | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index c51ed9d..b3a60b1 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2687,6 +2687,14 @@ cl-defstruct
 				   (= safety 1))
 			      (cons 'and (cl-cdddr pred-form))
                             `(,predicate cl-x))))
+    (when pred-form
+      (push `(cl-defsubst ,predicate (cl-x)
+               (declare (side-effect-free error-free))
+               ,(if (eq (car pred-form) 'and)
+                    (append pred-form '(t))
+                  `(and ,pred-form t)))
+            forms)
+      (push `(put ',name 'cl-deftype-satisfies ',predicate) forms))
     (let ((pos 0) (descp descs))
       (while descp
 	(let* ((desc (pop descp))
@@ -2741,14 +2749,6 @@ cl-defstruct
 	(setq pos (1+ pos))))
     (setq slots (nreverse slots)
 	  defaults (nreverse defaults))
-    (when pred-form
-      (push `(cl-defsubst ,predicate (cl-x)
-               (declare (side-effect-free error-free))
-               ,(if (eq (car pred-form) 'and)
-                    (append pred-form '(t))
-                  `(and ,pred-form t)))
-            forms)
-      (push `(put ',name 'cl-deftype-satisfies ',predicate) forms))
     (and copier
          (push `(defalias ',copier #'copy-sequence) forms))
     (if constructor
-- 
2.9.3


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

Previous Next


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