-
-
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
Add @inline for anonymous functions #34953
Conversation
Should we also look for
expressions? |
IMO, that is not necessary, this doesn't work for example:
Sure, you wouldn't write that but it still is easiest if the |
test/compiler/inline.jl
Outdated
function test_outer2(x) | ||
@inline x -> x^2 + 2x - 1 | ||
end | ||
test_inlined_symbols(test_outer2, Tuple{Int64}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't test that the inline declaration has been applied to the inner function; it tests that the inlining pass produced valid output for test_outer2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffBezanson
makes sense! How do I test if the inline declaration has been applied to the function?
Do I have to look at the Expr
produced when using the inline macro?
julia> Base.parse_input_line("x -> x^2 + 2x - 1")
:($(Expr(:toplevel, :(#= none:1 =#), :((x->begin
#= none:1 =#
(x ^ 2 + 2x) - 1
end)))))
julia> Base.parse_input_line("@inline x -> x^2 + 2x - 1")
:($(Expr(:toplevel, :(#= none:1 =#), :(#= none:1 =# @inline((x->begin
#= none:1 =#
(x ^ 2 + 2x) - 1
end))))))
Something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an easy way to test whether the inlining flag is set:
julia> ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(x->x)).source)
false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffBezanson
thanks! I added some tests to check :jl_ast_flag_inlineable
for both anonymous and normal functions in b8ddf2a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in 57ecb07
test/compiler/inline.jl
Outdated
|
||
@testset "check jl_ast_flag_inlineable for inline macro" begin | ||
ret = ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline x -> x)).source) | ||
@test ret == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ret
variable is redundant here; can just do @test ccall(...
etc. It is also more idiomatic to use @test x
and @test !x
instead of @test x == true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 57ecb07
Thanks for your patience in working through the review process @ssikdar1 ! LGTM now. |
* Add @inline for anonymous functions Co-authored-by: Rafael Fourquet <[email protected]>
* Add @inline for anonymous functions Co-authored-by: Rafael Fourquet <[email protected]>
Closes #34939
added a check for
ex.head === :->
infindmeta
so that@inline
will work anonymous functions.Testing
Add a few tests.
Added a test in
test/compiler/inline.jl
Add a NEWS item.