@@ -6255,17 +6255,14 @@ RValue SILGenFunction::emitDynamicMemberRef(SILLocation loc, SILValue operand,
6255
6255
emitManagedRValueWithCleanup (optResult, optTL));
6256
6256
}
6257
6257
6258
- RValue SILGenFunction::emitDynamicSubscriptExpr (DynamicSubscriptExpr *e,
6258
+ RValue
6259
+ SILGenFunction::emitDynamicSubscriptGetterApply (SILLocation loc,
6260
+ SILValue operand,
6261
+ ConcreteDeclRef subscriptRef,
6262
+ PreparedArguments &&indexArgs,
6263
+ CanType resultTy,
6259
6264
SGFContext c) {
6260
- // Emit the base operand.
6261
- ManagedValue managedBase = emitRValueAsSingleValue (e->getBase ());
6262
-
6263
- SILValue base = managedBase.getValue ();
6264
-
6265
- // Emit the index.
6266
- auto *indexExpr = e->getArgs ()->getUnaryExpr ();
6267
- assert (indexExpr);
6268
- RValue index = emitRValue (indexExpr);
6265
+ assert (resultTy->isOptional ());
6269
6266
6270
6267
// Create the continuation block.
6271
6268
SILBasicBlock *contBB = createBasicBlock ();
@@ -6276,72 +6273,77 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
6276
6273
// Create the has-member block.
6277
6274
SILBasicBlock *hasMemberBB = createBasicBlock ();
6278
6275
6279
- const TypeLowering &optTL = getTypeLowering (e->getType ());
6280
- auto loweredOptTy = optTL.getLoweredType ();
6281
- SILValue optTemp = emitTemporaryAllocation (e, loweredOptTy);
6276
+ const TypeLowering &optTL = getTypeLowering (resultTy);
6277
+ const SILValue optTemp = emitTemporaryAllocation (loc, optTL.getLoweredType ());
6282
6278
6283
6279
// Create the branch.
6284
- auto subscriptDecl = cast<SubscriptDecl>(e-> getMember () .getDecl ());
6280
+ auto * subscriptDecl = cast<SubscriptDecl>(subscriptRef .getDecl ());
6285
6281
auto member = SILDeclRef (subscriptDecl->getOpaqueAccessor (AccessorKind::Get),
6286
6282
SILDeclRef::Kind::Func)
6287
6283
.asForeign ();
6288
- B.createDynamicMethodBranch (e, base , member, hasMemberBB, noMemberBB);
6284
+ B.createDynamicMethodBranch (loc, operand , member, hasMemberBB, noMemberBB);
6289
6285
6290
6286
// Create the has-member branch.
6291
6287
{
6292
6288
B.emitBlock (hasMemberBB);
6293
6289
6294
- FullExpr hasMemberScope (Cleanups, CleanupLocation (e ));
6290
+ FullExpr hasMemberScope (Cleanups, CleanupLocation (loc ));
6295
6291
6296
6292
// The argument to the has-member block is the uncurried method.
6297
6293
// Build the substituted getter type from the AST nodes.
6298
- auto valueTy = e-> getType ()-> getCanonicalType () .getOptionalObjectType ();
6294
+ const CanType valueTy = resultTy .getOptionalObjectType ();
6299
6295
6300
- // Objective-C subscripts only ever have a single parameter.
6301
- //
6302
6296
// FIXME: Verify ExtInfo state is correct, not working by accident.
6303
6297
CanFunctionType::ExtInfo methodInfo;
6304
- FunctionType::Param indexArg (indexExpr-> getType ()-> getCanonicalType ());
6305
- auto methodTy = CanFunctionType::get ({indexArg} , valueTy, methodInfo);
6298
+ const auto methodTy =
6299
+ CanFunctionType::get (indexArgs. getParams () , valueTy, methodInfo);
6306
6300
auto foreignMethodTy =
6307
- getPartialApplyOfDynamicMethodFormalType (SGM, member, e-> getMember () );
6301
+ getPartialApplyOfDynamicMethodFormalType (SGM, member, subscriptRef );
6308
6302
6309
6303
// FIXME: Verify ExtInfo state is correct, not working by accident.
6310
6304
CanFunctionType::ExtInfo functionInfo;
6311
- FunctionType::Param baseArg (base ->getType ().getASTType ());
6305
+ FunctionType::Param baseArg (operand ->getType ().getASTType ());
6312
6306
auto functionTy = CanFunctionType::get ({baseArg}, methodTy, functionInfo);
6313
6307
auto loweredMethodTy = getDynamicMethodLoweredType (SGM.M , member,
6314
6308
functionTy);
6315
6309
SILValue memberArg =
6316
6310
hasMemberBB->createPhiArgument (loweredMethodTy, OwnershipKind::Owned);
6317
6311
// Emit the application of 'self'.
6318
- Scope applyScope (Cleanups, CleanupLocation (e));
6319
- ManagedValue result = emitDynamicPartialApply (*this , e, memberArg, base,
6320
- foreignMethodTy, methodTy);
6321
- // Emit the index.
6322
- llvm::SmallVector<ManagedValue, 2 > indexArgs;
6323
- std::move (index).getAll (indexArgs);
6324
-
6325
- auto resultRV = emitMonomorphicApply (e, result, indexArgs,
6312
+ Scope applyScope (Cleanups, CleanupLocation (loc));
6313
+ ManagedValue result = emitDynamicPartialApply (
6314
+ *this , loc, memberArg, operand, foreignMethodTy, methodTy);
6315
+
6316
+ // Collect the index values for application.
6317
+ llvm::SmallVector<ManagedValue, 2 > indexValues;
6318
+ for (auto &source : std::move (indexArgs).getSources ()) {
6319
+ // @objc subscripts cannot have 'inout' indices.
6320
+ RValue rVal = std::move (source).asKnownRValue (*this );
6321
+
6322
+ // @objc subscripts cannot have tuple indices.
6323
+ indexValues.push_back (std::move (rVal).getScalarValue ());
6324
+ }
6325
+
6326
+ auto resultRV = emitMonomorphicApply (loc, result, indexValues,
6326
6327
foreignMethodTy.getResult (), valueTy,
6327
6328
ApplyOptions (), None, None);
6328
6329
6329
6330
// Package up the result in an optional.
6330
- emitInjectOptionalValueInto (e, {e, std::move (resultRV)}, optTemp, optTL);
6331
+ emitInjectOptionalValueInto (loc, {loc, std::move (resultRV)}, optTemp,
6332
+ optTL);
6331
6333
6332
6334
applyScope.pop ();
6333
6335
// Branch to the continuation block.
6334
- B.createBranch (e , contBB);
6336
+ B.createBranch (loc , contBB);
6335
6337
}
6336
6338
6337
6339
// Create the no-member branch.
6338
6340
{
6339
6341
B.emitBlock (noMemberBB);
6340
6342
6341
- emitInjectOptionalNothingInto (e , optTemp, optTL);
6343
+ emitInjectOptionalNothingInto (loc , optTemp, optTL);
6342
6344
6343
6345
// Branch to the continuation block.
6344
- B.createBranch (e , contBB);
6346
+ B.createBranch (loc , contBB);
6345
6347
}
6346
6348
6347
6349
// Emit the continuation block.
@@ -6350,8 +6352,9 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
6350
6352
// Package up the result.
6351
6353
auto optResult = optTemp;
6352
6354
if (optTL.isLoadable ())
6353
- optResult = optTL.emitLoad (B, e, optResult, LoadOwnershipQualifier::Take);
6354
- return RValue (*this , e, emitManagedRValueWithCleanup (optResult, optTL));
6355
+ optResult = optTL.emitLoad (B, loc, optResult, LoadOwnershipQualifier::Take);
6356
+ return RValue (*this , loc, resultTy,
6357
+ emitManagedRValueWithCleanup (optResult, optTL));
6355
6358
}
6356
6359
6357
6360
SmallVector<ManagedValue, 4 > SILGenFunction::emitKeyPathSubscriptOperands (
0 commit comments