[ Home ]
SBCL Internals

The pages on this CLiki-driven site can be edited by anybody at any time. No warranty of any kind can therefore be made; any implied warranties of merchantability or fitness for a particular purpose are expressly disclaimed
[ Home ] [ Recent Changes ] [ About CLiki ] [ Text Formatting ]

Compiler

Structures containing related information

on types:

Type annotations

NODE-DERIVED-TYPE
LVAR-DERIVED-TYPE
Union of NODE-DERIVED-TYPE of all uses
LVAR-%DERIVED-TYPE
Cached derived type

The initial value of LEAF-TYPE is set to a global declaration.

Bound type declarations on a lexical variable are recorded in LEAF-TYPE, free on a lexical and all on a dynamic - in LEXENV-TYPE-RESTRICTIONS. Type declarations on a symbol macro are implemented by wrapping THE around its expansion, which is almost certainly non-conformant

NODE-DERIVED-TYPE of REF is set to LEAF-TYPE.

LVAR-DERIVED-TYPE of a function in a COMBINATION is used to set type assertions on the arguments and a derived type of the result. (See also bug 35.)

Type assertions

Type assertions are represented in IR1 with CAST nodes. During generation of CAST, type is weakened according to the current policy. Semantics: the argument is checked to be of type CAST-TYPE-TO-CHECK; after it it is considered to be of type CAST-ASSERTED-TYPE.

Possible type errors are caught at this stage: if the argument derived type does not intersect with CAST-ASSERTED-TYPE, CAST is replaced with a call of %COMPILE-TIME-TYPE-ERROR. We delay emitting warnings until IR2 conversion, thus preventing spurious warnings for dead branches of code.

Unsafe CAST nodes create problems for optimization: they complicate analyzing of arguments, prevent tail call optimization and unused code removing; on the other hand they are necessary for constraint propagation. We remove unused CASTs (this corresponds to the old SBCL behavior) and those masking a tail call (they are not used by constraint propagation).

In IR1 finalization we propagate trustable type assertions from CASTs to their argument nodes, so that we don't need to look forward in template selection, and combine externally checkable CASTs with the destination combination.

Generation of type checks

Wishlist

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively