IBM / pyflowgraph

Flow graphs for Python
Apache License 2.0
25 stars 8 forks source link

Replace sys.settrace with AST rewriting #13

Closed epatters closed 5 years ago

epatters commented 5 years ago

Using sys.settrace (or sys.setprofile) for tracing function calls was a quick way to get started but has fundamental limitations, some of which are documented in #10, #11, and #12.

A more flexible and scalable approach is to rewrite the AST with explicit tracing machinery. In a nutshell, replace function calls

f(x,y,z=1)

with

CALL(f, x, y, z=1)

where CALL is a special shim that calls and records a function.

It will take a little effort to get this approach off the ground, but it should ultimately work better. We took this approach from the beginning in rflowgraph, because R has no equivalent to sys.settrace AFAIK.

epatters commented 5 years ago

The macropy library shows how to implement a simple form of tracing by AST rewriting, although I don't think we need the full macropy machinery:

https://github.com/lihaoyi/macropy#tracing https://github.com/lihaoyi/macropy/blob/master/macropy/tracing.py