When config.type_checking is disabled we currently prepend a "shim" method that ignores validating the types in the user's code. So when calling a previously typed method there is always a guard method to go through. This impacts performance by adding additional method calls in the prepended "shim" method. Instead let's rewrite the method to contain no types at all.
Benefits:
- Improve performance (no "shim" method)
- Simplify debugging (one less step)
- Shorten stack traces (one less line)
Implementation
Rewrite the method's params to be "untyped". This involves redefining the method using class_eval, or eval if that's the only way we can mirror the line numbers of the original method. LowType will use Lowkey in the "redefiner" phase to alter each ParamProxy in a MethodProxy to be untyped, and to delete its ReturnProxy if it exists. Then you do "method_proxy.export" to export the modified code, and eval() that code or similar to overwrite existing typed methods. Lowkey is very good at understanding the start_line/end_line and has an array of "lines" just for your particular proxy. So you can easily target the right spot in the source code, but I've only just finished this feature and it needs more work.
When config.type_checking is disabled we currently prepend a "shim" method that ignores validating the types in the user's code. So when calling a previously typed method there is always a guard method to go through. This impacts performance by adding additional method calls in the prepended "shim" method. Instead let's rewrite the method to contain no types at all.
Benefits:
Implementation
Rewrite the method's params to be "untyped". This involves redefining the method using class_eval, or eval if that's the only way we can mirror the line numbers of the original method. LowType will use Lowkey in the "redefiner" phase to alter each ParamProxy in a MethodProxy to be untyped, and to delete its ReturnProxy if it exists. Then you do "method_proxy.export" to export the modified code, and eval() that code or similar to overwrite existing typed methods. Lowkey is very good at understanding the start_line/end_line and has an array of "lines" just for your particular proxy. So you can easily target the right spot in the source code, but I've only just finished this feature and it needs more work.