Skip to content
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 do blocks #35116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,11 @@ function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
inner = inner.args[end]::Expr
end

idx, exargs = findmeta(inner)
if idx != 0
push!(exargs[idx].args, tag)
found, metaargs = findmeta(inner)
if found
push!(metaargs, tag)
else
body::Expr = inner.args[2]
pushfirst!(body.args, Expr(:meta, tag))
pushfirst!(metaargs, Expr(:meta, tag))
end
ex
end
Expand Down Expand Up @@ -335,13 +334,18 @@ function findmeta(ex::Expr)
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)
idx, exargs = findmeta_block(ex.args)
if idx != 0
return true, exargs[idx].args
else
return false, ex.args[2].args
end
elseif ex.head === :do
return findmeta(ex.args[2])
end
error(ex, " is not a function expression")
end

findmeta(ex::Array{Any,1}) = findmeta_block(ex)

function findmeta_block(exargs, argsmatch=args->true)
for i = 1:length(exargs)
a = exargs[i]
Expand Down
2 changes: 2 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,6 @@ end
@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)
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline identity() do x; x end)).source)
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(identity() do x; x end)).source)
end
2 changes: 1 addition & 1 deletion test/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end
for m in [:foo1, :foo2, :foo3, :foo4, :foo5]
@test popmeta!(multi_meta, m)[1]
end
@test Base.findmeta(multi_meta.args)[1] == 0
@test Base.findmeta_block(multi_meta.args)[1] == 0

# Test that pushmeta! can push across other macros,
# in the case multiple pushmeta!-based macros are combined
Expand Down