Re: [swift-users] experimental conditional conformances flag

2017-12-05 Thread Matt Whiteside via swift-users
Here’s an explanation: https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md Matt > On Dec 5, 2017, at 22:46, Седых Александр wrote: > > Please explain, what is conditional conformances with another words? > >> Среда, 6 декабря 2017,

Re: [swift-users] experimental conditional conformances flag

2017-12-05 Thread Седых Александр via swift-users
Please explain, what is conditional conformances with another words? > Среда, 6 декабря 2017, 6:32 +03:00 от Matt Whiteside via swift-users > : > > Hello Swift Users, > > [This is a resend with smaller attachment]  Has anyone had luck passing the > new

Re: [swift-users] what is the use of "-frontend" argument to swift?

2017-12-05 Thread Atul Sowani via swift-users
Thanks Kyle and Jordan! That's the information I was looking for. Anyway I am not using these options explicitly, but found that they are invoked while Swift test suite is run. A few test cases are failing for me on ppc64le and while analyzing it I came across these options. Thanks for the info!

[swift-users] experimental conditional conformances flag

2017-12-05 Thread Matt Whiteside via swift-users
Hello Swift Users, [This is a resend with smaller attachment] Has anyone had luck passing the new '-enable-experimental-conditional-conformances' flag to Xcode? It works when I run swift from the command line, with the Dec. 5th snapshot toolchain, but not Xcode. I have tried whats in the

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Jordan Rose via swift-users
> On Dec 5, 2017, at 16:24, Romain Jacquinot wrote: > >> Ah, it's a Swift bug in the SynchronizedArray / MyClass cases > > If I remove the intermediate copy in the myArray getter, should it — without > Swift bug — also return a unique copy? > > public var myArray: Array {

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Sorry, forgot the “return" keyword in my example: public var myArray: Array { lock.lock() defer { lock.unlock() } return _myArray } > On Dec 6, 2017, at 1:24 AM, Romain Jacquinot via swift-users > wrote: > > public var myArray: Array { > lock.lock() >

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
> Ah, it's a Swift bug in the SynchronizedArray / MyClass cases If I remove the intermediate copy in the myArray getter, should it — without Swift bug — also return a unique copy? public var myArray: Array { lock.lock() defer { lock.unlock() } _myArray } By the way, here is a

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Jordan Rose via swift-users
Ah, it's a Swift bug in the SynchronizedArray / MyClass cases, and your bug in the very first example with the global (since access to the global itself is not synchronized). The case I actually tested myself was with your most recent example ("Yet, data race can occur here"). Jordan > On

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Hi Jordan, For which specific code sample(s) do you think it’s a bug? In the previous code samples, are there cases where you think a data race is to be expected? Thanks. > On Dec 6, 2017, at 12:05 AM, Jordan Rose wrote: > > I'm seeing the race too when compiling with

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Jordan Rose via swift-users
I'm seeing the race too when compiling with -O (and TSan enabled). I'm 95% sure this should be valid Swift code without any further synchronization, so please file a bug at https://bugs.swift.org. (But I'm only 95% sure because concurrency is hard.) Looking at the backtraces, it looks like one

Re: [swift-users] what is the use of "-frontend" argument to swift?

2017-12-05 Thread Kyle Murray via swift-users
Looks like it's an alias for -emit-object: https://github.com/apple/swift/blob/master/include/swift/Option/Options.td#L576 ...which will give an object file as output rather than the default, an executable.

Re: [swift-users] Why no unsafeRemainder(dividingBy: Self) in FixedWidthInteger?

2017-12-05 Thread Jens Persson via swift-users
What I actually want is the "true modulo", and it should not check for overflow, as it needs to be as fast as possible. infix operator &%%: MultiplicationPrecedence extension FixedWidthInteger { func unsafeTrueModulo(_ v: Self) -> Self { let rem = self % v return rem >= 0 ?

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Hi Jens, In the SynchronizedArray class, I use a lock to perform mutating operations on the array. However, my questions concern the case where an array is exposed as a public property of a thread-safe class, like this: public class MyClass { private var _myArray: Array = []

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Jens Alfke via swift-users
> On Dec 5, 2017, at 6:24 AM, Michel Fortin via swift-users > wrote: > > The array *storage* is copy on write. The array variable (which essentially > contains a pointer to the storage) is not copy on write. If you refer to the > same array variable from multiple

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Thank you Michel. > Rather, use a different copy of the variable to each thread. How should I copy a variable to each thread? I’m not sure to understand what you mean by “copy” in this case. If I have this: var a = Array() var b = a do you consider “b” as being a copy of the variable “a”? >

Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Michel Fortin via swift-users
The array *storage* is copy on write. The array variable (which essentially contains a pointer to the storage) is not copy on write. If you refer to the same array variable from multiple threads, you have a race. Rather, use a different copy of the variable to each thread. Copied variables will

[swift-users] Fwd: Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Small typo in the second sample code. Should read: return try closure(&_elements) > Begin forwarded message: > > From: Romain Jacquinot via swift-users > Subject: [swift-users] Data races with copy-on-write > Date: December 5, 2017 at 11:20:46 AM GMT+1 > To:

Re: [swift-users] Cast CFString to String

2017-12-05 Thread Dennis Weissmann via swift-users
Thanks Martin, that's much nicer! - Dennis > On Dec 5, 2017, at 11:15 AM, Martin R wrote: > > Another workaround would be > >public init(uti: String) { >switch uti.lowercased() { >case String(kUTTypeText): >self = .text >default: >

[swift-users] Data races with copy-on-write

2017-12-05 Thread Romain Jacquinot via swift-users
Hi, I'm trying to better understand how copy-on-write works, especially in a multithreaded environment, but there are a few things that confuse me. From the documentation, it is said that: "If the instance passed as object is being accessed by multiple threads simultaneously,

Re: [swift-users] Cast CFString to String

2017-12-05 Thread Martin R via swift-users
Another workaround would be public init(uti: String) { switch uti.lowercased() { case String(kUTTypeText): self = .text default: self = .unknown } } because there is a `String(_ cocoaString: NSString)` initializer in Foundation.

[swift-users] what is the use of "-frontend" argument to swift?

2017-12-05 Thread Atul Sowani via swift-users
Hi, What is the purpose of "-frontend -c" arguments of swift? I tried "swift --help" but that does not mention it. Also I couldn't find it easily in any swift documents. Can somebody kindly let me know the purpose of these arguments? Thanks, Atul. ___

Re: [swift-users] Cast CFString to String

2017-12-05 Thread Dennis Weissmann via swift-users
I found a related bug here: https://bugs.swift.org/browse/SR-6204 > On Dec 5, 2017, at 10:10 AM, Dennis Weissmann via swift-users > wrote: > > Hi swift-users, > > I have found another weird behavior (IMO) and wanted to ask for the right way > to handle this: > >