Modifying lowered code


My tracing package currently parses files to recover the AST behind every traced function. It works, but it’s slow. Perhaps working with lowered code would be better. I’ve read the devdocs and still have a few questions. Any help greatly appreciated!

  • I can get the lowered code for foo(::Int) with Base.uncompressed_ast. How do I change foo(::Int)'s definition with my new lowered code? That is, what’s the correct way to write eval(:(function foo() $new_lowered_code end))?
  • Keyword argument functions are lowered into three methods. I can trace both the kwfunc(fun) and fun, or the function with the actual code. The latter sounds simpler. Is there a function like kwfunc to get it?
  • f(x, a=2) = x+a defines two methods, but I don’t want to trace both. How can I identify that the f(x) method is a forwarding function?
  • I can get most of the functions defined in module M from names(M, true, true), but if M define Base.convert(...) = ... without importing convert, it won’t be part of names. How can I find all such methods defined in M?

Thank you!