<div><br><div class="gmail_quote"><div dir="auto">On Mon, Jul 31, 2017 at 02:49 Goffredo Marocchi &lt;<a href="mailto:panajev@gmail.com">panajev@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><br><br><div id="m_4837272081865673617AppleMailSignature">Sent from my iPhone</div></div><div dir="auto"><div><br>On 31 Jul 2017, at 08:40, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div><br><div class="gmail_quote"><div dir="auto">On Mon, Jul 31, 2017 at 02:15 Gor Gyolchanyan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt; On Jul 31, 2017, at 7:10 AM, John McCall via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; On Jul 30, 2017, at 11:43 PM, Daryle Walker &lt;<a href="mailto:darylew@mac.com" target="_blank">darylew@mac.com</a>&gt; wrote:<br>
&gt;&gt; The parameters for a fixed-size array type determine the type&#39;s size/stride, so how could the bounds not be needed during compile-time? The compiler can&#39;t layout objects otherwise.<br>
&gt;<br>
&gt; Swift is not C; it is perfectly capable of laying out objects at run time.  It already has to do that for generic types and types with resilient members.  That does, of course, have performance consequences, and those performance consequences might be unacceptable to you; but the fact that we can handle it means that we don&#39;t ultimately require a semantic concept of a constant expression, except inasmuch as we want to allow users to explicitly request guarantees about static layout.<br>
<br>
Doesn&#39;t this defeat the purpose of generic value parameters? We might as well use a regular parameter if there&#39;s no compile-time evaluation involved. In that case, fixed-sized arrays will be useless, because they&#39;ll be normal arrays with resizing disabled.</blockquote><div dir="auto"><br></div><div dir="auto">OTOH, if the compiler can prove that a local array is never resized, why *shouldn&#39;t* it get all the benefits of a fixed-sized array without having to use a special syntax? Put another way, why shouldn&#39;t fixed-size be one of those optional attributes for arrays, like ownership will be for variables, that users can opt into for more performance but is otherwise automatically worked out by the compiler?</div></div></div></div></blockquote><div><br></div></div><div dir="auto"><div>Because in some cases humans may make an easier judgement call than the compiler?</div></div></blockquote><div dir="auto"><br></div><div dir="auto">Hence, why I&#39;m asking why it shouldn&#39;t be an option for the human to help the compiler with an annotation.</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div> Because the compiler complexity is already growing and compile time is not exactly showing massive reductions and people are worried that as Swift gains more features and complexity with genetics and reflection and other features that compilation time will grow even more?</div></div></blockquote><div dir="auto"><br></div><div dir="auto">Do you have any evidence that this would be a performance-limiting task for the compiler? Even if so, what&#39;s wrong with limiting the compiler to inferring only the easiest cases, and allowing for manual annotation to help the compiler in more complicated ones as an optional performance enhancement? In other words, my question is, what is wrong with fixed-sized arrays being--syntactically--simply arrays with resizing disabled? The flip side of the coin is, why shouldn&#39;t normal arrays simply be--syntactically--fixed-sized arrays with resizing enabled?</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><blockquote type="cite"><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As far as I know, the pinnacle of uses for fixed-size arrays is having a compile-time pre-allocated space of the necessary size (either literally at compile-time if that&#39;s a static variable, or added to the pre-computed offset of the stack pointer in case of a local variable).<br>
<br>
&gt; Value equality would still affect the type-checker, but I think we could pretty easily just say that all bound expressions are assumed to potentially resolve unequally unless they are literals or references to the same &#39;let&#39; constant.<br>
<br>
Shouldn&#39;t the type-checker use the Equatable protocol conformance to test for equality? Moreover, as far as I know, Equatable is not recognized by the compiler in any way, so it&#39;s just a regular protocol. What would make it special? Some types would implement operator == to compare themselves to other types, that&#39;s beyond the scope of Equatable. What about those? And how are custom operator implementations going to serve this purpose at compile-time? Or will it just ignore the semantics of the type and reduce it to a sequence of bits? Or maybe only a few hand-picked types will be supported?<br>
<br>
The seemingly simple generic value parameter concept gets vastly complicated and/or poorly designed without an elaborate compile-time execution system... Unless I&#39;m missing an obvious way out.<br>
<br>
&gt; The only hard constraint is that types need to be consistent, but that just means that we need to have a model in which bound expressions are evaluated exactly once at runtime (and of course typically folded at compile time).<br>
<br>
What exactly would it take to be able to execute select piece of code at compile-time? Taking the AST, converting it to LLVM IR and feeding it to the MCJIT engine seems to be easy enough. But I&#39;m pretty sure it&#39;s more tricky than that. Is there a special assumption or two made about the code that prevents this from happening?<br>
<br>
&gt; John.<br>
&gt;<br>
&gt;&gt; Or do you mean that the bounds are integer literals? (That&#39;s what I have in the design document now.)<br>
&gt;&gt;<br>
&gt;&gt; Sent from my iPhone<br>
&gt;&gt;<br>
&gt;&gt; On Jul 30, 2017, at 8:51 PM, John McCall &lt;<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Jul 29, 2017, at 7:01 PM, Daryle Walker via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; The “constexpr” facility from C++ allows users to define constants and functions that are determined and usable at compile-time, for compile-time constructs but still usable at run-time. The facility is a key step for value-based generic parameters (and fixed-size arrays if you don’t want to be stuck with integer literals for bounds). Can figuring out Swift’s story here be part of Swift 5?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Note that there&#39;s no particular reason that value-based generic parameters, including fixed-size arrays, actually need to be constant expressions in Swift.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; John.<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote></div></div>