Tuesday, 27 July 2010

[Book] Chapter 5.1 External References Collection

Returned by sb-c::find-initial-dfo components are passed to sb-c::compile-component one by one, in the loop which is located inside sb-c::%compile function (src/compiler/main.lisp). Function sb-c::compile-component runs the individual compilation stages for the component. In case we skip the minor things (like the sanity checks), the first function's action is the analysis and collection of the component's external references. Let us discuss this process, along with the corresponding source file ('src/compiler/xref.lisp'). It starts with sb-c::record-component-xrefs function:




This code is pretty simple. For each cblock in the input component, the local function handle-node records the possible external references for every node in that block. The function uses sb-c::record-node-xrefs to analyse the individual node. The analysis is nothing but etypecase form, which handles every kind of node in a particular way. The complicated part comes with sb-c::call-with-block-external-functionals:




This function actually applies handle-node. It defines handle-functional local function, which filters functionals before passing them to the handler. Also, it handles all functionals whose ref nodes point on the initial functional, in the recursive manner.

The reference recording happens in sb-c::record-xref:




To understand the process results better, let us debug it a bit:




In this example, the reference kind is :calls. This means that f calls the global function #'+ (or just +, as you can see on the figure). The context is clambda which corresponds to f, then we see the reference node and nil instead of the source path. At this point we consider the external references collection to be explained enough. The author hopes that the readers also find this process and the related code to be simple.

1 comments:

  1. This chapter is a part of Chapter 5 'Component Compilation During IR1', which is planned to be quite long. Regarding 5.1, the material is really simple. Just review xref.lisp to agree with me.

    I plan to have a vacation starting in the middle of August. In case I finish 5.2 by that time, it will appear here before September. Otherwise, you are welcome to visit this blog in the middle of September, or a bit earlier :)

    ReplyDelete