mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user