Skip to content

Commit d6bed34

Browse files
authored
Merge pull request #4356 from jckarter/generic-objc-conformance-3.0
[3.0] Fixes for generic ObjC classes conforming to Swift protocols.
2 parents 1fe3f9f + 9ae709d commit d6bed34

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
20002000

20012001
auto nom = conformingType->getAnyNominal();
20022002
auto clas = dyn_cast<ClassDecl>(nom);
2003-
if (nom->isGenericContext() ||
2003+
if ((nom->isGenericContext() && (!clas || !clas->usesObjCGenericsModel())) ||
20042004
(clas && doesClassMetadataRequireDynamicInitialization(IGM, clas))) {
20052005
// Conformances for generics and concrete subclasses of generics
20062006
// are represented by referencing the nominal type descriptor.
@@ -2152,7 +2152,7 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
21522152
LinkEntity::forProtocolDescriptor(conformance->getProtocol()),
21532153
getPointerAlignment(), ProtocolDescriptorStructTy);
21542154
auto typeEntity = getTypeEntityInfo(*this,
2155-
conformance->getType()->getCanonicalType());
2155+
conformance->getType()->getCanonicalType());
21562156
auto flags = typeEntity.flags
21572157
.withConformanceKind(ProtocolConformanceReferenceKind::WitnessTable);
21582158

lib/SILGen/SILGenBridging.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,9 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
957957
SGM.M, SGM.M.getSwiftModule(), subs);
958958
SILType substSILTy = SILType::getPrimitiveObjectType(substTy);
959959

960+
// Use the same context generic params as the native entry point.
961+
F.setContextGenericParams(nativeInfo.ContextGenericParams);
962+
960963
auto loc = thunk.getAsRegularLocation();
961964
loc.markAutoGenerated();
962965
Scope scope(Cleanups, CleanupLocation::get(loc));
@@ -1116,6 +1119,9 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
11161119
auto nativeFnTy = F.getLoweredFunctionType();
11171120
assert(nativeFnTy == nativeCI.SILFnType);
11181121

1122+
// Use the same context generic params as the native entry point.
1123+
F.setContextGenericParams(nativeCI.ContextGenericParams);
1124+
11191125
// Find the foreign error convention and 'self' parameter index.
11201126
Optional<ForeignErrorConvention> foreignError;
11211127
if (nativeFnTy->hasErrorResult()) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import Foundation;
2+
3+
@interface Thingy<T>: NSObject
4+
5+
@end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir %s -import-objc-header %S/Inputs/objc_bridged_generic_conformance.h | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
// CHECK-NOT: _TMnCSo
5+
6+
// CHECK: @"\01l_protocol_conformances" = {{.*}} @"got.OBJC_CLASS_$_Thingy"
7+
8+
// CHECK-NOT: _TMnCSo
9+
10+
protocol P { func test() }
11+
12+
extension Thingy: P {
13+
func test() {}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import Foundation;
2+
3+
@interface Thingy<T>: NSObject
4+
5+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen %s -import-objc-header %S/Inputs/objc_bridged_generic_conformance.h -verify
2+
// REQUIRES: objc_interop
3+
4+
protocol P { func test() }
5+
6+
extension Thingy: P {
7+
func test() {}
8+
}

0 commit comments

Comments
 (0)