From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eric Ludlam <eric@siege-engine.com>
Cc: Emacs Development <emacs-devel@gnu.org>
Subject: Re: eieio-base patch to support EDE project loading
Date: Fri, 04 Oct 2019 16:45:18 -0400 [thread overview]
Message-ID: <jwvzhig1c3g.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <8d7cb453-41c9-f3eb-8395-01cb46079663@siege-engine.com> (Eric Ludlam's message of "Mon, 30 Sep 2019 22:18:24 -0400")
> 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.
next prev parent reply other threads:[~2019-10-04 20:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-10-06 12:18 ` Eric Ludlam
2019-10-06 20:02 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvzhig1c3g.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=eric@siege-engine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.