-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Function redefinition can improve performance/inlining/inference #32552
Comments
FWIW here is a code snippet to trigger a similar issue about inference. using Pkg
pkg"add https://github.com/tkf/NDReducibles.jl#inference-quirk"
pkgid = Base.PkgId(Base.UUID(0xe7e9fd8f232e412695ea53110d05d1fe), "NDReducibles")
path = Base.locate_package(pkgid)
testdir = joinpath(dirname(dirname(path)), "test")
Pkg.activate(testdir)
Pkg.instantiate()
using NDReducibles: AccessPattern, Index, plan
f1() = plan(AccessPattern.((
ones(0) => (Index(:i),),
ones(0, 0) => (Index(:i), Index(:j)),
))...)
using Test
try
@inferred f1()
catch exception
@info "Failed as expected" exception
end
@info "Redefining it..."
f2() = plan(AccessPattern.((
ones(0) => (Index(:i),),
ones(0, 0) => (Index(:i), Index(:j)),
))...)
@inferred f2()
@info "It worked!" |
For my case, I managed to turn it into a smaller example: g(p) = p[1] => identity.(p[2])
f() = g.((1 => (Val(2), Val(3)), 4 => (Val(5), Val(6)))) Example session:
|
In the last example, if I run |
Another example of this issue was discussed on the discourse recently. Are there any plans for resolving this issue? |
I don't think this is a particularly new observation and is likely related to #28683, #28940, enduring broadcasting struggles for StaticArrays (JuliaArrays/StaticArrays.jl#482, JuliaArrays/StaticArrays.jl#609), and associated lore about "recursion limiting heuristics" (#29816, #29294), but most of those linked issues are closed now so I figured I'd resurface this old test case that still seems to work in 1.2.0-rc2.0:
The text was updated successfully, but these errors were encountered: