Semantics of :: in return type vs. argument type annotations

So question. I have the functions f and g:

function f(x::Int64)::Float64 return x end
function g(x::Int64) return Base.convert(Float64, x)::Float64 end

g is doing a conversion before returning. Is f doing that too? Because that would be wild.

f lowers to:

CodeInfo(
1 ─ %1 = Base.convert
│   %2 = Main.Float64
│   %3 = (%1)(%2, x)
│   %4 = Core.typeassert(%3, Main.Float64)
└──      return %4
)

g lowers to:

CodeInfo(
1 ─ %1 = Base.convert
│   %2 = Main.Float64
│   %3 = (%1)(%2, x)
│   %4 = Core.typeassert(%3, Main.Float64)
└──      return %4
)
1 Like