-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra Cassette code doesn't compile away like it's supposed to? #84
Comments
My guess is that it can't do const folding due to these remaining julia> using Cassertte
julia> @code_warntype Cassertte.Toggles.toggle(Cassertte.CassertteSwitch(), +, 5,5)
Body::Int64
23 1 ── %1 = (getfield)(args, 1)::Int64 │
│ %2 = (getfield)(args, 2)::Int64 │
│ %3 = (Core.tuple)(%1, %2)::Tuple{Int64,Int64} │
│ %4 = (Base.sle_int)(1, 1)::Bool │╻╷╷╷╷╷╷╷ #toggle#2
└─── goto #3 if not %4 ││┃││││││ Type
2 ── %6 = (Base.sle_int)(1, 0)::Bool │││┃││││││ #ToggleCtx#1
└─── goto #4 ││││┃││││ Type
3 ── nothing │
4 ┄─ %9 = φ (#2 => %6, #3 => false)::Bool │││││┃│││ isempty
└─── goto #6 if not %9 ││││││┃││ iterate
5 ── invoke Base.getindex(()::Tuple{}, 1::Int64) │││││││┃│ iterate
└─── $(Expr(:unreachable)) ││││││││┃ iterate
6 ── goto #8 │││││││││
7 ── $(Expr(:unreachable)) │││││││││
8 ┄─ goto #9 ││││││││
9 ── goto #10 ││││││╻ iterate
10 ─ goto #11 ││││││
11 ─ goto #12 │││││
12 ─ goto #13 ││││
13 ─ goto #14 │││
14 ─ %21 = %new(getfield(Toggles, Symbol("##3#4")){Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},typeof(+),Tuple{Int64,Int64}}, $(QuoteNode(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}())), +, %3)::getfield(Toggles, Symbol("##3#4")){Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},typeof(+),Tuple{Int64,Int64}}
└─── goto #16 if not true ││╻ #3
15 ─ nothing │
16 ─ goto #18 if not true │││
17 ─ nothing │
18 ─ goto #20 if not true │││
19 ─ nothing │
20 ─ goto #22 if not true │││
21 ─ nothing │
22 ─ goto #24 if not true │││
23 ─ nothing │
24 ─ goto #26 if not true │││
25 ─ %33 = Core.getfield::typeof(getfield) │││
└─── %34 = (%33)(%21, :args)::Tuple{Int64,Int64} │││╻╷╷ overdub
26 ─ %35 = φ (#25 => %34, #24 => $(QuoteNode(Cassette.OverdubInstead())))::Union{OverdubInstead, Tuple{Int64,Int64}} │││
│ %36 = π (%35, Tuple{Int64,Int64}) │││
└─── goto #32 if not true │││
27 ─ %38 = Core._apply::typeof(Core._apply) ││││╻ apply_args
│ %39 = (%38)(tuple, %36)::Tuple{Int64,Int64} │││││
│ %40 = (getfield)(%39, 1)::Int64 │││╻ overdub
│ %41 = (getfield)(%39, 2)::Int64 ││││
└─── goto #29 if not true ││││╻ +
28 ─ %43 = Base.add_int::Core.IntrinsicFunction │││││
└─── %44 = (%43)(%40, %41)::Int64 │││││╻╷╷ overdub
29 ─ %45 = φ (#28 => %44, #27 => $(QuoteNode(Cassette.OverdubInstead())))::Union{OverdubInstead, Int64} │││││
│ %46 = π (%45, Int64) │││││
└─── goto #30 │││││
30 ─ %48 = π (%46, Int64) │││╻ overdub
└─── goto #31 ││││
31 ─ nothing │
32 ─ %51 = φ (#31 => %48, #26 => $(QuoteNode(Cassette.OverdubInstead())))::Union{OverdubInstead, Int64} │││
│ %52 = π (%51, Int64) │││
└─── goto #33 │││
33 ─ goto #34 ││
34 ─ return %52 │
julia> |
I've also opened NHDaly/Cassertte.jl#1 to track any changes needed in my code. Haha maybe I should consider a different name, just that one single |
The idea is that there should be no "de facto overhead" from contextual code execution using Cassette. Using your example (also using julia> using Cassette
julia> Cassette.@context Ctx
Cassette.Context{nametype(Ctx),M,P,T,B} where B<:Union{Nothing, IdDict{Module,Dict{Symbol,BindingMeta}}} where P<:Cassette.AbstractPass where T<:Union{Nothing, Tag} where M
julia> @code_llvm 5 + 5
; Function +
; Location: int.jl:53
define i64 @"julia_+_35546"(i64, i64) {
top:
%2 = add i64 %1, %0
ret i64 %2
}
julia> f(x, y) = Cassette.overdub(Ctx(), +, x, y)
f (generic function with 1 method)
julia> @code_llvm f(5,5)
; Function f
; Location: REPL[4]:1
define i64 @julia_f_36037(i64, i64) {
top:
; Function +; {
; Location: int.jl:53
; Function overdub; {
; Location: /Users/jarrettrevels/.julia/dev/Cassette/src/overdub.jl:437
; Function macro expansion; {
; Location: /Users/jarrettrevels/.julia/dev/Cassette/src/overdub.jl:403
; Function fallback; {
; Location: /Users/jarrettrevels/.julia/dev/Cassette/src/context.jl:439
; Function call; {
; Location: /Users/jarrettrevels/.julia/dev/Cassette/src/context.jl:441
%2 = add i64 %1, %0
;}}}}}
ret i64 %2
} As you can see, there's no performance overhead here for a "blank" context (note that there are definitely remaining edge cases, e.g. #71). Of course, Cassette obviously can't make any performance guarantees about extra instrumentation inserted by context authors, e.g. I could use Cassette to insert a I'm down to help fix any perf issues in downstream code, though, so let's continue discussion at NHDaly/Cassertte.jl#1. And, of course, if we find any upstreamable issues, that'd be a bonus! 🙂 |
Hey, sorry I didn't respond for forever. Okay cool gotcha! yes your explanation makes 100% sense. Thanks!! :) I'll move the discussion over there now then. :) Thanks! |
I seem to recall you stating somewhere that you want more people "using Cassette and posting bugs", so here i go! :P
I've created and pushed up Cassertte.jl, and the more general Toggles.jl I used to create it. Thanks for your help with it!
It works, but I'm surprised and sad to see all this native code bloat! Am i doing something wrong there, or is this a legitimate issue with Cassette that still remains?
:D So much fun!
The text was updated successfully, but these errors were encountered: