45
45
46
46
using namespace swift ;
47
47
48
+ static SILFunction *
49
+ getObjCToSwiftBridgingFunction (SILOptFunctionBuilder &funcBuilder,
50
+ SILDynamicCastInst dynamicCast) {
51
+ // inline constructor.
52
+ auto *bridgeFuncDecl = [&]() -> FuncDecl * {
53
+ auto &astContext = dynamicCast.getModule ().getASTContext ();
54
+ if (dynamicCast.isConditional ()) {
55
+ return astContext.getConditionallyBridgeFromObjectiveCBridgeable ();
56
+ }
57
+ return astContext.getForceBridgeFromObjectiveCBridgeable ();
58
+ }();
59
+
60
+ assert (bridgeFuncDecl && " Bridging function doesn't exist?!" );
61
+
62
+ SILDeclRef funcDeclRef (bridgeFuncDecl, SILDeclRef::Kind::Func);
63
+
64
+ // Lookup a function from the stdlib.
65
+ return funcBuilder.getOrCreateFunction (dynamicCast.getLocation (), funcDeclRef,
66
+ ForDefinition_t::NotForDefinition);
67
+ }
68
+
48
69
// / Create a call of _forceBridgeFromObjectiveC_bridgeable or
49
70
// / _conditionallyBridgeFromObjectiveC_bridgeable which converts an ObjC
50
71
// / instance into a corresponding Swift type, conforming to
@@ -67,20 +88,9 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
67
88
// The conformance to _BridgedToObjectiveC is statically known.
68
89
// Retrieve the bridging operation to be used if a static conformance
69
90
// to _BridgedToObjectiveC can be proven.
70
- FuncDecl *BridgeFuncDecl =
71
- isConditional
72
- ? M.getASTContext ().getConditionallyBridgeFromObjectiveCBridgeable ()
73
- : M.getASTContext ().getForceBridgeFromObjectiveCBridgeable ();
74
-
75
- assert (BridgeFuncDecl && " _forceBridgeFromObjectiveC should exist" );
76
-
77
- SILDeclRef FuncDeclRef (BridgeFuncDecl, SILDeclRef::Kind::Func);
78
-
79
- // Lookup a function from the stdlib.
80
- SILFunction *BridgedFunc = FunctionBuilder.getOrCreateFunction (
81
- Loc, FuncDeclRef, ForDefinition_t::NotForDefinition);
82
-
83
- if (!BridgedFunc)
91
+ SILFunction *bridgingFunc =
92
+ getObjCToSwiftBridgingFunction (FunctionBuilder, dynamicCast);
93
+ if (!bridgingFunc)
84
94
return nullptr ;
85
95
86
96
CanType CanBridgedTy = BridgedTargetTy->getCanonicalType ();
@@ -170,9 +180,9 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
170
180
M.getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
171
181
auto Conf = *M.getSwiftModule ()->lookupConformance (Target, BridgedProto);
172
182
173
- auto ParamTypes = BridgedFunc ->getLoweredFunctionType ()->getParameters ();
183
+ auto ParamTypes = bridgingFunc ->getLoweredFunctionType ()->getParameters ();
174
184
175
- auto *FuncRef = Builder.createFunctionRef (Loc, BridgedFunc );
185
+ auto *FuncRef = Builder.createFunctionRef (Loc, bridgingFunc );
176
186
177
187
auto MetaTy = MetatypeType::get (Target, MetatypeRepresentation::Thick);
178
188
auto SILMetaTy = F->getTypeLowering (MetaTy).getLoweredType ();
0 commit comments