Skip to content

[stdlib] Adopt availability macros #39994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,9 @@ Parser::parseAvailabilityMacro(SmallVectorImpl<AvailabilitySpec *> &Specs) {
if (NameMatch == Map.end())
return makeParserSuccess(); // No match, it could be a standard platform.

SyntaxParsingContext VersionRestrictionContext(
SyntaxContext, SyntaxKind::AvailabilityVersionRestriction);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do in practice here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what I'm doing, but it feels like these parsing contexts associate parsed entities with information about the specific grammar rule that was used to parse them (or rather, the underlying syntactic role).

This particular one lets Syntax know that SwiftStdlib 5.3 has the same syntactic role as iOS 12.4. Otherwise these entities (along with the entire decl the attribute appears on) get classified as unknown, which breaks things (incl. -verify-syntax-tree). (Perhaps these macros should have their own role, but I don't know enough to say for sure (c.f. 84827672).)

Cc @akyrtzi to tell me how terribly wrong I am. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting I missed this in the past and now I see where this is defined for the classic platform availability. Thanks for fixing it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\cc @ahoppen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

consumeToken();

llvm::VersionTuple Version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ self.test("\(testNamePrefix).partition/DispatchesThroughDirectStorageAccessors")
withUnsafeMutableBufferPointerIsSupported ? 1 : 0,
actualWUMBPIFNonNil + actualWCMSIAIFNonNil)

if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
if #available(SwiftStdlib 5.5, *) {
// `partition(by:)` is expected to dispatch to the public API in releases
// that contain https://github.com/apple/swift/pull/36003.
expectEqual(0, actualWUMBPIF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public func getUInt64(_ x: UInt64) -> UInt64 { return _opaqueIdentity(x) }
public func getUInt(_ x: UInt) -> UInt { return _opaqueIdentity(x) }

#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
@inline(never)
public func getFloat16(_ x: Float16) -> Float16 { return _opaqueIdentity(x) }
#endif
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public func _isStdlibDebugConfiguration() -> Bool {

// Return true if the Swift runtime available is at least 5.1
public func _hasSwift_5_1() -> Bool {
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
if #available(SwiftStdlib 5.1, *) {
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/AnyHashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ extension AnyHashable: CustomReflectable {
}
#endif

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(SwiftStdlib 5.5, *)
extension AnyHashable: _HasCustomAnyHashableRepresentation {
}

Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ internal func _internalInvariant_5_1(
// FIXME: The below won't run the assert on 5.1 stdlib if testing on older
// OSes, which means that testing may not test the assertion. We need a real
// solution to this.
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) else { return }
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) //SwiftStdlib 5.1
else { return }
_internalInvariant(condition(), message, file: file, line: line)
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/BridgeObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public protocol _ObjectiveCBridgeable {
// Note: This function is not intended to be called from Swift. The
// availability information here is perfunctory; this function isn't considered
// part of the Stdlib's Swift ABI.
@available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
@available(SwiftStdlib 5.2, *)
@_cdecl("_SwiftCreateBridgedArray")
@usableFromInline
internal func _SwiftCreateBridgedArray_DoNotCall(
Expand All @@ -103,7 +103,7 @@ internal func _SwiftCreateBridgedArray_DoNotCall(
// Note: This function is not intended to be called from Swift. The
// availability information here is perfunctory; this function isn't considered
// part of the Stdlib's Swift ABI.
@available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
@available(SwiftStdlib 5.2, *)
@_cdecl("_SwiftCreateBridgedMutableArray")
@usableFromInline
internal func _SwiftCreateBridgedMutableArray_DoNotCall(
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/CTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public typealias CLongLong = Int64

#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
/// The C '_Float16' type.
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
public typealias CFloat16 = Float16
#endif

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4732,7 +4732,7 @@ extension RawRepresentable where RawValue == Float, Self: Decodable {
}

#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
extension Float16: Codable {
/// Creates a new instance by decoding from the given decoder.
///
Expand Down
30 changes: 15 additions & 15 deletions stdlib/public/core/CollectionDifference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/// A collection of insertions and removals that describe the difference
/// between two ordered collection states.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
public struct CollectionDifference<ChangeElement> {
/// A single change to a collection.
@frozen
Expand Down Expand Up @@ -233,7 +233,7 @@ public struct CollectionDifference<ChangeElement> {
/// }
/// }
/// ```
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference: Collection {
public typealias Element = Change

Expand Down Expand Up @@ -281,7 +281,7 @@ extension CollectionDifference: Collection {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Index: Equatable {
@inlinable
public static func == (
Expand All @@ -292,7 +292,7 @@ extension CollectionDifference.Index: Equatable {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Index: Comparable {
@inlinable
public static func < (
Expand All @@ -303,27 +303,27 @@ extension CollectionDifference.Index: Comparable {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Index: Hashable {
@inlinable
public func hash(into hasher: inout Hasher) {
hasher.combine(_offset)
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Change: Equatable where ChangeElement: Equatable {}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference: Equatable where ChangeElement: Equatable {}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Change: Hashable where ChangeElement: Hashable {}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference: Hashable where ChangeElement: Hashable {}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference where ChangeElement: Hashable {
/// Returns a new collection difference with associations between individual
/// elements that have been removed and inserted only once.
Expand Down Expand Up @@ -380,7 +380,7 @@ extension CollectionDifference where ChangeElement: Hashable {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Change: Codable where ChangeElement: Codable {
private enum _CodingKeys: String, CodingKey {
case offset
Expand Down Expand Up @@ -417,12 +417,12 @@ extension CollectionDifference.Change: Codable where ChangeElement: Codable {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference: Codable where ChangeElement: Codable {}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference: Sendable where ChangeElement: Sendable { }
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Change: Sendable where ChangeElement: Sendable { }
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference.Index: Sendable where ChangeElement: Sendable { }
10 changes: 5 additions & 5 deletions stdlib/public/core/Diffing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// MARK: Diff application to RangeReplaceableCollection

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension CollectionDifference {
fileprivate func _fastEnumeratedApply(
_ consume: (Change) throws -> Void
Expand Down Expand Up @@ -67,7 +67,7 @@ extension RangeReplaceableCollection {
///
/// - Complexity: O(*n* + *c*), where *n* is `self.count` and *c* is the
/// number of changes contained by the parameter.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
public func applying(_ difference: CollectionDifference<Element>) -> Self? {

func append(
Expand Down Expand Up @@ -142,7 +142,7 @@ extension BidirectionalCollection {
/// - Complexity: Worst case performance is O(*n* * *m*), where *n* is the
/// count of this collection and *m* is `other.count`. You can expect
/// faster execution when the collections share many common elements.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
public func difference<C: BidirectionalCollection>(
from other: C,
by areEquivalent: (C.Element, Element) -> Bool
Expand All @@ -169,7 +169,7 @@ extension BidirectionalCollection where Element: Equatable {
/// count of this collection and *m* is `other.count`. You can expect
/// faster execution when the collections share many common elements, or
/// if `Element` conforms to `Hashable`.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
public func difference<C: BidirectionalCollection>(
from other: C
) -> CollectionDifference<Element> where C.Element == Self.Element {
Expand Down Expand Up @@ -224,7 +224,7 @@ private struct _V {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
private func _myers<C,D>(
from old: C, to new: D,
using cmp: (C.Element, D.Element) -> Bool
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/FloatingPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,8 @@ extension BinaryFloatingPoint {
switch (Source.exponentBitCount, Source.significandBitCount) {
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
case (5, 10):
guard #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) else {
guard #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) //SwiftStdlib 5.3
else {
// Convert signaling NaN to quiet NaN by multiplying by 1.
self = Self._convert(from: value).value * 1
break
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/FloatingPointParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool {
% end

%if bits == 16:
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
%end
extension ${Self}: LosslessStringConvertible {
/// Creates a new instance from the given string.
Expand Down Expand Up @@ -165,7 +165,7 @@ extension ${Self}: LosslessStringConvertible {
%if bits == 16:
self.init(Substring(text))
%else:
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { //SwiftStdlib 5.3
self.init(Substring(text))
} else {
self = 0.0
Expand Down Expand Up @@ -195,7 +195,7 @@ extension ${Self}: LosslessStringConvertible {
// In particular, we still have to export
// _swift_stdlib_strtoXYZ_clocale()
// as ABI to support old compiled code that still requires it.
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
public init?(_ text: Substring) {
self = 0.0
let success = withUnsafeMutablePointer(to: &self) { p -> Bool in
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/FloatingPointTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RawSignificand = 'UInt' + str(SignificandSize)

def Availability(bits):
if bits == 16:
return '@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)'
return '@available(SwiftStdlib 5.3, *)'
return ''

if Self == 'Float16':
Expand Down Expand Up @@ -1366,7 +1366,7 @@ internal struct _${Self}AnyHashableBox: _AnyHashableBox {
${SelfDocComment}
@frozen
% if bits == 16:
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
@available(SwiftStdlib 5.3, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
% else:
Expand All @@ -1385,7 +1385,7 @@ public struct ${Self} {
// from the implicit conformance emitted into the generated .swiftinterface
// file. See https://github.com/apple/swift/pull/36669 for details.
// FIXME: rdar://76092800
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
@available(SwiftStdlib 5.3, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
extension ${Self}: Sendable { }
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Identifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/// `ObjectIdentifier`), which is only guaranteed to remain unique for the
/// lifetime of an object. If an object has a stronger notion of identity, it
/// may be appropriate to provide a custom implementation.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
public protocol Identifiable {

/// A type representing the stable identity of the entity associated with
Expand All @@ -49,7 +49,7 @@ public protocol Identifiable {
var id: ID { get }
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(SwiftStdlib 5.1, *)
extension Identifiable where Self: AnyObject {
public var id: ObjectIdentifier {
return ObjectIdentifier(self)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/IntegerTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ public struct ${Self}
/// `source` must be representable in this type after rounding toward
/// zero.
% if FloatType == 'Float16':
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
% end
@_transparent
public init(_ source: ${FloatType}) {
Expand Down Expand Up @@ -1193,7 +1193,7 @@ public struct ${Self}
///
/// - Parameter source: A floating-point value to convert to an integer.
% if FloatType == 'Float16':
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
% end
@_transparent
public init?(exactly source: ${FloatType}) {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func _typeName(_ type: Any.Type, qualified: Bool = true) -> String {
UnsafeBufferPointer(start: stringPtr, count: count)).0
}

@available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
@_silgen_name("swift_getMangledTypeName")
public func _getMangledTypeName(_ type: Any.Type)
-> (UnsafePointer<UInt8>, Int)

/// Returns the mangled name for a given type.
@available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@available(SwiftStdlib 5.3, *)
public // SPI
func _mangledTypeName(_ type: Any.Type) -> String? {
let (stringPtr, count) = _getMangledTypeName(type)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Policy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ extension Never: Error {}

extension Never: Equatable, Comparable, Hashable {}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(SwiftStdlib 5.5, *)
extension Never: Identifiable {
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(SwiftStdlib 5.5, *)
public var id: Never {
switch self {}
}
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/ReflectionMirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extension Mirror {
}

/// Options for calling `_forEachField(of:options:body:)`.
@available(macOS 10.15.4, iOS 13.4, tvOS 13.4, watchOS 6.2, *)
@available(SwiftStdlib 5.2, *)
@_spi(Reflection)
public struct _EachFieldOptions: OptionSet {
public var rawValue: UInt32
Expand All @@ -211,7 +211,7 @@ public struct _EachFieldOptions: OptionSet {
}

/// The metadata "kind" for a type.
@available(macOS 10.15.4, iOS 13.4, tvOS 13.4, watchOS 6.2, *)
@available(SwiftStdlib 5.2, *)
@_spi(Reflection)
public enum _MetadataKind: UInt {
// With "flags":
Expand Down Expand Up @@ -259,7 +259,7 @@ public enum _MetadataKind: UInt {
/// and the `_MetadataKind` of the field's type.
/// - Returns: `true` if every invocation of `body` returns `true`; otherwise,
/// `false`.
@available(macOS 10.15.4, iOS 13.4, tvOS 13.4, watchOS 6.2, *)
@available(SwiftStdlib 5.2, *)
@discardableResult
@_spi(Reflection)
public func _forEachField(
Expand Down Expand Up @@ -302,7 +302,7 @@ public func _forEachField(
/// and the `_MetadataKind` of the field's type.
/// - Returns: `true` if every invocation of `body` returns `true`; otherwise,
/// `false`.
@available(macOS 11.3, iOS 14.5, tvOS 14.5, watchOS 7.4, *)
@available(SwiftStdlib 5.4, *)
@discardableResult
@_spi(Reflection)
public func _forEachFieldWithKeyPath<Root>(
Expand Down
Loading