Changes between Initial Version and Version 1 of UnderstandingApply

Show
Ignore:
Timestamp:
12/07/08 13:41:59 (12 months ago)
Author:
jmaessen
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UnderstandingApply

    v1 v1  
     1= Understanding the apply path in the interpreter = 
     2 
     3Because the interpreter deals with dynamic type inference and dynamic 
     4overloading resolution, the path for applying a function can be rather 
     5twisty. 
     6 
     7Note in particular that the class `DottedMethodApplication` is used to 
     8represent a pending method application (ie a pair of receiver and the 
     9method applied to that receiver); this substantially simplifies the 
     10code to handle e.g. juxtaposition in the interpreter, but it's worth 
     11understanding that these objects are only closures in the sense that 
     12they're waiting to be applied to arguments just as a top-level 
     13function might be. 
     14 
     15Most function application in the interpreter goes via 
     16`EvaluatorBase.functionInvocation`, and thence to 
     17`applyPossiblyGeneric`.  This deals with tupling / un-tupling of 
     18arguments and then calls through to `applyInnerPossiblyGeneric`, which 
     19is the method that gets specialized for the various sorts of closure 
     20(overloaded, method, generic, etc.). 
     21 
     22A concrete interpreted method or function eventually constructs a new environment 
     23for its arguments using `buildEnvFrom[EnvAnd]Params`.  If the method 
     24or function is built in, it instead calls the built-in version using 
     25`applyToArgs` or `applyMethod` rather than building an env. 
     26 
     27A generic function or method undergoes type inference using 
     28`EvaluatorBase.inferAndInstantiateGenericFunction`; this computes the 
     29actual type parameters and creates a non-generic monomorphic `Simple_fcn` 
     30that can be invoked directly. 
     31 
     32An overloaded function or method attempts to find the most specific 
     33applicable overloading using `bestMatch` (which in turn calls 
     34`bestMatchInternal`).  This includes instantiating any generic 
     35overloadings that might apply. 
     36 
     37A functional method must extract its `self` parameter, then call the 
     38corresponding (specially-named) dotted method to resolve any 
     39overloading or overriding that might have occurred. 
     40 
     41== Summary of functions on apply path == 
     42 
     43=== `applyPossiblyGeneric` === 
     44Uses 
     45      * `Driver.runProgramTask` 
     46      * `Evaluator.invokeGenericMethod` (on `DottedMethodApplication`) 
     47      * `Evaluator.handleException` (construct `forbiddenException`) 
     48      * `EvaluatorBase.functionInvocation` (surrounding `setContext`) 
     49      * `LHSEvaluator.forLValue` (invoke array constructor) 
     50      * `SpawnTask.compute` 
     51      * `DottedMethodApplication.invokeMethod` 
     52      * `GenericFunctionOrConstructor` (after `inferAndInstantiateGenericFunction`) 
     53      * `GenericSingleton.make` (invoke nullary constructor on instantiation) 
     54      * `NonPrimitive.buildEnvFromParams` (invoke varargs factory) 
     55      * `OverloadedFunction.applyInnerPossiblyGeneric` (invoke best match) 
     56      * `Reflect.makeReflectedType` (invoke nullary Reflect constructor after instantiation) 
     57Defs 
     58      * `Fcn`: unwrap, handle `UnificationError`, call `applyInnerPossiblyGeneric`. 
     59 
     60=== `applyInnerPossiblyGeneric` === 
     61Uses 
     62      * `Fcn`: `applyPossiblyGeneric` 
     63Defs 
     64      * `Fcn`: abstract 
     65      * `Dummy_fcn`: NYI (testing only) 
     66      * `Constructor`: call thru to `applyConstructor` 
     67      * `DottedMethodApplication`: `applyMethod` with `setContext` 
     68      * `FunctionalMethod`: pull out self, `DottedMethodApplication.invokeMethod` 
     69      * `FunctionClosure`: `applyToArgs` of native, else eval 
     70      * `GenericFunctionOrConstructor`: `inferAndInstantiate`, then `applyPossiblyGeneric` 
     71      * `MethodClosure`: check for functional-ness, `applyMethod` 
     72      * `OverloadedFunction`: find best match, `applyPossiblyGeneric` 
     73 
     74=== `applyMethod` === 
     75Uses 
     76      * `DottedMethodApplication`: `applyInnerPossiblyGeneric` with `setContext` 
     77      * `MethodClosure.applyInnerPossiblyGeneric`: chain for 
     78      functional method invocation. 
     79      * `OverloadedMethod.applyMethod`: get applicable method, `applyMethod` 
     80      * `IndexedArrayWrapper.put`,get: apply putter,getter 
     81Defs 
     82      * interface `Method` 
     83      * `MethodClosure`: check for native, `applyMethod` or `buildEnvFromEnvAndParams` and eval 
     84      * `OverloadedMethod`: get applicable method, `applyMethod` 
     85      * `TraitMethodInstance`: `buildEnvFromEnvAndParams` and eval (not called?) 
     86      * `NativeMeth`: call thru to `applyMethod` (2 args, no site/`envForInference`) 
     87 
     88=== `buildEnvFromEnvAndParams` === 
     89Uses 
     90      * `Constructor.applyConstructor` (`methodsEnv`) 
     91      * `MethodClosure.applyMethod` (`envForApplication`) 
     92      * `TraitMethodInstance.applyMethod` (`evaluationEnv`) 
     93Defs 
     94      * `NonPrimitive` `(extendAt(getAt())`, pass to `buildEnvFromParams`) 
     95 
     96=== `buildEnvFromParams` === 
     97Uses 
     98      * `FunctionClosure.applyInnerPossiblyGeneric` 
     99Defs 
     100      * `NonPrimitive` (def with, without env; uses within by default) 
     101 
     102=== `bestMatch` === 
     103Uses 
     104      * `OverloadJUTest` 
     105      * `OverloadedFunction.applyInnerPossiblyGeneric` 
     106      * `MethodClosure.getApplicableMethod` 
     107Defs 
     108      * `OverloadedFunction`: calls `bestMatchInternal`, twice if no index is found. 
     109 
     110=== `bestMatchInternal` === 
     111Uses 
     112      * `OverloadedFunction.bestMatch` chains to 
     113Defs 
     114      * `OverloadedFunction`: `inferAndInstantiateGenericFunction` for generic 
     115 
     116=== `inferAndInstantiateGenericFunction` === 
     117Uses 
     118      * `GenericFunctionOrConstructor.applyInnerPossiblyGeneric` 
     119      * `OverloadedFunction.applyInnerPossiblyGeneric` (redundant w/`bestMatchInternal`!) 
     120      * `OverloadedFunction.bestMatchInternal` 
     121Defs 
     122      * `EvaluatorBase` (HUGE wad of code) 
     123