Generator expression optimization for a known iteration set

I tend to run into a lot of situations where I’m iterating over something that is constant based on the input type. One example is a pattern where I want return a modified immutable function

function modifyfields(x::T, mods::NamedTuple) where T
    modGen = ( get(mods, fn, getproperty(x, fn)) for fn in fieldnames(T) )
    return T(modGen...)
end

I’m wondering if Julia optimizes this generator because you can literally write this down in multiple lines. I know it’s possible to use a generated function which I know will be fast, but it’s a bit of a hassle if you’re using a custom function inside the expression (because order of code definition becomes important).

I guess I’m asking is if this is automatically optimized as an expanded expression or is there an easy way to optimize this so that it’s type stable and easily inferred as if written by hand?