Skip to content

Eliminate Builtin.UnknownObject as an AST type #27378

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

Merged
merged 1 commit into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Types
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
type ::= 'BI' // Builtin.IntLiteral
type ::= 'BO' // Builtin.UnknownObject
type ::= 'BO' // Builtin.UnknownObject (no longer a distinct type, but still used for AnyObject)
type ::= 'Bo' // Builtin.NativeObject
type ::= 'Bp' // Builtin.RawPointer
type ::= 'Bt' // Builtin.SILToken
Expand Down
2 changes: 1 addition & 1 deletion docs/ARCOptimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ is_unique performs depends on the argument type:

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

- Bridged object types allow the dynamic object type check to be
bypassed based on the pointer encoding:
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ class ASTContext final {
const CanType TheAnyType; /// This is 'Any', the empty protocol composition
const CanType TheNativeObjectType; /// Builtin.NativeObject
const CanType TheBridgeObjectType; /// Builtin.BridgeObject
const CanType TheUnknownObjectType; /// Builtin.UnknownObject
const CanType TheRawPointerType; /// Builtin.RawPointer
const CanType TheUnsafeValueBufferType; /// Builtin.UnsafeValueBuffer
const CanType TheSILTokenType; /// Builtin.SILToken
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class TypeMatcher {
TRIVIAL_CASE(BuiltinRawPointerType)
TRIVIAL_CASE(BuiltinNativeObjectType)
TRIVIAL_CASE(BuiltinBridgeObjectType)
TRIVIAL_CASE(BuiltinUnknownObjectType)
TRIVIAL_CASE(BuiltinUnsafeValueBufferType)
TRIVIAL_CASE(BuiltinVectorType)
TRIVIAL_CASE(SILTokenType)
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ ABSTRACT_TYPE(Builtin, Type)
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
BUILTIN_TYPE(BuiltinUnknownObject, BuiltinType)
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
BUILTIN_TYPE(BuiltinVector, BuiltinType)
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
Expand Down
13 changes: 0 additions & 13 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1311,19 +1311,6 @@ class BuiltinBridgeObjectType : public BuiltinType {
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinBridgeObjectType, BuiltinType);

/// BuiltinUnknownObjectType - The builtin opaque Objective-C pointer type.
/// Useful for pushing an Objective-C type through swift.
class BuiltinUnknownObjectType : public BuiltinType {
friend class ASTContext;
BuiltinUnknownObjectType(const ASTContext &C)
: BuiltinType(TypeKind::BuiltinUnknownObject, C) {}
public:
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::BuiltinUnknownObject;
}
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinUnknownObjectType, BuiltinType);

/// BuiltinUnsafeValueBufferType - The builtin opaque fixed-size value
/// buffer type, into which storage for an arbitrary value can be
/// allocated using Builtin.allocateValueBuffer.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ class ReflectionContext
// Class existentials have trivial layout.
// It is itself the pointer to the instance followed by the witness tables.
case RecordKind::ClassExistential:
// This is just Builtin.UnknownObject
// This is just AnyObject.
*OutInstanceTR = ExistentialRecordTI->getFields()[0].TR;
*OutInstanceAddress = ExistentialAddress;
return true;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Runtime/BuiltinTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ BUILTIN_POINTER_TYPE(Bb, "Builtin.BridgeObject")
BUILTIN_POINTER_TYPE(Bp, "Builtin.RawPointer")
BUILTIN_TYPE(BB, "Builtin.UnsafeValueBuffer")

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

// Int8 vector types
Expand Down
2 changes: 0 additions & 2 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ class SILType {

/// Get the NativeObject type as a SILType.
static SILType getNativeObjectType(const ASTContext &C);
/// Get the UnknownObject type as a SILType.
static SILType getUnknownObjectType(const ASTContext &C);
/// Get the BridgeObject type as a SILType.
static SILType getBridgeObjectType(const ASTContext &C);
/// Get the RawPointer type as a SILType.
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWPOINTER = {
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
{"Builtin.UnsafeValueBuffer"};
/// The name of the Builtin type for UnknownObject
///
/// This no longer exists as an AST-accessible type, but it's still used for 
/// fields shaped like AnyObject when ObjC interop is enabled.
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNKNOWNOBJECT = {
"Builtin.UnknownObject"};
/// The name of the Builtin type for Vector
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ ASTContext::ASTContext(LangOptions &langOpts, SearchPathOptions &SearchPathOpts,
BuiltinNativeObjectType(*this)),
TheBridgeObjectType(new (*this, AllocationArena::Permanent)
BuiltinBridgeObjectType(*this)),
TheUnknownObjectType(new (*this, AllocationArena::Permanent)
BuiltinUnknownObjectType(*this)),
TheRawPointerType(new (*this, AllocationArena::Permanent)
BuiltinRawPointerType(*this)),
TheUnsafeValueBufferType(new (*this, AllocationArena::Permanent)
Expand Down
1 change: 0 additions & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3373,7 +3373,6 @@ namespace {
TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)
TRIVIAL_TYPE_PRINTER(BuiltinBridgeObject, builtin_bridge_object)
TRIVIAL_TYPE_PRINTER(BuiltinUnknownObject, builtin_unknown_object)
TRIVIAL_TYPE_PRINTER(BuiltinUnsafeValueBuffer, builtin_unsafe_value_buffer)
TRIVIAL_TYPE_PRINTER(SILToken, sil_token)

Expand Down
2 changes: 0 additions & 2 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,6 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
return appendOperator("Bo");
case TypeKind::BuiltinBridgeObject:
return appendOperator("Bb");
case TypeKind::BuiltinUnknownObject:
return appendOperator("BO");
case TypeKind::BuiltinUnsafeValueBuffer:
return appendOperator("BB");
case TypeKind::SILToken:
Expand Down
1 change: 0 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3601,7 +3601,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
}
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawPointerType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNativeObjectType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnknownObjectType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinBridgeObjectType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnsafeValueBufferType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinIntegerLiteralType)
Expand Down
5 changes: 0 additions & 5 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
return Context.TheRawPointerType;
if (Name == "NativeObject")
return Context.TheNativeObjectType;
if (Name == "UnknownObject")
return Context.TheUnknownObjectType;
if (Name == "BridgeObject")
return Context.TheBridgeObjectType;
if (Name == "SILToken")
Expand Down Expand Up @@ -2100,9 +2098,6 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
case BuiltinTypeKind::BuiltinNativeObject:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_NATIVEOBJECT);
break;
case BuiltinTypeKind::BuiltinUnknownObject:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_UNKNOWNOBJECT);
break;
case BuiltinTypeKind::BuiltinBridgeObject:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_BRIDGEOBJECT);
break;
Expand Down
4 changes: 0 additions & 4 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ bool CanType::isReferenceTypeImpl(CanType type, GenericSignature *sig,
llvm_unreachable("sugared canonical type?");

// These types are always class references.
case TypeKind::BuiltinUnknownObject:
case TypeKind::BuiltinNativeObject:
case TypeKind::BuiltinBridgeObject:
case TypeKind::Class:
Expand Down Expand Up @@ -4348,9 +4347,6 @@ ReferenceCounting TypeBase::getReferenceCounting() {
case TypeKind::BuiltinBridgeObject:
return ReferenceCounting::Bridge;

case TypeKind::BuiltinUnknownObject:
return ReferenceCounting::Unknown;

case TypeKind::Class:
return getClassReferenceCounting(cast<ClassType>(type)->getDecl());
case TypeKind::BoundGenericClass:
Expand Down
8 changes: 0 additions & 8 deletions lib/IRGen/GenClangType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ class GenClangType : public CanTypeVisitor<GenClangType, clang::CanQualType> {
clang::CanQualType visitBuiltinRawPointerType(CanBuiltinRawPointerType type);
clang::CanQualType visitBuiltinIntegerType(CanBuiltinIntegerType type);
clang::CanQualType visitBuiltinFloatType(CanBuiltinFloatType type);
clang::CanQualType visitBuiltinUnknownObjectType(
CanBuiltinUnknownObjectType type);
clang::CanQualType visitArchetypeType(CanArchetypeType type);
clang::CanQualType visitSILFunctionType(CanSILFunctionType type);
clang::CanQualType visitGenericTypeParamType(CanGenericTypeParamType type);
Expand Down Expand Up @@ -703,12 +701,6 @@ clang::CanQualType GenClangType::visitBuiltinFloatType(
llvm_unreachable("cannot translate floating-point format to C");
}

clang::CanQualType GenClangType::visitBuiltinUnknownObjectType(
CanBuiltinUnknownObjectType type) {
// Builtin.UnknownObject == AnyObject, so it is also translated to 'id'.
return getClangIdType(getClangASTContext());
}

clang::CanQualType GenClangType::visitArchetypeType(CanArchetypeType type) {
// We see these in the case where we invoke an @objc function
// through a protocol.
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ namespace {
case ClassMetadataStrategy::Fixed: {
// FIXME: Should this check HasImported instead?
auto type = (Target->checkAncestry(AncestryFlags::ObjC)
? IGM.Context.TheUnknownObjectType
? IGM.Context.getAnyObjectType()
: IGM.Context.TheNativeObjectType);
auto wtable = IGM.getAddrOfValueWitnessTable(type);
B.add(wtable);
Expand Down Expand Up @@ -4011,7 +4011,7 @@ namespace {
// Without Objective-C interop, foreign classes must still use
// Swift native reference counting.
auto type = (IGM.ObjCInterop
? IGM.Context.TheUnknownObjectType
? IGM.Context.getAnyObjectType()
: IGM.Context.TheNativeObjectType);
auto wtable = IGM.getAddrOfValueWitnessTable(type);
B.add(wtable);
Expand Down
5 changes: 3 additions & 2 deletions lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,16 @@ llvm::Value *irgen::emitObjCAutoreleaseReturnValue(IRGenFunction &IGF,
}

namespace {
/// A type-info implementation suitable for Builtin.UnknownObject.
/// A type-info implementation suitable for AnyObject on platforms with ObjC
/// interop.
class UnknownTypeInfo : public HeapTypeInfo<UnknownTypeInfo> {
public:
UnknownTypeInfo(llvm::PointerType *storageType, Size size,
SpareBitVector spareBits, Alignment align)
: HeapTypeInfo(storageType, size, spareBits, align) {
}

/// Builtin.UnknownObject requires ObjC reference-counting.
/// AnyObject requires ObjC reference-counting.
ReferenceCounting getReferenceCounting() const {
return ReferenceCounting::Unknown;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,14 @@ class FixedTypeMetadataBuilder : public ReflectionMetadataBuilder {
}

void layout() override {
addTypeRef(type, CanGenericSignature());
if (type->isAnyObject()) {
// AnyObject isn't actually a builtin type; we're emitting it as the old
// Builtin.UnknownObject type for ABI compatibility.
B.addRelativeAddress(
IGM.getAddrOfStringForTypeRef("BO", MangledTypeRefRole::Reflection));
} else {
addTypeRef(type, CanGenericSignature());
}

B.addInt32(ti->getFixedSize().getValue());

Expand Down Expand Up @@ -1251,7 +1258,7 @@ emitAssociatedTypeMetadataRecord(const RootProtocolConformance *conformance) {
void IRGenModule::emitBuiltinReflectionMetadata() {
if (getSwiftModule()->isStdlibModule()) {
BuiltinTypes.insert(Context.TheNativeObjectType);
BuiltinTypes.insert(Context.TheUnknownObjectType);
BuiltinTypes.insert(Context.getAnyObjectType());
BuiltinTypes.insert(Context.TheBridgeObjectType);
BuiltinTypes.insert(Context.TheRawPointerType);
BuiltinTypes.insert(Context.TheUnsafeValueBufferType);
Expand Down
2 changes: 0 additions & 2 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,8 +1788,6 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
}
case TypeKind::BuiltinNativeObject:
return &getNativeObjectTypeInfo();
case TypeKind::BuiltinUnknownObject:
return &getUnknownObjectTypeInfo();
case TypeKind::BuiltinBridgeObject:
return &getBridgeObjectTypeInfo();
case TypeKind::BuiltinUnsafeValueBuffer:
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenValueWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ getAddrOfKnownValueWitnessTable(IRGenModule &IGM, CanType type,
case ReferenceCounting::ObjC:
case ReferenceCounting::Block:
case ReferenceCounting::Unknown:
witnessSurrogate = C.TheUnknownObjectType;
witnessSurrogate = C.getAnyObjectType();
break;
case ReferenceCounting::Bridge:
witnessSurrogate = C.TheBridgeObjectType;
Expand Down
12 changes: 0 additions & 12 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,18 +1207,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
break;
}

case TypeKind::BuiltinUnknownObject: {
// The builtin opaque Objective-C pointer type. Useful for pushing
// an Objective-C type through swift.
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(0);
auto IdTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
MangledName, Scope, File, 0,
llvm::dwarf::DW_LANG_ObjC, 0, 0);
return DBuilder.createPointerType(IdTy, PtrSize, 0,
/* DWARFAddressSpace */ None,
MangledName);
}

case TypeKind::BuiltinNativeObject: {
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(0);
auto PTy =
Expand Down
23 changes: 21 additions & 2 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ class IRGenMangler : public Mangle::ASTMangler {
std::string mangleValueWitness(Type type, ValueWitness witness);

std::string mangleValueWitnessTable(Type type) {
return mangleTypeSymbol(type, "WV");
const char * const witnessTableOp = "WV";
if (type->isAnyObject()) {
// Special-case for AnyObject, whose witness table is under the old name
// Builtin.UnknownObject, even though we don't use that as a Type anymore.
beginMangling();
appendOperator("BO");
appendOperator(witnessTableOp);
return finalize();
}
return mangleTypeSymbol(type, witnessTableOp);
}

std::string mangleTypeMetadataAccessFunction(Type type) {
Expand Down Expand Up @@ -382,7 +391,17 @@ class IRGenMangler : public Mangle::ASTMangler {
}

std::string mangleReflectionBuiltinDescriptor(Type type) {
return mangleTypeSymbol(type, "MB");
const char * const reflectionDescriptorOp = "MB";
if (type->isAnyObject()) {
// Special-case for AnyObject, whose reflection descriptor is under the
// old name Builtin.UnknownObject, even though we don't use that as a Type
// anymore.
beginMangling();
appendOperator("BO");
appendOperator(reflectionDescriptorOp);
return finalize();
}
return mangleTypeSymbol(type, reflectionDescriptorOp);
}

std::string mangleReflectionFieldDescriptor(Type type) {
Expand Down
3 changes: 1 addition & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3913,8 +3913,7 @@ static bool hasReferenceSemantics(IRGenSILFunction &IGF,
return (objType->mayHaveSuperclass()
|| objType->isClassExistentialType()
|| objType->is<BuiltinNativeObjectType>()
|| objType->is<BuiltinBridgeObjectType>()
|| objType->is<BuiltinUnknownObjectType>());
|| objType->is<BuiltinBridgeObjectType>());
}

static llvm::Value *emitIsUnique(IRGenSILFunction &IGF, SILValue operand,
Expand Down
Loading