CodeTracking.jl icon indicating copy to clipboard operation
CodeTracking.jl copied to clipboard

Revise should track macro-created functions defined in the REPL

Open cjwyett opened this issue 3 years ago • 1 comments

macro makefn(name)
    name = Symbol(name)
    quote
        $(esc(name))() = print("hello")
    end
end

julia> @makefn f
f (generic function with 1 method)

julia> f()
hello

julia> @code_string f()
"        \$(esc(name))() = println(\"hello\")"

In an ideal world, @code_string f() would return something like f() = println(\"hello\")".

cjwyett avatar Apr 19 '22 23:04 cjwyett

@code_string is designed to operate on raw source files---it's the fallback in case all the fancy Revise-based machinery fails. There's basically no way this can work.

It seems that Revise cannot track macro-created methods at the REPL, either. But if you put it in a file, then

julia> using CodeTracking, Revise

julia> includet("/tmp/ct.jl")

julia> definition(Expr, only(methods(f)))
:(#= /tmp/ct.jl:8 =# @makefn f)

julia> @code_expr f()
:(#= /tmp/ct.jl:8 =# @makefn f)

I think we can narrow the issue here, so I've edited the title.

timholy avatar Feb 04 '23 14:02 timholy