Skip to content

Commit

Permalink
Add @inline for anonymous functions (JuliaLang#34953)
Browse files Browse the repository at this point in the history
* Add @inline for anonymous functions

Co-authored-by: Rafael Fourquet <[email protected]>
  • Loading branch information
ssikdar1 and rfourquet authored Mar 15, 2020
1 parent 3935491 commit 5808aea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Language changes

* The syntax `(;)` (which was deprecated in v1.4) now creates an empty named tuple ([#30115]).

* `@inline` macro can now be applied to short-form anonymous functions ([#34953]).

* In triple-quoted string literals, whitespace stripping is now done before processing
escape sequences instead of after. For example, the syntax
```
Expand All @@ -50,6 +52,7 @@ Language changes
Now the result is "a\n b", since the space before `b` is no longer considered to occur
at the start of a line. The old behavior is considered a bug ([#35001]).


Multi-threading changes
-----------------------

Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function is_short_function_def(ex)
end

function findmeta(ex::Expr)
if ex.head === :function || is_short_function_def(ex)
if ex.head === :function || is_short_function_def(ex) || ex.head === :->
body::Expr = ex.args[2]
body.head === :block || error(body, " is not a block expression")
return findmeta_block(ex.args)
Expand Down
7 changes: 7 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,10 @@ let ci = code_typed(f34900, Tuple{Int, Int})[1].first
@test length(ci.code) == 1 && isexpr(ci.code[1], :return) &&
ci.code[1].args[1].id == 2
end

@testset "check jl_ast_flag_inlineable for inline macro" begin
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline x -> x)).source)
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods( x -> x)).source)
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline function f(x) x end)).source)
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(function f(x) x end)).source)
end

0 comments on commit 5808aea

Please sign in to comment.