[swift-evolution] [Review] SE-0101: Rename sizeof and related functions to comply with API Guidelines
Dave Abrahams
dabrahams at apple.com
Thu Jun 30 17:41:33 CDT 2016
on Thu Jun 30 2016, Xiaodi Wu <xiaodi.wu-AT-gmail.com> wrote:
> On Thu, Jun 30, 2016 at 2:30 PM, Dave Abrahams <dabrahams at apple.com> wrote:
>
>>
>> on Wed Jun 29 2016, Erica Sadun <erica-AT-ericasadun.com> wrote:
>>
>> >> On Jun 29, 2016, at 3:59 PM, Xiaodi Wu via swift-evolution <
>> swift-evolution at swift.org> wrote:
>> >>
>> >> On Wed, Jun 29, 2016 at 4:50 PM, David Sweeris <davesweeris at mac.com
>> <mailto:davesweeris at mac.com>> wrote:
>> >> That’s the “as proposed” usage for getting the size of a value (from
>> >> https://gist.github.com/erica/57a64163870486468180b8bab8a6294e
>> >
>> >> <https://gist.github.com/erica/57a64163870486468180b8bab8a6294e>)
>> >> // Types
>> >> MemoryLayout<Int>.size // 8
>> >> MemoryLayout<Int>.arraySpacing // 8
>> >> MemoryLayout<Int>.alignment // 8
>> >>
>> >> // Value
>> >> let x: UInt8 = 5
>> >> MemoryLayout(x).dynamicType.size // 1
>> >> MemoryLayout("hello").dynamicType.arraySpacing // 24
>> >> MemoryLayout(29.2).dynamicType.alignment // 8
>> >>
>> >>
>> >> At least, I thought that was the latest version of the proposal. Maybe
>> I’ve gotten confused.
>> >>
>> >> There must be a typo in these examples.
>> `MemoryLayout(x.dynamicType).size` perhaps?
>> >
>> > I have listened. I have updated.
>> >
>> > https://gist.github.com/erica/57a64163870486468180b8bab8a6294e
>> >
>> > // Types
>> > MemoryLayout<Int>.size // 8
>> > MemoryLayout<Int>.arraySpacing // 8
>> > MemoryLayout<Int>.alignment // 8
>> >
>> > // Value
>> > let x: UInt8 = 5
>> > MemoryLayout.of(x).size // 1
>> > MemoryLayout.of(1).size // 8
>> > MemoryLayout.of("hello").arraySpacing // 24
>> > MemoryLayout.of(29.2).alignment // 8
>>
>> I am still very skeptical that anyone needs the “Value” version, and as
>> long as we're resyntaxing I am inclined to take it away and see how many
>> people complain. You can still always write it yourself.
>>
>
> So long as the issue regarding querying an existential value's dynamic type
> is addressed, yes?
Oh, I guess that's right.
> I mentioned this in a comment on the gist already, but I'm really not
> digging the "array" in `arraySpacing`. We've already moved from top-level
> "stride" to "memory layout spacing," gaining plenty of clarity. I'm
> skeptical that the "array" adds anything more. Moreover, it muddies the
> waters by mentioning a specific type (Array) in a context where you're
> querying the memory layout properties of another type.
OK, I agree with that. If we have “alignment” rather than
“defaultAlignment,” I suppose we can have plain “spacing.”
--
Dave
More information about the swift-evolution
mailing list