profile
viewpoint

attaswift/BTree 1194

Fast sorted collections for Swift using in-memory B-trees

attaswift/Attabench 1148

Microbenchmarking app for Swift with nice log-log plots

attaswift/BigInt 590

Arbitrary-precision arithmetic in pure Swift

attaswift/GlueKit 363

Type-safe observable values and collections in Swift

attaswift/SipHash 249

Simple and secure hashing in Swift with the SipHash algorithm

objcio/OptimizingCollections 214

Home of my talk about Optimizing Collections in Swift

attaswift/Deque 64

A double-ended queue type in pure Swift

staggerpkg/stagger 31

An ID3v1/ID3v2 tag manipulation package written in pure Python 3

attaswift/alfred-swift-evolution 29

An Alfred workflow for looking up Swift evolution proposals

numist/Diffing 26

A proposal for adding diffing functionality to the Swift standard library

pull request commentapple/swift

mailmap: Fix parse issue

@swift-ci smoke test and merge

lorentey

comment created time in 21 hours

PR opened apple/swift

mailmap: Fix parse issue

There is a stray angle bracket that confuses some git commands.

+1 -1

0 comment

1 changed file

pr created time in 21 hours

create barnchapple/swift

branch : malmap-parse

created branch time in 21 hours

delete branch lorentey/swift

delete branch : array-cannot-append

delete time in 2 days

delete branch lorentey/swift

delete branch : array-cannot-append-5.3

delete time in 2 days

push eventapple/swift

Karoy Lorentey

commit sha 4826224d90b68e562811393d47f4aeb5f85a6289

[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements. The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.) When the argument to `Array.append(contentsOf:)` is of type NSArray, the `newElements is [Element]` expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount` currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to `self` at all. Turning the `is` test into a direct equality check between the metatype instances resolves the issue. (cherry picked from commit 184367ca8f6fc7c8dd06582e8774db816479988c)

view details

Karoy Lorentey

commit sha 3250715a6273a889797896516abb6b00a734c220

Merge pull request #34445 from lorentey/array-cannot-append-5.3 [5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

view details

push time in 2 days

PR merged apple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Cherry-picked from https://github.com/apple/swift/pull/34426, reviewed by @kylemacomber.

Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements. The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.)

When the argument to Array.append(contentsOf:) is of type NSArray, the newElements is [Element] expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to self at all.

Turning the is test into a direct equality check between the metatype instances resolves the issue.

Resolves rdar://70448247.

+10 -1

4 comments

2 changed files

lorentey

pr closed time in 2 days

pull request commentapple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

@swift-ci test windows platform

lorentey

comment created time in 3 days

pull request commentapple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

@swift-ci test windows platform

lorentey

comment created time in 3 days

pull request commentapple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Windows failure looks unrelated:

ci@SWIFTCI-WINDOWS S:\jenkins\workspace\swift-PR-windows>EME"
'EME"' is not recognized as an internal or external command,
operable program or batch file.
lorentey

comment created time in 3 days

pull request commentapple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

@swift-ci test

lorentey

comment created time in 3 days

PR opened apple/swift

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Cherry-picked from https://github.com/apple/swift/pull/34426, reviewed by @kylemacomber.

Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements. The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.)

When the argument to Array.append(contentsOf:) is of type NSArray, the newElements is [Element] expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to self at all.

Turning the is test into a direct equality check between the metatype instances resolves the issue.

Resolves rdar://70448247.

+10 -1

0 comment

2 changed files

pr created time in 3 days

create barnchlorentey/swift

branch : array-cannot-append-5.3

created branch time in 3 days

push eventapple/swift

Karoy Lorentey

commit sha 184367ca8f6fc7c8dd06582e8774db816479988c

[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements. The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.) When the argument to `Array.append(contentsOf:)` is of type NSArray, the `newElements is [Element]` expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount` currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to `self` at all. Turning the `is` test into a direct equality check between the metatype instances resolves the issue.

view details

Karoy Lorentey

commit sha 58d07a4efd0d9e5a38dc4b0d029d6f80d7152a62

Merge pull request #34426 from lorentey/array-cannot-append [stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

view details

push time in 3 days

PR merged apple/swift

Reviewers
[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements.

The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.)

When the argument to Array.append(contentsOf:) is of type NSArray, the newElements is [Element] expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to self at all.

Turning the is test into a direct equality check between the metatype instances resolves the issue.

Resolves rdar://70448247

+10 -1

1 comment

2 changed files

lorentey

pr closed time in 3 days

Pull request review commentapple/swift

[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

 ArrayTestSuite.test("BridgedToObjC.Nonverbatim.RoundtripThroughSwiftArray") {   } } +ArrayTestSuite.test("append(contentsOf: NSArray)") {+  // A stray runtime `is` test caused this particular operation to fail in 5.3.+  // rdar://70448247

Note: I did not add an availability test here on the theory that we aren't running these tests with stdlib binaries built from the 5.3 release. If this proves wrong, we may need to add one later.

lorentey

comment created time in 3 days

PullRequestReviewEvent

issue commentapple/swift-system

Foundation additions

One thing we could do is to put the combo overlay APIs into a separate build product that must be imported explicitly.

benrimmington

comment created time in 5 days

pull request commentapple/swift

[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

@swift-ci test

lorentey

comment created time in 5 days

PR opened apple/swift

Reviewers
[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements.

The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.)

When the argument to Array.append(contentsOf:) is of type NSArray, the newElements is [Element] expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCountcurrently returns 0, so the earlier _copyContents call is a noop, so no elements get added toself` at all.

Turning the is test into a direct equality check between the metatype instances resolves the issue.

Resolves rdar://70448247

+10 -1

0 comment

2 changed files

pr created time in 5 days

create barnchlorentey/swift

branch : array-cannot-append

created branch time in 5 days

PullRequestReviewEvent

push eventapple/swift-atomics

JP Simard

commit sha 55a062c4a86102455fc32e1d1fec7672a165e7ca

Fix typo in AtomicMemoryOrderings.swift docstring

view details

Karoy Lorentey

commit sha ccce007d5d5462860cf0cb7839a233307424c61c

Merge pull request #14 from jpsim/patch-1 Fix typo in AtomicMemoryOrderings.swift docstring

view details

push time in 7 days

PR merged apple/swift-atomics

Fix typo in AtomicMemoryOrderings.swift docstring

I was reading through the orderings and came across this small typo.

Looking forward to learning more about this!

+1 -1

1 comment

1 changed file

jpsim

pr closed time in 7 days

pull request commentapple/swift-atomics

Fix typo in AtomicMemoryOrderings.swift docstring

Thank you!

jpsim

comment created time in 7 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentapple/swift-system

Syscall mock testing

I don't think it's a good idea to rely on the optimizer to eliminate these -- the mocking entry points introduce a level of userspace dynamism that feels inappropriate for a low-level syscall wrapper. Why not compile these out entirely?

milseman

comment created time in 8 days

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {

I don't think it's a good idea to rely on the optimizer to eliminate these -- the mocking entry points introduce a level of userspace dynamism that feels inappropriate for syscalls.

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

 let targets: [PackageDescription.Target] = [     path: "Sources/System"),   .target(     name: "SystemInternals",-    dependencies: ["CSystem"]),+    dependencies: ["CSystem"],+    swiftSettings: [+      .define("ENABLE_MOCKING")

It's a rather unfortunate choice, but we also have the option to build & run tests outside SPM's limitations. (swift-atomics will likely also need to do that to be able to run lit tests for codegen verification.)

In this sort of setup, the test environment would build the package with ENABLE_MOCKING enabled on the swiftpm command line, enabling both the mocking infrastructure and the mocking tests themselves.

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {

@testable would be a good way to hide these.

But I still think these should be entirely compiled out from build products that external code links with. (I.e., the mock* functions and the if conditions within the syscall shims must not be compiled into production libraries.)

We are forced to do invasive testing here because we lack good alternatives -- but potentially leaving traces of the testing infrastructure in production code is a hazard I don't like.

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {+  public struct Entry: Hashable {+    var name: String+    var arguments: [AnyHashable]++    public init(name: String, _ arguments: [AnyHashable]) {+      self.name = name+      self.arguments = arguments+    }+  }++  private var entries: [Entry] = []+  private var firstEntry: Int = 0++  public var isEmpty: Bool { firstEntry >= entries.count }++  public mutating func dequeue() -> Entry? {+    guard !self.isEmpty else { return nil }+    defer { firstEntry += 1 }+    return entries[firstEntry]+  }++  internal mutating func add(_ e: Entry) {+    entries.append(e)+  }++  public mutating func clear() { entries.removeAll() }+}++// TODO: Track+public struct WriteBuffer {+  public var enabled: Bool = false++  private var buffer: [UInt8] = []+  private var chunkSize: Int? = nil++  internal mutating func write(_ buf: UnsafeRawBufferPointer) -> Int {+    guard enabled else { return 0 }+    let chunk = chunkSize ?? buf.count+    buffer.append(contentsOf: buf.prefix(chunk))+    return chunk+  }++  public var contents: [UInt8] { buffer }+}++public enum ForceErrno: Equatable {+  case none+  case always(errno: CInt)++  case counted(errno: CInt, count: Int)+}++// Provide access to the driver, context, and trace stack of mocking+public class MockingDriver {+  // Record syscalls and their arguments+  public var trace = Trace()++  // Mock errors inside syscalls+  public var forceErrno = ForceErrno.none++  // A buffer to put `write` bytes into+  public var writeBuffer = WriteBuffer()+}++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+import Darwin+#elseif os(Linux) || os(FreeBSD) || os(Android)+import Glibc+#else+#error("Unsupported Platform")+#endif++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+private func releaseObject(_ raw: UnsafeMutableRawPointer) -> () {+  Unmanaged<MockingDriver>.fromOpaque(raw).release()+}+#elseif os(Linux) || os(FreeBSD) || os(Android)+private func releaseObject(_ raw: UnsafeMutableRawPointer?) -> () {+  guard let object = raw else { return }+  Unmanaged<MockingDriver>.fromOpaque(object).release()+}+#else+#error("Unsupported Platform")+#endif+++internal let key: pthread_key_t = {+  var raw = pthread_key_t()+  guard 0 == pthread_key_create(&raw, releaseObject) else {+    fatalError("Unable to create key")+  }+  return raw+}()++internal var currentMockingDriver: MockingDriver? {+  #if !ENABLE_MOCKING+    fatalError("Contextual mocking in non-mocking build")+  #endif++  guard let rawPtr = pthread_getspecific(key) else { return nil }++  return Unmanaged<MockingDriver>.fromOpaque(rawPtr).takeUnretainedValue()+}++extension MockingDriver {+  /// Enables mocking for the duration of `f` with a clean trace queue+  /// Restores prior mocking status and trace queue after execution+  public static func withMockingEnabled(+    _ f: (MockingDriver) throws -> ()+  ) rethrows {+    let priorMocking = currentMockingDriver+    defer {+      if let object = priorMocking {+        pthread_setspecific(key, Unmanaged.passUnretained(object).toOpaque())+      } else {+        pthread_setspecific(key, nil)+      }+    }++    let driver = MockingDriver()+    guard 0 == pthread_setspecific(key, Unmanaged.passRetained(driver).toOpaque()) else {

Ah, I see what you mean -- removing the destructor could work too!

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {+  public struct Entry: Hashable {+    var name: String+    var arguments: [AnyHashable]++    public init(name: String, _ arguments: [AnyHashable]) {+      self.name = name+      self.arguments = arguments+    }+  }++  private var entries: [Entry] = []+  private var firstEntry: Int = 0++  public var isEmpty: Bool { firstEntry >= entries.count }++  public mutating func dequeue() -> Entry? {+    guard !self.isEmpty else { return nil }+    defer { firstEntry += 1 }+    return entries[firstEntry]+  }++  internal mutating func add(_ e: Entry) {+    entries.append(e)+  }++  public mutating func clear() { entries.removeAll() }+}++// TODO: Track+public struct WriteBuffer {+  public var enabled: Bool = false++  private var buffer: [UInt8] = []+  private var chunkSize: Int? = nil++  internal mutating func write(_ buf: UnsafeRawBufferPointer) -> Int {+    guard enabled else { return 0 }+    let chunk = chunkSize ?? buf.count+    buffer.append(contentsOf: buf.prefix(chunk))+    return chunk+  }++  public var contents: [UInt8] { buffer }+}++public enum ForceErrno: Equatable {+  case none+  case always(errno: CInt)++  case counted(errno: CInt, count: Int)+}++// Provide access to the driver, context, and trace stack of mocking+public class MockingDriver {+  // Record syscalls and their arguments+  public var trace = Trace()++  // Mock errors inside syscalls+  public var forceErrno = ForceErrno.none++  // A buffer to put `write` bytes into+  public var writeBuffer = WriteBuffer()+}++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+import Darwin+#elseif os(Linux) || os(FreeBSD) || os(Android)+import Glibc+#else+#error("Unsupported Platform")+#endif++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+private func releaseObject(_ raw: UnsafeMutableRawPointer) -> () {+  Unmanaged<MockingDriver>.fromOpaque(raw).release()+}+#elseif os(Linux) || os(FreeBSD) || os(Android)+private func releaseObject(_ raw: UnsafeMutableRawPointer?) -> () {+  guard let object = raw else { return }+  Unmanaged<MockingDriver>.fromOpaque(object).release()+}+#else+#error("Unsupported Platform")+#endif+++internal let key: pthread_key_t = {+  var raw = pthread_key_t()+  guard 0 == pthread_key_create(&raw, releaseObject) else {+    fatalError("Unable to create key")+  }+  return raw+}()++internal var currentMockingDriver: MockingDriver? {+  #if !ENABLE_MOCKING+    fatalError("Contextual mocking in non-mocking build")+  #endif++  guard let rawPtr = pthread_getspecific(key) else { return nil }++  return Unmanaged<MockingDriver>.fromOpaque(rawPtr).takeUnretainedValue()+}++extension MockingDriver {+  /// Enables mocking for the duration of `f` with a clean trace queue+  /// Restores prior mocking status and trace queue after execution+  public static func withMockingEnabled(+    _ f: (MockingDriver) throws -> ()+  ) rethrows {+    let priorMocking = currentMockingDriver+    defer {+      if let object = priorMocking {+        pthread_setspecific(key, Unmanaged.passUnretained(object).toOpaque())+      } else {+        pthread_setspecific(key, nil)+      }+    }++    let driver = MockingDriver()+    guard 0 == pthread_setspecific(key, Unmanaged.passRetained(driver).toOpaque()) else {

My point is that the destructor hook isn't called by pthread_setspecific -- it is only called at thread exit. When withMockingEnabled restores the original driver, it must also release the driver that it replaced.

(It doesn't seem feasible to prevent all leaks if someone calls pthread_exit, but we should make sure not to leak in regular use.)

Slight nit: it would make this code slightly simpler if it simply used getspecific instead of currentMockingDriver -- it wouldn't need to deal with the back-n-forth conversion and optionals at all.

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++import XCTest+import SystemInternals+import SystemPackage++internal protocol TestCase {+  // TODO: want a source location stack, more fidelity, kinds of stack entries, etc+  var file: StaticString { get }+  var line: UInt { get }++  // TODO: Instead have an attribute to register a test in a allTests var, similar to the argument parser.+  func runAllTests()+}+extension TestCase {+  func expectEqualSequence<S1: Sequence, S2: Sequence>(+    _ actual: S1, _ expected: S2,+    _ message: String? = nil+  ) where S1.Element: Equatable, S1.Element == S2.Element {+    if !actual.elementsEqual(expected) {+      fail(message)+    }+  }+  func expectEqual<E: Equatable>(+    _ actual: E, _ expected: E,+    _ message: String? = nil+  ) {+    if actual != expected {+      fail(message)+    }+  }+  func expectTrue(+    _ actual: Bool,+    _ message: String? = nil+  ) {+    expectEqual(true, actual, message)+  }+  func expectFalse(+    _ actual: Bool,+    _ message: String? = nil+  ) {+    expectEqual(false, actual, message)+  }++  func fail(_ reason: String? = nil) {+    XCTAssert(false, reason ?? "", file: file, line: line)+  }+}++internal struct MockTestCase: TestCase {+  var file: StaticString+  var line: UInt++  var expected: Trace.Entry+  var interruptable: Bool++  var body: (_ retryOnInterrupt: Bool) throws -> ()++  init(+    _ file: StaticString = #file,+    _ line: UInt = #line,+    name: String,+    _ args: AnyHashable...,+    interruptable: Bool,+    _ body: @escaping (_ retryOnInterrupt: Bool) throws -> ()+  ) {+    self.file = file+    self.line = line+    self.expected = Trace.Entry(name: name, args)+    self.interruptable = interruptable+    self.body = body+  }++  func runAllTests() {+    MockingDriver.withMockingEnabled { mocking in+      // Make sure we completely match the trace queue+      self.expectTrue(mocking.trace.isEmpty)+      defer { self.expectTrue(mocking.trace.isEmpty) }++      // Test our API mappings to the lower-level syscall invocation+      do {+        try body(true)+        self.expectEqual(mocking.trace.dequeue(), self.expected)+      } catch {+        self.fail()+      }++      // Test interupt behavior. Interruptable calls will be told not to+      // retry to catch the EINTR. Non-interruptable calls will be told to+      // retry, to make sure they don't spin (e.g. if API changes to include+      // interruptable)

I believe the set of errno cases a particular syscall is allowed to return is pretty much set in stone at this point; API changes are unlikely. (For well-established syscalls at least.)

milseman

comment created time in 8 days

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {+  public struct Entry: Hashable {+    var name: String+    var arguments: [AnyHashable]++    public init(name: String, _ arguments: [AnyHashable]) {+      self.name = name+      self.arguments = arguments+    }+  }++  private var entries: [Entry] = []+  private var firstEntry: Int = 0++  public var isEmpty: Bool { firstEntry >= entries.count }++  public mutating func dequeue() -> Entry? {+    guard !self.isEmpty else { return nil }+    defer { firstEntry += 1 }+    return entries[firstEntry]+  }++  internal mutating func add(_ e: Entry) {+    entries.append(e)+  }++  public mutating func clear() { entries.removeAll() }+}++// TODO: Track+public struct WriteBuffer {+  public var enabled: Bool = false++  private var buffer: [UInt8] = []+  private var chunkSize: Int? = nil++  internal mutating func write(_ buf: UnsafeRawBufferPointer) -> Int {+    guard enabled else { return 0 }+    let chunk = chunkSize ?? buf.count+    buffer.append(contentsOf: buf.prefix(chunk))+    return chunk+  }++  public var contents: [UInt8] { buffer }+}++public enum ForceErrno: Equatable {+  case none+  case always(errno: CInt)++  case counted(errno: CInt, count: Int)+}++// Provide access to the driver, context, and trace stack of mocking+public class MockingDriver {+  // Record syscalls and their arguments+  public var trace = Trace()++  // Mock errors inside syscalls+  public var forceErrno = ForceErrno.none++  // A buffer to put `write` bytes into+  public var writeBuffer = WriteBuffer()+}++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+import Darwin+#elseif os(Linux) || os(FreeBSD) || os(Android)+import Glibc+#else+#error("Unsupported Platform")+#endif++#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)+private func releaseObject(_ raw: UnsafeMutableRawPointer) -> () {+  Unmanaged<MockingDriver>.fromOpaque(raw).release()+}+#elseif os(Linux) || os(FreeBSD) || os(Android)+private func releaseObject(_ raw: UnsafeMutableRawPointer?) -> () {+  guard let object = raw else { return }+  Unmanaged<MockingDriver>.fromOpaque(object).release()+}+#else+#error("Unsupported Platform")+#endif+++internal let key: pthread_key_t = {+  var raw = pthread_key_t()+  guard 0 == pthread_key_create(&raw, releaseObject) else {+    fatalError("Unable to create key")+  }+  return raw+}()++internal var currentMockingDriver: MockingDriver? {+  #if !ENABLE_MOCKING+    fatalError("Contextual mocking in non-mocking build")+  #endif++  guard let rawPtr = pthread_getspecific(key) else { return nil }++  return Unmanaged<MockingDriver>.fromOpaque(rawPtr).takeUnretainedValue()+}++extension MockingDriver {+  /// Enables mocking for the duration of `f` with a clean trace queue+  /// Restores prior mocking status and trace queue after execution+  public static func withMockingEnabled(+    _ f: (MockingDriver) throws -> ()+  ) rethrows {+    let priorMocking = currentMockingDriver+    defer {+      if let object = priorMocking {+        pthread_setspecific(key, Unmanaged.passUnretained(object).toOpaque())+      } else {+        pthread_setspecific(key, nil)+      }+    }++    let driver = MockingDriver()+    guard 0 == pthread_setspecific(key, Unmanaged.passRetained(driver).toOpaque()) else {

IIUC, this will leak the driver when this method returns -- I think the defer block is missing an explicit release for it.

milseman

comment created time in 8 days

Pull request review commentapple/swift-system

Syscall mock testing

 let targets: [PackageDescription.Target] = [     path: "Sources/System"),   .target(     name: "SystemInternals",-    dependencies: ["CSystem"]),+    dependencies: ["CSystem"],+    swiftSettings: [+      .define("ENABLE_MOCKING")

Shouldn't this be conditional on the current build configuration? (Or, if that's even possible, only enabled in a special test target dependency, and never in the production library?)

milseman

comment created time in 8 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift-system

Syscall mock testing

+/*+ This source file is part of the Swift System open source project++ Copyright (c) 2020 Apple Inc. and the Swift System project authors+ Licensed under Apache License v2.0 with Runtime Library Exception++ See https://swift.org/LICENSE.txt for license information+*/++// Syscall mocking support.+//+// NOTE: This is currently the bare minimum needed for System's testing purposes, though we do+// eventually want to expose some solution to users.+//+// Mocking is contextual, accessible through MockingDriver.withMockingEnabled. Mocking+// state, including whether it is enabled, is stored in thread-local storage. Mocking is only+// enabled in testing builds of System currently, to minimize runtime overhead of release builds.+//++public struct Trace {

I think the entire mocking infrastructure ought to be compiled out of the codebase when we aren't building for testing -- so this entire file should be inside a #if ENABLE_MOCKING block, or it should live in a special target that's only ever imported in the test targets.

milseman

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentapple/swift

[CMake] Make sure that library evolution is set when compiling overlays.

 set(SWIFT_NATIVE_CLANG_TOOLS_PATH "${TOOLCHAIN_DIR}/usr/bin" CACHE STRING set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${TOOLCHAIN_DIR}/usr/bin" CACHE STRING   "Path to Swift tools that are executable on the build machine.") +# HACK: This initialization code is duplicated in stdlib/CMakeLists.txt++if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")+  # All Darwin platforms have ABI stability.+  set(SWIFT_STDLIB_STABLE_ABI_default TRUE)+elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")

I'm pretty sure that this file is only used to build the overlays for official Apple platform releases, so we won't need this platform switch here -- this only ever applies to Darwin.

varungandhi-apple

comment created time in 9 days

PullRequestReviewEvent

issue commentapple/swift-atomics

Linux Support?

Oh, excellent catch! I agree completely -- SPM packages ought to build using the same target architecture as the stdlib itself.

I wonder if the stdlib really needs core2, or it could work with the narrower cx16 feature. (IIUC, core2 also enables SSE3/SSSE3 and SAHF. On the other hand, core2 conveniently matches the default arch on Darwin, and I expect it might be a universal baseline at this point, including for AMD processors.) (cc @drexin)

In the short term, we should probably update the instructions in the README to ask people to manually add -mcore2 rather than -mcx16 -- if only for consistency's sake.

If/when a version of SPM or swiftc ships that configures the target correctly, Package.swift will need to somehow figure out whether it is being compiled with the right SPM version, and if so, then automatically define the ENABLE_DOUBLEWIDE_ATOMICS conditional flag. (I think the only way to do this right now is by basing the decision on an #if swift() or if compiler() conditional.)

mohok

comment created time in 9 days

pull request commentapple/swift

Bump the swift-version to 5 for lit tests

Remaining failures: (In optimized mode)

Failed Tests (48):
  Swift(macosx-x86_64) :: ClangImporter/enum-dataflow.swift
  Swift(macosx-x86_64) :: ClangImporter/enum.swift
  Swift(macosx-x86_64) :: ClangImporter/objc_parse.swift
  Swift(macosx-x86_64) :: ClangImporter/swift2_warnings.swift
  Swift(macosx-x86_64) :: Constraints/casts_objc.swift
  Swift(macosx-x86_64) :: Constraints/diag_ambiguities.swift
  Swift(macosx-x86_64) :: Constraints/iuo.swift
  Swift(macosx-x86_64) :: Constraints/keypath.swift
  Swift(macosx-x86_64) :: Constraints/optional.swift
  Swift(macosx-x86_64) :: IDE/complete_after_self.swift
  Swift(macosx-x86_64) :: IDE/complete_value_expr.swift
  Swift(macosx-x86_64) :: IRGen/enum_value_semantics.sil
  Swift(macosx-x86_64) :: IRGen/enum_value_semantics_future.sil
  Swift(macosx-x86_64) :: IRGen/objc_factory_method.sil
  Swift(macosx-x86_64) :: IRGen/partial_apply_objc.sil
  Swift(macosx-x86_64) :: Incremental/Dependencies/reference-dependencies-fine.swift
  Swift(macosx-x86_64) :: Interpreter/SDK/mapkit_header_static.swift
  Swift(macosx-x86_64) :: Interpreter/SDK/objc_factory_method.swift
  Swift(macosx-x86_64) :: Interpreter/SDK/object_literals.swift
  Swift(macosx-x86_64) :: Interpreter/dynamic_cast_optionals_to_nsobject.swift
  Swift(macosx-x86_64) :: ModuleInterface/access-filter.swift
  Swift(macosx-x86_64) :: NameLookup/nio_shadowing.swift
  Swift(macosx-x86_64) :: Parse/enum.swift
  Swift(macosx-x86_64) :: PrintAsObjC/availability.swift
  Swift(macosx-x86_64) :: PrintAsObjC/classes.swift
  Swift(macosx-x86_64) :: PrintAsObjC/protocols.swift
  Swift(macosx-x86_64) :: Python/build_swift.swift
  Swift(macosx-x86_64) :: Python/python_lint.swift
  Swift(macosx-x86_64) :: SILGen/functions.swift
  Swift(macosx-x86_64) :: SILGen/guaranteed_normal_args.swift
  Swift(macosx-x86_64) :: SILGen/inlinable_attribute.swift
  Swift(macosx-x86_64) :: SILGen/weak_multiple_modules.swift
  Swift(macosx-x86_64) :: SILOptimizer/definite_init_diagnostics.swift
  Swift(macosx-x86_64) :: Sema/diag_unintended_optional_behavior.swift
  Swift(macosx-x86_64) :: Serialization/struct.swift
  Swift(macosx-x86_64) :: attr/accessibility_print.swift
  Swift(macosx-x86_64) :: attr/attr_noescape.swift
  Swift(macosx-x86_64) :: compiler_crashers_2_fixed/0160-sr7958.swift
  Swift(macosx-x86_64) :: compiler_crashers_fixed/28638-anonymous-namespace-verifier-checksametype-swift-type-swift-type-char-const.swift
  Swift(macosx-x86_64) :: decl/init/failable.swift
  Swift(macosx-x86_64) :: decl/overload.swift
  Swift(macosx-x86_64) :: decl/protocol/protocols.swift
  Swift(macosx-x86_64) :: expr/unary/keypath/keypath.swift
  Swift(macosx-x86_64) :: multifile/extensions/two-modules/main.swift
  Swift(macosx-x86_64) :: multifile/inlinable.swift
  Swift(macosx-x86_64) :: multifile/synthesized-accessors/two-modules-imported/main.swift
  Swift(macosx-x86_64) :: sil-func-extractor/load-serialized-sil.swift
  Swift(macosx-x86_64) :: type/types.swift
shahmishal

comment created time in 13 days

push eventapple/swift

Karoy Lorentey

commit sha 3de361e087532e9916305b251148902ec8a87d72

[test] Add an explicit language mode to Migrator tests that lack them

view details

push time in 13 days

created tagapple/swift

tagrelease-1.0.0

The Swift Programming Language

created time in 13 days

push eventapple/swift

Karoy Lorentey

commit sha d7f51363cfaa50fe4029b40ad9d3685bc3b518a3

[test] Update stdlib tests to support compiling in Swift 5 mode

view details

push time in 13 days

release apple/swift-atomics

0.0.2

released time in 14 days

created tagapple/swift-atomics

tag0.0.2

This package implements an atomics library for Swift, providing atomic operations for a variety of Swift types, including integers and pointer values. The goal is to enable intrepid developers to start building synchronization constructs directly in Swift.

created time in 14 days

issue openedapple/swift-atomics

Revive lit tests

This repository contains a couple of lit tests that look at generated code to catch potential codegen issues and to verify that constant folding gets rid of switch statements over memory ordering enumerations. These do not cover all supported atomic types and they aren't currently configured for execution.

  • Set up a lit configuration that allows us to easily execute these tests. This does not need to be integrated into the package manager.
  • Update and extend the existing tests to look at double-wide atomics, atomic booleans and other features that aren't currently covered.

created time in 17 days

delete branch lorentey/swift-atomics

delete branch : restore-linux-support

delete time in 17 days

push eventapple/swift-atomics

Karoy Lorentey

commit sha 34caa6fbd57dcf60d02106ff702cf68bb9e6cbe4

[test] Split basic tests into 25 separate test cases This prevents an “unable to typecheck in reasonable time” error when compiling the test registry. 1612 tests under one test case is currently too many for swift-corelibs-xctest. While we’re here, add explicit test cases for UnsafeRawPointer and Optional<UnsafeRawPointer>.

view details

Karoy Lorentey

commit sha 56753d183fbe45ebea97ca1fbee22cfdf0a9059f

generate-sources: Adjust mktemp invocation for portability

view details

Karoy Lorentey

commit sha 9ad914d11849ecf5aa34969c42aa6d527a5f6ba1

Make double-wide atomics conditional on platform support Linux on x86_64 unfortunately disables support for cmpxchg16 by default, making double-wide atomic operations fall back to using locks. We cannot currently override this on the package level, so stop providing double-wide atomics in this configuration by default. To enable codegen support for double-wide atomics on Linux/x86_64, compile the package with `-Xcc -mcx16 -Xswiftc -DENABLE_DOUBLEWIDE_ATOMICS`.

view details

Karoy Lorentey

commit sha ed324ec42e8b9211cb8c95be03850f44252161ff

generate-sources: Don’t invoke —generate-linuxmain SPM’s --generate-linuxmain feature doesn’t support conditionally compiled tests. To run tests on non-Darwin platforms, use `swift test --enable-test-discovery`.

view details

Karoy Lorentey

commit sha 230c1aa6769ec1233da01248c0c4471d4187c244

Add note on portability of double-wide atomics

view details

Karoy Lorentey

commit sha 7658766e6137f85ba027ac4789317b725b8dc652

Remove LinuxMain.swift This package requires --enable-test-discovery.

view details

Karoy Lorentey

commit sha 26e346cd64f6b92d4089e7fafe2f8e82f60ddb8c

Merge pull request #12 from lorentey/restore-linux-support Fix Linux compatibility

view details

push time in 17 days

PR merged apple/swift-atomics

Reviewers
Fix Linux compatibility

This PR resolves issues preventing this package from working as designed on Linux:

  • [X] One of the test cases has grown to >1600 tests, which triggers a compiler timeout while type checking the test registry.
  • [X] generate-sources is not compatible with GNU coreutils.
  • [X] The package definition is lacking a conditional link dependency on libatomics.so on Linux. (Triggered by support for double-wide atomics -- see below.)
  • [x] Double-wide atomics need to be disabled on Linux/x86_64 unless cmpxchg16b support is manually enabled via -Xcc -mcx16.

Closes #10.

+11540 -9982

0 comment

15 changed files

lorentey

pr closed time in 17 days

issue closedapple/swift-atomics

Linux Support?

Linker error occurrs on Ubuntu 20.04, Swift 5.3 in resolving packages.

.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_load'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_load'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_compare_exchange'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_load'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_load'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_is_lock_free'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_is_lock_free'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_is_lock_free'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_compare_exchange'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_compare_exchange'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_compare_exchange'
.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/_AtomicsShims.h:325: error: undefined reference to '__atomic_is_lock_free'
../.build/checkouts/swift-atomics/Sources/Atomics/autogenerated/IntegerConformances.swift:0: error: undefined reference to '__atomic_store'
../.build/checkouts/swift-atomics/Sources/Atomics/autogenerated/IntegerConformances.swift:0: error: undefined reference to '__atomic_exchange'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

closed time in 17 days

mohok

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 7658766e6137f85ba027ac4789317b725b8dc652

Remove LinuxMain.swift This package requires --enable-test-discovery.

view details

push time in 17 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 230c1aa6769ec1233da01248c0c4471d4187c244

Add note on portability of double-wide atomics

view details

push time in 20 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 82bfd8d171d023f745cbf70576e8f5b8b52d6624

Add note on portability of double-wide atomics

view details

push time in 20 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 6e09389a3d013bea562c33a7c43cbc513fc5c247

Revert "[shims] Make retain_n/release_n shims header-only"

view details

Karoy Lorentey

commit sha dc49369e9601ee93410747390ad6d795f02db821

Merge pull request #11 from apple/revert-9-fix-implicit-runtime-dependency Revert "[shims] Make retain_n/release_n shims header-only"

view details

Karoy Lorentey

commit sha 34caa6fbd57dcf60d02106ff702cf68bb9e6cbe4

[test] Split basic tests into 25 separate test cases This prevents an “unable to typecheck in reasonable time” error when compiling the test registry. 1612 tests under one test case is currently too many for swift-corelibs-xctest. While we’re here, add explicit test cases for UnsafeRawPointer and Optional<UnsafeRawPointer>.

view details

Karoy Lorentey

commit sha 56753d183fbe45ebea97ca1fbee22cfdf0a9059f

generate-sources: Adjust mktemp invocation for portability

view details

Karoy Lorentey

commit sha 9ad914d11849ecf5aa34969c42aa6d527a5f6ba1

Make double-wide atomics conditional on platform support Linux on x86_64 unfortunately disables support for cmpxchg16 by default, making double-wide atomic operations fall back to using locks. We cannot currently override this on the package level, so stop providing double-wide atomics in this configuration by default. To enable codegen support for double-wide atomics on Linux/x86_64, compile the package with `-Xcc -mcx16 -Xswiftc -DENABLE_DOUBLEWIDE_ATOMICS`.

view details

Karoy Lorentey

commit sha ed324ec42e8b9211cb8c95be03850f44252161ff

generate-sources: Don’t invoke —generate-linuxmain SPM’s --generate-linuxmain feature doesn’t support conditionally compiled tests. To run tests on non-Darwin platforms, use `swift test --enable-test-discovery`.

view details

push time in 20 days

PullRequestReviewEvent

startedapple/swift-algorithms

started time in 21 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 963e3a7217eaac27be88ff894ff6393671e0ec24

Add a dependency on libatomics on Linux This is required because of the lack of unconditional support for cmpxchg16b on Linux distributions for x86_64. (Which implies we’ll need to disable double-wide atomics on Linux/x86-64, at least by default.)

view details

push time in 21 days

PR opened apple/swift-atomics

Fix Linux compatibility

This PR resolves issues preventing this package from working as designed on Linux:

  • [X] The package definition is lacking a conditional link dependency on libatomics.so on Linux. (Triggered by support for double-wide atomics -- see below.)
  • [X] One of the test cases has grown to >1600 tests, which triggers a compiler timeout while type checking the test registry.
  • [ ] Double-wide atomics need to be disabled on Linux/x86_64 unless cmpxchg16b support is manually enabled via -Xcc -mcx16.

Closes #10.

+7274 -3670

0 comment

4 changed files

pr created time in 21 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 0c901ffb806b2a5efde279a2a27080c3ed01560c

generate-sources: Adjust mktemp invocation for portability

view details

push time in 21 days

push eventapple/swift-atomics

Karoy Lorentey

commit sha 6e09389a3d013bea562c33a7c43cbc513fc5c247

Revert "[shims] Make retain_n/release_n shims header-only"

view details

Karoy Lorentey

commit sha dc49369e9601ee93410747390ad6d795f02db821

Merge pull request #11 from apple/revert-9-fix-implicit-runtime-dependency Revert "[shims] Make retain_n/release_n shims header-only"

view details

push time in 21 days

delete branch apple/swift-atomics

delete branch : revert-9-fix-implicit-runtime-dependency

delete time in 21 days

PR merged apple/swift-atomics

Revert "[shims] Make retain_n/release_n shims header-only"

Reverts apple/swift-atomics#9, as it triggered a compiler issue in Swift 5.3. (https://bugs.swift.org/browse/SR-13708)

+13 -15

0 comment

3 changed files

lorentey

pr closed time in 21 days

PR opened apple/swift-atomics

Revert "[shims] Make retain_n/release_n shims header-only"

Reverts apple/swift-atomics#9, as it triggered a compiler issue in Swift 5.3. (https://bugs.swift.org/browse/SR-13708)

+13 -15

0 comment

3 changed files

pr created time in 21 days

create barnchapple/swift-atomics

branch : revert-9-fix-implicit-runtime-dependency

created branch time in 21 days

IssuesEvent

issue commentapple/swift-atomics

Will not build in generated Xcode projects

Unfortunately the fix triggered a compiler issue (https://bugs.swift.org/browse/SR-13708), so I'll need to revert it.

ckornher

comment created time in 21 days

issue commentapple/swift-atomics

Linux Support?

There are multiple problems, most of which have a relatively straightforward resolution:

  1. The package definition is lacking a conditional link dependency on libatomics.so on Linux. (Triggered by support for double-wide atomics -- see point 4 below.)
  2. One of the test cases has grown to >1600 tests, which triggers a compiler timeout while type checking the test registry. (Oops)
  3. PR #9 reintroduced a compiler issue (https://bugs.swift.org/browse/SR-13708).
  4. Double-wide atomics need to be disabled on Linux/x86_64 unless cmpxchg16b support is manually enabled via -Xcc -mcx16. Declaring this to the package manager is tricky, but there are some potential workarounds. This does mean that for most Linux users, double-wide atomics won't be available.
mohok

comment created time in 21 days

create barnchlorentey/swift-atomics

branch : restore-linux-support

created branch time in 22 days

PullRequestReviewEvent

pull request commentapple/swift

[build] Don’t mark toolchain snapshots as requiring a dev Swift runtime

@gottesmm People will be able to test new compiler features/fixes on more platforms with these changes.

Documenting the use of DYLD_LIBRARY_PATH will help people try out new stdlib features/fixes independent of whether they use xcodebuild or SwiftPM or any of the million other ways to build binaries. This latter use case will forever be limited by the fact that custom-built stdlib binaries don't necessarily work as a drop-in replacement for the OS-provided ones.

lorentey

comment created time in 22 days

PullRequestReviewEvent

Pull request review commentapple/swift

[build] Adjust install name for Differentiation and Concurrency

 add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I     ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}     -parse-stdlib   LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"-  DARWIN_INSTALL_NAME_DIR "@rpath"

Note: this change is right -- the install_name should be left with the default /usr/lib/swift/ prefix, matching the other stdlib libraries.

edymtt

comment created time in 22 days

PullRequestReviewEvent

Pull request review commentapple/swift

[build] Adjust install name for Differentiation and Concurrency

 add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB   Actor.swift   PartialAsyncTask.swift+  "${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"

This isn't right -- magic-symbols-for-install-name only affects the install_name on operating systems that shipped without the Swift runtime, allowing the 5.0 compatibility libraries to continue to get picked up from the app bundle. This doesn't apply to libraries introduced since 5.0 shipped, like this one.

This is essentially a noop.

edymtt

comment created time in 22 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentapple/swift

[AutoDiff] fix _Differentiation rpath

I think /usr/lib/swift/libFoo.dylib is the right install_name for these libraries -- after all, this is where they are expected to install when they get released, and it matches the configuration of other libraries. (Ignoring the pre-5.0 compatibility overrides in magic-symbols-for-install-name, which don't apply here.)

To test locally built libraries, our test configuration uses DYLD_LIBRARY_PATH to override the install_name. Would setting that be an acceptable workflow?

marcrasi

comment created time in 22 days

PullRequestReviewEvent

issue closedapple/swift-atomics

Will not build in generated Xcode projects

This may not be a bug in this package, but the following sequence of commands:

swift package init
# ... add dependencies as described in `README.md`
swift package update
swift package generate-xcodeproj

generates an Xcode project that fails to build with this error:

Undefined symbols for architecture x86_64:
  "_swift_release_n", referenced from:
      __sa_release_n in _AtomicsShims.o
  "_swift_retain_n", referenced from:
      __sa_retain_n in _AtomicsShims.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is using the code 12 beta 2 toolchain. A project in Xcode 12 beta2 builds correctly when this package is added via the Swift Package tab.

Package.swift:

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "swift_atomic_test",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "swift_atomic_test",
            targets: ["swift_atomic_test"]),
    ],
    dependencies: [
        .package(
          url: "https://github.com/apple/swift-atomics.git", 
          from: "0.0.1"
        )
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "swift_atomic_test",
            dependencies: [
                .product(name: "Atomics", package: "swift-atomics")
            ]
        ),
        .testTarget(
            name: "swift_atomic_testTests",
            dependencies: ["swift_atomic_test"]
        )
    ]
)

closed time in 23 days

ckornher

issue commentapple/swift-atomics

Will not build in generated Xcode projects

@ckornher Thanks for reporting this issue! I believe it is now fixed on main. Please reopen if you can still reproduce it with the current head revision.

ckornher

comment created time in 23 days

delete branch lorentey/swift-atomics

delete branch : fix-implicit-runtime-dependency

delete time in 23 days

push eventapple/swift-atomics

Karoy Lorentey

commit sha 45fa32a9225c6292b687c488ce9954b3d6934439

[shims] Make retain_n/release_n shims header-only. Resolves issue #8.

view details

Karoy Lorentey

commit sha 40bd3bac4f0df421e4bf1527fcfd86a6e4a0b10a

[shims] Force-inline new shims

view details

Karoy Lorentey

commit sha c6e526aa429cfd1b64c49296791e33971028ffe5

Merge pull request #9 from lorentey/fix-implicit-runtime-dependency [shims] Make retain_n/release_n shims header-only

view details

push time in 23 days

PR merged apple/swift-atomics

[shims] Make retain_n/release_n shims header-only

This allows the shims module to be built as a standalone target. Previously the module needed to be linked with the Swift runtime, but this wasn't explicit in the package description, causing build failures in generated Xcode projects.

Resolves issue #8.

+15 -13

0 comment

3 changed files

lorentey

pr closed time in 23 days

push eventlorentey/swift-atomics

Karoy Lorentey

commit sha 40bd3bac4f0df421e4bf1527fcfd86a6e4a0b10a

[shims] Force-inline new shims

view details

push time in 23 days

Pull request review commentapple/swift-atomics

[shims] Make retain_n/release_n shims header-only

 SWIFTATOMIC_DEFINE_TYPE(COMPLEX, DoubleWord, _sa_dword, uint64_t) #error "Unsupported intptr_t bit width" #endif // __INTPTR_WIDTH -extern void _sa_retain_n(void *object, uint32_t n);-extern void _sa_release_n(void *object, uint32_t n);+static inline void _sa_retain_n(void *object, uint32_t n) {

Good point! In fact I already have it as SWIFTATOMIC_INLINE, I just forgot to use it. 🙈

lorentey

comment created time in 23 days

PullRequestReviewEvent

pull request commentapple/swift

[test] Don’t check for new behavior on older systems that don’t include the change

@swift-ci smoke test and merge

lorentey

comment created time in 23 days

PR opened apple/swift-atomics

[shims] Make retain_n/release_n shims header-only

This allows the shims module to be built as a standalone target. Previously the module needed to be linked with the Swift runtime, but this wasn't explicit in the package description, causing build failures in generated Xcode projects.

Resolves issue #8.

+13 -13

0 comment

3 changed files

pr created time in 23 days

create barnchlorentey/swift-atomics

branch : fix-implicit-runtime-dependency

created branch time in 23 days

pull request commentapple/swift

[test] Don’t check for new behavior on older systems that don’t include the change

13:29:31 CMake Error at Sources/SwiftDriver/CMakeLists.txt:9 (add_library):
13:29:31   Cannot find source file:
13:29:31 
13:29:31     Incremental Compilation/Multidictionary.swift
13:29:31 
13:29:31   Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
13:29:31   .hpp .hxx .in .txx
13:29:31 
13:29:31 
13:29:31 CMake Error at Sources/SwiftDriver/CMakeLists.txt:9 (add_library):
13:29:31   No SOURCES given to target: SwiftDriver
lorentey

comment created time in 23 days

more