mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #85128 from nate-chandler/rdar162922634
[CastOptimizer] Use TypeConverter to lower type.
This commit is contained in:
@@ -331,8 +331,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
|
||||
OptionalTy = OptionalType::get(Dest->getType().getASTType())
|
||||
->getImplementationType()
|
||||
->getCanonicalType();
|
||||
Tmp = Builder.createAllocStack(Loc,
|
||||
SILType::getPrimitiveObjectType(OptionalTy));
|
||||
Tmp = Builder.createAllocStack(Loc, F->getLoweredType(OptionalTy));
|
||||
outOptionalParam = Tmp;
|
||||
} else {
|
||||
outOptionalParam = Dest;
|
||||
@@ -446,10 +445,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
|
||||
|
||||
static bool canOptimizeCast(const swift::Type &BridgedTargetTy,
|
||||
swift::SILFunctionConventions &substConv,
|
||||
TypeExpansionContext context) {
|
||||
const SILFunction *F) {
|
||||
auto context = F->getTypeExpansionContext();
|
||||
|
||||
// DestTy is the type which we want to convert to
|
||||
SILType DestTy =
|
||||
SILType::getPrimitiveObjectType(BridgedTargetTy->getCanonicalType());
|
||||
SILType DestTy = F->getLoweredType(BridgedTargetTy->getCanonicalType());
|
||||
// ConvTy is the return type of the _bridgeToObjectiveCImpl()
|
||||
auto ConvTy = substConv.getSILResultType(context).getObjectType();
|
||||
if (ConvTy == DestTy) {
|
||||
@@ -652,8 +652,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
|
||||
|
||||
// Check that this is a case that the authors of this code thought it could
|
||||
// handle.
|
||||
if (!canOptimizeCast(BridgedTargetTy, substConv,
|
||||
F->getTypeExpansionContext())) {
|
||||
if (!canOptimizeCast(BridgedTargetTy, substConv, F)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
9
validation-test/SILOptimizer/rdar162922634.swift
Normal file
9
validation-test/SILOptimizer/rdar162922634.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
// RUN: %target-swift-frontend -O -emit-sil -verify %s
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
|
||||
func f(_ x: [AnyHashable]) -> [NSObject.Type]? {
|
||||
return x as? [NSObject.Type]
|
||||
}
|
||||
Reference in New Issue
Block a user