[swift-evolution] [Pitch] Ban the top value in Int/UInt / use smaller Integer

Haravikk swift-evolution at haravikk.me
Thu Oct 20 10:25:17 CDT 2016

> On 20 Oct 2016, at 15:51, Martin Waitz via swift-evolution <swift-evolution at swift.org> wrote:
> Hello,
>> It's just that a common data type wasting almost half the space seems inefficient. I guess this is also the reason why they didn't adopt optional integers widely in stdlib.
> When someone is really interested in fitting an optional integer into one machine word,
> then the best way would be to use a smaller integer type (e.g. Int32 instead of Int64).
> These also can be mapped well into Enums (a single reserved value does not help at all here).
> There are some almost 64-bit integers (Builtin.Int60 .. Builtin.Int63).
> Maybe something like this could also be provided for normal use?

I mentioned earlier, but it'd be nice to see the ability to specify arbitrary width integers up to the word size. I myself have a type where I could more efficiently use a 7-bit integer, to offset the extra bit for an optional, but currently have to just use a byte (or else use some kind of awkward trickery). Presumably all of the weird builtin sizes are implemented somehow to as 64-bit operations, it's just the size that differs.

I'm not very knowledgeable on the subject though, so I'm not sure if I'd be the best person to write up a proposal, though I could always keep it high level.

More information about the swift-evolution mailing list