typed_python
typed_python copied to clipboard
Add IR inspection methods
Motivation and Context
Adds the minimum viable code introspection tooling to Runtime - given a compiled Function, this will check the associated converter for functions with matching names and generate the string representations thereof. Will throw a ValueError if nothing is found (most likely because the relevant Function hasn't been run/compiled yet).
Approach
The ideal approach would add a method to the jit-compiled code (see numba's inspect_types), however this can't be done with the existing Entrypoint decorator as Functions don't implement the dict method, so setattr() doesn't work. A C++ method on the Functions would generate overhead for little gain. One workaround would be to implement a wrapper and masquerade such that the interpreter got access to a wrapped version of the Function with the associated utility methods, with the compiler ignoring this wrapper (credit to @guslonergan).
Further work - some equivalent of https://python-ast-explorer.com/ for the two ASTs, perhaps using ODB.
How Has This Been Tested?
Ran test script on a basic sum function with and without compilation, and checked the output.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist:
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
can you maybe add some tests that verify that you can compile something, call this method, and then get a string back out?