@@ -93,7 +93,7 @@ static CanType unwrapExistential(CanType e) {
93
93
// / into an existential type by performing a static check
94
94
// / of protocol conformances if it is possible.
95
95
static DynamicCastFeasibility
96
- classifyDynamicCastToProtocol (CanType source, CanType target,
96
+ classifyDynamicCastToProtocol (SILFunction *function, CanType source, CanType target,
97
97
bool isWholeModuleOpts) {
98
98
assert (target.isExistentialType () &&
99
99
" target should be an existential type" );
@@ -468,7 +468,7 @@ static bool isCFBridgingConversion(CanType sourceFormalType,
468
468
469
469
// / Try to classify the dynamic-cast relationship between two types.
470
470
DynamicCastFeasibility
471
- swift::classifyDynamicCast (ModuleDecl *M ,
471
+ swift::classifyDynamicCast (SILFunction *function ,
472
472
CanType source,
473
473
CanType target,
474
474
bool isSourceTypeExact,
@@ -481,19 +481,20 @@ swift::classifyDynamicCast(ModuleDecl *M,
481
481
482
482
auto sourceObject = source.getOptionalObjectType ();
483
483
auto targetObject = target.getOptionalObjectType ();
484
+ ModuleDecl *M = function->getModule ().getSwiftModule ();
484
485
485
486
// A common level of optionality doesn't affect the feasibility,
486
487
// except that we can't fold things to failure because nil inhabits
487
488
// both types.
488
489
if (sourceObject && targetObject) {
489
- return atWorst (classifyDynamicCast (M , sourceObject, targetObject),
490
+ return atWorst (classifyDynamicCast (function , sourceObject, targetObject),
490
491
DynamicCastFeasibility::MaySucceed);
491
492
492
493
// Casting to a more optional type follows the same rule unless we
493
494
// know that the source cannot dynamically be an optional value,
494
495
// in which case we'll always just cast and inject into an optional.
495
496
} else if (targetObject) {
496
- auto result = classifyDynamicCast (M , source, targetObject,
497
+ auto result = classifyDynamicCast (function , source, targetObject,
497
498
/* isSourceTypeExact */ false ,
498
499
isWholeModuleOpts);
499
500
if (canDynamicallyStoreOptional (source))
@@ -502,12 +503,12 @@ swift::classifyDynamicCast(ModuleDecl *M,
502
503
503
504
// Casting to a less-optional type can always fail.
504
505
} else if (sourceObject) {
505
- auto result = atBest (classifyDynamicCast (M , sourceObject, target,
506
+ auto result = atBest (classifyDynamicCast (function , sourceObject, target,
506
507
/* isSourceTypeExact */ false ,
507
508
isWholeModuleOpts),
508
509
DynamicCastFeasibility::MaySucceed);
509
510
if (target.isExistentialType ()) {
510
- result = atWorst (result, classifyDynamicCastToProtocol (
511
+ result = atWorst (result, classifyDynamicCastToProtocol (function,
511
512
source, target, isWholeModuleOpts));
512
513
}
513
514
return result;
@@ -522,7 +523,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
522
523
// Check conversions from non-protocol types into protocol types.
523
524
if (!source.isExistentialType () &&
524
525
target.isExistentialType ())
525
- return classifyDynamicCastToProtocol (source, target,
526
+ return classifyDynamicCastToProtocol (function, source, target,
526
527
isWholeModuleOpts);
527
528
528
529
// Check conversions from protocol types to non-protocol types.
@@ -552,7 +553,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
552
553
// Hashable is not actually a legal existential type right now, but
553
554
// the check doesn't care about that.
554
555
if (auto hashable = getHashableExistentialType (M)) {
555
- return classifyDynamicCastToProtocol (source, hashable,
556
+ return classifyDynamicCastToProtocol (function, source, hashable,
556
557
isWholeModuleOpts);
557
558
}
558
559
}
@@ -589,7 +590,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
589
590
590
591
if (targetMetatype.isAnyExistentialType () && target->isExistentialType ()) {
591
592
auto Feasibility =
592
- classifyDynamicCastToProtocol (source, target, isWholeModuleOpts);
593
+ classifyDynamicCastToProtocol (function, source, target, isWholeModuleOpts);
593
594
// Cast from existential metatype to existential metatype may still
594
595
// succeed, even if we cannot prove anything statically.
595
596
if (Feasibility != DynamicCastFeasibility::WillFail ||
@@ -699,7 +700,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
699
700
700
701
// Combine the result of prior elements with this element type.
701
702
result = std::max (result,
702
- classifyDynamicCast (M ,
703
+ classifyDynamicCast (function ,
703
704
sourceElt.getType ()->getCanonicalType (),
704
705
targetElt.getType ()->getCanonicalType (),
705
706
isSourceTypeExact,
@@ -758,7 +759,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
758
759
// question there.
759
760
if (bridgedSource) source = bridgedSource;
760
761
if (bridgedTarget) target = bridgedTarget;
761
- return classifyDynamicCast (M , source, target, false , isWholeModuleOpts);
762
+ return classifyDynamicCast (function , source, target, false , isWholeModuleOpts);
762
763
}
763
764
764
765
// Casts from a class into a non-class can never succeed if the target must
@@ -833,7 +834,7 @@ swift::classifyDynamicCast(ModuleDecl *M,
833
834
if (Type ObjCTy = M->getASTContext ().getBridgedToObjC (M, source)) {
834
835
// If the bridged ObjC type is known, check if
835
836
// this type can be cast into target type.
836
- return classifyDynamicCast (M ,
837
+ return classifyDynamicCast (function ,
837
838
ObjCTy->getCanonicalType (),
838
839
target,
839
840
/* isSourceTypeExact */ false , isWholeModuleOpts);
@@ -861,16 +862,16 @@ swift::classifyDynamicCast(ModuleDecl *M,
861
862
// Arrays and sets.
862
863
if (sourceStruct->isArray () || sourceStruct->isSet ()) {
863
864
auto valueFeasibility =
864
- classifyDynamicCast (M , sourceArgs[0 ], targetArgs[0 ]);
865
+ classifyDynamicCast (function , sourceArgs[0 ], targetArgs[0 ]);
865
866
return atWorst (valueFeasibility,
866
867
DynamicCastFeasibility::MaySucceed);
867
868
868
869
// Dictionaries.
869
870
} else if (sourceStruct->isDictionary ()) {
870
871
auto keyFeasibility =
871
- classifyDynamicCast (M , sourceArgs[0 ], targetArgs[0 ]);
872
+ classifyDynamicCast (function , sourceArgs[0 ], targetArgs[0 ]);
872
873
auto valueFeasibility =
873
- classifyDynamicCast (M , sourceArgs[1 ], targetArgs[1 ]);
874
+ classifyDynamicCast (function , sourceArgs[1 ], targetArgs[1 ]);
874
875
return atWorst (atBest (keyFeasibility, valueFeasibility),
875
876
DynamicCastFeasibility::MaySucceed);
876
877
}
@@ -1240,7 +1241,7 @@ swift::emitSuccessfulScalarUnconditionalCast(SILBuilder &B, ModuleDecl *M,
1240
1241
CanType sourceFormalType,
1241
1242
CanType targetFormalType,
1242
1243
SILInstruction *existingCast) {
1243
- assert (classifyDynamicCast (M , sourceFormalType, targetFormalType)
1244
+ assert (classifyDynamicCast (&B. getFunction () , sourceFormalType, targetFormalType)
1244
1245
== DynamicCastFeasibility::WillSucceed);
1245
1246
1246
1247
// Casts to/from existential types cannot be further improved.
@@ -1277,7 +1278,7 @@ bool swift::emitSuccessfulIndirectUnconditionalCast(
1277
1278
SILBuilder &B, ModuleDecl *M, SILLocation loc, SILValue src,
1278
1279
CanType sourceFormalType, SILValue dest, CanType targetFormalType,
1279
1280
SILInstruction *existingCast) {
1280
- assert (classifyDynamicCast (M , sourceFormalType, targetFormalType)
1281
+ assert (classifyDynamicCast (&B. getFunction () , sourceFormalType, targetFormalType)
1281
1282
== DynamicCastFeasibility::WillSucceed);
1282
1283
1283
1284
assert (src->getType ().isAddress ());
0 commit comments