Type Inference


This code infers the types of all local variables. The main recursive function takes an arbitrary form and returns a form in which the head of each operation has been replaced by a vector [type head].

The types of most forms are determined by rule:

Special type rules are required for forms headed by: begin, set!, multiple-set!, constant-set!, values, while, unary-if, binary-if, make-point, scan, return, no-value (used to drop an output value on the floor), and begin.

In particular, the type of a unary-if statement is unspecified. The type of a binary-if form is the common type of its two clauses if they have the same type, and unspecified otherwise.

When the type of a symbol is first recorded, we might not have complete type information. It might be assigned an integer value when it is really a real. It might be assigned only a missing value. If the value is reset, the information from the two instances is fused. If fusion is impossible, an error is triggered.

In the first pass (step 5a), type inference is run twice. The first time is used to mark types for all the variables. Notice that the type of a variable may be upgraded (e.g. from integer to real) as this proceeds through the code. Type inference is run a second time to add type markings to subforms.

If an integer value is assigned to a real variable, the integer value is converted to a real using exact->inexact.


Ownership, Maintenance and Disclaimers

Manual Top Page

Last modified