The benchmark expands to:
julia> @macroexpand @inferred 1+1
quote
let
begin
#1#args = (1, 1)
#2#result = +(#1#args...)
#3#inftypes = Base.Test.Base.return_types(+, Base.Test.Base.typesof(#1#args...))
end
if (Base.Test.length)(#3#inftypes) == 1
nothing
else
(Base.throw)(Base.Main.Base.AssertionError("(\$(Expr(:globalref, Base.Test, :(==))))((\$(Expr(:globalref, Base.Test, :length)))(#3#inftypes), 1)"))
end
#4#rettype = if #2#result isa Base.Test.Type
(Base.Test.Type){#2#result}
else
(Base.Test.typeof)(#2#result)
end
#4#rettype == #3#inftypes[1] || (Base.Test.error)("return type $(#4#rettype) does not match inferred return type $(#3#inftypes[1])")
#2#result
end
end
So it will do a bunch of splatting, calling Base.return_types
etc every time. @inferred
is written to be used in unit testing (which is why it is in the Test
module).