[swift-dev] statically initialized arrays

Andrew Trick atrick at apple.com
Thu Jun 15 18:26:46 CDT 2017


> On Jun 14, 2017, at 12:03 PM, Jordan Rose via swift-dev <swift-dev at swift.org> wrote:
> 
>> ad 3) IRGen support
>> 
>> Generating statically initialized globals is already done today for structs and tuples.
>> What’s needed is the handling of objects.
>> In addition to creating the global itself, we also need a runtime call to initialize the object header. In other words: the object is statically initialized, except the header.
>> 
>> HeapObject *swift::swift_initImmortalObject(HeapMetadata const *metadata, HeapObject *object)
>> 
>> There are 2 reasons for that: first, the object header format is not part of the ABI. And second, in case of a bound generic type (e.g. array buffers) the metadata is not statically available.
>> 
>> One way to call this runtime function is dynamically at the global_object instruction whenever the metadata pointer is still null (via swift_once).
>> Another possibility would be to call it in a global constructor.
>> 
>> If you have any feedback, please let me know
> 
> Please do not use a global constructor.

What’s the objection to a global constructor about? We’re worried about dyld performance in this case?

> :-)

:-/

> Globals are already set up to handle one-time initialization; the fact that that initialization is now cheaper is still a good thing.


These array literals aren’t Swift globals to begin with so I’m not sure what that means. Introducing a swift-once accessor everywhere they’re used means we can’t do the global optimizations that we normally do for globals with constant initializers. That might be the right choice but it would be good to understand why we’re making it.

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170615/e38b64e7/attachment.html>


More information about the swift-dev mailing list