SILGen: Object to metatype casts have to take the slow path

It looks like we don't know how to open-code the "is-a metatype" check
for scalar casts, so just tighten up canUseScalarCheckedCastInstructions()
so that if the target type is a metatype, the source also has to be a
metatype.

This fixes a regression from "SIL: Use scalar casts more".

Fixes <rdar://problem/21003923>.

Swift SVN r28729
This commit is contained in:
Slava Pestov
2015-05-18 23:59:43 +00:00
parent 7e010855b3
commit d368700a6e
3 changed files with 30 additions and 12 deletions

View File

@@ -806,16 +806,19 @@ bool swift::emitSuccessfulIndirectUnconditionalCast(SILBuilder &B, Module *M,
bool swift::canUseScalarCheckedCastInstructions(CanType sourceType,
CanType targetType) {
// Look through one level of optionality on the source.
auto sourceObjectType = sourceType;
if (auto type = sourceObjectType.getAnyOptionalObjectType())
sourceObjectType = type;
auto objectType = sourceType;
if (auto type = objectType.getAnyOptionalObjectType())
objectType = type;
// The source and destination can be metatypes or anything that
// embeds a class reference.
if ((sourceObjectType.isAnyClassReferenceType() ||
isa<AnyMetatypeType>(sourceObjectType)) &&
(targetType->isAnyClassReferenceType() ||
isa<AnyMetatypeType>(targetType)))
// Three supported cases:
// - metatype to metatype
// - metatype to object
// - object to object
if ((objectType.isAnyClassReferenceType() || isa<AnyMetatypeType>(objectType))
&& targetType->isAnyClassReferenceType())
return true;
if (isa<AnyMetatypeType>(objectType) && isa<AnyMetatypeType>(targetType))
return true;
// Otherwise, we need to use the general indirect-cast functions.