@@ -113,6 +113,12 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
113113 if (!bridgingFunc)
114114 return nullptr ;
115115
116+ auto paramTypes = bridgingFunc->getLoweredFunctionType ()->getParameters ();
117+ (void )paramTypes;
118+ assert (paramTypes[0 ].getConvention () ==
119+ ParameterConvention::Direct_Guaranteed &&
120+ " Parameter should be @guaranteed" );
121+
116122 CanType CanBridgedTy = BridgedTargetTy->getCanonicalType ();
117123 SILType silBridgedTy = SILType::getPrimitiveObjectType (CanBridgedTy);
118124
@@ -181,19 +187,15 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
181187 auto BridgedProto =
182188 mod.getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
183189 auto Conf = *mod.getSwiftModule ()->lookupConformance (target, BridgedProto);
184-
185- auto ParamTypes = bridgingFunc->getLoweredFunctionType ()->getParameters ();
190+ // Add substitutions
191+ auto SubMap = SubstitutionMap::getProtocolSubstitutions (Conf.getRequirement (),
192+ target, Conf);
186193
187194 auto *FuncRef = Builder.createFunctionRef (Loc, bridgingFunc);
188195
189196 auto MetaTy = MetatypeType::get (target, MetatypeRepresentation::Thick);
190197 auto SILMetaTy = F->getTypeLowering (MetaTy).getLoweredType ();
191198 auto *MetaTyVal = Builder.createMetatype (Loc, SILMetaTy);
192- SmallVector<SILValue, 1 > Args;
193-
194- // Add substitutions
195- auto SubMap = SubstitutionMap::getProtocolSubstitutions (Conf.getRequirement (),
196- target, Conf);
197199
198200 // Temporary to hold the intermediate result.
199201 AllocStackInst *Tmp = nullptr ;
@@ -211,13 +213,10 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
211213 InOutOptionalParam = Dest;
212214 }
213215
214- (void )ParamTypes;
215- assert (ParamTypes[0 ].getConvention () == ParameterConvention::Direct_Guaranteed &&
216- " Parameter should be @guaranteed" );
217-
218216 // Emit a retain.
219217 Builder.createRetainValue (Loc, srcOp, Builder.getDefaultAtomicity ());
220218
219+ SmallVector<SILValue, 1 > Args;
221220 Args.push_back (InOutOptionalParam);
222221 Args.push_back (srcOp);
223222 Args.push_back (MetaTyVal);
0 commit comments