JuliaLang/julia — pull request #8297 by timholy (2014-09-10 18:28:59+00:00)
Title: WIP: add inline macro via :meta expressions

This reinstates @vtjnash's contribution of the ability to declare that a function should be inlined at the call site. However, this implementation provides an `@inline` macro and a new `Expr(:meta, ...)` construct. meta-expressions can be used for other things too (I wonder if @ArchRobison may be interested in using it to introduce `@SLPvectorize`...)

Demo:
```julia
function f(x)
y = x+5
z = y*y
q = z/y
m = q-3
end

@inline function f_inlined(x)
y = x+5
z = y*y
q = z/y
m = q-3
end

g(x) = f(2x)
g_inlined(x) = f_inlined(2x)

julia> code_typed(g, (Int,))
1-element Array{Any,1}:
:($(Expr(:lambda, {:x}, {{},{{:x,Int64,0}},{}}, :(begin # none, line 1:
return f((top(box))(Int64,(top(mul_int))(2,x::Int64))::Int64)::Float64
end::Float64))))

julia> code_typed(g_inlined, (Int,))
1-element Array{Any,1}:
:($(Expr(:lambda, {:x}, {{:_var0,:_var1,:_var2,:_var3,:_var4},{{:x,Int64,0},{:_var0,Int64,18},{:_var1,Int64,18},{:_var2,Float64,18},{:_var3,Float64,18},{:_var4,Float64,18}},{}}, :(begin # none, line 1:
_var0 = (top(box))(Int64,(top(add_int))((top(box))(Int64,(top(mul_int))(2,x::Int64))::Int64,5))::Int64
_var1 = (top(box))(Int64,(top(mul_int))(_var0::Int64,_var0::Int64))::Int64
_var2 = (top(box))(Float64,(top(div_float))((top(box))(Float64,(top(sitofp))(Float64,_var1::Int64))::Float64,(top(box))(Float64,(top(sitofp))(Float64,_var0::Int64))::Float64))::Float64
_var3 = (top(box))(Float64,(top(sub_float))(_var2::Float64,(top(box))(Float64,(top(sitofp))(Float64,3))::Float64))::Float64
_var4 = _var3::Float64
return _var3::Float64
end::Float64))))
```
Everything seems to work, except for some reason my attempt to "register" the `meta_sym` doesn't seem to have succeeded:
```julia
julia> g(3)
8.0

julia> g_inlined(3)
8.0

julia> f(3)
5.0

julia> f_inlined(3)
ERROR: error compiling f_inlined: unsupported or misplaced expression meta in function f_inlined
```
Anyone know why? @ArchRobison, you had to go through this with `simdloop_sym`, any tips?

Reference: discussion starting at https://github.com/JuliaLang/julia/pull/3796#issuecomment-21433164.

Also CC @carlobaldassi (cartesian iteration).