<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=""><div class="">[I’m not sure which list should cover this.]</div><div class=""><br class=""></div><div class="">I once thought of having a “#protocols(SomeTypeOrProtocol)” that was a type alias to a composition of all protocols the given type/protocol conforms to (or “Any” if none). It seems simple, but all current uses of protocols requires explicit mentions by the user, while this new facility would require looking back at the table of existing protocols.</div><div class=""><br class=""></div><div class="">It seems that implementing something like C++’s “constexpr” would have the same problem. The compiler stages can’t be one way anymore; a non-literal that’s needed for a compile-time context has to be deferred until its components can be evaluated in compile-time contexts (down to literals). So we would partially evaluate down to SIL, run the SIL in the compiler’s environment to determine all the compile-time data (not a big deal for discrete data, but we’ll have to ignore differences between the compiler’s environment and the target platform’s environment w.r.t. floating-point processing), then go back to the semantic phase to fill in the “constexpr” constants and evaluate the SIL again, possibly taking several cycles depending how deep “constexpr” is needed.</div><div class=""><br class=""></div><div class="">As an example, take a mythical function that converts a mythical one-dimensional fixed-size array to a tuple:</div><div class=""><br class=""></div><div class="">func tuple&lt;T, let N: Int&gt;(from: [N; T]) -&gt; ( #dup(N ; T) )</div><div class=""><br class=""></div><div class="">We would have to defer the return type until each call of “tuple(from:)”, where we look at the input’s type’s shape to determine N, then expand the #dup, then run the semantic phase again with the final type. What if N itself was based off a “constexpr” function? Then we would need (at least) two passes.</div><div class=""><br class=""></div><div class="">Should we start preparing the compiler stages for loopback now? Or do we have to figure out what exactly we want “Swift constexpr” to mean first?</div><div class=""><br class=""></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">—&nbsp;</div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com&nbsp;</div></div>
</div>
<br class=""></body></html>