FastClosures.jl
FastClosures.jl copied to clipboard
Example is not _bad_ anymore
The last example seems to work now without @closure
julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: 11th Gen Intel(R) Core(TM) i7-11700KF @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, icelake-client)
Environment:
JULIA_NUM_THREADS = 16
julia> using FastClosures
julia> # code_warntype problem
function f1()
if true
end
r = 1
cb = ()->r
identity(cb)
end
f1 (generic function with 1 method)
julia> # code_warntype clean
function f2()
if true
end
r = 1
cb = @closure ()->r
identity(cb)
end
f2 (generic function with 1 method)
julia> @code_warntype f1()
MethodInstance for f1()
from f1() in Main at REPL[42]:2
Arguments
#self#::Core.Const(f1)
Locals
#16::var"#16#17"{Int64}
cb::var"#16#17"{Int64}
r::Int64
Body::var"#16#17"{Int64}
1 ─ Core.NewvarNode(:(#16))
│ Core.NewvarNode(:(cb))
│ Core.NewvarNode(:(r))
└── goto #2 if not true
2 ─ (r = 1)
│ %6 = Main.:(var"#16#17")::Core.Const(var"#16#17")
│ %7 = Core.typeof(r::Core.Const(1))::Core.Const(Int64)
│ %8 = Core.apply_type(%6, %7)::Core.Const(var"#16#17"{Int64})
│ (#16 = %new(%8, r::Core.Const(1)))
│ (cb = #16::Core.Const(var"#16#17"{Int64}(1)))
│ %11 = Main.identity(cb::Core.Const(var"#16#17"{Int64}(1)))::Core.Const(var"#16#17"{Int64}(1))
└── return %11
julia> @code_warntype f2()
MethodInstance for f2()
from f2() in Main at REPL[43]:2
Arguments
#self#::Core.Const(f2)
Locals
cb::var"#18#19"{Int64}
r@_3::Int64
#18::var"#18#19"{Int64}
r@_5::Int64
Body::var"#18#19"{Int64}
1 ─ Core.NewvarNode(:(cb))
│ Core.NewvarNode(:(r@_3))
└── goto #2 if not true
2 ─ (r@_3 = 1)
│ %5 = r@_3::Core.Const(1)
│ (r@_5 = %5)
│ %7 = Main.:(var"#18#19")::Core.Const(var"#18#19")
│ %8 = Core.typeof(r@_5::Core.Const(1))::Core.Const(Int64)
│ %9 = Core.apply_type(%7, %8)::Core.Const(var"#18#19"{Int64})
│ (#18 = %new(%9, r@_5::Core.Const(1)))
│ (cb = #18::Core.Const(var"#18#19"{Int64}(1)))
│ %12 = Main.identity(cb::Core.Const(var"#18#19"{Int64}(1)))::Core.Const(var"#18#19"{Int64}(1))
└── return %12