[swift-evolution] [swift-evolution-announce] [Review] SE-0101: Rename sizeof and related functions to comply with API Guidelines
Scott James Remnant
scott at netsplit.com
Tue Jun 21 14:50:16 CDT 2016
I’ve given this a pretty thorough couple of readings, and experimented with the different options in my own code.
Global functions in Swift are a rare thing, in general the language prefers not to have them, so where we do have them I feel it’s important to get them right. Addressing them is, to me, an significant improvement to Swift and the proposal makes good steps towards that.
I do have some comments.
It is clear to me that the purpose of functions that return details about the size in memory of a type, the alignment in memory of a type, and the distance between memory of two values of a given type, are consistently within the realm of dealing with types. For example, the “what is distance between memory of a value” makes no sense as a question, the only way to make that question make sense is to instead say “what is the distance between memory of two values of the type of a value.” Likewise “what is the size in memory of the type of a value,” and “what is the alignment in memory of the type of a value.”
Allowing these functions to operate on values is really just a shortcut, these functions should naturally operate on types.
To that end, I would prefer that the “ofValue” variations be removed, and SE-0096 to be preserve as-is.
The proposal brings up the issue that you cannot ask for the size of an existential type, but is that actually an issue? The purpose of these functions is to permit memory allocation, low-level memory manipulation, etc. Is there ever a situation where it is valid to do this on an existential type? Isn’t the very error here a sign that the type you’re attempting to manipulate isn’t one that you should be performing low-level memory manipulation for?
More information about the swift-evolution