Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IR inspection methods #398

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

wllgrnt
Copy link

@wllgrnt wllgrnt commented Sep 28, 2022

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)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@braxtonmckee
Copy link
Collaborator

can you maybe add some tests that verify that you can compile something, call this method, and then get a string back out?

Copy link
Collaborator

@braxtonmckee braxtonmckee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely needs a test exercising the functionality

typed_python/compiler/runtime.py Outdated Show resolved Hide resolved
@wllgrnt wllgrnt force-pushed the will_grant/add_codegen_inspection_methods branch from f995abc to 94e97b1 Compare March 9, 2023 00:05
Given a compiled Function, this looks for a matching function in the
converter and pulls the string representation, throwing if not found.
@wllgrnt wllgrnt force-pushed the will_grant/add_codegen_inspection_methods branch from 94e97b1 to 196da9e Compare March 9, 2023 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants