@@ -808,7 +808,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
808
808
// / The lvalue or rvalue representing the argument source of self.
809
809
ArgumentSource selfParam;
810
810
811
- ApplyExpr *selfApply = nullptr ;
811
+ SelfApplyExpr *selfApply = nullptr ;
812
812
ApplyExpr *callSite = nullptr ;
813
813
Expr *sideEffect = nullptr ;
814
814
@@ -831,26 +831,29 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
831
831
selfParam = std::move (theSelfParam);
832
832
}
833
833
834
- bool isMethodSelfApply (Expr *e) {
835
- return (isa<SelfApplyExpr>(e) &&
836
- !isa<AutoClosureExpr>(
837
- cast<SelfApplyExpr>(e)->getFn ()));
834
+ SelfApplyExpr *getAsMethodSelfApply (Expr *e) {
835
+ auto *SAE = dyn_cast<SelfApplyExpr>(e);
836
+ if (!SAE)
837
+ return nullptr ;
838
+ if (isa<AutoClosureExpr>(SAE->getFn ()))
839
+ return nullptr ;
840
+ return SAE;
838
841
}
839
842
840
843
void decompose (ApplyExpr *e) {
841
- if (isMethodSelfApply (e)) {
842
- selfApply = e ;
844
+ if (auto *SAE = getAsMethodSelfApply (e)) {
845
+ selfApply = SAE ;
843
846
844
847
visit (selfApply->getFn ());
845
848
return ;
846
849
}
847
850
848
851
callSite = e;
849
852
850
- if (isMethodSelfApply (e->getFn ())) {
851
- selfApply = cast<ApplyExpr>(e-> getFn ()) ;
853
+ if (auto *SAE = getAsMethodSelfApply (e->getFn ())) {
854
+ selfApply = SAE ;
852
855
853
- if (selfApply->getArg ()->isSuperExpr ()) {
856
+ if (selfApply->getBase ()->isSuperExpr ()) {
854
857
applySuper (selfApply);
855
858
return ;
856
859
}
@@ -960,14 +963,14 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
960
963
961
964
void processProtocolMethod (DeclRefExpr *e, AbstractFunctionDecl *afd,
962
965
ProtocolDecl *proto) {
963
- ArgumentSource selfValue = selfApply->getArg ();
966
+ ArgumentSource selfValue = selfApply->getBase ();
964
967
965
968
auto subs = e->getDeclRef ().getSubstitutions ();
966
969
967
970
SILDeclRef::Kind kind = SILDeclRef::Kind::Func;
968
971
if (isa<ConstructorDecl>(afd)) {
969
972
if (proto->isObjC ()) {
970
- SILLocation loc = selfApply->getArg ();
973
+ SILLocation loc = selfApply->getBase ();
971
974
972
975
// For Objective-C initializers, we only have an initializing
973
976
// initializer. We need to allocate the object ourselves.
@@ -1017,8 +1020,8 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1017
1020
1018
1021
// Required constructors are statically dispatched when the 'self'
1019
1022
// value is statically derived.
1020
- assert (selfApply->getArg ()->getType ()->is <AnyMetatypeType>());
1021
- if (selfApply->getArg ()->isStaticallyDerivedMetatype ())
1023
+ assert (selfApply->getBase ()->getType ()->is <AnyMetatypeType>());
1024
+ if (selfApply->getBase ()->isStaticallyDerivedMetatype ())
1022
1025
return false ;
1023
1026
}
1024
1027
@@ -1027,7 +1030,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1027
1030
}
1028
1031
1029
1032
void processClassMethod (DeclRefExpr *e, AbstractFunctionDecl *afd) {
1030
- ArgumentSource selfArgSource (selfApply->getArg ());
1033
+ ArgumentSource selfArgSource (selfApply->getBase ());
1031
1034
setSelfParam (std::move (selfArgSource));
1032
1035
1033
1036
// Directly dispatch to calls of the replaced function inside of
@@ -1036,7 +1039,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1036
1039
if (SGF.getOptions ()
1037
1040
.EnableDynamicReplacementCanCallPreviousImplementation &&
1038
1041
isCallToReplacedInDynamicReplacement (SGF, afd, isObjCReplacementCall) &&
1039
- selfApply->getArg ()->isSelfExprOf (
1042
+ selfApply->getBase ()->isSelfExprOf (
1040
1043
cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()), false )) {
1041
1044
auto constant = SILDeclRef (afd).asForeign (
1042
1045
!isObjCReplacementCall && requiresForeignEntryPoint (e->getDecl ()));
@@ -1089,7 +1092,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1089
1092
// Enum case constructor references are open-coded.
1090
1093
if (auto *eed = dyn_cast<EnumElementDecl>(e->getDecl ())) {
1091
1094
if (selfApply) {
1092
- ArgumentSource selfArgSource (selfApply->getArg ());
1095
+ ArgumentSource selfArgSource (selfApply->getBase ());
1093
1096
setSelfParam (std::move (selfArgSource));
1094
1097
}
1095
1098
@@ -1131,15 +1134,16 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1131
1134
// dynamically_replaceable inside of a dynamic_replacement(for:) function.
1132
1135
ApplyExpr *thisCallSite = (selfApply ? selfApply : callSite);
1133
1136
bool isObjCReplacementSelfCall = false ;
1137
+ auto *unaryArg = thisCallSite->getArgs ()->getUnaryExpr ();
1134
1138
bool isSelfCallToReplacedInDynamicReplacement =
1135
1139
SGF.getOptions ()
1136
1140
.EnableDynamicReplacementCanCallPreviousImplementation &&
1137
1141
isCallToReplacedInDynamicReplacement (
1138
1142
SGF, cast<AbstractFunctionDecl>(constant.getDecl ()),
1139
1143
isObjCReplacementSelfCall) &&
1140
1144
(afd->getDeclContext ()->isModuleScopeContext () ||
1141
- thisCallSite-> getArg () ->isSelfExprOf (
1142
- cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()), false ));
1145
+ (unaryArg && unaryArg ->isSelfExprOf (
1146
+ cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()), false ))) ;
1143
1147
1144
1148
if (isSelfCallToReplacedInDynamicReplacement && !isObjCReplacementSelfCall)
1145
1149
setCallee (Callee::forDirect (
@@ -1152,7 +1156,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1152
1156
1153
1157
if (selfApply) {
1154
1158
// This is a statically-dispatched method with a 'self' parameter.
1155
- ArgumentSource selfArgSource (selfApply->getArg ());
1159
+ ArgumentSource selfArgSource (selfApply->getBase ());
1156
1160
setSelfParam (std::move (selfArgSource));
1157
1161
}
1158
1162
@@ -1259,9 +1263,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1259
1263
visit (e->getSubExpr ());
1260
1264
}
1261
1265
1262
- void applySuper (ApplyExpr *apply) {
1266
+ void applySuper (SelfApplyExpr *apply) {
1263
1267
// Load the 'super' argument.
1264
- Expr *arg = apply->getArg ();
1268
+ Expr *arg = apply->getBase ();
1265
1269
RValue super;
1266
1270
CanType superFormalType = arg->getType ()->getCanonicalType ();
1267
1271
@@ -1400,7 +1404,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1400
1404
}
1401
1405
1402
1406
// / Try to emit the given application as initializer delegation.
1403
- bool applyInitDelegation (ApplyExpr *expr) {
1407
+ bool applyInitDelegation (SelfApplyExpr *expr) {
1404
1408
// Dig out the constructor we're delegating to.
1405
1409
Expr *fn = expr->getFn ();
1406
1410
auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(
@@ -1439,7 +1443,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1439
1443
}
1440
1444
1441
1445
// Load the 'self' argument.
1442
- Expr *arg = expr->getArg ();
1446
+ Expr *arg = expr->getBase ();
1443
1447
ManagedValue self;
1444
1448
CanType selfFormalType = arg->getType ()->getCanonicalType ();
1445
1449
@@ -4273,20 +4277,14 @@ CallEmission CallEmission::forApplyExpr(SILGenFunction &SGF, ApplyExpr *e) {
4273
4277
}
4274
4278
4275
4279
// Apply arguments from the actual call site.
4276
- if (apply.callSite ) {
4277
- Expr *arg = apply.callSite ->getArg ();
4278
-
4279
- SmallVector<AnyFunctionType::Param, 8 > params;
4280
- AnyFunctionType::decomposeTuple (arg->getType (), params);
4281
-
4282
- PreparedArguments preparedArgs (params, arg);
4283
-
4284
- emission.addCallSite (apply.callSite , std::move (preparedArgs),
4285
- apply.callSite ->isNoThrows (),
4286
- apply.callSite ->isNoAsync ());
4280
+ if (auto *call = apply.callSite ) {
4281
+ auto fnTy = call->getFn ()->getType ()->castTo <FunctionType>();
4282
+ PreparedArguments preparedArgs (fnTy->getParams (), call->getArgs ());
4283
+ emission.addCallSite (call, std::move (preparedArgs), call->isNoThrows (),
4284
+ call->isNoAsync ());
4287
4285
4288
4286
// For an implicitly-async call, record the target of the actor hop.
4289
- if (auto target = apply. callSite ->isImplicitlyAsync ())
4287
+ if (auto target = call ->isImplicitlyAsync ())
4290
4288
emission.setImplicitlyAsync (target);
4291
4289
}
4292
4290
@@ -5629,9 +5627,7 @@ PreparedArguments
5629
5627
SILGenFunction::prepareSubscriptIndices (SubscriptDecl *subscript,
5630
5628
SubstitutionMap subs,
5631
5629
AccessStrategy strategy,
5632
- Expr *indexExpr) {
5633
- // FIXME: we should expect an array of index expressions.
5634
-
5630
+ ArgumentList *argList) {
5635
5631
// TODO: use the real abstraction pattern from the accessor(s) in the
5636
5632
// strategy.
5637
5633
// Currently we use the substituted type so that we can reconstitute these
@@ -5653,7 +5649,7 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
5653
5649
5654
5650
// Prepare the unevaluated index expression.
5655
5651
auto substParams = substFnType->getParams ();
5656
- PreparedArguments args (substParams, indexExpr );
5652
+ PreparedArguments args (substParams, argList );
5657
5653
5658
5654
// Now, force it to be evaluated.
5659
5655
SmallVector<ManagedValue, 4 > argValues;
@@ -5666,11 +5662,11 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
5666
5662
PreparedArguments result (substParams);
5667
5663
5668
5664
ArrayRef<ManagedValue> remainingArgs = argValues;
5669
- for (auto substParam : substParams) {
5670
- auto substParamType = substParam .getParameterType ()->getCanonicalType ();
5665
+ for (auto i : indices ( substParams) ) {
5666
+ auto substParamType = substParams[i] .getParameterType ()->getCanonicalType ();
5671
5667
auto count = RValue::getRValueSize (substParamType);
5672
5668
RValue elt (*this , remainingArgs.slice (0 , count), substParamType);
5673
- result.add (indexExpr , std::move (elt));
5669
+ result.add (argList-> getExpr (i) , std::move (elt));
5674
5670
remainingArgs = remainingArgs.slice (count);
5675
5671
}
5676
5672
assert (remainingArgs.empty ());
@@ -6178,7 +6174,9 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
6178
6174
SILValue base = managedBase.getValue ();
6179
6175
6180
6176
// Emit the index.
6181
- RValue index = emitRValue (e->getIndex ());
6177
+ auto *indexExpr = e->getArgs ()->getUnaryExpr ();
6178
+ assert (indexExpr);
6179
+ RValue index = emitRValue (indexExpr);
6182
6180
6183
6181
// Create the continuation block.
6184
6182
SILBasicBlock *contBB = createBasicBlock ();
@@ -6214,7 +6212,7 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
6214
6212
//
6215
6213
// FIXME: Verify ExtInfo state is correct, not working by accident.
6216
6214
CanFunctionType::ExtInfo methodInfo;
6217
- FunctionType::Param indexArg (e-> getIndex () ->getType ()->getCanonicalType ());
6215
+ FunctionType::Param indexArg (indexExpr ->getType ()->getCanonicalType ());
6218
6216
auto methodTy = CanFunctionType::get ({indexArg}, valueTy, methodInfo);
6219
6217
auto foreignMethodTy =
6220
6218
getPartialApplyOfDynamicMethodFormalType (SGM, member, e->getMember ());
@@ -6268,7 +6266,7 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
6268
6266
}
6269
6267
6270
6268
SmallVector<ManagedValue, 4 > SILGenFunction::emitKeyPathSubscriptOperands (
6271
- SubscriptDecl *subscript, SubstitutionMap subs, Expr *indexExpr ) {
6269
+ SubscriptDecl *subscript, SubstitutionMap subs, ArgumentList *argList ) {
6272
6270
Type interfaceType = subscript->getInterfaceType ();
6273
6271
CanFunctionType substFnType =
6274
6272
subs ? cast<FunctionType>(interfaceType->castTo <GenericFunctionType>()
@@ -6291,7 +6289,7 @@ SmallVector<ManagedValue, 4> SILGenFunction::emitKeyPathSubscriptOperands(
6291
6289
auto prepared =
6292
6290
prepareSubscriptIndices (subscript, subs,
6293
6291
// Strategy doesn't matter
6294
- AccessStrategy::getStorage (), indexExpr );
6292
+ AccessStrategy::getStorage (), argList );
6295
6293
emitter.emitPreparedArgs (std::move (prepared), origFnType);
6296
6294
6297
6295
if (!delayedArgs.empty ())
0 commit comments