-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Annotate Foundation overlay with __shared/__owned #19143
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl | |
} | ||
} | ||
|
||
mutating func append(contentsOf other: [Int]) { | ||
mutating func append(contentsOf other: __owned [Int]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this probably isn't necessary since it's just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, Array of Int is not a trivial type, i.e. involves reference counting of the array buffer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but IndexPath doesn't gain anything by taking the array owned, since it's not going to be able to use that buffer for storage, and the type isn't generic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, assuming that the case where self is empty and size of other > 2 is not the common case, it's better to pass other as guaranteed. |
||
switch self { | ||
case .empty: | ||
switch other.count { | ||
|
@@ -684,7 +684,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl | |
|
||
// MARK: - Bridging Helpers | ||
|
||
fileprivate init(nsIndexPath: ReferenceType) { | ||
fileprivate init(nsIndexPath: __shared ReferenceType) { | ||
let count = nsIndexPath.length | ||
if count == 0 { | ||
_indexes = [] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,7 +387,7 @@ fileprivate struct _JSONEncodingStorage { | |
return array | ||
} | ||
|
||
fileprivate mutating func push(container: NSObject) { | ||
fileprivate mutating func push(container: __owned NSObject) { | ||
self.containers.append(container) | ||
} | ||
|
||
|
@@ -961,7 +961,7 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder { | |
|
||
/// Initializes `self` by referencing the given dictionary container in the given encoder. | ||
fileprivate init(referencing encoder: _JSONEncoder, | ||
key: CodingKey, convertedKey: CodingKey, wrapping dictionary: NSMutableDictionary) { | ||
key: CodingKey, convertedKey: __shared CodingKey, wrapping dictionary: NSMutableDictionary) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why only the one parameter changed here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is not stored; all others are. Based on your comments, it sounds to me like I've misunderstood something critical here. Let me start an email thread so we can sort this out. |
||
self.encoder = encoder | ||
self.reference = .dictionary(dictionary, convertedKey.stringValue) | ||
super.init(options: encoder.options, codingPath: encoder.codingPath) | ||
|
@@ -1273,7 +1273,7 @@ fileprivate struct _JSONDecodingStorage { | |
return self.containers.last! | ||
} | ||
|
||
fileprivate mutating func push(container: Any) { | ||
fileprivate mutating func push(container: __owned Any) { | ||
self.containers.append(container) | ||
} | ||
|
||
|
@@ -1616,7 +1616,7 @@ fileprivate struct _JSONKeyedDecodingContainer<K : CodingKey> : KeyedDecodingCon | |
return _JSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array) | ||
} | ||
|
||
private func _superDecoder(forKey key: CodingKey) throws -> Decoder { | ||
private func _superDecoder(forKey key: __owned CodingKey) throws -> Decoder { | ||
self.decoder.codingPath.append(key) | ||
defer { self.decoder.codingPath.removeLast() } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be
owned
, no? Since you're immediately going to store it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it's not a public entry point anyway, so it doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_MutableHandle
makes a copy of the reference given to it so we never store the original — I've propagated__shared
out to everyinit(reference:)
which uses this, per @eeckstein's recommendation.