What are nodes of typechecking residues in F# TAST?

Viewed 78

I am learning f# compiler internals (https://github.com/Microsoft/visualfsharp repo, dev16.0 branch), and I came across on interesting parts of its "typecheked" abstract syntax tree. In short, Expr type is used to represent some nodes of tree, here is part of its definition:

Expr =
    /// A constant expression. 
    | Const of Const * range * TType

    ///....

    /// Typechecking residue: Indicates a free choice of typars that arises due to 
    /// minimization of polymorphism at let-rec bindings.  These are 
    /// resolved to a concrete instantiation on subsequent rewrites. 
    | TyChoose of Typars * Expr * range

    /// Typechecking residue: A Expr.Link occurs for every use of a recursively bound variable. While type-checking 
    /// the recursive bindings a dummy expression is stored in the mutable reference cell. 
    /// After type checking the bindings this is replaced by a use of the variable, perhaps at an 
    /// appropriate type instantiation. These are immediately eliminated on subsequent rewrites. 
    | Link of Expr ref

What's the meaning of TyChoose and Link nodes? Comments give some explanations, but it's still too vague for me. Is there any code which can clarify such expressions? Basically, I thought that typecheked ast cannot have some residues of type inference algorithm (in other words it used only at phase of converting AST to AST with signatures). Final ast has only expressions with completed types.

UPD: It seems like Link node is not used during converting TAST -> ILX. Here is piece of code, which shows that it is stripped:

let rec GenExpr (cenv:cenv) (cgbuf:CodeGenBuffer) eenv sp expr sequel =
    let expr =  stripExpr expr
    //......

let rec stripExpr e = 
    match e with 
    | Expr.Link eref -> stripExpr !eref
    | _ -> e   
0 Answers
Related