Generated functions
A generated function is a user-defined function that gets expanded at compile time, allowing it to generate code based on its argument types. It has proved to be of value in some specialized areas but is not widely used.
To define a generated function, we use the @generated
macro, which indicates that the function should be expanded at compile time, rather than executed at runtime.
The body of the generated function has access to the types of arguments but not their values, so it is possible to perform type-based dispatch based on the function’s arguments.
They are seen as being useful when the behavior of the code depends on the specific types involved. For example, when mathematical operations need to be performed differently for integers and floating-point numbers, a generated function can create optimized code for each case.
It should be noted that work on the compilation and execution of “regular” Julia code has currently made...