Skip to content

Commit ab75459

Browse files
committed
Remove aliases for @_objcImpl type metadata
1 parent 6f3e24a commit ab75459

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

include/swift/IRGen/Linking.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ class LinkEntity {
810810

811811
static LinkEntity forTypeMetadata(CanType concreteType,
812812
TypeMetadataAddress addr) {
813+
assert(!isObjCImplementation(concreteType));
813814
LinkEntity entity;
814815
entity.setForType(Kind::TypeMetadata, concreteType);
815816
entity.Data |= LINKENTITY_SET_FIELD(MetadataAddress, unsigned(addr));
@@ -872,12 +873,14 @@ class LinkEntity {
872873
}
873874

874875
static LinkEntity forNominalTypeDescriptor(NominalTypeDecl *decl) {
876+
assert(!isObjCImplementation(decl));
875877
LinkEntity entity;
876878
entity.setForDecl(Kind::NominalTypeDescriptor, decl);
877879
return entity;
878880
}
879881

880882
static LinkEntity forNominalTypeDescriptorRecord(NominalTypeDecl *decl) {
883+
assert(!isObjCImplementation(decl));
881884
LinkEntity entity;
882885
entity.setForDecl(Kind::NominalTypeDescriptorRecord, decl);
883886
return entity;
@@ -1553,6 +1556,16 @@ class LinkEntity {
15531556
bool isAlwaysSharedLinkage() const;
15541557
#undef LINKENTITY_GET_FIELD
15551558
#undef LINKENTITY_SET_FIELD
1559+
1560+
private:
1561+
static bool isObjCImplementation(NominalTypeDecl *NTD) {
1562+
if (NTD)
1563+
return !NTD->getObjCImplementationDecls().empty();
1564+
return false;
1565+
}
1566+
static bool isObjCImplementation(CanType ty) {
1567+
return isObjCImplementation(ty->getClassOrBoundGenericClass());
1568+
}
15561569
};
15571570

15581571
struct IRLinkage {

lib/IRGen/GenDecl.cpp

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4714,17 +4714,17 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
47144714
return cast<llvm::GlobalValue>(addr);
47154715
}
47164716

4717-
auto swiftEntity =
4717+
auto entity =
47184718
(isPrespecialized &&
47194719
!irgen::isCanonicalInitializableTypeMetadataStaticallyAddressable(
47204720
*this, concreteType))
47214721
? LinkEntity::forNoncanonicalSpecializedGenericTypeMetadata(
47224722
concreteType)
4723-
: LinkEntity::forTypeMetadata(concreteType,
4724-
TypeMetadataAddress::FullMetadata);
4725-
auto entity = isObjCImpl
4726-
? LinkEntity::forObjCClass(concreteType->getClassOrBoundGenericClass())
4727-
: swiftEntity;
4723+
: (isObjCImpl
4724+
? LinkEntity::forObjCClass(
4725+
concreteType->getClassOrBoundGenericClass())
4726+
: LinkEntity::forTypeMetadata(
4727+
concreteType, TypeMetadataAddress::FullMetadata));
47284728

47294729
auto DbgTy = DebugTypeInfo::getMetadata(MetatypeType::get(concreteType),
47304730
entity.getDefaultDeclarationType(*this)->getPointerTo(),
@@ -4757,19 +4757,14 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
47574757
if (!isObjCImpl)
47584758
addRuntimeResolvableType(nominal);
47594759

4760-
// Don't define the alias for foreign type metadata or prespecialized
4761-
// generic metadata, since neither is ABI.
4762-
if (requiresForeignTypeMetadata(nominal) || isPrespecialized)
4760+
// Don't define the alias for foreign type metadata, prespecialized
4761+
// generic metadata, or @_objcImplementation classes, since they're not ABI.
4762+
if (requiresForeignTypeMetadata(nominal) || isPrespecialized || isObjCImpl)
47634763
return var;
47644764

47654765
// Native Swift class metadata has a destructor before the address point.
47664766
if (isa<ClassDecl>(nominal)) {
47674767
adjustmentIndex = MetadataAdjustmentIndex::Class;
4768-
4769-
// But `@_objcImplementation` extensions have nothing at all!
4770-
if (!cast<ClassDecl>(nominal)->getObjCImplementationDecls().empty()) {
4771-
adjustmentIndex = MetadataAdjustmentIndex::None;
4772-
}
47734768
}
47744769
}
47754770

@@ -4781,17 +4776,9 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
47814776
addr = llvm::ConstantExpr::getBitCast(addr, TypeMetadataPtrTy);
47824777

47834778
// For concrete metadata, declare the alias to its address point.
4784-
// FIXME: Should probably skip all of this for @_objcImpl and just use the
4785-
// ObjC symbol instead.
47864779
auto directEntity = LinkEntity::forTypeMetadata(
47874780
concreteType, TypeMetadataAddress::AddressPoint);
4788-
auto directAlias = defineAlias(directEntity, addr);
4789-
4790-
if (!isObjCImpl)
4791-
return directAlias;
4792-
4793-
defineAlias(swiftEntity, directAlias);
4794-
return var;
4781+
return defineAlias(directEntity, addr);
47954782
}
47964783

47974784
/// Fetch the declaration of the (possibly uninitialized) metadata for a type.

lib/TBDGen/TBDGen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,14 @@ void TBDGenVisitor::visitSubscriptDecl(SubscriptDecl *SD) {
870870
void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) {
871871
auto declaredType = NTD->getDeclaredType()->getCanonicalType();
872872

873-
addSymbol(LinkEntity::forNominalTypeDescriptor(NTD));
873+
if (NTD->getObjCImplementationDecls().empty()) {
874+
addSymbol(LinkEntity::forNominalTypeDescriptor(NTD));
874875

875-
// Generic types do not get metadata directly, only through the function.
876-
if (!NTD->isGenericContext()) {
877-
addSymbol(LinkEntity::forTypeMetadata(declaredType,
878-
TypeMetadataAddress::AddressPoint));
876+
// Generic types do not get metadata directly, only through the function.
877+
if (!NTD->isGenericContext()) {
878+
addSymbol(LinkEntity::forTypeMetadata(declaredType,
879+
TypeMetadataAddress::AddressPoint));
880+
}
879881
}
880882
addSymbol(LinkEntity::forTypeMetadataAccessFunction(declaredType));
881883

test/IRGen/objc_implementation.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
// CHECK: @"objc_classes_OBJC_CLASS_$_ImplClass" = internal global i8* bitcast (<{ i64, %objc_class*, %swift.opaque*, %swift.opaque*, { i32, i32, i32, i32, i8*, i8*, { i32, i32, [1 x { i8*, i8*, i8* }] }*, i8*, i8*, i8*, i8* }* }>* @"OBJC_CLASS_$_ImplClass" to i8*), section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
3636
// CHECK: @objc_categories = internal global [1 x i8*] [i8* bitcast ({ i8*, %objc_class*, { i32, i32, [1 x { i8*, i8*, i8* }] }*, i8*, i8*, i8*, i8*, i32 }* [[_CATEGORY_ImplClass_Category1]] to i8*)], section "__DATA,__objc_catlist,regular,no_dead_strip", align 8
3737

38-
// CHECK: @"$sSo9ImplClassCN" = alias %swift.type, bitcast (<{ i64, %objc_class*, %swift.opaque*, %swift.opaque*, { i32, i32, i32, i32, i8*, i8*, { i32, i32, [1 x { i8*, i8*, i8* }] }*, i8*, i8*, i8*, i8* }* }>* @"OBJC_CLASS_$_ImplClass" to %swift.type*)
39-
// CHECK: @"$sSo9ImplClassCMf" = internal alias %swift.type, %swift.type* @"$sSo9ImplClassCN"
40-
// FIXME: Remove these instead of using aliases?
41-
4238
// CHECK: define internal void @"$sSo9ImplClassC19objc_implementationE10mainMethodyys5Int32VFTo"
4339
// CHECK: define internal void @"$sSo9ImplClassC19objc_implementationE15category1Methodyys5Int32VFTo"
4440

@@ -47,3 +43,5 @@
4743
// NEGATIVE-NOT: OBJC_CLASS_$_ImplClass.{{[0-9]}}
4844
// NEGATIVE-NOT: $sSo9ImplClassCMn
4945
// NEGATIVE-NOT: $sSo9ImplClassCHn
46+
// NEGATIVE-NOT: $sSo9ImplClassCN
47+
// NEGATIVE-NOT: $sSo9ImplClassCMf

0 commit comments

Comments
 (0)