1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-24 06:20:43 -08:00

* eieio-core.el (eieio--full-class-object): New function.

Rather than explicitly call eieio-class-un-autoload, the autoloading is
now performed on-demand if you use eieio--full-class-object.

* lisp/emacs-lisp/eieio-core.el (eieio-class-un-autoload): Remove.
(eieio--full-class-object): New function, to replace it.
(eieio-oref, eieio--class-precedence-list):
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-convert-list-to-object):
Use it instead of eieio-class-un-autoload.
* lisp/emacs-lisp/eieio.el (eieio-class-parents, child-of-class-p):
Load the class if needed.
This commit is contained in:
Stefan Monnier 2019-10-06 16:00:21 -04:00
parent dc8108e109
commit 47cf2a37e7
3 changed files with 27 additions and 25 deletions

View file

@ -277,8 +277,7 @@ identified, and needing more object creation."
(progn (progn
;; If OBJCLASS is an eieio autoload object, then we need to ;; If OBJCLASS is an eieio autoload object, then we need to
;; load it. ;; load it.
(eieio-class-un-autoload objclass) (eieio--full-class-object objclass))))
(eieio--class-object objclass))))
(while slots (while slots
(let ((initarg (car slots)) (let ((initarg (car slots))

View file

@ -125,7 +125,8 @@ Currently under control of this var:
(defsubst eieio--class-object (class) (defsubst eieio--class-object (class)
"Return the class object." "Return the class object."
(if (symbolp class) (if (symbolp class)
;; Keep the symbol if class-v is nil, for better error messages. ;; Return the symbol if the class object doesn't exist,
;; for better error messages.
(or (cl--find-class class) class) (or (cl--find-class class) class)
class)) class))
@ -217,10 +218,6 @@ It creates an autoload function for CNAME's constructor."
(make-obsolete-variable cname (format "use \\='%s instead" cname) (make-obsolete-variable cname (format "use \\='%s instead" cname)
"25.1")) "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) (setf (cl--find-class cname) newc)
;; Create an autoload on top of our constructor function. ;; Create an autoload on top of our constructor function.
@ -230,9 +227,17 @@ It creates an autoload function for CNAME's constructor."
(autoload (intern (format "%s-child-p" cname)) filename "" nil nil) (autoload (intern (format "%s-child-p" cname)) filename "" nil nil)
(autoload (intern (format "%s-list-p" cname)) filename "" nil nil))))) (autoload (intern (format "%s-list-p" cname)) filename "" nil nil)))))
(defsubst eieio-class-un-autoload (cname) (defun eieio--full-class-object (class)
"If class CNAME is in an autoload state, load its file." "Like `eieio--class-object' but loads the class if needed."
(autoload-do-load (symbol-function cname))) ; cname (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) (cl-deftype list-of (elem-type)
`(and list `(and list
@ -730,9 +735,7 @@ Argument FN is the function calling this verifier."
(cl-check-type obj (or eieio-object class)) (cl-check-type obj (or eieio-object class))
(let* ((class (cond ((symbolp obj) (let* ((class (cond ((symbolp obj)
(error "eieio-oref called on a class: %s" obj) (error "eieio-oref called on a class: %s" obj)
(let ((c (cl--find-class obj))) (eieio--full-class-object obj))
(if (eieio--class-p c) (eieio-class-un-autoload obj))
c))
(t (eieio--object-class obj)))) (t (eieio--object-class obj))))
(c (eieio--slot-name-index class slot))) (c (eieio--slot-name-index class slot)))
(if (not c) (if (not c)
@ -1013,16 +1016,15 @@ The order, in which the parents are returned depends on the
method invocation orders of the involved classes." method invocation orders of the involved classes."
(if (or (null class) (eq class eieio-default-superclass)) (if (or (null class) (eq class eieio-default-superclass))
nil nil
(unless (eieio--class-default-object-cache class) (let ((class (eieio--full-class-object class)))
(eieio-class-un-autoload (eieio--class-name class)))
(cl-case (eieio--class-method-invocation-order class) (cl-case (eieio--class-method-invocation-order class)
(:depth-first (:depth-first
(eieio--class-precedence-dfs class)) (eieio--class-precedence-dfs class))
(:breadth-first (:breadth-first
(eieio--class-precedence-bfs class)) (eieio--class-precedence-bfs class))
(:c3 (:c3
(eieio--class-precedence-c3 class)))) (eieio--class-precedence-c3 class))))))
)
(define-obsolete-function-alias (define-obsolete-function-alias
'class-precedence-list 'eieio--class-precedence-list "24.4") 'class-precedence-list 'eieio--class-precedence-list "24.4")

View file

@ -425,10 +425,11 @@ If EXTRA, include that in the string returned to represent the symbol."
'object-class-name 'eieio-object-class-name "24.4") 'object-class-name 'eieio-object-class-name "24.4")
(defun eieio-class-parents (class) (defun eieio-class-parents (class)
;; FIXME: What does "(overload of variable)" mean here?
"Return parent classes to CLASS. (overload of variable). "Return parent classes to CLASS. (overload of variable).
The CLOS function `class-direct-superclasses' is aliased to this function." The CLOS function `class-direct-superclasses' is aliased to this function."
(eieio--class-parents (eieio--class-object class))) (eieio--class-parents (eieio--full-class-object class)))
(define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4") (define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4")
@ -468,7 +469,7 @@ The CLOS function `class-direct-subclasses' is aliased to this function."
(defun child-of-class-p (child class) (defun child-of-class-p (child class)
"Return non-nil if CHILD class is a subclass of 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) (cl-check-type child eieio--class)
;; `eieio-default-superclass' is never mentioned in eieio--class-parents, ;; `eieio-default-superclass' is never mentioned in eieio--class-parents,
;; so we have to special case it here. ;; so we have to special case it here.