@@ -93,7 +93,7 @@ static CanType unwrapExistential(CanType e) {
9393// / into an existential type by performing a static check
9494// / of protocol conformances if it is possible.
9595static DynamicCastFeasibility
96- classifyDynamicCastToProtocol (CanType source, CanType target,
96+ classifyDynamicCastToProtocol (SILFunction *function, CanType source, CanType target,
9797 bool isWholeModuleOpts) {
9898 assert (target.isExistentialType () &&
9999 " target should be an existential type" );
@@ -468,7 +468,7 @@ static bool isCFBridgingConversion(CanType sourceFormalType,
468468
469469// / Try to classify the dynamic-cast relationship between two types.
470470DynamicCastFeasibility
471- swift::classifyDynamicCast (ModuleDecl *M ,
471+ swift::classifyDynamicCast (SILFunction *function ,
472472 CanType source,
473473 CanType target,
474474 bool isSourceTypeExact,
@@ -481,19 +481,20 @@ swift::classifyDynamicCast(ModuleDecl *M,
481481
482482 auto sourceObject = source.getOptionalObjectType ();
483483 auto targetObject = target.getOptionalObjectType ();
484+ ModuleDecl *M = function->getModule ().getSwiftModule ();
484485
485486 // A common level of optionality doesn't affect the feasibility,
486487 // except that we can't fold things to failure because nil inhabits
487488 // both types.
488489 if (sourceObject && targetObject) {
489- return atWorst (classifyDynamicCast (M , sourceObject, targetObject),
490+ return atWorst (classifyDynamicCast (function , sourceObject, targetObject),
490491 DynamicCastFeasibility::MaySucceed);
491492
492493 // Casting to a more optional type follows the same rule unless we
493494 // know that the source cannot dynamically be an optional value,
494495 // in which case we'll always just cast and inject into an optional.
495496 } else if (targetObject) {
496- auto result = classifyDynamicCast (M , source, targetObject,
497+ auto result = classifyDynamicCast (function , source, targetObject,
497498 /* isSourceTypeExact */ false ,
498499 isWholeModuleOpts);
499500 if (canDynamicallyStoreOptional (source))
@@ -502,12 +503,12 @@ swift::classifyDynamicCast(ModuleDecl *M,
502503
503504 // Casting to a less-optional type can always fail.
504505 } else if (sourceObject) {
505- auto result = atBest (classifyDynamicCast (M , sourceObject, target,
506+ auto result = atBest (classifyDynamicCast (function , sourceObject, target,
506507 /* isSourceTypeExact */ false ,
507508 isWholeModuleOpts),
508509 DynamicCastFeasibility::MaySucceed);
509510 if (target.isExistentialType ()) {
510- result = atWorst (result, classifyDynamicCastToProtocol (
511+ result = atWorst (result, classifyDynamicCastToProtocol (function,
511512 source, target, isWholeModuleOpts));
512513 }
513514 return result;
@@ -522,7 +523,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
522523 // Check conversions from non-protocol types into protocol types.
523524 if (!source.isExistentialType () &&
524525 target.isExistentialType ())
525- return classifyDynamicCastToProtocol (source, target,
526+ return classifyDynamicCastToProtocol (function, source, target,
526527 isWholeModuleOpts);
527528
528529 // Check conversions from protocol types to non-protocol types.
@@ -552,7 +553,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
552553 // Hashable is not actually a legal existential type right now, but
553554 // the check doesn't care about that.
554555 if (auto hashable = getHashableExistentialType (M)) {
555- return classifyDynamicCastToProtocol (source, hashable,
556+ return classifyDynamicCastToProtocol (function, source, hashable,
556557 isWholeModuleOpts);
557558 }
558559 }
@@ -589,7 +590,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
589590
590591 if (targetMetatype.isAnyExistentialType () && target->isExistentialType ()) {
591592 auto Feasibility =
592- classifyDynamicCastToProtocol (source, target, isWholeModuleOpts);
593+ classifyDynamicCastToProtocol (function, source, target, isWholeModuleOpts);
593594 // Cast from existential metatype to existential metatype may still
594595 // succeed, even if we cannot prove anything statically.
595596 if (Feasibility != DynamicCastFeasibility::WillFail ||
@@ -699,7 +700,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
699700
700701 // Combine the result of prior elements with this element type.
701702 result = std::max (result,
702- classifyDynamicCast (M ,
703+ classifyDynamicCast (function ,
703704 sourceElt.getType ()->getCanonicalType (),
704705 targetElt.getType ()->getCanonicalType (),
705706 isSourceTypeExact,
@@ -758,7 +759,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
758759 // question there.
759760 if (bridgedSource) source = bridgedSource;
760761 if (bridgedTarget) target = bridgedTarget;
761- return classifyDynamicCast (M , source, target, false , isWholeModuleOpts);
762+ return classifyDynamicCast (function , source, target, false , isWholeModuleOpts);
762763 }
763764
764765 // Casts from a class into a non-class can never succeed if the target must
@@ -833,7 +834,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
833834 if (Type ObjCTy = M->getASTContext ().getBridgedToObjC (M, source)) {
834835 // If the bridged ObjC type is known, check if
835836 // this type can be cast into target type.
836- return classifyDynamicCast (M ,
837+ return classifyDynamicCast (function ,
837838 ObjCTy->getCanonicalType (),
838839 target,
839840 /* isSourceTypeExact */ false , isWholeModuleOpts);
@@ -861,16 +862,16 @@ swift::classifyDynamicCast(ModuleDecl *M,
861862 // Arrays and sets.
862863 if (sourceStruct->isArray () || sourceStruct->isSet ()) {
863864 auto valueFeasibility =
864- classifyDynamicCast (M , sourceArgs[0 ], targetArgs[0 ]);
865+ classifyDynamicCast (function , sourceArgs[0 ], targetArgs[0 ]);
865866 return atWorst (valueFeasibility,
866867 DynamicCastFeasibility::MaySucceed);
867868
868869 // Dictionaries.
869870 } else if (sourceStruct->isDictionary ()) {
870871 auto keyFeasibility =
871- classifyDynamicCast (M , sourceArgs[0 ], targetArgs[0 ]);
872+ classifyDynamicCast (function , sourceArgs[0 ], targetArgs[0 ]);
872873 auto valueFeasibility =
873- classifyDynamicCast (M , sourceArgs[1 ], targetArgs[1 ]);
874+ classifyDynamicCast (function , sourceArgs[1 ], targetArgs[1 ]);
874875 return atWorst (atBest (keyFeasibility, valueFeasibility),
875876 DynamicCastFeasibility::MaySucceed);
876877 }
@@ -1240,7 +1241,7 @@ swift::emitSuccessfulScalarUnconditionalCast(SILBuilder &B, ModuleDecl *M,
12401241 CanType sourceFormalType,
12411242 CanType targetFormalType,
12421243 SILInstruction *existingCast) {
1243- assert (classifyDynamicCast (M , sourceFormalType, targetFormalType)
1244+ assert (classifyDynamicCast (&B. getFunction () , sourceFormalType, targetFormalType)
12441245 == DynamicCastFeasibility::WillSucceed);
12451246
12461247 // Casts to/from existential types cannot be further improved.
@@ -1277,7 +1278,7 @@ bool swift::emitSuccessfulIndirectUnconditionalCast(
12771278 SILBuilder &B, ModuleDecl *M, SILLocation loc, SILValue src,
12781279 CanType sourceFormalType, SILValue dest, CanType targetFormalType,
12791280 SILInstruction *existingCast) {
1280- assert (classifyDynamicCast (M , sourceFormalType, targetFormalType)
1281+ assert (classifyDynamicCast (&B. getFunction () , sourceFormalType, targetFormalType)
12811282 == DynamicCastFeasibility::WillSucceed);
12821283
12831284 assert (src->getType ().isAddress ());
0 commit comments