[Accepted] SE-0125: Remove NonObjectiveCBase and isUniquelyReferenced


(Chris Lattner) #1

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0125-remove-nonobjectivecbase.md

The review of "SE-0125: Remove NonObjectiveCBase and isUniquelyReferenced" ran from Active review July 19...22. The proposal has been *accepted*.

This proposal had significant community feedback to help refine and improve its design, and Arnold has incorporated that into his v2 of the proposal. The core team agrees the new revision is a good design.

Thank you to Arnold Schwaighofer for driving this discussion forward!

-Chris Lattner
Review Manager


(Brent Royal-Gordon) #2

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0125-remove-nonobjectivecbase.md

The review of "SE-0125: Remove NonObjectiveCBase and isUniquelyReferenced" ran from Active review July 19...22. The proposal has been *accepted*.

This proposal had significant community feedback to help refine and improve its design, and Arnold has incorporated that into his v2 of the proposal. The core team agrees the new revision is a good design.

A minor quibble with the documentation in the revised version:

/// Returns `true` iff `object` is class instance with a single strong
/// reference.
///
/// * Does *not* modify `object`; the use of `inout` is an
/// implementation artifact.
/// * Weak references do not affect the result of this function.
///
/// Useful for implementing the copy-on-write optimization for the
/// deep storage of value types:
///
/// mutating func modifyMe(_ arg: X) {
/// if isKnownUniquelyReferenced(&myStorage) {
/// myStorage.modifyInPlace(arg)
/// }
/// else {
/// myStorage = self.createModified(myStorage, arg)
/// }
/// }
public func isKnownUniquelyReferenced<T : AnyObject>(_ object: inout T) -> Bool
public func isKnownUniquelyReferenced<T : AnyObject>(_ object: inout T?) -> Bool

Just to be crystal clear about its behavior, I would add a third bullet point to the list:

/// * Implementation limits may cause this function to always return
/// `false` for some objects, even if they actually are uniquely referenced.
/// It will never return `true` for an object with multiple strong references.

Or perhaps simply:

/// * This function may return false negatives, but never false positives.

ยทยทยท

On Jul 25, 2016, at 8:47 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:

--
Brent Royal-Gordon
Architechies