@@ -72,17 +72,25 @@ getObjCToSwiftBridgingFunction(SILOptFunctionBuilder &funcBuilder,
72
72
// / _ObjectiveCBridgeable.
73
73
SILInstruction *
74
74
CastOptimizer::optimizeBridgedObjCToSwiftCast (SILDynamicCastInst dynamicCast) {
75
+ CanType target = dynamicCast.getTargetType ();
76
+ auto &mod = dynamicCast.getModule ();
77
+
78
+ // AnyHashable is a special case that we do not handle since we only handle
79
+ // objc targets in this function. Bailout early.
80
+ if (auto dt = target.getNominalOrBoundGenericNominal ()) {
81
+ if (dt == mod.getASTContext ().getAnyHashableDecl ()) {
82
+ return nullptr ;
83
+ }
84
+ }
75
85
76
86
SILInstruction *Inst = dynamicCast.getInstruction ();
77
87
bool isConditional = dynamicCast.isConditional ();
78
88
SILValue Src = dynamicCast.getSource ();
79
89
SILValue Dest = dynamicCast.getDest ();
80
- CanType Target = dynamicCast.getTargetType ();
81
90
CanType BridgedTargetTy = dynamicCast.getBridgedTargetType ();
82
91
SILBasicBlock *SuccessBB = dynamicCast.getSuccessBlock ();
83
92
SILBasicBlock *FailureBB = dynamicCast.getFailureBlock ();
84
93
auto *F = Inst->getFunction ();
85
- auto &M = Inst->getModule ();
86
94
auto Loc = Inst->getLoc ();
87
95
88
96
// The conformance to _BridgedToObjectiveC is statically known.
@@ -103,14 +111,6 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
103
111
assert (Src->getType ().isAddress () && " Source should have an address type" );
104
112
assert (Dest->getType ().isAddress () && " Source should have an address type" );
105
113
106
- // AnyHashable is a special case - it does not conform to NSObject -
107
- // If AnyHashable - Bail out of the optimization
108
- if (auto DT = Target.getNominalOrBoundGenericNominal ()) {
109
- if (DT == M.getASTContext ().getAnyHashableDecl ()) {
110
- return nullptr ;
111
- }
112
- }
113
-
114
114
// If this is a conditional cast:
115
115
// We need a new fail BB in order to add a dealloc_stack to it
116
116
SILBasicBlock *ConvFailBB = nullptr ;
@@ -130,7 +130,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
130
130
// - then convert _ObjectiveCBridgeable._ObjectiveCType to
131
131
// a Swift type using _forceBridgeFromObjectiveC.
132
132
133
- if (!Src->getType ().isLoadable (M )) {
133
+ if (!Src->getType ().isLoadable (mod )) {
134
134
// This code path is never reached in current test cases
135
135
// If reached, we'd have to convert from an ObjC Any* to a loadable type
136
136
// Should use check_addr / make a source we can actually load
@@ -177,25 +177,25 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
177
177
178
178
// Lookup the _ObjectiveCBridgeable protocol.
179
179
auto BridgedProto =
180
- M .getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
181
- auto Conf = *M .getSwiftModule ()->lookupConformance (Target , BridgedProto);
180
+ mod .getASTContext ().getProtocol (KnownProtocolKind::ObjectiveCBridgeable);
181
+ auto Conf = *mod .getSwiftModule ()->lookupConformance (target , BridgedProto);
182
182
183
183
auto ParamTypes = bridgingFunc->getLoweredFunctionType ()->getParameters ();
184
184
185
185
auto *FuncRef = Builder.createFunctionRef (Loc, bridgingFunc);
186
186
187
- auto MetaTy = MetatypeType::get (Target , MetatypeRepresentation::Thick);
187
+ auto MetaTy = MetatypeType::get (target , MetatypeRepresentation::Thick);
188
188
auto SILMetaTy = F->getTypeLowering (MetaTy).getLoweredType ();
189
189
auto *MetaTyVal = Builder.createMetatype (Loc, SILMetaTy);
190
190
SmallVector<SILValue, 1 > Args;
191
191
192
192
// Add substitutions
193
193
auto SubMap = SubstitutionMap::getProtocolSubstitutions (Conf.getRequirement (),
194
- Target , Conf);
194
+ target , Conf);
195
195
196
196
auto SILFnTy = FuncRef->getType ();
197
- SILType SubstFnTy = SILFnTy.substGenericArgs (M , SubMap);
198
- SILFunctionConventions substConv (SubstFnTy.castTo <SILFunctionType>(), M );
197
+ SILType SubstFnTy = SILFnTy.substGenericArgs (mod , SubMap);
198
+ SILFunctionConventions substConv (SubstFnTy.castTo <SILFunctionType>(), mod );
199
199
200
200
// Temporary to hold the intermediate result.
201
201
AllocStackInst *Tmp = nullptr ;
@@ -263,7 +263,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
263
263
SILBasicBlock *ConvSuccessBB = Inst->getFunction ()->createBasicBlock ();
264
264
SmallVector<std::pair<EnumElementDecl *, SILBasicBlock *>, 1 > CaseBBs;
265
265
CaseBBs.push_back (
266
- std::make_pair (M .getASTContext ().getOptionalNoneDecl (), FailureBB));
266
+ std::make_pair (mod .getASTContext ().getOptionalNoneDecl (), FailureBB));
267
267
Builder.createSwitchEnumAddr (Loc, InOutOptionalParam, ConvSuccessBB,
268
268
CaseBBs);
269
269
0 commit comments