@@ -66,6 +66,15 @@ getObjCToSwiftBridgingFunction(SILOptFunctionBuilder &funcBuilder,
66
66
ForDefinition_t::NotForDefinition);
67
67
}
68
68
69
+ static SubstitutionMap lookupBridgeToObjCProtocolSubs (SILModule &mod,
70
+ CanType target) {
71
+ auto bridgedProto =
72
+ mod.getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
73
+ auto conf = *mod.getSwiftModule ()->lookupConformance (target, bridgedProto);
74
+ return SubstitutionMap::getProtocolSubstitutions (conf.getRequirement (),
75
+ target, conf);
76
+ }
77
+
69
78
// / Create a call of _forceBridgeFromObjectiveC_bridgeable or
70
79
// / _conditionallyBridgeFromObjectiveC_bridgeable which converts an ObjC
71
80
// / instance into a corresponding Swift type, conforming to
@@ -181,17 +190,8 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
181
190
// Now emit the a cast from the casted ObjC object into a target type.
182
191
// This is done by means of calling _forceBridgeFromObjectiveC or
183
192
// _conditionallyBridgeFromObjectiveC_bridgeable from the Target type.
184
- // Lookup the required function in the Target type.
185
-
186
- // Lookup the _ObjectiveCBridgeable protocol.
187
- auto BridgedProto =
188
- mod.getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
189
- auto Conf = *mod.getSwiftModule ()->lookupConformance (target, BridgedProto);
190
- // Add substitutions
191
- auto SubMap = SubstitutionMap::getProtocolSubstitutions (Conf.getRequirement (),
192
- target, Conf);
193
-
194
- auto *FuncRef = Builder.createFunctionRef (Loc, bridgingFunc);
193
+ auto *funcRef = Builder.createFunctionRef (Loc, bridgingFunc);
194
+ SubstitutionMap subMap = lookupBridgeToObjCProtocolSubs (mod, target);
195
195
196
196
auto MetaTy = MetatypeType::get (target, MetatypeRepresentation::Thick);
197
197
auto SILMetaTy = F->getTypeLowering (MetaTy).getLoweredType ();
@@ -221,7 +221,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
221
221
Args.push_back (srcOp);
222
222
Args.push_back (MetaTyVal);
223
223
224
- auto *AI = Builder.createApply (Loc, FuncRef, SubMap , Args, false );
224
+ auto *AI = Builder.createApply (Loc, funcRef, subMap , Args, false );
225
225
226
226
// If we have guaranteed normal arguments, insert the destroy.
227
227
//
0 commit comments