Skip to content

Commit a6dd630

Browse files
authored
Eliminate Builtin.UnknownObject as an AST type (swiftlang#27378)
This removes it from the AST and largely replaces it with AnyObject at the SIL and IRGen layers. Some notes: - Reflection still uses the notion of "unknown object" to mean an object with unknown refcounting. There's no real reason to make this different from AnyObject (an existential containing a single object with unknown refcounting), but this way nothing changes for clients of Reflection, and it's consistent with how native objects are represented. - The value witness table and reflection descriptor for AnyObject use the mangling "BO" instead of "yXl". - The demangler and remangler continue to support "BO" because it's still in use as a type encoding, even if it's not an AST-level Type anymore. - Type-based alias analysis for Builtin.UnknownObject was incorrect, so it's a good thing we weren't using it. - Same with enum layout. (This one assumed UnknownObject never referred to an Objective-C tagged pointer. That certainly wasn't how we were using it!)
1 parent 777d557 commit a6dd630

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+208
-338
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Types
481481
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
482482
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
483483
type ::= 'BI' // Builtin.IntLiteral
484-
type ::= 'BO' // Builtin.UnknownObject
484+
type ::= 'BO' // Builtin.UnknownObject (no longer a distinct type, but still used for AnyObject)
485485
type ::= 'Bo' // Builtin.NativeObject
486486
type ::= 'Bp' // Builtin.RawPointer
487487
type ::= 'Bt' // Builtin.SILToken

docs/ARCOptimization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ is_unique performs depends on the argument type:
335335

336336
- Objective-C object types require an additional check that the
337337
dynamic object type uses native Swift reference counting:
338-
(Builtin.UnknownObject, unknown class reference, class existential)
338+
(unknown class reference, class existential)
339339

340340
- Bridged object types allow the dynamic object type check to be
341341
bypassed based on the pointer encoding:

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ class ASTContext final {
605605
const CanType TheAnyType; /// This is 'Any', the empty protocol composition
606606
const CanType TheNativeObjectType; /// Builtin.NativeObject
607607
const CanType TheBridgeObjectType; /// Builtin.BridgeObject
608-
const CanType TheUnknownObjectType; /// Builtin.UnknownObject
609608
const CanType TheRawPointerType; /// Builtin.RawPointer
610609
const CanType TheUnsafeValueBufferType; /// Builtin.UnsafeValueBuffer
611610
const CanType TheSILTokenType; /// Builtin.SILToken

include/swift/AST/TypeMatcher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class TypeMatcher {
107107
TRIVIAL_CASE(BuiltinRawPointerType)
108108
TRIVIAL_CASE(BuiltinNativeObjectType)
109109
TRIVIAL_CASE(BuiltinBridgeObjectType)
110-
TRIVIAL_CASE(BuiltinUnknownObjectType)
111110
TRIVIAL_CASE(BuiltinUnsafeValueBufferType)
112111
TRIVIAL_CASE(BuiltinVectorType)
113112
TRIVIAL_CASE(SILTokenType)

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ ABSTRACT_TYPE(Builtin, Type)
9898
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
9999
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
100100
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
101-
BUILTIN_TYPE(BuiltinUnknownObject, BuiltinType)
102101
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
103102
BUILTIN_TYPE(BuiltinVector, BuiltinType)
104103
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)

include/swift/AST/Types.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,19 +1311,6 @@ class BuiltinBridgeObjectType : public BuiltinType {
13111311
};
13121312
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinBridgeObjectType, BuiltinType);
13131313

1314-
/// BuiltinUnknownObjectType - The builtin opaque Objective-C pointer type.
1315-
/// Useful for pushing an Objective-C type through swift.
1316-
class BuiltinUnknownObjectType : public BuiltinType {
1317-
friend class ASTContext;
1318-
BuiltinUnknownObjectType(const ASTContext &C)
1319-
: BuiltinType(TypeKind::BuiltinUnknownObject, C) {}
1320-
public:
1321-
static bool classof(const TypeBase *T) {
1322-
return T->getKind() == TypeKind::BuiltinUnknownObject;
1323-
}
1324-
};
1325-
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinUnknownObjectType, BuiltinType);
1326-
13271314
/// BuiltinUnsafeValueBufferType - The builtin opaque fixed-size value
13281315
/// buffer type, into which storage for an arbitrary value can be
13291316
/// allocated using Builtin.allocateValueBuffer.

include/swift/Reflection/ReflectionContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class ReflectionContext
671671
// Class existentials have trivial layout.
672672
// It is itself the pointer to the instance followed by the witness tables.
673673
case RecordKind::ClassExistential:
674-
// This is just Builtin.UnknownObject
674+
// This is just AnyObject.
675675
*OutInstanceTR = ExistentialRecordTI->getFields()[0].TR;
676676
*OutInstanceAddress = ExistentialAddress;
677677
return true;

include/swift/Runtime/BuiltinTypes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ BUILTIN_POINTER_TYPE(Bb, "Builtin.BridgeObject")
5656
BUILTIN_POINTER_TYPE(Bp, "Builtin.RawPointer")
5757
BUILTIN_TYPE(BB, "Builtin.UnsafeValueBuffer")
5858

59+
// No longer used in the compiler as an AST type, but still used for fields 
60+
// shaped like AnyObject (normal mangling yXl).
5961
BUILTIN_POINTER_TYPE(BO, "Builtin.UnknownObject")
6062

6163
// Int8 vector types

include/swift/SIL/SILType.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ class SILType {
512512

513513
/// Get the NativeObject type as a SILType.
514514
static SILType getNativeObjectType(const ASTContext &C);
515-
/// Get the UnknownObject type as a SILType.
516-
static SILType getUnknownObjectType(const ASTContext &C);
517515
/// Get the BridgeObject type as a SILType.
518516
static SILType getBridgeObjectType(const ASTContext &C);
519517
/// Get the RawPointer type as a SILType.

include/swift/Strings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWPOINTER = {
106106
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
107107
{"Builtin.UnsafeValueBuffer"};
108108
/// The name of the Builtin type for UnknownObject
109+
///
110+
/// This no longer exists as an AST-accessible type, but it's still used for 
111+
/// fields shaped like AnyObject when ObjC interop is enabled.
109112
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNKNOWNOBJECT = {
110113
"Builtin.UnknownObject"};
111114
/// The name of the Builtin type for Vector

0 commit comments

Comments
 (0)