Need @inline for constructors?

as I saw in codes of various packages, @inline is not seen for inner constructor. So, is it valid at all to annotate @inline for inner constructors?
what about outer constructors? thanks.

What makes you think it is not valid? Eg

struct Foo
    @inline function Foo()
        @info "we are so inline"
        @assert 1 + 1 == 2 # just making sure
        new()
    end
end
    
@inline Foo(y) = Foo() # ignore variable to spite users

inlines just fine.

Generally you may not be seeing a lot of @inline these days because the compiler is getting eerrily good at figuring out these things so you don’t need to hint.

A lot of older code is peppered with @inline all over the place because no one bothered to remove it.

2 Likes