<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 15, 2017, at 4:26 PM, Andrew Trick &lt;<a href="mailto:atrick@apple.com" class="">atrick@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 14, 2017, at 12:03 PM, Jordan Rose via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">ad 3) IRGen support</div><div class=""><br class=""></div><div class="">Generating statically initialized globals is already done today for structs and tuples.</div><div class="">What’s needed is the handling of objects.</div><div class="">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.</div><div class=""><br class=""></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);">HeapObject<span class="">&nbsp;*</span>swift::swift_initImmortalObject(HeapMetadata&nbsp;<span class="" style="color: rgb(186, 45, 162);">const</span>&nbsp;*metadata, HeapObject *object)</div></div></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">One way to call this runtime function is dynamically at the global_object instruction whenever the metadata pointer is still null (via swift_once).</div><div class="">Another possibility would be to call it in a global constructor.</div><div class=""><br class=""></div><div class="">If you have any feedback, please let me know</div></div></div></blockquote><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div><div class="">Please do not use a global constructor.</div></div></div></blockquote><div class=""><br class=""></div><div class="">What’s the objection to a global constructor about? We’re worried about dyld performance in this case?</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""> :-)</div></div></div></blockquote><div class=""><br class=""></div><div class="">:-/</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""> Globals are already set up to handle one-time initialization; the fact that that initialization is now cheaper is still a good thing.</div></div></div></blockquote></div><div class=""><br class=""></div><div class="">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.</div></div></div></blockquote><div><br class=""></div>Erik answered this. I forgot we need to initialize metadata. I agree we don’t want to do that in a global constructor. The fast path won’t go through swift-once, so the accessor will be just a bit of extra code size.<br class=""></div><div><br class=""></div><div>-Andy</div><br class=""></body></html>