Skip to content

Commit ef6bd64

Browse files
committed
[CastOptimizer] Use TypeConverter to lower type.
rdar://162922634
1 parent 9953b1e commit ef6bd64

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
332332
->getImplementationType()
333333
->getCanonicalType();
334334
Tmp = Builder.createAllocStack(Loc,
335-
SILType::getPrimitiveObjectType(OptionalTy));
335+
F->getLoweredType(OptionalTy));
336336
outOptionalParam = Tmp;
337337
} else {
338338
outOptionalParam = Dest;
@@ -446,10 +446,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
446446

447447
static bool canOptimizeCast(const swift::Type &BridgedTargetTy,
448448
swift::SILFunctionConventions &substConv,
449-
TypeExpansionContext context) {
449+
const SILFunction *F) {
450+
auto context = F->getTypeExpansionContext();
451+
450452
// DestTy is the type which we want to convert to
451-
SILType DestTy =
452-
SILType::getPrimitiveObjectType(BridgedTargetTy->getCanonicalType());
453+
SILType DestTy = F->getLoweredType(BridgedTargetTy->getCanonicalType());
453454
// ConvTy is the return type of the _bridgeToObjectiveCImpl()
454455
auto ConvTy = substConv.getSILResultType(context).getObjectType();
455456
if (ConvTy == DestTy) {
@@ -652,8 +653,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
652653

653654
// Check that this is a case that the authors of this code thought it could
654655
// handle.
655-
if (!canOptimizeCast(BridgedTargetTy, substConv,
656-
F->getTypeExpansionContext())) {
656+
if (!canOptimizeCast(BridgedTargetTy, substConv, F)) {
657657
return nullptr;
658658
}
659659

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -O -emit-sil -verify %s
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
func f(_ x: [AnyHashable]) -> [NSObject.Type]? {
8+
return x as? [NSObject.Type]
9+
}

0 commit comments

Comments
 (0)