emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: feature/type-hierarchy 8a63e50036f 1/5: * Define 'cl--type-hierarchy


From: Andrea Corallo
Subject: Re: feature/type-hierarchy 8a63e50036f 1/5: * Define 'cl--type-hierarchy' and compute 'cl--typeof-types' from it
Date: Sun, 03 Mar 2024 13:05:27 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Looks to me better now, this is the content on my Emacs after having
>> pushed 8d11b7e4275, please have a look:
>
> looks OK, thanks (modulo structure/class because I don't know what these 
> mean).

Cool, I'll comeback on the structure/class subject.

>> Also is not clear to me if 'cl--typeof-types' should include all types
>> or only leaf ones.
>
> The intention was to include only leaf types, i.e. the types that
> `type-of` can return, since the main purpose was to find the (ordered)
> list of parents in:
>
>     (cl-generic-define-generalizer cl--generic-typeof-generalizer
>       ;; FIXME: We could also change `type-of' to return `null' for nil.
>       10 (lambda (name &rest _) `(if ,name (type-of ,name) 'null))
>       (lambda (tag &rest _)
>         (and (symbolp tag) (assq tag cl--typeof-types))))
>
>> The original was inconsistent on this,
>
> Maybe that was an oversight.
> Do you remember which inconsistency you had noticed in this respect?

I remember (symbol-with-pos symbol atom) (symbol atom), there might have
been others.

>> this version evidently includes all types but should be easy to
>> generate only based on the leaf ones if necessary.
>
> Having extra types doesn't bring any benefit that I can see but is
> fairly harmless (it may just slow down ever so slightly a few method
> dispatches, when we have a miss in the method cache).

Mmmmh, I tried:

=======
--- a/lisp/emacs-lisp/cl-preloaded.el
+++ b/lisp/emacs-lisp/cl-preloaded.el
@@ -117,8 +117,12 @@ cl--supertypes-for-typeof-types
     (cl--supertypes-for-typeof-types-rec type)
     (merge-ordered-lists cl--supertypes-lanes-res)))

+(defun cl--type-leaf-p (type)
+  (null (assq type cl--type-hierarchy)))
+
 (maphash (lambda (type _)
-           (push (cl--supertypes-for-typeof-types type) cl--typeof-types))
+           (when (cl--type-leaf-p type)
+             (push (cl--supertypes-for-typeof-types type) cl--typeof-types)))
          cl--direct-supertypes-of-type)

 (defconst cl--all-builtin-types
======

This generates as 'cl--typeof-types':

((subr-primitive subr function atom)
 (subr-native-elisp subr function atom)
 (module-function function atom)
 (byte-code-function compiled-function function atom)
 (cons list sequence)
 (null list sequence boolean symbol atom)
 (string array sequence atom)
 (char-table array sequence atom)
 (bool-vector array sequence atom)
 (vector array sequence atom)
 (keyword symbol-with-pos symbol atom)
 (fixnum integer number number-or-marker integer-or-marker atom)
 (bignum integer number number-or-marker integer-or-marker atom)
 (marker number-or-marker integer-or-marker atom)
 (float number number-or-marker atom)
 (obarray atom)
 (overlay atom)
 (window-configuration atom)
 (process atom)
 (window atom)
 (buffer atom)
 (frame atom)
 (hash-table atom)
 (terminal atom)
 (thread atom)
 (mutex atom)
 (condvar atom)
 (font-spec atom)
 (font-entity atom)
 (font-object atom)
 (user-ptr atom)
 (tree-sitter-parser atom)
 (tree-sitter-node atom)
 (tree-sitter-compiled-query atom)
 (structure atom)
 (class atom))

Which looks okay to me at a first glance, but make check explodes 🤷...
I might be doing something wrong.

  Andrea



reply via email to

[Prev in Thread] Current Thread [Next in Thread]