[swift-dev] Question about size of Character type
Slava Pestov
spestov at apple.com
Fri Aug 19 20:22:38 CDT 2016
> On Aug 19, 2016, at 2:04 PM, Jordan Rose via swift-dev <swift-dev at swift.org> wrote:
>
> We have an old Radar about this, rdar://problem/16754935 <rdar://problem/16754935>. It's probably just a case we're missing in enum layout. My guess is that it's because we don't have a whole spare bit in a RawPointer, but we should be able to pick some up either from alignment or from ABI knowledge.
>
> Jordan
Hi Jordan,
I asked about a related issue, which is that RawPointer only has 1 extra inhabitant instead of 4096. You guys said you wanted non-zero integers to round-trip through RawPointer. It seems that declaring the high bits of a RawPointer as spare bits would cause the same problem as allowing more extra inhabitants.
Also I don’t think alignment is the answer here, RawPointer should be able to represent a char *, where you have no low spare bits.
Slava
>
>
>> On Aug 19, 2016, at 13:30, Ole Begemann via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>>
>> The Character type is essentially defined like this [1]:
>>
>> struct Character {
>> enum Representation {
>> // A _StringBuffer whose first grapheme cluster is self.
>> // NOTE: may be more than 1 Character long.
>> case large(_StringBuffer._Storage)
>> case small(Builtin.Int63)
>> }
>>
>> var _representation: Representation
>> }
>>
>> Note the type of the associated value for `case .small`, `Builtin.Int63`. Presumably, this is so that the type fits into a single word, including the single bit that is needed for the enum case.
>>
>> However, `MemoryLayout<Character>.size` returns 9. Given the above, I would have expected 8 bytes.
>>
>> Why? Is this a potential optimization that hasn't been implemented? Or am I missing something?
>>
>> Thanks
>> Ole
>>
>> [1]: https://github.com/apple/swift/blob/master/stdlib/public/core/Character.swift <https://github.com/apple/swift/blob/master/stdlib/public/core/Character.swift>
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev at swift.org <mailto:swift-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-dev
>
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160819/a67e7e36/attachment.html>
More information about the swift-dev
mailing list