Skip to content

Commit

Permalink
Merge pull request #68 from lorentey/remove-obsolete-workarounds
Browse files Browse the repository at this point in the history
Remove obsolete workarounds for older toolchains
  • Loading branch information
lorentey committed Mar 17, 2023
2 parents a79166d + 275fb6b commit 71a1f86
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 78 deletions.
6 changes: 1 addition & 5 deletions Sources/Atomics/AtomicLazyReference.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -47,10 +47,8 @@ public struct UnsafeAtomicLazyReference<Instance: AnyObject> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension UnsafeAtomicLazyReference: @unchecked Sendable
where Instance: Sendable {}
#endif

extension UnsafeAtomicLazyReference {
/// The storage representation for an atomic lazy reference value.
Expand Down Expand Up @@ -152,10 +150,8 @@ public class ManagedAtomicLazyReference<Instance: AnyObject> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension ManagedAtomicLazyReference: @unchecked Sendable
where Instance: Sendable {}
#endif

% for type in ["UnsafeAtomicLazyReference", "ManagedAtomicLazyReference"]:
extension ${type} {
Expand Down
6 changes: 1 addition & 5 deletions Sources/Atomics/HighLevelTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -71,9 +71,7 @@ public struct UnsafeAtomic<Value: AtomicValue> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {}
#endif

/// A reference type holding an atomic value, with automatic memory management.
@_fixed_layout
Expand All @@ -99,9 +97,7 @@ public class ManagedAtomic<Value: AtomicValue> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension ManagedAtomic: @unchecked Sendable where Value: Sendable {}
#endif

% for type in ["UnsafeAtomic", "ManagedAtomic"]:
extension ${type} {
Expand Down
34 changes: 1 addition & 33 deletions Sources/Atomics/IntegerConformances.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -39,24 +39,7 @@ extension ${swiftType}: AtomicValue {

@inline(__always) @_alwaysEmitIntoClient
public func dispose() -> Value {
% if swiftType == "DoubleWord":
// Work around https://github.com/apple/swift-atomics/issues/41
#if compiler(>=5.5) && arch(arm64) && DEBUG
var copy = self // This is not great
var expected = DoubleWord(high: 0, low: 0)
withUnsafeMutablePointer(to: &copy) { pointer in
_ = _sa_cmpxchg_strong_relaxed_relaxed_DoubleWord(
pointer._extract,
&expected,
DoubleWord(high: 0, low: 0))
}
return expected
#else
% end
return _sa_dispose_${swiftType}(_storage)
% if swiftType == "DoubleWord":
#endif
% end
}
}
}
Expand All @@ -78,18 +61,6 @@ extension ${swiftType}.AtomicRepresentation: AtomicStorage {
at pointer: UnsafeMutablePointer<Self>,
ordering: AtomicLoadOrdering
) -> Value {
% if swiftType == "DoubleWord":
// Work around https://github.com/apple/swift-atomics/issues/41
#if compiler(>=5.5) && arch(arm64) && DEBUG
let (_, original) = atomicCompareExchange(
expected: DoubleWord(high: 0, low: 0),
desired: DoubleWord(high: 0, low: 0),
at: pointer,
successOrdering: .relaxed, // Note: this relies on the FIXME below.
failureOrdering: ordering)
return original
#else
% end
switch ordering {
% for (swiftOrder, shimOrder) in loadOrderings:
case .${swiftOrder}:
Expand All @@ -98,9 +69,6 @@ extension ${swiftType}.AtomicRepresentation: AtomicStorage {
default:
fatalError("Unsupported ordering")
}
% if swiftType == "DoubleWord":
#endif
% end
}

@_semantics("atomics.requires_constant_orderings")
Expand Down
6 changes: 1 addition & 5 deletions Sources/Atomics/autogenerated/AtomicLazyReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -50,10 +50,8 @@ public struct UnsafeAtomicLazyReference<Instance: AnyObject> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension UnsafeAtomicLazyReference: @unchecked Sendable
where Instance: Sendable {}
#endif

extension UnsafeAtomicLazyReference {
/// The storage representation for an atomic lazy reference value.
Expand Down Expand Up @@ -155,10 +153,8 @@ public class ManagedAtomicLazyReference<Instance: AnyObject> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension ManagedAtomicLazyReference: @unchecked Sendable
where Instance: Sendable {}
#endif

extension UnsafeAtomicLazyReference {
/// Atomically initializes this reference if its current value is nil, then
Expand Down
6 changes: 1 addition & 5 deletions Sources/Atomics/autogenerated/HighLevelTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -73,9 +73,7 @@ public struct UnsafeAtomic<Value: AtomicValue> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {}
#endif

/// A reference type holding an atomic value, with automatic memory management.
@_fixed_layout
Expand All @@ -101,9 +99,7 @@ public class ManagedAtomic<Value: AtomicValue> {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension ManagedAtomic: @unchecked Sendable where Value: Sendable {}
#endif

extension UnsafeAtomic {
/// Atomically loads and returns the current value, applying the specified
Expand Down
26 changes: 1 addition & 25 deletions Sources/Atomics/autogenerated/IntegerConformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -4964,20 +4964,7 @@ extension DoubleWord: AtomicValue {

@inline(__always) @_alwaysEmitIntoClient
public func dispose() -> Value {
// Work around https://github.com/apple/swift-atomics/issues/41
#if compiler(>=5.5) && arch(arm64) && DEBUG
var copy = self // This is not great
var expected = DoubleWord(high: 0, low: 0)
withUnsafeMutablePointer(to: &copy) { pointer in
_ = _sa_cmpxchg_strong_relaxed_relaxed_DoubleWord(
pointer._extract,
&expected,
DoubleWord(high: 0, low: 0))
}
return expected
#else
return _sa_dispose_DoubleWord(_storage)
#endif
}
}
}
Expand All @@ -4999,16 +4986,6 @@ extension DoubleWord.AtomicRepresentation: AtomicStorage {
at pointer: UnsafeMutablePointer<Self>,
ordering: AtomicLoadOrdering
) -> Value {
// Work around https://github.com/apple/swift-atomics/issues/41
#if compiler(>=5.5) && arch(arm64) && DEBUG
let (_, original) = atomicCompareExchange(
expected: DoubleWord(high: 0, low: 0),
desired: DoubleWord(high: 0, low: 0),
at: pointer,
successOrdering: .relaxed, // Note: this relies on the FIXME below.
failureOrdering: ordering)
return original
#else
switch ordering {
case .relaxed:
return _sa_load_relaxed_DoubleWord(pointer._extract)
Expand All @@ -5019,7 +4996,6 @@ extension DoubleWord.AtomicRepresentation: AtomicStorage {
default:
fatalError("Unsupported ordering")
}
#endif
}

@_semantics("atomics.requires_constant_orderings")
Expand Down

0 comments on commit 71a1f86

Please sign in to comment.