alex-gutev / cl-form-types

Library for determining the types of Common Lisp forms based on information stored in the environment.
MIT License
19 stars 1 forks source link

custom-form-type for cl:aref can misbehave due to non-simple form-type of `the` form #9

Closed digikar99 closed 1 year ago

digikar99 commented 2 years ago

https://github.com/alex-gutev/cl-form-types/blob/7a68e67abca423e622349ef0ca97b73fa3f6c212/src/cl-functions.lisp#L141-L145

Multiple aspects, let's start with the example that triggered this:

CL-USER> (cl-form-types:form-type `(aref (the (simple-array single-float 1) a)
                                         (the (unsigned-byte 32 i)))
                                  nil)
(VALUES T &OPTIONAL)
  1. It should be (form-type (first form) env) instead of (form-type form env), and form isn't a form but rest of the form arguments.
  2. One needs to additionally check if the first element of the returned type (the value of element-type) is a list with its first element cl:array or cl:simple-array or such.
  3. Applying fix 1, we find that element-type gets the value (and (simple-array single-float) t). To keep things simple, if type1 is a subtype of type2, and combination can be avoided. I'm unsure if you want to apply this (and similar!) fix in combine-values-types or in the special-form-type specializing on cl:the. EDIT: Another factor is the form-type of (the type-1 form-2) should not result in type-1, because CLHS allows implementations to allow form-2 to be of a type other than type-2.

PS: Would it be recommendable to use spaces instead of tabs for indentation?

digikar99 commented 1 year ago

Point 3 is taken care of by https://github.com/alex-gutev/cl-form-types/pull/15.

Points 1 and 2 will be taken care of by https://github.com/alex-gutev/cl-form-types/pull/17.