Add generic copy stagedfunction for all types

It is a no-op for all immutable types, and for mutable types it instantiates a new object with the same fields; the fields are not copied.