[Pitch] Compile-Time Constant Values

Moved to a separate thread per request.

Original comment

I poked at this a little bit more and the outcome was interesting (and beyond my understanding of how the optimizer works).

It turns out OptionSets by themselves aren't a problem; some of them are able to outline into static objects fine. Your WebURL case does if we stop the array after element 0x67. But once we add element 0x68, or anything after that, it stops outlining.

I looked more closely at the generated post-opt SIL and it looks like in the 0x00-0x67 case, the ObjectOutliner pass outlines the whole array into a single SIL value mainTv_, which is what we want.

In the 0x00-0x68 case, it looks like the individual arrays inside the larger array (the option set unions) are outlined separately (mainTv_...mainTv7_), and the overall array is never outlined.

Maybe the inner array outlining is an intermediate step to outlining the whole thing, and the 0x68th element pushes the number of basic blocks or instructions past some limit that's coded into an optimizer pass that makes it claim it's too complex to analyze, causing it to break down after that?

Hopefully someone like @Erik_Eckstein might have some more insight here. I've been looking into taking advantage of swift_allocStaticObject-based values for other projects but if they're sensitive to small perturbations in the input like this, then that gets a lot trickier.

3 Likes