@@ -808,7 +808,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
808808 // / The lvalue or rvalue representing the argument source of self.
809809 ArgumentSource selfParam;
810810
811- ApplyExpr *selfApply = nullptr ;
811+ SelfApplyExpr *selfApply = nullptr ;
812812 ApplyExpr *callSite = nullptr ;
813813 Expr *sideEffect = nullptr ;
814814
@@ -831,26 +831,29 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
831831 selfParam = std::move (theSelfParam);
832832 }
833833
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;
838841 }
839842
840843 void decompose (ApplyExpr *e) {
841- if (isMethodSelfApply (e)) {
842- selfApply = e ;
844+ if (auto *SAE = getAsMethodSelfApply (e)) {
845+ selfApply = SAE ;
843846
844847 visit (selfApply->getFn ());
845848 return ;
846849 }
847850
848851 callSite = e;
849852
850- if (isMethodSelfApply (e->getFn ())) {
851- selfApply = cast<ApplyExpr>(e-> getFn ()) ;
853+ if (auto *SAE = getAsMethodSelfApply (e->getFn ())) {
854+ selfApply = SAE ;
852855
853- if (selfApply->getArg ()->isSuperExpr ()) {
856+ if (selfApply->getBase ()->isSuperExpr ()) {
854857 applySuper (selfApply);
855858 return ;
856859 }
@@ -960,14 +963,14 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
960963
961964 void processProtocolMethod (DeclRefExpr *e, AbstractFunctionDecl *afd,
962965 ProtocolDecl *proto) {
963- ArgumentSource selfValue = selfApply->getArg ();
966+ ArgumentSource selfValue = selfApply->getBase ();
964967
965968 auto subs = e->getDeclRef ().getSubstitutions ();
966969
967970 SILDeclRef::Kind kind = SILDeclRef::Kind::Func;
968971 if (isa<ConstructorDecl>(afd)) {
969972 if (proto->isObjC ()) {
970- SILLocation loc = selfApply->getArg ();
973+ SILLocation loc = selfApply->getBase ();
971974
972975 // For Objective-C initializers, we only have an initializing
973976 // initializer. We need to allocate the object ourselves.
@@ -1017,8 +1020,8 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
10171020
10181021 // Required constructors are statically dispatched when the 'self'
10191022 // 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 ())
10221025 return false ;
10231026 }
10241027
@@ -1027,7 +1030,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
10271030 }
10281031
10291032 void processClassMethod (DeclRefExpr *e, AbstractFunctionDecl *afd) {
1030- ArgumentSource selfArgSource (selfApply->getArg ());
1033+ ArgumentSource selfArgSource (selfApply->getBase ());
10311034 setSelfParam (std::move (selfArgSource));
10321035
10331036 // Directly dispatch to calls of the replaced function inside of
@@ -1036,7 +1039,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
10361039 if (SGF.getOptions ()
10371040 .EnableDynamicReplacementCanCallPreviousImplementation &&
10381041 isCallToReplacedInDynamicReplacement (SGF, afd, isObjCReplacementCall) &&
1039- selfApply->getArg ()->isSelfExprOf (
1042+ selfApply->getBase ()->isSelfExprOf (
10401043 cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()), false )) {
10411044 auto constant = SILDeclRef (afd).asForeign (
10421045 !isObjCReplacementCall && requiresForeignEntryPoint (e->getDecl ()));
@@ -1089,7 +1092,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
10891092 // Enum case constructor references are open-coded.
10901093 if (auto *eed = dyn_cast<EnumElementDecl>(e->getDecl ())) {
10911094 if (selfApply) {
1092- ArgumentSource selfArgSource (selfApply->getArg ());
1095+ ArgumentSource selfArgSource (selfApply->getBase ());
10931096 setSelfParam (std::move (selfArgSource));
10941097 }
10951098
@@ -1131,15 +1134,16 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11311134 // dynamically_replaceable inside of a dynamic_replacement(for:) function.
11321135 ApplyExpr *thisCallSite = (selfApply ? selfApply : callSite);
11331136 bool isObjCReplacementSelfCall = false ;
1137+ auto *unaryArg = thisCallSite->getArgs ()->getUnaryExpr ();
11341138 bool isSelfCallToReplacedInDynamicReplacement =
11351139 SGF.getOptions ()
11361140 .EnableDynamicReplacementCanCallPreviousImplementation &&
11371141 isCallToReplacedInDynamicReplacement (
11381142 SGF, cast<AbstractFunctionDecl>(constant.getDecl ()),
11391143 isObjCReplacementSelfCall) &&
11401144 (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 ))) ;
11431147
11441148 if (isSelfCallToReplacedInDynamicReplacement && !isObjCReplacementSelfCall)
11451149 setCallee (Callee::forDirect (
@@ -1152,7 +1156,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11521156
11531157 if (selfApply) {
11541158 // This is a statically-dispatched method with a 'self' parameter.
1155- ArgumentSource selfArgSource (selfApply->getArg ());
1159+ ArgumentSource selfArgSource (selfApply->getBase ());
11561160 setSelfParam (std::move (selfArgSource));
11571161 }
11581162
@@ -1259,9 +1263,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
12591263 visit (e->getSubExpr ());
12601264 }
12611265
1262- void applySuper (ApplyExpr *apply) {
1266+ void applySuper (SelfApplyExpr *apply) {
12631267 // Load the 'super' argument.
1264- Expr *arg = apply->getArg ();
1268+ Expr *arg = apply->getBase ();
12651269 RValue super;
12661270 CanType superFormalType = arg->getType ()->getCanonicalType ();
12671271
@@ -1400,7 +1404,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
14001404 }
14011405
14021406 // / Try to emit the given application as initializer delegation.
1403- bool applyInitDelegation (ApplyExpr *expr) {
1407+ bool applyInitDelegation (SelfApplyExpr *expr) {
14041408 // Dig out the constructor we're delegating to.
14051409 Expr *fn = expr->getFn ();
14061410 auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(
@@ -1439,7 +1443,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
14391443 }
14401444
14411445 // Load the 'self' argument.
1442- Expr *arg = expr->getArg ();
1446+ Expr *arg = expr->getBase ();
14431447 ManagedValue self;
14441448 CanType selfFormalType = arg->getType ()->getCanonicalType ();
14451449
@@ -4273,20 +4277,14 @@ CallEmission CallEmission::forApplyExpr(SILGenFunction &SGF, ApplyExpr *e) {
42734277 }
42744278
42754279 // 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 ());
42874285
42884286 // 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 ())
42904288 emission.setImplicitlyAsync (target);
42914289 }
42924290
@@ -5629,9 +5627,7 @@ PreparedArguments
56295627SILGenFunction::prepareSubscriptIndices (SubscriptDecl *subscript,
56305628 SubstitutionMap subs,
56315629 AccessStrategy strategy,
5632- Expr *indexExpr) {
5633- // FIXME: we should expect an array of index expressions.
5634-
5630+ ArgumentList *argList) {
56355631 // TODO: use the real abstraction pattern from the accessor(s) in the
56365632 // strategy.
56375633 // Currently we use the substituted type so that we can reconstitute these
@@ -5653,7 +5649,7 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
56535649
56545650 // Prepare the unevaluated index expression.
56555651 auto substParams = substFnType->getParams ();
5656- PreparedArguments args (substParams, indexExpr );
5652+ PreparedArguments args (substParams, argList );
56575653
56585654 // Now, force it to be evaluated.
56595655 SmallVector<ManagedValue, 4 > argValues;
@@ -5666,11 +5662,11 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
56665662 PreparedArguments result (substParams);
56675663
56685664 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 ();
56715667 auto count = RValue::getRValueSize (substParamType);
56725668 RValue elt (*this , remainingArgs.slice (0 , count), substParamType);
5673- result.add (indexExpr , std::move (elt));
5669+ result.add (argList-> getExpr (i) , std::move (elt));
56745670 remainingArgs = remainingArgs.slice (count);
56755671 }
56765672 assert (remainingArgs.empty ());
@@ -6178,7 +6174,9 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
61786174 SILValue base = managedBase.getValue ();
61796175
61806176 // Emit the index.
6181- RValue index = emitRValue (e->getIndex ());
6177+ auto *indexExpr = e->getArgs ()->getUnaryExpr ();
6178+ assert (indexExpr);
6179+ RValue index = emitRValue (indexExpr);
61826180
61836181 // Create the continuation block.
61846182 SILBasicBlock *contBB = createBasicBlock ();
@@ -6214,7 +6212,7 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
62146212 //
62156213 // FIXME: Verify ExtInfo state is correct, not working by accident.
62166214 CanFunctionType::ExtInfo methodInfo;
6217- FunctionType::Param indexArg (e-> getIndex () ->getType ()->getCanonicalType ());
6215+ FunctionType::Param indexArg (indexExpr ->getType ()->getCanonicalType ());
62186216 auto methodTy = CanFunctionType::get ({indexArg}, valueTy, methodInfo);
62196217 auto foreignMethodTy =
62206218 getPartialApplyOfDynamicMethodFormalType (SGM, member, e->getMember ());
@@ -6268,7 +6266,7 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
62686266}
62696267
62706268SmallVector<ManagedValue, 4 > SILGenFunction::emitKeyPathSubscriptOperands (
6271- SubscriptDecl *subscript, SubstitutionMap subs, Expr *indexExpr ) {
6269+ SubscriptDecl *subscript, SubstitutionMap subs, ArgumentList *argList ) {
62726270 Type interfaceType = subscript->getInterfaceType ();
62736271 CanFunctionType substFnType =
62746272 subs ? cast<FunctionType>(interfaceType->castTo <GenericFunctionType>()
@@ -6291,7 +6289,7 @@ SmallVector<ManagedValue, 4> SILGenFunction::emitKeyPathSubscriptOperands(
62916289 auto prepared =
62926290 prepareSubscriptIndices (subscript, subs,
62936291 // Strategy doesn't matter
6294- AccessStrategy::getStorage (), indexExpr );
6292+ AccessStrategy::getStorage (), argList );
62956293 emitter.emitPreparedArgs (std::move (prepared), origFnType);
62966294
62976295 if (!delayedArgs.empty ())
0 commit comments