<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, May 16, 2017 at 1:47 PM Ben Rimmington <<a href="mailto:me@benrimmington.com">me@benrimmington.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 16 May 2017, at 21:27, Tony Allevato <<a href="mailto:tony.allevato@gmail.com" target="_blank">tony.allevato@gmail.com</a>> wrote:<br>
><br>
>> On Tue, May 16, 2017 at 1:25 PM David Hart <<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>> wrote:<br>
>> The problem I see is that + is an operator of the Standard Library and not part of the core language. I wouldn’t want + to sometimes to be a runtime operation and other times a compile-time operation. No, I really think we need strong language support here.<br>
><br>
> Why not? Compile-time concatenation of string literals delimited by `+` sounds like a perfectly reasonable compiler optimization.<br>
><br>
> Your argument would also state that the compiler should not do constant folding like turning `5 + 7` into `12`, would it not? What makes that situation different?<br>
<br>
When does the compiler do constant folding?<br>
<br>
Welcome to Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42). Type :help for assistance.<br>
1> import Foundation<br>
2> let x: NSNumber = 12<br>
x: __NSCFNumber = Int64(12)<br>
3> let y: NSNumber = 5 + 7<br>
error: repl.swift:3:21: error: cannot convert value of type 'Int' to specified type 'NSNumber'<br>
let y: NSNumber = 5 + 7<br>
~~^~~<br>
NSNumber( )<br>
<br>
-- Ben<br></blockquote><div><br></div><div><div>$ swiftc -emit-sil - <<EOF</div><div>let x = 5 + 7</div><div>EOF</div></div><div><br></div><div><div>// main</div><div>sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {</div><div>bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):</div><div> alloc_global @_Tv4main1xSi, loc "<stdin>":1:5, scope 1 // id: %2</div><div> %3 = global_addr @_Tv4main1xSi : $*Int, loc "<stdin>":1:5, scope 1 // user: %6</div><div><b> %4 = integer_literal $Builtin.Int64, 12, loc "<stdin>":1:11, scope 1 // user: %5</b></div><div> %5 = struct $Int (%4 : $Builtin.Int64), loc "<stdin>":1:11, scope 1 // user: %6</div><div> store %5 to %3 : $*Int, loc "<stdin>":1:11, scope 1 // id: %6</div><div> %7 = integer_literal $Builtin.Int32, 0, scope 1 // user: %8</div><div> %8 = struct $Int32 (%7 : $Builtin.Int32), scope 1 // user: %9</div><div> return %8 : $Int32, scope 1 // id: %9</div><div>} // end sil function 'main'</div></div><div><br></div><div>The resulting SIL is the run-time vs. compile-time distinction that I was addressing; if someone is concerned about `+` being different for strings, then that SIL shouldn't be allowed either.</div><div><br></div><div>The results you show for NSNumber are honestly surprising to me, but the intricacies of Obj-C bridging are definitely one of the areas of Swift that I don't understand deeply.</div><div><br></div></div></div>