tryToGenerateSpecialPrimitiveInvocation

open override fun tryToGenerateSpecialPrimitiveInvocation(functionToCallReg: L2ReadBoxedOperand, rawFunction: A_RawFunction, arguments: List<L2ReadBoxedOperand>, argumentTypes: List<A_Type>, translator: L1Translator, callSiteHelper: L1Translator.CallSiteHelper): Boolean

The arguments list initially has two entries: the register holding the function to invoke, and the register holding the tuple of arguments to pass it. If the call will always succeed (i.e., the supplied arguments satisfy the function's parameter types) then generate a direct invocation of the function with those arguments.

If the call cannot be checked until runtime, assume that the most likely scenario by far is that the argument types will conform to the required parameter types. Create a path of dynamic type tests that leads to code where the call will always succeed and the function is being directly invoked. On the rare failure paths, we still have to invoke the invoker function (the one defined as this primitive), as its failure code must be executed. Since this is exceedingly rare, let the primitive do the usual dynamic type tests (redundantly), just to fail the primitive in a way that hides the optimization.

If the call will always fail, just invoke this primitive normally, and let it fail.