Skip to content

Commit a28c9d6

Browse files
authored
Merge pull request #19143 from itaiferber/foundation-overlay-owned-annotations
Annotate Foundation overlay with __shared/__owned
2 parents c88d4e4 + 832317c commit a28c9d6

29 files changed

+127
-127
lines changed

stdlib/public/SDK/Foundation/AffineTransform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct AffineTransform : ReferenceConvertible, Hashable, CustomStringConv
3333
self.tY = tY
3434
}
3535

36-
fileprivate init(reference: NSAffineTransform) {
36+
fileprivate init(reference: __shared NSAffineTransform) {
3737
m11 = reference.transformStruct.m11
3838
m12 = reference.transformStruct.m12
3939
m21 = reference.transformStruct.m21

stdlib/public/SDK/Foundation/Boxing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal final class _MutableHandle<MutableType : NSObject>
1919
where MutableType : NSCopying {
2020
fileprivate var _pointer : MutableType
2121

22-
init(reference : MutableType) {
22+
init(reference : __shared MutableType) {
2323
_pointer = reference.copy() as! MutableType
2424
}
2525

stdlib/public/SDK/Foundation/Calendar.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
9797
/// Returns a new Calendar.
9898
///
9999
/// - parameter identifier: The kind of calendar to use.
100-
public init(identifier: Identifier) {
100+
public init(identifier: __shared Identifier) {
101101
let result = __NSCalendarCreate(Calendar._toNSCalendarIdentifier(identifier))
102102
_handle = _MutableHandle(adoptingReference: result as! NSCalendar)
103103
_autoupdating = false
@@ -106,7 +106,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
106106
// MARK: -
107107
// MARK: Bridging
108108

109-
fileprivate init(reference : NSCalendar) {
109+
fileprivate init(reference : __shared NSCalendar) {
110110
_handle = _MutableHandle(reference: reference)
111111
if __NSCalendarIsAutoupdating(reference) {
112112
_autoupdating = true

stdlib/public/SDK/Foundation/CharacterSet.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,23 +390,23 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
390390
/// Initialize with the characters in the given string.
391391
///
392392
/// - parameter string: The string content to inspect for characters.
393-
public init(charactersIn string: String) {
393+
public init(charactersIn string: __shared String) {
394394
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInString(nil, string as CFString))
395395
}
396396

397397
/// Initialize with a bitmap representation.
398398
///
399399
/// This method is useful for creating a character set object with data from a file or other external data source.
400400
/// - parameter data: The bitmap representation.
401-
public init(bitmapRepresentation data: Data) {
401+
public init(bitmapRepresentation data: __shared Data) {
402402
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
403403
}
404404

405405
/// Initialize with the contents of a file.
406406
///
407407
/// Returns `nil` if there was an error reading the file.
408408
/// - parameter file: The file to read.
409-
public init?(contentsOfFile file: String) {
409+
public init?(contentsOfFile file: __shared String) {
410410
do {
411411
let data = try Data(contentsOf: URL(fileURLWithPath: file), options: .mappedIfSafe)
412412
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
@@ -415,7 +415,7 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
415415
}
416416
}
417417

418-
fileprivate init(_bridged characterSet: NSCharacterSet) {
418+
fileprivate init(_bridged characterSet: __shared NSCharacterSet) {
419419
_storage = _CharacterSetStorage(immutableReference: characterSet.copy() as! CFCharacterSet)
420420
}
421421

@@ -427,7 +427,7 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
427427
_storage = _uncopiedStorage
428428
}
429429

430-
fileprivate init(_builtIn: CFCharacterSetPredefinedSet) {
430+
fileprivate init(_builtIn: __shared CFCharacterSetPredefinedSet) {
431431
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetGetPredefined(_builtIn))
432432
}
433433

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
11781178
/// - parameter url: The `URL` to read.
11791179
/// - parameter options: Options for the read operation. Default value is `[]`.
11801180
/// - throws: An error in the Cocoa domain, if `url` cannot be read.
1181-
public init(contentsOf url: URL, options: Data.ReadingOptions = []) throws {
1181+
public init(contentsOf url: __shared URL, options: Data.ReadingOptions = []) throws {
11821182
let d = try NSData(contentsOf: url, options: ReadingOptions(rawValue: options.rawValue))
11831183
_backing = _DataStorage(immutableReference: d, offset: 0)
11841184
_sliceRange = 0..<d.length
@@ -1189,7 +1189,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
11891189
/// Returns nil when the input is not recognized as valid Base-64.
11901190
/// - parameter base64String: The string to parse.
11911191
/// - parameter options: Encoding options. Default value is `[]`.
1192-
public init?(base64Encoded base64String: String, options: Data.Base64DecodingOptions = []) {
1192+
public init?(base64Encoded base64String: __shared String, options: Data.Base64DecodingOptions = []) {
11931193
if let d = NSData(base64Encoded: base64String, options: Base64DecodingOptions(rawValue: options.rawValue)) {
11941194
_backing = _DataStorage(immutableReference: d, offset: 0)
11951195
_sliceRange = 0..<d.length
@@ -1204,7 +1204,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
12041204
///
12051205
/// - parameter base64Data: Base-64, UTF-8 encoded input data.
12061206
/// - parameter options: Decoding options. Default value is `[]`.
1207-
public init?(base64Encoded base64Data: Data, options: Data.Base64DecodingOptions = []) {
1207+
public init?(base64Encoded base64Data: __shared Data, options: Data.Base64DecodingOptions = []) {
12081208
if let d = NSData(base64Encoded: base64Data, options: Base64DecodingOptions(rawValue: options.rawValue)) {
12091209
_backing = _DataStorage(immutableReference: d, offset: 0)
12101210
_sliceRange = 0..<d.length
@@ -1220,7 +1220,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
12201220
/// If the resulting value is mutated, then `Data` will invoke the `mutableCopy()` function on the reference to copy the contents. You may customize the behavior of that function if you wish to return a specialized mutable subclass.
12211221
///
12221222
/// - parameter reference: The instance of `NSData` that you wish to wrap. This instance will be copied by `struct Data`.
1223-
public init(referencing reference: NSData) {
1223+
public init(referencing reference: __shared NSData) {
12241224
#if DEPLOYMENT_RUNTIME_SWIFT
12251225
let providesConcreteBacking = reference._providesConcreteBacking()
12261226
#else

stdlib/public/SDK/Foundation/DateComponents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
269269

270270
// MARK: - Bridging Helpers
271271

272-
fileprivate init(reference: NSDateComponents) {
272+
fileprivate init(reference: __shared NSDateComponents) {
273273
_handle = _MutableHandle(reference: reference)
274274
}
275275

stdlib/public/SDK/Foundation/Decimal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ extension Decimal {
452452
}
453453

454454
extension Decimal : CustomStringConvertible {
455-
public init?(string: String, locale: Locale? = nil) {
455+
public init?(string: __shared String, locale: __shared Locale? = nil) {
456456
let scan = Scanner(string: string)
457457
var theDecimal = Decimal()
458458
scan.locale = locale

stdlib/public/SDK/Foundation/IndexPath.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
156156
}
157157
}
158158

159-
mutating func append(contentsOf other: [Int]) {
159+
mutating func append(contentsOf other: __owned [Int]) {
160160
switch self {
161161
case .empty:
162162
switch other.count {
@@ -684,7 +684,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
684684

685685
// MARK: - Bridging Helpers
686686

687-
fileprivate init(nsIndexPath: ReferenceType) {
687+
fileprivate init(nsIndexPath: __shared ReferenceType) {
688688
let count = nsIndexPath.length
689689
if count == 0 {
690690
_indexes = []

stdlib/public/SDK/Foundation/IndexSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
661661
return _handle.reference
662662
}
663663

664-
fileprivate init(reference: NSIndexSet) {
664+
fileprivate init(reference: __shared NSIndexSet) {
665665
_handle = _MutablePairHandle(reference)
666666
}
667667
}

stdlib/public/SDK/Foundation/JSONEncoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fileprivate struct _JSONEncodingStorage {
387387
return array
388388
}
389389

390-
fileprivate mutating func push(container: NSObject) {
390+
fileprivate mutating func push(container: __owned NSObject) {
391391
self.containers.append(container)
392392
}
393393

@@ -961,7 +961,7 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder {
961961

962962
/// Initializes `self` by referencing the given dictionary container in the given encoder.
963963
fileprivate init(referencing encoder: _JSONEncoder,
964-
key: CodingKey, convertedKey: CodingKey, wrapping dictionary: NSMutableDictionary) {
964+
key: CodingKey, convertedKey: __shared CodingKey, wrapping dictionary: NSMutableDictionary) {
965965
self.encoder = encoder
966966
self.reference = .dictionary(dictionary, convertedKey.stringValue)
967967
super.init(options: encoder.options, codingPath: encoder.codingPath)
@@ -1273,7 +1273,7 @@ fileprivate struct _JSONDecodingStorage {
12731273
return self.containers.last!
12741274
}
12751275

1276-
fileprivate mutating func push(container: Any) {
1276+
fileprivate mutating func push(container: __owned Any) {
12771277
self.containers.append(container)
12781278
}
12791279

@@ -1616,7 +1616,7 @@ fileprivate struct _JSONKeyedDecodingContainer<K : CodingKey> : KeyedDecodingCon
16161616
return _JSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array)
16171617
}
16181618

1619-
private func _superDecoder(forKey key: CodingKey) throws -> Decoder {
1619+
private func _superDecoder(forKey key: __owned CodingKey) throws -> Decoder {
16201620
self.decoder.codingPath.append(key)
16211621
defer { self.decoder.codingPath.removeLast() }
16221622

stdlib/public/SDK/Foundation/Locale.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public struct Locale : Hashable, Equatable, ReferenceConvertible {
5252
_autoupdating = false
5353
}
5454

55-
fileprivate init(reference: NSLocale) {
55+
fileprivate init(reference: __shared NSLocale) {
5656
_wrapped = reference.copy() as! NSLocale
5757
if __NSLocaleIsAutoupdating(reference) {
5858
_autoupdating = true

stdlib/public/SDK/Foundation/NSArray.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Array : _ObjectiveCBridgeable {
3030
///
3131
/// The provided `NSArray` will be copied to ensure that the copy can
3232
/// not be mutated by other code.
33-
internal init(_cocoaArray: NSArray) {
33+
internal init(_cocoaArray: __shared NSArray) {
3434
assert(_isBridgedVerbatimToObjectiveC(Element.self),
3535
"Array can be backed by NSArray only when the element type can be bridged verbatim to Objective-C")
3636
// FIXME: We would like to call CFArrayCreateCopy() to avoid doing an
@@ -153,7 +153,7 @@ extension NSArray {
153153
/// Discussion: After an immutable array has been initialized in
154154
/// this way, it cannot be modified.
155155
@nonobjc
156-
public convenience init(array anArray: NSArray) {
156+
public convenience init(array anArray: __shared NSArray) {
157157
self.init(array: anArray as Array)
158158
}
159159
}

stdlib/public/SDK/Foundation/NSDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension Dictionary {
3434
///
3535
/// The provided `NSDictionary` will be copied to ensure that the copy can
3636
/// not be mutated by other code.
37-
public init(_cocoaDictionary: _NSDictionary) {
37+
public init(_cocoaDictionary: __shared _NSDictionary) {
3838
assert(
3939
_isBridgedVerbatimToObjectiveC(Key.self) &&
4040
_isBridgedVerbatimToObjectiveC(Value.self),
@@ -165,7 +165,7 @@ extension NSDictionary : Sequence {
165165
return nil
166166
}
167167

168-
internal init(_ _dict: NSDictionary) {
168+
internal init(_ _dict: __shared NSDictionary) {
169169
_fastIterator = NSFastEnumerationIterator(_dict)
170170
}
171171
}
@@ -219,7 +219,7 @@ extension NSDictionary {
219219
/// than the original receiver--containing the keys and values
220220
/// found in `otherDictionary`.
221221
@objc(_swiftInitWithDictionary_NSDictionary:)
222-
public convenience init(dictionary otherDictionary: NSDictionary) {
222+
public convenience init(dictionary otherDictionary: __shared NSDictionary) {
223223
// FIXME(performance)(compiler limitation): we actually want to do just
224224
// `self = otherDictionary.copy()`, but Swift does not have factory
225225
// initializers right now.

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ extension CFError : Error {
359359
public protocol _ObjectiveCBridgeableError : Error {
360360
/// Produce a value of the error type corresponding to the given NSError,
361361
/// or return nil if it cannot be bridged.
362-
init?(_bridgedNSError: NSError)
362+
init?(_bridgedNSError: __shared NSError)
363363
}
364364

365365
/// A hook for the runtime to use _ObjectiveCBridgeableError in order to
@@ -398,7 +398,7 @@ extension _BridgedNSError {
398398
extension _BridgedNSError where Self.RawValue: FixedWidthInteger {
399399
public var _code: Int { return Int(rawValue) }
400400

401-
public init?(_bridgedNSError: NSError) {
401+
public init?(_bridgedNSError: __shared NSError) {
402402
if _bridgedNSError.domain != Self._nsErrorDomain {
403403
return nil
404404
}

stdlib/public/SDK/Foundation/NSExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
extension NSExpression {
1616
// + (NSExpression *) expressionWithFormat:(NSString *)expressionFormat, ...;
1717
public
18-
convenience init(format expressionFormat: String, _ args: CVarArg...) {
18+
convenience init(format expressionFormat: __shared String, _ args: CVarArg...) {
1919
let va_args = getVaList(args)
2020
self.init(format: expressionFormat, arguments: va_args)
2121
}

0 commit comments

Comments
 (0)