unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* eieio-base patch to support EDE project loading
@ 2019-10-01  2:18 Eric Ludlam
  2019-10-01 12:14 ` Stefan Monnier
  2019-10-04 20:45 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Ludlam @ 2019-10-01  2:18 UTC (permalink / raw)
  To: Emacs Development

Hi,

I've spent the last few years on emacs24, and just recently updated to 
newer version, and also attempted to switch to using built-in CEDET at 
the same time.  (I'd been using sourceforge version before.)  I am 
clearly a few years behind, hopefully you can forgive the transgression.

In so doing, I discovered I couldn't load some of my old EDE projects.
The error is in eieio-base.el (eieio-persistent-validate/fix-slot-value) 
with a call to `child-of-class-p' with a class being loaded that is 
still an autoload.

The core problem is in eieio-core.el (eieio-defclass-autoload).  There 
is a handy comment that explains it:

;; We used to store the list of superclasses in the `parent' slot (as a list
;; of class names).  But now this slot holds a list of class objects, and
;; those parents may not exist yet, so the corresponding class objects may
;; simply not exist yet.  So instead we just don't store the list of parents
;; here in eieio-defclass-autoload at all, since it seems that they're just
;; not needed before the class is actually loaded.


Without that list of superclasses, `child-of-class-p' fails.  Since 
having the superclass list in autoloads is a non-starter, this patch 
will un-autoload classes found in the file being read before the call to 
`child-of-class-p'.

It would be better to store the superclasses in the autoload declaration 
so that extensible class hierarchies can be more dynamically loaded 
without internal checks with un-autoload, but I don't know enough about 
how the new version of eieio works to provide that patch.

I didn't extensively test this beyond a couple old EDE projects of mine.

Hope this helps.

Eric (original author of eieio from a few years back)

-----


diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 534613811d..9131263761 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -342,6 +342,10 @@ eieio-persistent-validate/fix-slot-value

  		  ;; We have a predicate, but it doesn't satisfy the predicate?
  		  (dolist (PV (cdr proposed-value))
+                    ;; If PV is an autoload class, then we must load it 
before `child-of-class-p' will
+                    ;; successfully detect what it is.
+                    (eieio-class-un-autoload (car PV))
+                    ;; Test the class found in the file
  		    (unless (child-of-class-p (car PV) (car classtype))
  		      (error "Invalid object: slot member %s does not match class %s"
                               (car PV) (car classtype))))



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: eieio-base patch to support EDE project loading
  2019-10-01  2:18 eieio-base patch to support EDE project loading Eric Ludlam
@ 2019-10-01 12:14 ` Stefan Monnier
  2019-10-04 20:45 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2019-10-01 12:14 UTC (permalink / raw)
  To: Eric Ludlam; +Cc: Emacs Development

Hi Eric,

Thanks for the bug report and patch.  I'll look at it ASAP,


        Stefan


Eric Ludlam [2019-09-30 22:18:24] wrote:

> Hi,
>
> I've spent the last few years on emacs24, and just recently updated to newer
> version, and also attempted to switch to using built-in CEDET at the same
> time.  (I'd been using sourceforge version before.)  I am clearly a few
> years behind, hopefully you can forgive the transgression.
>
> In so doing, I discovered I couldn't load some of my old EDE projects.
> The error is in eieio-base.el (eieio-persistent-validate/fix-slot-value)
> with a call to `child-of-class-p' with a class being loaded that is 
> still an autoload.
>
> The core problem is in eieio-core.el (eieio-defclass-autoload).  There is
> a handy comment that explains it:
>
> ;; We used to store the list of superclasses in the `parent' slot (as a list
> ;; of class names).  But now this slot holds a list of class objects, and
> ;; those parents may not exist yet, so the corresponding class objects may
> ;; simply not exist yet.  So instead we just don't store the list of parents
> ;; here in eieio-defclass-autoload at all, since it seems that they're just
> ;; not needed before the class is actually loaded.
>
>
> Without that list of superclasses, `child-of-class-p' fails.  Since having
> the superclass list in autoloads is a non-starter, this patch will
> un-autoload classes found in the file being read before the call to
> `child-of-class-p'.
>
> It would be better to store the superclasses in the autoload declaration so
> that extensible class hierarchies can be more dynamically loaded without
> internal checks with un-autoload, but I don't know enough about how the new
> version of eieio works to provide that patch.
>
> I didn't extensively test this beyond a couple old EDE projects of mine.
>
> Hope this helps.
>
> Eric (original author of eieio from a few years back)
>
> -----
>
>
> diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
> index 534613811d..9131263761 100644
> --- a/lisp/emacs-lisp/eieio-base.el
> +++ b/lisp/emacs-lisp/eieio-base.el
> @@ -342,6 +342,10 @@ eieio-persistent-validate/fix-slot-value
>
>  		  ;; We have a predicate, but it doesn't satisfy the predicate?
>  		  (dolist (PV (cdr proposed-value))
> +                    ;; If PV is an autoload class, then we must load it
> before `child-of-class-p' will
> +                    ;; successfully detect what it is.
> +                    (eieio-class-un-autoload (car PV))
> +                    ;; Test the class found in the file
>  		    (unless (child-of-class-p (car PV) (car classtype))
>  		      (error "Invalid object: slot member %s does not match class %s"
>                               (car PV) (car classtype))))




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: eieio-base patch to support EDE project loading
  2019-10-01  2:18 eieio-base patch to support EDE project loading Eric Ludlam
  2019-10-01 12:14 ` Stefan Monnier
@ 2019-10-04 20:45 ` Stefan Monnier
  2019-10-06 12:18   ` Eric Ludlam
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2019-10-04 20:45 UTC (permalink / raw)
  To: Eric Ludlam; +Cc: Emacs Development

> Without that list of superclasses, `child-of-class-p' fails.  Since having
> the superclass list in autoloads is a non-starter, this patch will
> un-autoload classes found in the file being read before the call to
> `child-of-class-p'.

Looks good, but I felt like those un-autoloads scattered around felt
a bit haphazard (with tests slightly different each time), so I suggest
the patch below instead, WDYT (which also moves the un-autoload to
child-of-class-p so it applies not just to
eieio-persistent-validate/fix-slot-value but to all users of
child-of-class-p).

> It would be better to store the superclasses in the autoload declaration so
> that extensible class hierarchies can be more dynamically loaded without
> internal checks with un-autoload, but I don't know enough about how the new
> version of eieio works to provide that patch.

It would allow child-of-class-p to be computed without loading the
class, hence a bit more laziness, but I'm wondering how often it would
make a real difference: how likely are you to use child-of-class-p
without either already having an instance of that class or being right
about to build such an instance?

Can you test the patch below before I push it?


        Stefan


diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 534613811d..fc78b3e098 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -277,8 +277,7 @@ eieio-persistent-convert-list-to-object
 	  (progn
 	    ;; If OBJCLASS is an eieio autoload object, then we need to
 	    ;; load it.
-	    (eieio-class-un-autoload objclass)
-	    (eieio--class-object objclass))))
+	    (eieio--full-class-object objclass))))
 
     (while slots
       (let ((initarg (car slots))
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index 620b47e68d..3d5d4765f1 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -125,7 +125,8 @@ eieio--object-class-tag
 (defsubst eieio--class-object (class)
   "Return the class object."
   (if (symbolp class)
-      ;; Keep the symbol if class-v is nil, for better error messages.
+      ;; Keep the symbol if the class object doesn't exist,
+      ;; for better error messages.
       (or (cl--find-class class) class)
     class))
 
@@ -217,10 +218,6 @@ eieio-defclass-autoload
         (make-obsolete-variable cname (format "use \\='%s instead" cname)
                                 "25.1"))
 
-      ;; Store the new class vector definition into the symbol.  We need to
-      ;; do this first so that we can call defmethod for the accessor.
-      ;; The vector will be updated by the following while loop and will not
-      ;; need to be stored a second time.
       (setf (cl--find-class cname) newc)
 
       ;; Create an autoload on top of our constructor function.
@@ -230,9 +227,17 @@ eieio-defclass-autoload
         (autoload (intern (format "%s-child-p" cname)) filename "" nil nil)
         (autoload (intern (format "%s-list-p" cname)) filename "" nil nil)))))
 
-(defsubst eieio-class-un-autoload (cname)
-  "If class CNAME is in an autoload state, load its file."
-  (autoload-do-load (symbol-function cname))) ; cname
+(defun eieio--full-class-object (class)
+  "Like `eieio--class-object' but loads the class if needed."
+  (let ((c (eieio--class-object class)))
+    (and (not (symbolp c))
+         ;; If the default-object-cache slot is nil, the class object
+         ;; is still a "dummy" setup by eieio-defclass-autoload.
+         (not (eieio--class-default-object-cache c))
+         ;; FIXME: We rely on the autoload setup for the "standard"
+         ;; constructor, here!
+         (autoload-do-load (symbol-function (eieio--class-name c))))
+    c))
 
 (cl-deftype list-of (elem-type)
   `(and list
@@ -730,9 +735,7 @@ eieio-oref
   (cl-check-type obj (or eieio-object class))
   (let* ((class (cond ((symbolp obj)
                        (error "eieio-oref called on a class: %s" obj)
-                       (let ((c (cl--find-class obj)))
-                         (if (eieio--class-p c) (eieio-class-un-autoload obj))
-                         c))
+                       (eieio--full-class-object obj))
                       (t (eieio--object-class obj))))
 	 (c (eieio--slot-name-index class slot)))
     (if (not c)
@@ -1013,16 +1016,15 @@ eieio--class-precedence-list
 method invocation orders of the involved classes."
   (if (or (null class) (eq class eieio-default-superclass))
       nil
-    (unless (eieio--class-default-object-cache class)
-      (eieio-class-un-autoload (eieio--class-name class)))
-    (cl-case (eieio--class-method-invocation-order class)
-      (:depth-first
-       (eieio--class-precedence-dfs class))
-      (:breadth-first
-       (eieio--class-precedence-bfs class))
-      (:c3
-       (eieio--class-precedence-c3 class))))
-  )
+    (let ((class (eieio--full-class-object class)))
+      (cl-case (eieio--class-method-invocation-order class)
+        (:depth-first
+         (eieio--class-precedence-dfs class))
+        (:breadth-first
+         (eieio--class-precedence-bfs class))
+        (:c3
+         (eieio--class-precedence-c3 class))))))
+
 (define-obsolete-function-alias
   'class-precedence-list 'eieio--class-precedence-list "24.4")
 
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 4b899cdc64..103c02f795 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -468,7 +468,7 @@ 'obj-of-class-p
 
 (defun child-of-class-p (child class)
   "Return non-nil if CHILD class is a subclass of CLASS."
-  (setq child (eieio--class-object child))
+  (setq child (eieio--full-class-object child))
   (cl-check-type child eieio--class)
   ;; `eieio-default-superclass' is never mentioned in eieio--class-parents,
   ;; so we have to special case it here.




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: eieio-base patch to support EDE project loading
  2019-10-04 20:45 ` Stefan Monnier
@ 2019-10-06 12:18   ` Eric Ludlam
  2019-10-06 20:02     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Ludlam @ 2019-10-06 12:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Development

On 10/4/19 4:45 PM, Stefan Monnier wrote:
>> Without that list of superclasses, `child-of-class-p' fails.  Since having
>> the superclass list in autoloads is a non-starter, this patch will
>> un-autoload classes found in the file being read before the call to
>> `child-of-class-p'.
> 
> Looks good, but I felt like those un-autoloads scattered around felt
> a bit haphazard (with tests slightly different each time), so I suggest
> the patch below instead, WDYT (which also moves the un-autoload to
> child-of-class-p so it applies not just to
> eieio-persistent-validate/fix-slot-value but to all users of
> child-of-class-p).

Patch looks like a good idea to me.  I was worried about overhead of 
always checking and un-autoloading, but this patch seems to deal with 
that nicely.

The original problem arose when trying to identify the class parents. 
Perhaps using eieio--full-class-object in eieio-class-parents would cast 
a slightly wider net?

> 
>> It would be better to store the superclasses in the autoload declaration so
>> that extensible class hierarchies can be more dynamically loaded without
>> internal checks with un-autoload, but I don't know enough about how the new
>> version of eieio works to provide that patch.
> 
> It would allow child-of-class-p to be computed without loading the
> class, hence a bit more laziness, but I'm wondering how often it would
> make a real difference: how likely are you to use child-of-class-p
> without either already having an instance of that class or being right
> about to build such an instance?

I agree.  The patch solves the problem in a more pragmatic way.

> Can you test the patch below before I push it?

It works great.  Thanks for looking into it!

Eric



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: eieio-base patch to support EDE project loading
  2019-10-06 12:18   ` Eric Ludlam
@ 2019-10-06 20:02     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2019-10-06 20:02 UTC (permalink / raw)
  To: Eric Ludlam; +Cc: Emacs Development

> Patch looks like a good idea to me.  I was worried about overhead of always
> checking and un-autoloading, but this patch seems to deal with that nicely.

Right, I think it's only used in places which should hopefully not be
performance-sensitive.

> The original problem arose when trying to identify the class
> parents.  Perhaps using eieio--full-class-object in eieio-class-parents would
> cast a slightly wider net?

eieio-class-parents is not used internally, so it's not sufficient, but
it's indeed a good idea to make it load the class if needed, so I made
that change as well.

>> Can you test the patch below before I push it?
> It works great.  Thanks for looking into it!

Great, pushed to `master`, thanks,


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-06 20:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01  2:18 eieio-base patch to support EDE project loading Eric Ludlam
2019-10-01 12:14 ` Stefan Monnier
2019-10-04 20:45 ` Stefan Monnier
2019-10-06 12:18   ` Eric Ludlam
2019-10-06 20:02     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).