JuliaLabs / Cassette.jl

Overdub Your Julia Code
Other
371 stars 35 forks source link

don't splat into _apply calls #134

Open vchuravy opened 5 years ago

vchuravy commented 5 years ago

In https://github.com/vchuravy/GPUifyLoops.jl/pull/88 I noticed that calls like f(a, b, args...) = Core._apply(g, (a, b), args...) where not being inlined, whereas f(a, b, args...) = Core._apply(f, (a, b), args) will be inlined.

@jrevels I am not sure if that impacts any of the _apply handling in overdub.jl.

vchuravy commented 5 years ago
using Cassette
using InteractiveUtils

Cassette.@context Ctx

g(x, y, args...) = args
f(x, y, args...) = Cassette.overdub(Ctx(), Core._apply, g, x, y, args...)
@show @code_typed f(1, 2)

Before:

➜  experiments git:(master) ✗ ~/builds/julia/julia apply.jl
#= /home/vchuravy/src/experiments/apply.jl:8 =# @code_typed(f(1, 2)) = CodeInfo(
1 ─ %1 = Core._apply::typeof(Core._apply)
│   %2 = (%1)(Cassette.overdub, (Cassette.Context{nametype(Ctx),Nothing,Nothing,getfield(Cassette, Symbol("##PassType#399")),Nothing,Nothing}(nametype(Ctx)(), nothing, nothing, getfield(Cassette, Symbol("##PassType#399"))(), nothing, nothing), g), x, y)::Tuple{}
└──      return %2
) => Tuple{}

After:

➜  experiments git:(master) ✗ ~/builds/julia/julia apply.jl
#= /home/vchuravy/src/experiments/apply.jl:8 =# @code_typed(f(1, 2)) = CodeInfo(
1 ─     return ()
) => Tuple{}

But apparently it breaks other things right now.