-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
https://github.com/JuliaLang/julia/blob/master/doc/src/devdocs/meta.md is outdated. Example:
:metaexpressions are created with macros. As an example, consider the implementation of the
@inlinemacro:
macro inline(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :inline) : ex)
endHere,
exis expected to be an expression defining a function. A statement like this:
@inline function myfunction(x)
x*(x+3)
endgets turned into an expression like this:
quote
function myfunction(x)
Expr(:meta, :inline)
x*(x+3)
end
endThat's no longer the case, since, e.g., the inline macro was changed from
macro inline(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :inline) : ex)
endto
macro inline(x)
return annotate_meta_def_or_block(x, :inline)
end, where annotate_meta_def_or_block:
function annotate_meta_def_or_block(@nospecialize(ex), meta::Symbol)
inner = unwrap_macrocalls(ex)
if is_function_def(inner)
# annotation on a definition
return esc(pushmeta!(ex, meta))
else
# annotation on a block
return Expr(:block,
Expr(meta, true),
Expr(:local, Expr(:(=), :val, esc(ex))),
Expr(meta, false),
:val)
end
endThis change was carried out in 2a0ab37#diff-6805ce4225f84b60b14f09c34f810459b8fc107b969581982d6b3c70091b934f, as part of #41328. It essentially was done to enable @inline/@noinline annotations on function callsites.
With the new change, if the annotation is on a callsite, the generated expression is different.
In other words, while the following part of the current doc:
Here,
exis expected to be an expression defining a function. A statement like this:
@inline function myfunction(x)
x*(x+3)
endgets turned into an expression like this:
quote
function myfunction(x)
Expr(:meta, :inline)
x*(x+3)
end
endholds true, if on a callsite, it should be:
function myfunction(x)
@inline x*(x+3)
endgets turned into an expression like this:
quote
function myfunction(x)
begin
Expr(:inline, true)
local val = x*(x+3)
Expr(:inline, false)
val
end
end
endThis is subject to minimally (?) change (?) due to #48910. I can submit a quick PR to include the new functionality in the devdocs.