1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-10 08:10:21 -08:00

cl-types: The big renaming to "derived types"

`cl-defstruct` also defines a type and is also in CL, so
"cl-type" is not precise enough to talk about those types
defined with `cl-deftype`.  Use the term "derived type" to be
more clear, as is done in the HyperSpec.

* doc/misc/cl.texi (Derived types): Move `cl-deftype` to this
new subsection.  Document the use of derived types as method specializers.

* lisp/emacs-lisp/cl-extra.el (cl--types-of-memo): Rename from
`cl--type-unique`.
(cl--derived-type-dispatch-list): Rename from `cl--type-dispatch-list`.
(cl--derived-type-generalizer): Rename from `cl--type-generalizer`.
(cl--derived-type-generalizers): Rename from `cl--type-generalizers`.

* lisp/emacs-lisp/cl-lib.el (cl-generic-generalizers) <derived-types>:
Rename from <cl-types-of>.  Catch but don't hide errors when a derived
type cannot be used as an atomic type specifier.

* lisp/emacs-lisp/cl-preloaded.el (cl--derived-type-list): Rename from
`cl--type-list`.
(cl-derived-type-class): Rename from `cl-type-class`.
(cl--derived-type-class-make): Rename from `cl--type-class-make`.
(cl--define-derived-type): Rename from `cl--type-deftype`.
This commit is contained in:
Stefan Monnier 2025-05-07 13:24:07 -04:00
parent f6f35644b7
commit b13044dae3
5 changed files with 73 additions and 49 deletions

View file

@ -467,18 +467,18 @@ The fields are used as follows:
;;;; Support for `cl-deftype'.
(defvar cl--type-list nil
(defvar cl--derived-type-list nil
"Precedence list of the defined cl-types.")
;; FIXME: The `cl-deftype-handler' property should arguably be turned
;; into a field of this struct (but it has performance and
;; compatibility implications, so let's not make that change for now).
(cl-defstruct
(cl-type-class
(cl-derived-type-class
(:include cl--class)
(:noinline t)
(:constructor nil)
(:constructor cl--type-class-make
(:constructor cl--derived-type-class-make
(name
docstring
parent-types
@ -489,15 +489,15 @@ The fields are used as follows:
(error "Unknown type: %S" type)))
parent-types))))
(:copier nil))
"Type descriptors for types defined by `cl-deftype'.")
"Type descriptors for derived types, i.e. defined by `cl-deftype'.")
(defun cl--type-deftype (name parents arglist &optional docstring)
"Register cl-type with NAME for method dispatching.
(defun cl--define-derived-type (name parents arglist &optional docstring)
"Register derived type with NAME for method dispatching.
PARENTS is a list of types NAME is a subtype of, or nil.
DOCSTRING is an optional documentation string."
(let* ((class (cl--find-class name)))
(when class
(or (cl-type-class-p class)
(or (cl-derived-type-class-p class)
;; FIXME: We have some uses `cl-deftype' in Emacs that
;; "complement" another declaration of the same type,
;; so maybe we should turn this into a warning (and
@ -505,11 +505,11 @@ DOCSTRING is an optional documentation string."
(error "Type in another class: %S" (type-of class))))
;; Setup a type descriptor for NAME.
(setf (cl--find-class name)
(cl--type-class-make name docstring parents))
(cl--derived-type-class-make name docstring parents))
;; Record new type. The constructor of the class
;; `cl-type-class' already ensures that parent types must be
;; defined before their "child" types (i.e. already added to
;; the `cl--type-list' for types defined with `cl-deftype').
;; the `cl--derived-type-list' for types defined with `cl-deftype').
;; So it is enough to simply push a new type at the beginning
;; of the list.
;; Redefinition is more complicated, because child types may
@ -524,11 +524,11 @@ DOCSTRING is an optional documentation string."
;; `parents` slots point to the old class object. That's a
;; problem that affects all types and that we don't really try
;; to solve currently.
(or (memq name cl--type-list)
(or (memq name cl--derived-type-list)
;; Exclude types that can't be used without arguments.
;; They'd signal errors in `cl-types-of'!
(not (memq (car arglist) '(nil &rest &optional &keys)))
(push name cl--type-list))))
(push name cl--derived-type-list))))
;; Make sure functions defined with cl-defsubst can be inlined even in
;; packages which do not require CL. We don't put an autoload cookie