Skip to content

Commit b477708

Browse files
Merge pull request #85128 from nate-chandler/rdar162922634
[CastOptimizer] Use TypeConverter to lower type.
2 parents 186f88b + 41a7d7c commit b477708

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
331331
OptionalTy = OptionalType::get(Dest->getType().getASTType())
332332
->getImplementationType()
333333
->getCanonicalType();
334-
Tmp = Builder.createAllocStack(Loc,
335-
SILType::getPrimitiveObjectType(OptionalTy));
334+
Tmp = Builder.createAllocStack(Loc, F->getLoweredType(OptionalTy));
336335
outOptionalParam = Tmp;
337336
} else {
338337
outOptionalParam = Dest;
@@ -446,10 +445,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
446445

447446
static bool canOptimizeCast(const swift::Type &BridgedTargetTy,
448447
swift::SILFunctionConventions &substConv,
449-
TypeExpansionContext context) {
448+
const SILFunction *F) {
449+
auto context = F->getTypeExpansionContext();
450+
450451
// DestTy is the type which we want to convert to
451-
SILType DestTy =
452-
SILType::getPrimitiveObjectType(BridgedTargetTy->getCanonicalType());
452+
SILType DestTy = F->getLoweredType(BridgedTargetTy->getCanonicalType());
453453
// ConvTy is the return type of the _bridgeToObjectiveCImpl()
454454
auto ConvTy = substConv.getSILResultType(context).getObjectType();
455455
if (ConvTy == DestTy) {
@@ -652,8 +652,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
652652

653653
// Check that this is a case that the authors of this code thought it could
654654
// handle.
655-
if (!canOptimizeCast(BridgedTargetTy, substConv,
656-
F->getTypeExpansionContext())) {
655+
if (!canOptimizeCast(BridgedTargetTy, substConv, F)) {
657656
return nullptr;
658657
}
659658

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)