Skip to content

Commit 87d73e9

Browse files
committed
Merge pull request #2708 from jckarter/bridging-objc-generic-containers
AST/SILGen: Consider bridgeable value types to be bridgeable when bound to generic parameters.
2 parents 2795cc9 + f6723c3 commit 87d73e9

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,10 @@ getForeignRepresentable(Type type, ForeignLanguage language,
21082108
nullptr };
21092109
}
21102110

2111+
// In Objective-C, type parameters are always objects.
2112+
if (type->isTypeParameter() && language == ForeignLanguage::ObjectiveC)
2113+
return { ForeignRepresentableKind::Object, nullptr };
2114+
21112115
auto nominal = type->getAnyNominal();
21122116
if (!nominal)
21132117
return failure();

lib/SILGen/SILGenBridging.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,6 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
10401040
};
10411041

10421042
{
1043-
GenericContextScope genericScope(SGM.Types,
1044-
foreignFnTy->getGenericSignature());
1045-
10461043
for (unsigned nativeParamIndex : indices(params)) {
10471044
// Bring the parameter to +1.
10481045
auto paramValue = params[nativeParamIndex];

test/IRGen/objc_generic_class_metadata.sil

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ entry(%0: $ImplicitlyUnwrappedOptional<NSString>, %1: $Subclass):
6161
unreachable
6262
}
6363

64+
sil @_TToFC27objc_generic_class_metadata8SubclasscfT13arrayOfThingsGSaCSo8NSString__GSQS0__ : $@convention(objc_method) (NSArray, @owned Subclass) -> @owned ImplicitlyUnwrappedOptional<Subclass> {
65+
entry(%0: $NSArray, %1: $Subclass):
66+
unreachable
67+
}
68+
6469
sil @_TToFC27objc_generic_class_metadata8SubclasscfT_S0_ : $@convention(objc_method) (@owned Subclass) -> @owned Subclass {
6570
entry(%0: $Subclass):
6671
unreachable

test/Inputs/clang-importer-sdk/usr/include/objc_generics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
@interface GenericClass<T> : NSObject
44
- (id)initWithThing:(T)thing;
5+
- (id)initWithArrayOfThings:(NSArray<T> *__nonnull)things;
56
- (void)dealloc;
67
- (__nullable T)thing;
78
- (int)count;
89
+ (__nullable T)classThing;
910
- (__nonnull NSArray<T> *)arrayOfThings;
11+
- (void)setArrayOfThings:(NSArray<T> *__nonnull)things;
1012

1113
- (T __nonnull)objectAtIndexedSubscript:(uint16_t)i;
1214
- (void)setObject:(T __nonnull)object atIndexedSubscript:(uint16_t)i;
1315

1416
@property (nonatomic) __nullable T propertyThing;
17+
@property (nonatomic) __nullable NSArray<T> *propertyArrayOfThings;
1518
@end
1619

1720
@interface GenericClass<T> (Private)

test/SILGen/objc_imported_generic.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,18 @@ public func genericPropertyOnAnyObject(o: AnyObject, b: Bool) -> AnyObject?? {
4040
// CHECK-LABEL: sil @_TF21objc_imported_generic26genericPropertyOnAnyObject
4141
// CHECK: dynamic_method_br %4 : $@opened([[TAG:.*]]) AnyObject, #GenericClass.propertyThing!getter.1.foreign, bb1
4242
// CHECK: bb1({{%.*}} : $@convention(objc_method) (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
43+
44+
// CHECK-LABEL: sil @_TF21objc_imported_generic20arraysOfGenericParam
45+
public func arraysOfGenericParam<T: AnyObject>(y: Array<T>) {
46+
// CHECK: function_ref {{@_TFCSo12GenericClassCfT13arrayOfThings.*}} : $@convention(method) <τ_0_0 where τ_0_0 : AnyObject> (@owned Array<τ_0_0>, @thick GenericClass<τ_0_0>.Type) -> @owned ImplicitlyUnwrappedOptional<GenericClass<τ_0_0>>
47+
let x = GenericClass<T>(arrayOfThings: y)!
48+
// CHECK: class_method [volatile] {{%.*}} : $GenericClass<T>, #GenericClass.setArrayOfThings!1.foreign {{.*}}, $@convention(objc_method) <τ_0_0 where τ_0_0 : AnyObject> (NSArray, GenericClass<τ_0_0>) -> ()
49+
x.setArrayOfThings(y)
50+
// CHECK: class_method [volatile] {{%.*}} : $GenericClass<T>, #GenericClass.propertyArrayOfThings!getter.1.foreign {{.*}}, $@convention(objc_method) <τ_0_0 where τ_0_0 : AnyObject> (GenericClass<τ_0_0>) -> @autoreleased Optional<NSArray>
51+
_ = x.propertyArrayOfThings
52+
// CHECK: class_method [volatile] {{%.*}} : $GenericClass<T>, #GenericClass.propertyArrayOfThings!setter.1.foreign {{.*}}, $@convention(objc_method) <τ_0_0 where τ_0_0 : AnyObject> (Optional<NSArray>, GenericClass<τ_0_0>) -> ()
53+
x.propertyArrayOfThings = y
54+
}
55+
56+
// CHECK-LABEL: sil shared [thunk] @_TTOFCSo12GenericClasscfT13arrayOfThings
57+
// CHECK: class_method [volatile] {{%.*}} : $GenericClass<T>, #GenericClass.init!initializer.1.foreign {{.*}}, $@convention(objc_method) <τ_0_0 where τ_0_0 : AnyObject> (NSArray, @owned GenericClass<τ_0_0>) -> @owned ImplicitlyUnwrappedOptional<GenericClass<τ_0_0>>

0 commit comments

Comments
 (0)