## simplified-types

2019-08-13

Simplification of Common Lisp type specifiers.

### Upstream URL

### Author

### License

Common Lisp has powerful facilities for reasoning about types, including logical connectives, numeric intervals, and predicates involving arbitrary functions. A downside of this expressiveness is that the manipulation of type specifiers is an arduous and error-prone task. This library provides functions to simplify type specifiers.

The API consists of two functions:

`simplify-type`

takes a type specifier and, optionally, an environment,and returns the corresponding simplified type.`simplified-type-of`

takes an object and returns the simplified type ofthat object.

The simplified type hierarchy has been chosen to strike a balance between simplicity and expressiveness. The following simplified type specifiers exist:

- The symbols
`t`

and`nil`

. - The symbols
`function`

,`character`

,`symbol`

, and`cons`

. - The symbols
`short-float`

,`single-float`

,`double-float`

, and`long-float`

. - The compound type specifier
`(integer <lower-limit> <upper-limit>)`

,where`<lower-limit`

and`<upper-limit>`

are either an integer, or thesymbol`*`

. - The compound type specifier
`(complex <float-type>)`

, where`<float-type>`

is one of the symbols`short-float`

,`single-float`

,`double-float`

, or`long-float`

.

A consequence of restricting all types this way is that the simplified type
lattice has only a single layer of disjoint types between `t`

and `nil`

.
That means that all types except `t`

and `nil`

are disjoint, that the join
of any of these disjoint types is `t`

, and that the meet of any of these
disjoint types is `nil`

.

Despite its simplicity, this set of types is expressive enough to help a compiler generate fast code. In particular, it covers all upgraded array element types that are usually provided by an implementation.

The special variable `*precise-integer-types*`

decides whether integer
types have a precise upper and lower limit, or whether the simplification
may also upgrade the bounds to the symbol `*`

. The advantage of the latter
approach is that type simplification will not cons.