I’m not aware of non-isbits types being a restriction for @generated functions. You might be referring to this bit in the Manual
- Generated functions must not mutate or observe any non-constant global state (including, for example, IO, locks, non-local dictionaries, or using
hasmethod). This means they can only read global constants, and cannot have any side effects. In other words, they must be completely pure. Due to an implementation limitation, this also means that they currently cannot define a closure or generator.
but most of that just refers to the part of the @generated function that constructs the output expression, which only has access to the types of your input data so it can’t mutate the actual instances. Only nested functions (closures, comprehensions, @task/@spawn) can’t be defined in the code of the output expression, otherwise people do just about anything else a normal method does. Note that the README of RuntimeGeneratedFunctions.jl involves an expression that mutates an input vector:
ex = :(function f(_du, _u, _p, _t)
@inbounds _du[1] = _u[1]
@inbounds _du[2] = _u[2]
nothing
end)
f1 = @RuntimeGeneratedFunction(ex)
du = rand(2)
u = rand(2)
...
f1(du, u, p, t)