Skip to content

Commit 5808aea

Browse files
ssikdar1rfourquet
andauthored
Add @inline for anonymous functions (JuliaLang#34953)
* Add @inline for anonymous functions Co-authored-by: Rafael Fourquet <[email protected]>
1 parent 3935491 commit 5808aea

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Language changes
4040

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

43+
* `@inline` macro can now be applied to short-form anonymous functions ([#34953]).
44+
4345
* In triple-quoted string literals, whitespace stripping is now done before processing
4446
escape sequences instead of after. For example, the syntax
4547
```
@@ -50,6 +52,7 @@ Language changes
5052
Now the result is "a\n b", since the space before `b` is no longer considered to occur
5153
at the start of a line. The old behavior is considered a bug ([#35001]).
5254

55+
5356
Multi-threading changes
5457
-----------------------
5558

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function is_short_function_def(ex)
332332
end
333333

334334
function findmeta(ex::Expr)
335-
if ex.head === :function || is_short_function_def(ex)
335+
if ex.head === :function || is_short_function_def(ex) || ex.head === :->
336336
body::Expr = ex.args[2]
337337
body.head === :block || error(body, " is not a block expression")
338338
return findmeta_block(ex.args)

test/compiler/inline.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,10 @@ let ci = code_typed(f34900, Tuple{Int, Int})[1].first
275275
@test length(ci.code) == 1 && isexpr(ci.code[1], :return) &&
276276
ci.code[1].args[1].id == 2
277277
end
278+
279+
@testset "check jl_ast_flag_inlineable for inline macro" begin
280+
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline x -> x)).source)
281+
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods( x -> x)).source)
282+
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline function f(x) x end)).source)
283+
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(function f(x) x end)).source)
284+
end

0 commit comments

Comments
 (0)