Skip to content

[Runtime] Reference ObjC class objects indirectly in conformance records #14646

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
Feb 15, 2018
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
3 changes: 3 additions & 0 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ class LinkEntity {
bool isForeignTypeMetadataCandidate() const {
return getKind() == Kind::ForeignTypeMetadataCandidate;
}
bool isObjCClassRef() const {
return getKind() == Kind::ObjCClassRef;
}

/// Determine whether this entity will be weak-imported.
bool isWeakImported(ModuleDecl *module) const {
Expand Down
5 changes: 4 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,9 @@ IRGenModule::getAddrOfLLVMVariableOrGOTEquivalent(LinkEntity entity,
auto foreignCandidate
= getAddrOfForeignTypeMetadataCandidate(entity.getType());
(void)foreignCandidate;
} else if (entity.isObjCClassRef()) {
(void)getAddrOfObjCClassRef(
const_cast<ClassDecl *>(cast<ClassDecl>(entity.getDecl())));
} else {
getAddrOfLLVMVariable(entity, alignment, ConstantInit(),
defaultType, DebugTypeInfo());
Expand Down Expand Up @@ -2442,7 +2445,7 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
typeKind = TypeMetadataRecordKind::IndirectObjCClass;
defaultTy = IGM.TypeMetadataPtrTy;
defaultPtrTy = IGM.TypeMetadataPtrTy;
entity = LinkEntity::forObjCClass(clas);
entity = LinkEntity::forObjCClassRef(clas);
} else {
// Conformances for generics and concrete subclasses of generics
// are represented by referencing the nominal type descriptor.
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/objc_bridged_generic_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// CHECK-NOT: _TMnCSo

// CHECK: @"$SSo6ThingyCyxG32objc_bridged_generic_conformance1PADMc" = hidden constant %swift.protocol_conformance_descriptor {{.*}} @"got.OBJC_CLASS_$_Thingy"
// CHECK: @"$SSo6ThingyCyxG32objc_bridged_generic_conformance1PADMc" = hidden constant %swift.protocol_conformance_descriptor {{.*}} @"OBJC_CLASS_REF_$_Thingy"

// CHECK-NOT: _TMnCSo

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/protocol_conformance_records_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension NSRect: Runcible {
// -- protocol descriptor
// CHECK-SAME: [[RUNCIBLE]]
// -- class object reference
// CHECK-SAME: @"got.OBJC_CLASS_$_Gizmo"
// CHECK-SAME: @"OBJC_CLASS_REF_$_Gizmo"
// -- witness table
// CHECK-SAME: @"$SSo5GizmoC33protocol_conformance_records_objc8RuncibleACWP"
// -- flags
Expand Down