JuliaLabs / Cassette.jl

Overdub Your Julia Code
Other
371 stars 35 forks source link

Discriminating overdub calls for "same" function/args #179

Open robertfeldt opened 4 years ago

robertfeldt commented 4 years ago

This can probably be done with a specific pass but I wonder if there is a simpler way to "tag" the calls to overdub so I can related them back to the original code of the overdubbed method?

One way to illustrate this is that for a function like:

function f(x, y)
  if x < y           # line 1
    return x + y     # line 2 
  else
    a = x + y        # line 4
    return a
  end
end

I would want a way to discriminate between the Cassette.overdub(ctx, :+, :x, :y) call on "line" 2 and the same call on "line" 4. So essentially something like a Cassette.overdub(context::Context, n::Int, f, args...) where n is unique Int for each unique call site of the overdubbed code.

What I'm trying to achieve here is a simple expression coverage calculation and even though the calls have the same arguments and returns the same result the calls correspond to different "call sites" so for some applications (like mine) we need to keep them apart.

Any ideas how to easily achieve this? Or have you seen anyone implementing a code/expression coverage tool using Cassette? Thanks in advance for any pointers/insight.

vchuravy commented 3 years ago

@robertfeldt did you find an answer to your question? I suspect one could do this with a pass, where you insert before each call a push!(ctx, (f, args...), LineInfo). The question is how do you do "differentiation". If you just need a trace you can do that with prehook/posthook.