Subject: Re: bug#77725: 31.0.50; Add support for types accepted by `cl-typep' to cl-generic?

From: David Ponce <[email-masked]>
Date: Tue, 6 May 2025 00:37:07 +0200

On 2025-05-05 20:59, Stefan Monnier wrote:
>>> Thanks, pushed to the branch.  I think the code is looking pretty good now.
>> Thank you, that's great!
> 
> I just pushed to the branch a further patch (see attached) which tries
> to simplify the code a bit more.

Thank you!

The only change I cannot understand is this one in `cl-types-of':

"Don't bother skipping the `root-type` since that's a built-in type,
so it should never happen anyway."

The `root-type' was not skipped, but, on the contrary, was used to test
only types which have the same `root-type', i.e. skip types with a
different `root-type', which we are sure cannot match.  Your change just
removed this improvement and now all types are tested even if we can know
they cannot match.

As mentioned in a previous message, `cl--type-flag' explored the idea of
​​mapping a set of cl-types to a built-in type (root-type), and its value
allowed us to know whether the type is worth checking, i.e. either not
yet passed a `cl-typep' in `cl-types-of', or its root-type match the
`root-type' of the checked object:

(or (null cl--type-flag) (eq cl--type-flag root-type))

For example:

(cl-deftype2 icon ()
   "Builtin icon type."
   '(and symbol (satisfies iconp)))

(cl-types-of 'button) => button match `icon' type, so the `cl--type-flag'
of `icon' is set to `symbol' (cl-type-of or root-type of `button')

(cl-types-of 12) => `root-type' of 12 is `fixnum', so cl-types-of doesn't
waste time checking if 12 if of type `icon', because we are sure it cannot
match (their root-types are different).  An so on with other types whose
root-type is known.

Hope I am clear enough.

David