Skip to content

Commit 8921811

Browse files
committed
[Sema/SILGen] Bridge Objective-C objects to Swift value types via _ObjectiveCBridgeable.
Extend the use of _ObjectiveCBridgeable._unconditionallyBridgeFromObjectiveC to all bridged types rather than using the custom entry points. Note that there is a lot of hackery around ensuring that the conformance is correct, because Sema needs to anticipate that SILGen (or later SIL passes) might need those conformances. This primarily affects the overlays, but with generalized bridging that means any mixed Objective-C/Swift framework with bridged types.
1 parent c40e683 commit 8921811

11 files changed

+114
-63
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,6 @@ emitBridgeObjectiveCToNative(SILGenFunction &gen,
177177
.getAsSingleValue(gen, loc);
178178
}
179179

180-
static ManagedValue emitBridgeCollectionToNative(SILGenFunction &gen,
181-
SILLocation loc,
182-
SILDeclRef bridgeFnRef,
183-
ManagedValue collection,
184-
SILType nativeTy) {
185-
SILValue bridgeFn = gen.emitGlobalFunctionRef(loc, bridgeFnRef);
186-
187-
auto collectionTy = nativeTy.getSwiftRValueType()->castTo<BoundGenericType>();
188-
auto subs = collectionTy->getSubstitutions(gen.SGM.M.getSwiftModule(),
189-
nullptr);
190-
auto substFnType = bridgeFn->getType().substGenericArgs(gen.SGM.M, subs);
191-
192-
Type inputType = collection.getType().getSwiftRValueType();
193-
if (!inputType->getOptionalObjectType()) {
194-
SILType loweredOptTy = gen.SGM.getLoweredType(OptionalType::get(inputType));
195-
auto *someDecl = gen.getASTContext().getOptionalSomeDecl();
196-
auto *enumInst = gen.B.createEnum(loc, collection.getValue(), someDecl,
197-
loweredOptTy);
198-
collection = ManagedValue(enumInst, collection.getCleanup());
199-
}
200-
201-
SILValue result = gen.B.createApply(loc, bridgeFn,
202-
substFnType,
203-
nativeTy,
204-
subs,
205-
{ collection.forward(gen) });
206-
207-
return gen.emitManagedRValueWithCleanup(result);
208-
}
209-
210180
static ManagedValue emitBridgeBoolToObjCBool(SILGenFunction &gen,
211181
SILLocation loc,
212182
ManagedValue swiftBool) {
@@ -665,7 +635,7 @@ static ManagedValue emitCBridgedToNativeValue(SILGenFunction &gen,
665635
auto conformance =
666636
gen.SGM.getConformanceToObjectiveCBridgeable(loc, loweredNativeTy);
667637
assert(conformance &&
668-
"Missing String conformation to _ObjectiveCBridgeable?");
638+
"Missing String conformance to _ObjectiveCBridgeable?");
669639
if (auto result = emitBridgeObjectiveCToNative(gen, loc, v, conformance))
670640
return *result;
671641

@@ -676,24 +646,42 @@ static ManagedValue emitCBridgedToNativeValue(SILGenFunction &gen,
676646
// Bridge NSArray to Array.
677647
if (auto arrayDecl = gen.getASTContext().getArrayDecl()) {
678648
if (nativeTy.getSwiftRValueType()->getAnyNominal() == arrayDecl) {
679-
SILDeclRef bridgeFn = gen.SGM.getNSArrayToArrayFn();
680-
return emitBridgeCollectionToNative(gen, loc, bridgeFn, v, nativeTy);
649+
auto conformance =
650+
gen.SGM.getConformanceToObjectiveCBridgeable(loc, loweredNativeTy);
651+
assert(conformance &&
652+
"Missing Array conformance to _ObjectiveCBridgeable?");
653+
if (auto result = emitBridgeObjectiveCToNative(gen, loc, v, conformance))
654+
return *result;
655+
656+
return gen.emitUndef(loc, nativeTy);
681657
}
682658
}
683659

684660
// Bridge NSDictionary to Dictionary.
685661
if (auto dictDecl = gen.getASTContext().getDictionaryDecl()) {
686662
if (nativeTy.getSwiftRValueType()->getAnyNominal() == dictDecl) {
687-
SILDeclRef bridgeFn = gen.SGM.getNSDictionaryToDictionaryFn();
688-
return emitBridgeCollectionToNative(gen, loc, bridgeFn, v, nativeTy);
663+
auto conformance =
664+
gen.SGM.getConformanceToObjectiveCBridgeable(loc, loweredNativeTy);
665+
assert(conformance &&
666+
"Missing Dictionary conformance to _ObjectiveCBridgeable?");
667+
if (auto result = emitBridgeObjectiveCToNative(gen, loc, v, conformance))
668+
return *result;
669+
670+
return gen.emitUndef(loc, nativeTy);
689671
}
690672
}
691673

692674
// Bridge NSSet to Set.
693675
if (auto setDecl = gen.getASTContext().getSetDecl()) {
694676
if (nativeTy.getSwiftRValueType()->getAnyNominal() == setDecl) {
695-
SILDeclRef bridgeFn = gen.SGM.getNSSetToSetFn();
696-
return emitBridgeCollectionToNative(gen, loc, bridgeFn, v, nativeTy);
677+
auto conformance =
678+
gen.SGM.getConformanceToObjectiveCBridgeable(loc, loweredNativeTy);
679+
assert(conformance &&
680+
"Missing Set conformance to _ObjectiveCBridgeable?");
681+
if (auto result = emitBridgeObjectiveCToNative(gen, loc, v, conformance))
682+
return *result;
683+
684+
return gen.emitUndef(loc, nativeTy);
697685
}
698686
}
699687

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,12 @@ namespace {
33933393
Expr *walkToExprPost(Expr *expr) {
33943394
Expr *result = visit(expr);
33953395

3396+
// Mark any _ObjectiveCBridgeable conformances as 'used'.
3397+
if (result) {
3398+
auto &tc = cs.getTypeChecker();
3399+
tc.useObjectiveCBridgeableConformances(cs.DC, result->getType());
3400+
}
3401+
33963402
assert(expr == ExprStack.back());
33973403
ExprStack.pop_back();
33983404

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,8 @@ void swift::markAsObjC(TypeChecker &TC, ValueDecl *D,
22272227

22282228
// Make sure we have the appropriate bridging operations.
22292229
checkBridgedFunctions(TC);
2230+
TC.useObjectiveCBridgeableConformances(D->getInnermostDeclContext(),
2231+
D->getInterfaceType());
22302232

22312233
// Record the name of this Objective-C method in its class.
22322234
if (auto classDecl

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,6 +4010,9 @@ bool TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto,
40104010

40114011
const DeclContext *topLevelContext = DC->getModuleScopeContext();
40124012
auto recordDependency = [=](ProtocolConformance *conformance = nullptr) {
4013+
if (options.contains(ConformanceCheckFlags::SuppressDependencyTracking))
4014+
return;
4015+
40134016
// Record that we depend on the type's conformance.
40144017
auto *constSF = dyn_cast<SourceFile>(topLevelContext);
40154018
if (!constSF)
@@ -4066,6 +4069,39 @@ bool TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto,
40664069
}
40674070
}
40684071

4072+
/// Mark any _ObjectiveCBridgeable conformances in the given type as "used".
4073+
void TypeChecker::useObjectiveCBridgeableConformances(DeclContext *dc,
4074+
Type type) {
4075+
class Walker : public TypeWalker {
4076+
TypeChecker &TC;
4077+
DeclContext *DC;
4078+
ProtocolDecl *Proto;
4079+
4080+
public:
4081+
Walker(TypeChecker &tc, DeclContext *dc, ProtocolDecl *proto)
4082+
: TC(tc), DC(dc), Proto(proto) { }
4083+
4084+
virtual Action walkToTypePre(Type ty) {
4085+
// If we have a nominal type, "use" its conformance to
4086+
// _ObjectiveCBridgeable if it has one.
4087+
if (ty->getAnyNominal()) {
4088+
ConformanceCheckOptions options = ConformanceCheckFlags::InExpression
4089+
| ConformanceCheckFlags::Used
4090+
| ConformanceCheckFlags::SuppressDependencyTracking;
4091+
(void)TC.conformsToProtocol(ty, Proto, DC, options);
4092+
}
4093+
4094+
return Action::Continue;
4095+
}
4096+
};
4097+
4098+
auto proto = getProtocol(SourceLoc(),
4099+
KnownProtocolKind::ObjectiveCBridgeable);
4100+
if (!proto) return;
4101+
4102+
type.walk(Walker(*this, dc, proto));
4103+
}
4104+
40694105
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
40704106
checkConformsToProtocol(*this, conformance);
40714107
}

lib/Sema/TypeChecker.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ enum class ConformanceCheckFlags {
423423
/// Whether we will be using the conformance in the AST.
424424
///
425425
/// This implies that the conformance will have to be complete.
426-
Used = 0x02
426+
Used = 0x02,
427+
/// Whether to suppress dependency tracking entirely.
428+
///
429+
/// FIXME: This deals with some oddities with the
430+
/// _ObjectiveCBridgeable conformances.
431+
SuppressDependencyTracking = 0x04,
427432
};
428433

429434
/// Options that control protocol conformance checking.
@@ -1469,6 +1474,9 @@ class TypeChecker final : public LazyResolver {
14691474
ProtocolConformance **Conformance = nullptr,
14701475
SourceLoc ComplainLoc = SourceLoc());
14711476

1477+
/// Mark any _ObjectiveCBridgeable conformances in the given type as "used".
1478+
void useObjectiveCBridgeableConformances(DeclContext *dc, Type type);
1479+
14721480
/// Derive an implicit declaration to satisfy a requirement of a derived
14731481
/// protocol conformance.
14741482
///

test/NameBinding/reference-dependencies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ struct Use4 : TopLevelProto1 {
250250
}
251251

252252
// CHECK-DAG: - "*"
253-
print(42 * 30)
253+
_ = 42 * 30
254254

255255
// FIXME: Incorrectly marked non-private dependencies
256256
// CHECK-DAG: - "topLevel6"
257-
print(topLevel6())
257+
_ = topLevel6()
258258
// CHECK-DAG: - "topLevel7"
259259
private var use7 = topLevel7()
260260
// CHECK-DAG: - "topLevel8"

test/SILGen/Inputs/Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension Set : _ObjectiveCBridgeable {
173173
return true
174174
}
175175
public static func _unconditionallyBridgeFromObjectiveC(
176-
x: NSSet
176+
x: NSSet?
177177
) -> Set {
178178
return Set()
179179
}

test/SILGen/objc_bridged_results.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import Foundation
1111
func testNonnull(obj: Test) -> [AnyObject] {
1212
// CHECK: [[METHOD:%[0-9]+]] = class_method [volatile] %0 : $Test, #Test.nonnullArray!getter.1.foreign : Test -> () -> [AnyObject] , $@convention(objc_method) (Test) -> @autoreleased Optional<NSArray>
1313
// CHECK: [[COCOA_VAL:%[0-9]+]] = apply [[METHOD]](%0) : $@convention(objc_method) (Test) -> @autoreleased Optional<NSArray>
14-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation22_convertNSArrayToArray
15-
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_VAL]]) : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
14+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationSa36_unconditionallyBridgeFromObjectiveCfGSqCSo7NSArray_GSax_
15+
// CHECK: [[ARRAY_META:%[0-9]+]] = metatype $@thin Array<AnyObject>.Type
16+
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_VAL]], [[ARRAY_META]])
1617
// CHECK: strong_release %0 : $Test
1718
// CHECK: return [[RESULT]] : $Array<AnyObject>
1819
return obj.nonnullArray
@@ -28,9 +29,10 @@ func testNullable(obj: Test) -> [AnyObject]? {
2829

2930
// CHECK: [[CASE_NON_NIL]]:
3031
// CHECK: [[COCOA_VAL_NON_NIL:%[0-9]+]] = unchecked_enum_data [[COCOA_VAL]] : $Optional<NSArray>, #Optional.some!enumelt.1
31-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation22_convertNSArrayToArray
32+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationSa36_unconditionallyBridgeFromObjectiveCfGSqCSo7NSArray_GSax_
3233
// CHECK: [[COCOA_SOME_VAL:%[0-9]+]] = enum $Optional<NSArray>, #Optional.some!enumelt.1, [[COCOA_VAL_NON_NIL]]
33-
// CHECK: [[RESULT_VAL:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_SOME_VAL]]) : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
34+
// CHECK: [[ARRAY_META:%[0-9]+]] = metatype $@thin Array<AnyObject>.Type
35+
// CHECK: [[RESULT_VAL:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_SOME_VAL]], [[ARRAY_META]])
3436
// CHECK: [[RESULT_SOME:%[0-9]+]] = enum $Optional<Array<AnyObject>>, #Optional.some!enumelt.1, [[RESULT_VAL]] : $Array<AnyObject>
3537
// CHECK: br [[FINISH:bb[0-9]+]]([[RESULT_SOME]] : $Optional<Array<AnyObject>>)
3638

@@ -53,9 +55,10 @@ func testNullUnspecified(obj: Test) -> [AnyObject]! {
5355

5456
// CHECK: [[CASE_NON_NIL]]:
5557
// CHECK: [[COCOA_VAL_NON_NIL:%[0-9]+]] = unchecked_enum_data [[COCOA_VAL]] : $ImplicitlyUnwrappedOptional<NSArray>, #ImplicitlyUnwrappedOptional.some!enumelt.1
56-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation22_convertNSArrayToArray
58+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationSa36_unconditionallyBridgeFromObjectiveCfGSqCSo7NSArray_GSax_
5759
// CHECK: [[COCOA_SOME_VAL:%[0-9]+]] = enum $Optional<NSArray>, #Optional.some!enumelt.1, [[COCOA_VAL_NON_NIL]]
58-
// CHECK: [[RESULT_VAL:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_SOME_VAL]]) : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
60+
// CHECK: [[ARRAY_META:%[0-9]+]] = metatype $@thin Array<AnyObject>.Type
61+
// CHECK: [[RESULT_VAL:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_SOME_VAL]], [[ARRAY_META]])
5962
// CHECK: [[RESULT_SOME:%[0-9]+]] = enum $ImplicitlyUnwrappedOptional<Array<AnyObject>>, #ImplicitlyUnwrappedOptional.some!enumelt.1, [[RESULT_VAL]] : $Array<AnyObject>
6063
// CHECK: br [[FINISH:bb[0-9]+]]([[RESULT_SOME]] : $ImplicitlyUnwrappedOptional<Array<AnyObject>>)
6164

@@ -74,8 +77,9 @@ func testNullUnspecified(obj: Test) -> [AnyObject]! {
7477
func testNonnullDictionary(obj: Test) -> [NSObject: AnyObject] {
7578
// CHECK: [[METHOD:%[0-9]+]] = class_method [volatile] %0 : $Test, #Test.nonnullDictionary!getter.1.foreign : Test -> () -> [NSObject : AnyObject] , $@convention(objc_method) (Test) -> @autoreleased Optional<NSDictionary>
7679
// CHECK: [[COCOA_VAL:%[0-9]+]] = apply [[METHOD]](%0) : $@convention(objc_method) (Test) -> @autoreleased Optional<NSDictionary>
77-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation32_convertNSDictionaryToDictionary
78-
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<NSObject, AnyObject>([[COCOA_VAL]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : NSObject, τ_0_0 : Hashable, τ_0_1 : AnyObject> (@owned Optional<NSDictionary>) -> @owned Dictionary<τ_0_0, τ_0_1>
80+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCfGSqCSo12NSDictionary_GS0_xq__
81+
// CHECK: [[DICT_META:%[0-9]+]] = metatype $@thin Dictionary<NSObject, AnyObject>.Type
82+
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<NSObject, AnyObject>([[COCOA_VAL]], [[DICT_META]])
7983
// CHECK: strong_release %0 : $Test
8084
// CHECK: return [[RESULT]] : $Dictionary<NSObject, AnyObject>
8185
return obj.nonnullDictionary
@@ -85,8 +89,9 @@ func testNonnullDictionary(obj: Test) -> [NSObject: AnyObject] {
8589
func testNonnullSet(obj: Test) -> Set<NSObject> {
8690
// CHECK: [[METHOD:%[0-9]+]] = class_method [volatile] %0 : $Test, #Test.nonnullSet!getter.1.foreign : Test -> () -> Set<NSObject> , $@convention(objc_method) (Test) -> @autoreleased Optional<NSSet>
8791
// CHECK: [[COCOA_VAL:%[0-9]+]] = apply [[METHOD]](%0) : $@convention(objc_method) (Test) -> @autoreleased Optional<NSSet>
88-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation18_convertNSSetToSet
89-
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<NSObject>([[COCOA_VAL]]) : $@convention(thin) <τ_0_0 where τ_0_0 : NSObject, τ_0_0 : Hashable> (@owned Optional<NSSet>) -> @owned Set<τ_0_0>
92+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationVs3Set36_unconditionallyBridgeFromObjectiveCfGSqCSo5NSSet_GS0_x_
93+
// CHECK: [[SET_META:%[0-9]+]] = metatype $@thin Set<NSObject>.Type
94+
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<NSObject>([[COCOA_VAL]], [[SET_META]])
9095
// CHECK: strong_release %0 : $Test
9196
// CHECK: return [[RESULT]] : $Set<NSObject>
9297
return obj.nonnullSet
@@ -112,8 +117,9 @@ func testNonnullString(obj: Test) -> String {
112117
func testNonnullSubscript(obj: Test) -> [AnyObject] {
113118
// CHECK: [[METHOD:%[0-9]+]] = class_method [volatile] %0 : $Test, #Test.subscript!getter.1.foreign : (Test) -> (Int) -> [AnyObject] , $@convention(objc_method) (Int, Test) -> @autoreleased Optional<NSArray>
114119
// CHECK: [[COCOA_VAL:%[0-9]+]] = apply [[METHOD]]({{%[0-9]+}}, %0) : $@convention(objc_method) (Int, Test) -> @autoreleased Optional<NSArray>
115-
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TF10Foundation22_convertNSArrayToArray
116-
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_VAL]]) : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
120+
// CHECK: [[CONVERT:%[0-9]+]] = function_ref @_TZFE10FoundationSa36_unconditionallyBridgeFromObjectiveCfGSqCSo7NSArray_GSax_
121+
// CHECK: [[ARRAY_META:%[0-9]+]] = metatype $@thin Array<AnyObject>.Type,
122+
// CHECK: [[RESULT:%[0-9]+]] = apply [[CONVERT]]<AnyObject>([[COCOA_VAL]], [[ARRAY_META]])
117123
// CHECK: strong_release %0 : $Test
118124
// CHECK: return [[RESULT]] : $Array<AnyObject>
119125
return obj[0]

test/SILGen/objc_bridging.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ class Bas : NSObject {
337337
// CHECK: bb0([[NSARRAY:%[0-9]+]] : $NSArray, [[SELF:%[0-9]+]] : $Bas):
338338
// CHECK: strong_retain [[NSARRAY]] : $NSArray
339339
// CHECK: strong_retain [[SELF]] : $Bas
340-
// CHECK: [[CONV_FN:%[0-9]+]] = function_ref @_TF10Foundation22_convertNSArrayToArray{{.*}} : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
340+
// CHECK: [[CONV_FN:%[0-9]+]] = function_ref @_TZFE10FoundationSa36_unconditionallyBridgeFromObjectiveCfGSqCSo7NSArray_GSax_
341341
// CHECK-NEXT: [[OPT_NSARRAY:%[0-9]+]] = enum $Optional<NSArray>, #Optional.some!enumelt.1, [[NSARRAY]] : $NSArray
342-
// CHECK-NEXT: [[ARRAY:%[0-9]+]] = apply [[CONV_FN]]<AnyObject>([[OPT_NSARRAY]]) : $@convention(thin) <τ_0_0> (@owned Optional<NSArray>) -> @owned Array<τ_0_0>
342+
// CHECK-NEXT: [[ARRAY_META:%[0-9]+]] = metatype $@thin Array<AnyObject>.Type
343+
// CHECK-NEXT: [[ARRAY:%[0-9]+]] = apply [[CONV_FN]]<AnyObject>([[OPT_NSARRAY]], [[ARRAY_META]])
343344
// CHECK: [[SWIFT_FN:%[0-9]+]] = function_ref @_TFC13objc_bridging3Bas{{.*}} : $@convention(method) (@owned Array<AnyObject>, @guaranteed Bas) -> ()
344345
// CHECK: [[RESULT:%[0-9]+]] = apply [[SWIFT_FN]]([[ARRAY]], [[SELF]]) : $@convention(method) (@owned Array<AnyObject>, @guaranteed Bas) -> ()
345346
// CHECK: strong_release [[SELF]] : $Bas

test/SILGen/objc_dictionary_bridging.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import gizmo
1313
// CHECK-LABEL: sil hidden [thunk] @_TToFC24objc_dictionary_bridging3Foo23bridge_Dictionary_param{{.*}} : $@convention(objc_method) (NSDictionary, Foo) -> ()
1414
func bridge_Dictionary_param(dict: Dictionary<Foo, Foo>) {
1515
// CHECK: bb0([[NSDICT:%[0-9]+]] : $NSDictionary, [[SELF:%[0-9]+]] : $Foo):
16-
// CHECK: [[CONVERTER:%[0-9]+]] = function_ref @_TF10Foundation32_convertNSDictionaryToDictionary{{.*}} : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : NSObject, τ_0_0 : Hashable, τ_0_1 : AnyObject> (@owned Optional<NSDictionary>) -> @owned Dictionary<τ_0_0, τ_0_1>
16+
// CHECK: [[CONVERTER:%[0-9]+]] = function_ref @_TZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCfGSqCSo12NSDictionary_GS0_xq__
1717
// CHECK-NEXT: [[OPT_NSDICT:%[0-9]+]] = enum $Optional<NSDictionary>, #Optional.some!enumelt.1, [[NSDICT]] : $NSDictionary
18-
// CHECK-NEXT: [[DICT:%[0-9]+]] = apply [[CONVERTER]]<Foo, Foo>([[OPT_NSDICT]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : NSObject, τ_0_0 : Hashable, τ_0_1 : AnyObject> (@owned Optional<NSDictionary>) -> @owned Dictionary<τ_0_0, τ_0_1>
18+
// CHECK-NEXT: [[DICT_META:%[0-9]+]] = metatype $@thin Dictionary<Foo, Foo>.Type
19+
// CHECK-NEXT: [[DICT:%[0-9]+]] = apply [[CONVERTER]]<Foo, Foo>([[OPT_NSDICT]], [[DICT_META]])
1920

2021
// CHECK: [[SWIFT_FN:%[0-9]+]] = function_ref @_TFC24objc_dictionary_bridging3Foo23bridge_Dictionary_param
2122
// CHECK: [[RESULT:%[0-9]+]] = apply [[SWIFT_FN]]([[DICT]], [[SELF]]) : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()
@@ -51,9 +52,10 @@ import gizmo
5152
// Property setter
5253
// CHECK-LABEL: sil hidden [transparent] [thunk] @_TToFC24objc_dictionary_bridging3Foos8propertyGVs10DictionaryS0_S0__ : $@convention(objc_method) (NSDictionary, Foo) -> ()
5354
// CHECK: bb0([[NSDICT:%[0-9]+]] : $NSDictionary, [[SELF:%[0-9]+]] : $Foo):
54-
// CHECK: [[CONVERTER:%[0-9]+]] = function_ref @_TF10Foundation32_convertNSDictionaryToDictionary{{.*}} : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : NSObject, τ_0_0 : Hashable, τ_0_1 : AnyObject> (@owned Optional<NSDictionary>) -> @owned Dictionary<τ_0_0, τ_0_1>
55+
// CHECK: [[CONVERTER:%[0-9]+]] = function_ref @_TZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCfGSqCSo12NSDictionary_GS0_xq__
5556
// CHECK: [[OPT_NSDICT:%[0-9]+]] = enum $Optional<NSDictionary>, #Optional.some!enumelt.1, [[NSDICT]] : $NSDictionary
56-
// CHECK: [[DICT:%[0-9]+]] = apply [[CONVERTER]]<Foo, Foo>([[OPT_NSDICT]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : NSObject, τ_0_0 : Hashable, τ_0_1 : AnyObject> (@owned Optional<NSDictionary>) -> @owned Dictionary<τ_0_0, τ_0_1>
57+
// CHECK: [[DICT_META:%[0-9]+]] = metatype $@thin Dictionary<Foo, Foo>.Type
58+
// CHECK: [[DICT:%[0-9]+]] = apply [[CONVERTER]]<Foo, Foo>([[OPT_NSDICT]], [[DICT_META]])
5759

5860
// CHECK: [[SETTER:%[0-9]+]] = function_ref @_TFC24objc_dictionary_bridging3Foos8propertyGVs10DictionaryS0_S0__ : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()
5961
// CHECK: [[RESULT:%[0-9]+]] = apply [[SETTER]]([[DICT]], [[SELF]]) : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()

0 commit comments

Comments
 (0)