Re: [swift-users] How to Debug: Swift 3.1 Optimizations Causes All Sorts of Memory Crashes on My Apps

2017-04-05 Thread Michael Gottesman via swift-users

> On Apr 5, 2017, at 3:13 PM, Felipe Cypriano via swift-users 
>  wrote:
> 
> Hello,
> 
> We have updated our codebase to Xcode 8.3 and to my knowledge that means we 
> are now using Swift 3.1 compiler. Our first release using it - almost no 
> change to code since we release very often - had a huge increase in crashes 
> related to memory all over the codebase. The solution was to turn off all 
> Swift optimizations. This forum thread is related to the problem: 
> https://forums.developer.apple.com/message/219236#219236 
> 
> 
> I have never debugged an compiler related problem so I'm looking into advice 
> on how to pin point what the problem really is. Why our code works with 
> -Onone but crashes with both -O and -Owholemodule? Any tips would be 
> appreciated.

So this is happening with just -O (i.e. no whole module). In that case I would 
do this. Take the main command line that you are passing to swiftc and add the 
option -###. This causes the driver to dump the subcommands that it is going to 
run. So for instance if I have the following command line:

   xcrun swiftc test.swift  test2.swift main.swift  -module-name Test -O  -###

I get the following output:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
 -frontend -c -primary-file test.swift test2.swift main.swift -target 
x86_64-apple-macosx10.9 -enable-objc-interop -sdk 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
 -color-diagnostics -O -module-name Test -o 
/var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/test-00eef5.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
 -frontend -c test.swift -primary-file test2.swift main.swift -target 
x86_64-apple-macosx10.9 -enable-objc-interop -sdk 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
 -color-diagnostics -O -module-name Test -o 
/var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/test2-a29a57.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
 -frontend -c test.swift test2.swift -primary-file main.swift -target 
x86_64-apple-macosx10.9 -enable-objc-interop -sdk 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
 -color-diagnostics -O -module-name Test -o 
/var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/main-bfcad6.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
 /var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/test-00eef5.o 
/var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/test2-a29a57.o 
/var/folders/z0/zl5mqfcj25db895ldcgpzdxmgn/T/main-bfcad6.o -force_load 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a
 -framework CoreFoundation -syslibroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
 -lobjc -lSystem -arch x86_64 -L 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
 -rpath 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
 -macosx_version_min 10.9.0 -no_objc_category_merging -o Test

Notice how the -O is on each line. This is the flag that ensures that 
optimizations are being run. To disable optimizations on a specific swift file, 
you can add to the -c line the flag:

  -disable-sil-perf-optzns

This will disable sil performance optimizations while ensuring that everything 
else is exactly as if one is running with optimizations enabled.

Then I would create a little script that takes in these command lines and puts 
-disable-sil-perf-optzns on all such .o command lines except for 1. This will 
then allow you to figure out which specific compilation invocation is causing 
the miscompile.

Why don't you try that and respond back if it works for you?

Michael

> 
> Thanks,
> Felipe Cypriano
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] How to Debug: Swift 3.1 Optimizations Causes All Sorts of Memory Crashes on My Apps

2017-04-05 Thread Felipe Cypriano via swift-users
Hello,



We have updated our codebase to Xcode 8.3 and to my knowledge that means
we are now using Swift 3.1 compiler. Our first release using it - almost
no change to code since we release very often - had a huge increase in
crashes related to memory all over the codebase. The solution was to
turn off all Swift optimizations. This forum thread is related to the
problem: https://forums.developer.apple.com/message/219236#219236


I have never debugged an compiler related problem so I'm looking into
advice on how to pin point what the problem really is. Why our code
works with -Onone but crashes with both -O and -Owholemodule? Any tips
would be appreciated.


Thanks,

Felipe Cypriano
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Linux equivalent of macOS/iOS run loop, aka libdispatch/Dispatch on Linux

2017-04-05 Thread Rick Mann via swift-users

> On Apr 5, 2017, at 13:32 , Jon Shier  wrote:
> 
> Dispatch equivalent should be dispatchMain(), unless that’s not available on 
> Linux for some reason.

As seems to always be the case, as soon as I post to the list, I find that 
answer. I swear I searched for 30 minutes before finding it.

I finally found a Swift example that used dispatch_main(), and the Swift 
compiler helpfully told me to try dispatchMain().

Thank you for confirming!

> 
> 
> 
> Jon
> 
>> On Apr 5, 2017, at 4:28 PM, Rick Mann via swift-users 
>>  wrote:
>> 
>> I've got Swift and libdispatch installed and linking under Ubuntu 16.04, but 
>> I'm not sure how to set up the Linux equivalent of the macOS run loop in 
>> order to service all the dispatch queues.
>> 
>> I'm having a hard time finding an example of how to do this. Some GCD C code 
>> calls dispatch_main() from the main thread after initial program setup. I 
>> couldn't find an equivalent in the Dispatch package, when looking through 
>> the sources.
>> 
>> Can anyone tell me how to do this, or point me at an example?
>> 
>> Thanks!
>> 
>> 
>> 
>> -- 
>> Rick Mann
>> rm...@latencyzero.com
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 


-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Linux equivalent of macOS/iOS run loop, aka libdispatch/Dispatch on Linux

2017-04-05 Thread Jon Shier via swift-users
Dispatch equivalent should be dispatchMain(), unless that’s not available on 
Linux for some reason.



Jon

> On Apr 5, 2017, at 4:28 PM, Rick Mann via swift-users  
> wrote:
> 
> I've got Swift and libdispatch installed and linking under Ubuntu 16.04, but 
> I'm not sure how to set up the Linux equivalent of the macOS run loop in 
> order to service all the dispatch queues.
> 
> I'm having a hard time finding an example of how to do this. Some GCD C code 
> calls dispatch_main() from the main thread after initial program setup. I 
> couldn't find an equivalent in the Dispatch package, when looking through the 
> sources.
> 
> Can anyone tell me how to do this, or point me at an example?
> 
> Thanks!
> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Linux equivalent of macOS/iOS run loop, aka libdispatch/Dispatch on Linux

2017-04-05 Thread Rick Mann via swift-users
I've got Swift and libdispatch installed and linking under Ubuntu 16.04, but 
I'm not sure how to set up the Linux equivalent of the macOS run loop in order 
to service all the dispatch queues.

I'm having a hard time finding an example of how to do this. Some GCD C code 
calls dispatch_main() from the main thread after initial program setup. I 
couldn't find an equivalent in the Dispatch package, when looking through the 
sources.

Can anyone tell me how to do this, or point me at an example?

Thanks!



-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Vladimir.S via swift-users

On 05.04.2017 20:30, David Sweeris via swift-users wrote:



On Apr 5, 2017, at 07:49, Rien via swift-users  wrote:



On 05 Apr 2017, at 16:26, Maxim Veksler via swift-users  
wrote:

Hi,

Swift 3.1 compiler seems to introduces a new complier warning regarding 
String(describing: )

So this line:
Log.info("Update name for user \(fbUser)”)


Log.info(“Update name for user \(fbUser ?? “Unknown”)”)


I thought we couldn't nest quotes. Has that changed (because that would be 
fantastic)?


Yes, this is working currently.
Btw, also should be mentioned that fbUser.debugDescription can be used 
explicitly to silence the warning, but 'Optional("username")' will be 
printed in log (instead of just 'username').




- Dave Sweeris
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread David Sweeris via swift-users

> On Apr 5, 2017, at 07:49, Rien via swift-users  wrote:
> 
> 
>> On 05 Apr 2017, at 16:26, Maxim Veksler via swift-users 
>>  wrote:
>> 
>> Hi,
>> 
>> Swift 3.1 compiler seems to introduces a new complier warning regarding 
>> String(describing: )
>> 
>> So this line:
>> Log.info("Update name for user \(fbUser)”)
> 
> Log.info(“Update name for user \(fbUser ?? “Unknown”)”)

I thought we couldn't nest quotes. Has that changed (because that would be 
fantastic)?

- Dave Sweeris 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Rien via swift-users

> On 05 Apr 2017, at 16:26, Maxim Veksler via swift-users 
>  wrote:
> 
> Hi,
> 
> Swift 3.1 compiler seems to introduces a new complier warning regarding 
> String(describing: )
> 
> So this line:
> Log.info("Update name for user \(fbUser)”)

Log.info(“Update name for user \(fbUser ?? “Unknown”)”)

Rien.

> 
> Produces the warning: "note: use 'String(describing:)' to silence this 
> warning"
> 
> and becomes this line
> Log.info("Update name for user \(String(describing: fbUser))")
> 
> This new syntax is not very sexy, especially for logging. Any suggestions, 
> possibility on the API end of Log to make this warning go away? or write it 
> differently.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Jon Shier via swift-users
This was something that sounded like a good change but is extremely 
annoying in use. Once I get time I’m going to try writing an extension on 
Optional that generates a logDescription property so I don’t have to use that 
awful String(describing:) API.



Jon Shier


> On Apr 5, 2017, at 10:35 AM, Shawn Erickson via swift-users 
>  wrote:
> 
> Avoid using optionals in string interpolation or make it explicit as the 
> fix-it suggests.
> 
> On Wed, Apr 5, 2017 at 7:27 AM Maxim Veksler via swift-users 
> mailto:swift-users@swift.org>> wrote:
> Hi,
> 
> Swift 3.1 compiler seems to introduces a new complier warning regarding 
> String(describing: )
> 
> So this line:
> Log.info("Update name for user \(fbUser)")
> 
> Produces the warning: "note: use 'String(describing:)' to silence this 
> warning"
> 
> and becomes this line
> Log.info("Update name for user \(String(describing: fbUser))")
> 
> This new syntax is not very sexy, especially for logging. Any suggestions, 
> possibility on the API end of Log to make this warning go away? or write it 
> differently.
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Shawn Erickson via swift-users
Avoid using optionals in string interpolation or make it explicit as the
fix-it suggests.

On Wed, Apr 5, 2017 at 7:27 AM Maxim Veksler via swift-users <
swift-users@swift.org> wrote:

> Hi,
>
> Swift 3.1 compiler seems to introduces a new complier warning regarding
> String(describing: )
>
> So this line:
>
> Log.info("Update name for user \(fbUser)")
>
>
> Produces the warning: "note: use 'String(describing:)' to silence this
> warning"
>
>
> and becomes this line
>
> Log.info("Update name for user \(String(describing: fbUser))")
>
>
> This new syntax is not very sexy, especially for logging. Any suggestions,
> possibility on the API end of Log to make this warning go away? or write it
> differently.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Zhao Xin via swift-users
I always use `NSLog("Update name for user %@", fbUser)`. Is `Log.info` your
own implementation?

Zhaoxin


On Wed, Apr 5, 2017 at 10:26 PM, Maxim Veksler via swift-users <
swift-users@swift.org> wrote:

> Hi,
>
> Swift 3.1 compiler seems to introduces a new complier warning regarding
> String(describing: )
>
> So this line:
>
> Log.info("Update name for user \(fbUser)")
>
>
> Produces the warning: "note: use 'String(describing:)' to silence this
> warning"
>
>
> and becomes this line
>
> Log.info("Update name for user \(String(describing: fbUser))")
>
>
> This new syntax is not very sexy, especially for logging. Any suggestions,
> possibility on the API end of Log to make this warning go away? or write it
> differently.
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Swift 3.1 String(

2017-04-05 Thread Maxim Veksler via swift-users
Hi,

Swift 3.1 compiler seems to introduces a new complier warning regarding
String(describing: )

So this line:

Log.info("Update name for user \(fbUser)")


Produces the warning: "note: use 'String(describing:)' to silence this
warning"


and becomes this line

Log.info("Update name for user \(String(describing: fbUser))")


This new syntax is not very sexy, especially for logging. Any suggestions,
possibility on the API end of Log to make this warning go away? or write it
differently.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users