[swift-dev] Implementation of swift's value types

Johannes Neubauer neubauer at kingsware.de
Fri Jul 15 11:25:01 CDT 2016


Hi Arnold,

> Am 15.07.2016 um 02:17 schrieb Arnold <aschwaighofer at apple.com>:
> 
>> On Jul 14, 2016, at 4:04 PM, Johannes Neubauer <neubauer at kingsware.de> wrote:
>> 
>> Hi Arnold,
>> 
>> Thank you and atrick at apple.com very much for your answers. That helps already a lot. Are you Arnold from the WWDC Video?
> 
> Yes.

Cool. Thank you for the great answers. Last words to this topic inline:

>> Are there corresponding plans? Storing „big“ values (using some statistics to evaluate where the break-even is) as reference types always, storing them in a big table per type (each value occurs only once) should be possible, right? Is this something I should post on the swift-evolution mailing list?
> 
> No hashed out plans only discussions on hallways. The swift team  focuses on finishing up swift 3.
> 
> But yes, similar ideas are being discussed.

AFAIK the JVM does such things for Strings (they call it a pool not a table) and they use a pool of values as reference types for inboxing/outboxing of primitive types to their Wrapper class counterparts (in order to speed this process up). So if you put an `int` into a method that expects an `Integer` they lookup the corresponding instance of the Wrapper type and return it.

> This a simplification that might overlook specific cases where this is not necessarily true. (The swift compiler can flatten structs to its individual member properties -- scalarize the struct -- and that can lead to better optimization …)

OK. Good to know.

>> Are there already proposals available or is it still in early discussions? Can you give me a hint where to find more about it?
> 
> No proposals at the moment.

Is there some documentation of the current implementation of Existential Container, Protocol Witness Table, and co.? Where do I find it?

> 
> This is an abstract description that does not contradict mine.
> Conceptually the value witness table is a dictionary (value witness's function kind to implementation). It is implemented as a block of memory (a table) that contains pointers to functions. At offset 2 (made up I would have to lookup what the offset is) say you will find the function that knows how to allocate memory for that type.
> For an Int this function will just return a pointer into the inline value buffer.
> 
> For a struct of 4 integers this function will malloc memory on the heap store the pointer into the online value buffer and will return that pointer.

OK, so this table contains 4 entries alloc/dealloc, copy, and destroy and is not a table of all values. I got it.

> Buffers for big values are created when we create a protocol value. This code is not clever. It allocates memory on the heap and copies the value's storage to that heap memory.

OK. Thanks.

All the best
Johannes

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160715/9b429391/attachment.sig>


More information about the swift-dev mailing list