Add wrappers around Builtin.isUnique.

The wrappers for the _native variants provide point-of-use sanity checking.
They also allows stdlib code to use regular (Bool) types.

These need to be fully generic to support class protocols. It also
avoids a massive amount of overloading for all the reference type
variations (AnyObject, Native, Unknown, Bridge) x 2 for optional
versions of each.

Because the wrapper is generic, type checking had to be deferred until
IRGen. Generating code for the wrapper itself will result in an
IRGen-time type error. They need to be transparent anyway for proper
diagnostics, but also must be internal.

The external API passes type checks because it forces conformance to AnyObject.

Swift SVN r27930
This commit is contained in:
Andrew Trick
2015-04-29 21:59:19 +00:00
parent 9ec8fe58ca
commit 09db0dda92
9 changed files with 111 additions and 73 deletions

View File

@@ -2703,12 +2703,12 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
internal mutating func isUniquelyReferenced() -> Bool {
if _fastPath(guaranteedNative) {
return Bool(Builtin.isUnique_native(&self))
return _isUnique_native(&self)
}
switch self {
case .Native:
return Bool(Builtin.isUnique_native(&self))
return _isUnique_native(&self)
case .Cocoa:
// Don't consider Cocoa storage mutable, even if it is mutable and is
// uniquely referenced.