Compile-time errors in generic operators
Generic operators are primitive operators, and they handle runtime errors similarly. However, generic operators are unique in that they can detect some errors at compile time.
Catching compile-time errors is one of the main benefits of implementing generic operators. The Perl API that is exposed in mixed-mode has a rich set of functions to aid in detecting errors that are related to types, model specification, and parameters. The general principle is that if an error can be detected at compile time, then detect it.
When an error is detected, generic operators emit error messages that indicate what the error is, and where in the source code the error occurred. The function SPL::CodeGen::error() emits an error message, and takes an optional last parameter that is the source location of the offending piece of code. Perl objects in mixed-mode that can cause such errors have a getSourceLocation() method that reports the line of SPL source that they appear on. If the error prevents further parsing of the operator, then operator developers instead must call SPL::CodeGen::exit(), which emits an error message, the optional line number, and then immediately exits. However, if it is possible to continue processing the operator invocation, developers can use the error() function instead. Using the error() function eventually causes the compiler to exit with an error condition, but it might be able to catch multiple errors. Reporting multiple errors is easier on SPL programmers who use the operator, because it allows them to fix multiple errors before each recompile.
- The validity of the window expressions.
- The number of output ports and the join that is being requested.
- That the default tuples match both the type of join and the types of their respective ports.
- That the left-side and right-side equality expressions match in number and type.
- If there are appropriate partitioning parameters.
All of these errors are caught at compile time. For examples of how to perform such error checking, see the Advanced code generation section.