mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:
- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
Builtin.BridgeObject
Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
"ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
interfere with the reference identity of the resulting value. In other words,
it is undefined behavior unless:
castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref
This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
object pointer, "bits" must not have any non-spare bits set (unless they're
already set in the pointer value). The native discriminator bit may only be set
if the object is Swift-refcounted.
- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T
Extracts the reference from a BridgeObject.
- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word
Presents the bit pattern of a BridgeObject as a Word.
BridgeObject's bits are set up as follows on the various platforms:
i386, armv7:
No ObjC tagged pointers
Swift native refcounting flag bit: 0x0000_0001
Other available spare bits: 0x0000_0002
x86_64:
Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
Swift native refcounting flag bit: 0x0000_0000_0000_0002
Other available spare bits: 0x7F00_0000_0000_0004
arm64:
Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
Swift native refcounting flag bit: 0x4000_0000_0000_0000
Other available spare bits: 0x3F00_0000_0000_0007
TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.
Swift SVN r22880
This commit is contained in:
@@ -418,22 +418,14 @@ static bool typedAccessTBAAMayAlias(SILType LTy, SILType RTy, SILModule &Mod) {
|
||||
|
||||
ClassDecl *LTyClass = LTy.getClassOrBoundGenericClass();
|
||||
|
||||
// If RTy is a Builtin unknown object address type...
|
||||
if (RTy.is<BuiltinUnknownObjectType>()) {
|
||||
// And LTy is a swift class address type, they can not alias since swift
|
||||
// classes and objective-c classes are allocated differently.
|
||||
if (LTyClass)
|
||||
return false;
|
||||
|
||||
// Otherwise bail and assume that the two values can alias.
|
||||
// The Builtin reference types can alias any class instance.
|
||||
if (RTy.is<BuiltinUnknownObjectType>() && LTyClass)
|
||||
return true;
|
||||
}
|
||||
|
||||
// If RTy is a Builtin Native Object Type, since Builtin Native Object is the
|
||||
// root of the class hierarchy, it may alias any class.
|
||||
if (RTy.is<BuiltinNativeObjectType>() && LTyClass)
|
||||
return true;
|
||||
|
||||
if (RTy.is<BuiltinBridgeObjectType>() && LTyClass)
|
||||
return true;
|
||||
|
||||
// If one type is an aggregate and it contains the other type then the record
|
||||
// reference may alias the aggregate reference.
|
||||
if (LTy.aggregateContainsRecord(RTy, Mod) ||
|
||||
|
||||
Reference in New Issue
Block a user