Changes between Version 6 and Version 7 of Commentary/Rts/HaskellExecution


Ignore:
Timestamp:
Sep 12, 2006 3:54:25 PM (8 years ago)
Author:
simonmar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/HaskellExecution

    v6 v7  
    5454  * '''Known function, saturated call'''.   The function is applied to exactly the right number of arguments to satisfy its arity.  In that case, we simply load the arguments according to the standard entry convention, and tail-call (jump to) the function's entry point. 
    5555 
    56   * '''Known function, too few arguments'''.  In this case, we build a partial application (PAP), and return with a pointer to the PAP in the return register. 
     56  * '''Known function, too few arguments'''.  In this case, we want to build a partial application (PAP), and return with a pointer to the PAP in the return register.  Since building a PAP is a complicated business, instead we just behave as for an unknown function call, which will end up calling into the [[ref(Generic apply)]] code, which will build the PAP for us. 
    5757 
    58   * '''Known function, too many arguments'''.  Save the extra arguments on the stack, push a return address, and then behave just like a saturated call.  When the result comes back, behave like "unknown call". 
     58  * '''Known function, too many arguments'''.  We want to save the extra arguments on the stack, push a return address, and then behave just like a saturated call.  When the result comes back, we should behave like "unknown call".  However, to avoid needing to generate code for a new continuation here, the return address that we push on the stack is that of an appropriate [[ref(Generic apply)]] function, which will perform the application of the extra arguments to the (unknown) function returned by the saturated call. 
    5959 
    6060  * '''Unknown function''';  a call in which we do not statically know what the function is.  In that case we must do a "generic apply".  This is so exciting that it deserves its [wiki:Commentary/Rts/HaskellExecution#Genericapply own section]. 
     
    6464Files: [[GhcFile(utils/genapply)]] 
    6565 
    66 When compiling a call that has an unknown function, we must generate code 
     66When compiling a call that has an unknown function, we must generate code to 
    6767  * Evaluate the function 
    6868  * Scrutinise the function value returned to see its arity, and dispatch into the same three cases as in the case of known calls: 
     
    7070    * Too few arguments: build a PAP 
    7171    * Too many arguments: save the excess arguments, and tail call the function as for a saturated cal. 
    72 All of this takes quite a lot of code, so we pre-generate a whole bunch of generic-apply code sequencues, one for each combination of arguments.  This code is generated by the tool [[GhcFile(utils/genapply)]], and appears in [[GhcFile(rts/AutoApply.cmm)]]. 
     72All of this takes quite a lot of code, so we pre-generate a whole bunch of generic-apply code sequencues, one for each combination of arguments.  This code is generated by the tool [[GhcFile(utils/genapply)]], and the generated code appears in `rts/AutoApply.cmm`. 
    7373 
    74 For example, if we find a call to an unknown function applied to two (boxed) `Int` arguments, load the function and its two arguments into the standard places (?) and jump to `stg_ap_pp_entry`.  This latter code is in [[GhcFile(rts/AutoApply.cmm)]], generated by the `autoapply` tool.  The "`pp`" part is the bit that says the code is specialised for two pointer arguments. 
     74For example, if we find a call to an unknown function applied to two (boxed) `Int` arguments, load the function and its two arguments as for the standard entry convention and jump to `stg_ap_pp_fast`.  This latter code is in `rts/AutoApply.cmm`, generated by the `genapply` tool.  The "`pp`" part is the bit that says the code is specialised for two pointer arguments. 
    7575 
    76 If none of the canned sequences apply, then we have to do somthing yet more exotic, and I have forgotten what it is.  Simon!  Help! 
     76In addition to the family of `stg_ap_<pattern>_fast` functions for making calls to unknown functions with various argument patterns, there is a corresponding family of return addresses `stg_ap_<pattern>_info`.  The idea is that you can push a continuation that will make a call to the function that is returned to it.  For example, to push a continuation that will apply a single pointer argument, we would push the following words on the stack: 
     77 
     78|| arg || 
     79|| `stg_ap_p_info` || 
    7780 
    7881== Entry conventions ==