<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">I was in the process of writing something along those lines :)</p>
<p style="margin:0px 0px 1.2em!important">But I would prefer this attribute to be added implicitly by the compiler.<br>Then, if we want to <em>validate</em> that some function is statically computable, we add <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">@pure</code> to the function.<br>If we want to <em>require</em> that some variable is computed at compilation time (even if it takes a lot of time, even in debug builds), we add <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">@pure</code> to the declaration.</p>
<p style="margin:0px 0px 1.2em!important">2016-12-17 21:59 GMT+03:00 David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:</p>
<p style="margin:0px 0px 1.2em!important"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It wouldn't have to be restricted to a subset of the language; just to functions whose evaluation doesn't depend on anything that happens at runtime.<br>
<br>
Any "@pure" (or whatever... it's easier to type on my phone than "@constantExpression") function should work fine, if we define a "pure" function to be something like:<br>
1) Doesn't mutate anything outside its own scope<br>
2) Doesn't call anything involving rand() or other non-deterministic functions<br>
3) Doesn't have a result that depends on the host or target architectures (I'm not sure if this extends to FP subtleties)<br>
4) Doesn't reference any non-local variables which don't themselves have a value that's either itself a literal or the result of evaluating a "pure" function<br>
5) Doesn't call any other functions which aren't themselves "pure", or instantiate any variables using inits that aren't "pure"<br>
<br>
Since there's already a Swift REPL, at least conceptually speaking, this doesn't seem too hard (although it does raise the bar a bit for what it takes to have a "full" Swift compiler, since it'd then depend on having a working REPL on the host platform, which IIRC wasn't the case on Linux for a while... dunno, maybe this is a non-issue).</blockquote><p></p></div><p style="margin:0px 0px 1.2em!important"></p>
<div title="MDH:PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPjxkaXYgY2xhc3M9ImdtYWlsX3F1b3RlIj5JIHdhcyBp
biB0aGUgcHJvY2VzcyBvZiB3cml0aW5nIHNvbWV0aGluZyBhbG9uZyB0aGF0IGxpbmVzIDopPC9k
aXY+PGRpdiBjbGFzcz0iZ21haWxfcXVvdGUiPjxicj48L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9x
dW90ZSI+QnV0IEkgd291bGQgcHJlZmVyIHRoaXMgYXR0cmlidXRlIHRvIGJlIGFkZGVkIGltcGxp
Y2l0bHkgYnkgdGhlIGNvbXBpbGVyLjwvZGl2PjxkaXYgY2xhc3M9ImdtYWlsX3F1b3RlIj5UaGVu
LCBpZiB3ZSB3YW50IHRvICp2YWxpZGF0ZSogdGhhdCBzb21lIGZ1bmN0aW9uIGlzIHN0YXRpY2Fs
bHkgY29tcHV0YWJsZSwgd2UgYWRkIGBAcHVyZWAgdG8gdGhlIGZ1bmN0aW9uLjwvZGl2PjxkaXYg
Y2xhc3M9ImdtYWlsX3F1b3RlIj5JZiB3ZSB3YW50IHRvICpyZXF1aXJlKiB0aGF0IHNvbWUgdmFy
aWFibGUgaXMgY29tcHV0ZWQgYXQgY29tcGlsYXRpb24gdGltZSAoZXZlbiBpZiBpdCB0YWtlcyBh
IGxvdCBvZiB0aW1lLCBldmVuIGluIGRlYnVnIGJ1aWxkcyksIHdlIGFkZCBgQHB1cmVgIHRvIHRo
ZSBkZWNsYXJhdGlvbi48L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9xdW90ZSI+PGJyPjwvZGl2Pjxk
aXYgY2xhc3M9ImdtYWlsX3F1b3RlIj4yMDE2LTEyLTE3IDIxOjU5IEdNVCswMzowMCBEYXZpZCBT
d2VlcmlzIHZpYSBzd2lmdC1ldm9sdXRpb24gPHNwYW4gZGl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