(Regarding Michael Gray's answer above).
Not sure if this is specifically documented for Swift, or even the Swift compiler makes full use of it. But the standard compiler project allocates storage for the instance on the stack, if the compiler knows the called function, will not try to keep the pointer to this instance on the heap and throw a compile-time error if the function tries to do this.
This is especially useful when passing non-scalar value types (for example, enumerations, structures, closures), since copying them is potentially much more expensive than just passing a pointer to the stack. Allocating an instance is also significantly cheaper (one instruction against calling malloc ()). So this is a double win if the compiler can do this optimization.
Again, does this version of the Swift compiler really have to be announced by the Swift team, or will you have to read the source code when they are open source. From the “minor optimization” quote above, it sounds like it’s not, or the Swift team considers it “minor”. I would consider this a significant optimization.
Presumably, the attribute exists so that (at least in the future) the compiler will be able to perform this optimization.
David Goodine Oct 24 '15 at 20:31 2015-10-24 20:31
source share