2323#include " swift/AST/ParameterList.h"
2424#include " swift/AST/PropertyWrappers.h"
2525#include " swift/Basic/Defer.h"
26+ #include " swift/Basic/Generators.h"
2627#include " swift/SIL/SILArgument.h"
2728#include " swift/SIL/SILArgumentConvention.h"
2829#include " swift/SIL/SILInstruction.h"
@@ -76,22 +77,22 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
7677 SILBasicBlock *parent;
7778 SILLocation loc;
7879 CanSILFunctionType fnTy;
79- ArrayRef<SILParameterInfo> ¶meters;
80+ ArrayRefGenerator< ArrayRef<SILParameterInfo> > ¶meters;
8081 bool isNoImplicitCopy;
8182 LifetimeAnnotation lifetimeAnnotation;
8283
8384 EmitBBArguments (SILGenFunction &sgf, SILBasicBlock *parent, SILLocation l,
8485 CanSILFunctionType fnTy,
85- ArrayRef<SILParameterInfo> ¶meters, bool isNoImplicitCopy,
86+ ArrayRefGenerator<ArrayRef<SILParameterInfo>> ¶meters,
87+ bool isNoImplicitCopy,
8688 LifetimeAnnotation lifetimeAnnotation)
8789 : SGF(sgf), parent(parent), loc(l), fnTy(fnTy), parameters(parameters),
8890 isNoImplicitCopy (isNoImplicitCopy),
8991 lifetimeAnnotation(lifetimeAnnotation) {}
9092
9193 ManagedValue claimNextParameter () {
9294 // Pop the next parameter info.
93- auto parameterInfo = parameters.front ();
94- parameters = parameters.slice (1 );
95+ auto parameterInfo = parameters.claimNext ();
9596
9697 auto paramType =
9798 SGF.F .mapTypeIntoContext (SGF.getSILType (parameterInfo, fnTy));
@@ -408,28 +409,48 @@ namespace {
408409
409410// / A helper for creating SILArguments and binding variables to the argument
410411// / names.
411- struct ArgumentInitHelper {
412+ class ArgumentInitHelper {
412413 SILGenFunction &SGF;
413414 SILFunction &f;
414- SILGenBuilder &initB;
415415
416- // / An ArrayRef that we use in our SILParameterList queue. Parameters are
417- // / sliced off of the front as they're emitted.
418- ArrayRef<SILParameterInfo> parameters;
416+ ArrayRefGenerator<ArrayRef<SILParameterInfo>> parameters;
419417 uint16_t ArgNo = 0 ;
420418
421419 Optional<AbstractionPattern> OrigFnType;
422420
421+ public:
423422 ArgumentInitHelper (SILGenFunction &SGF, SILFunction &f,
424- Optional<AbstractionPattern> origFnType)
425- : SGF(SGF), f(f), initB(SGF.B),
423+ Optional<AbstractionPattern> origFnType,
424+ unsigned numIgnoredTrailingParameters)
425+ : SGF(SGF), f(f),
426426 parameters (
427427 f.getLoweredFunctionTypeInContext(SGF.B.getTypeExpansionContext())
428- ->getParameters()),
428+ ->getParameters().drop_back(numIgnoredTrailingParameters) ),
429429 OrigFnType(origFnType)
430430 {}
431431
432- unsigned getNumArgs () const { return ArgNo; }
432+ // / Emit the given list of parameters.
433+ unsigned emitParams (ParameterList *paramList, ParamDecl *selfParam) {
434+ if (paramList) {
435+ for (auto *param : *paramList)
436+ emitParam (param);
437+ }
438+
439+ // The self parameter follows the formal parameters in all of
440+ // our representations.
441+ if (selfParam) {
442+ emitParam (selfParam);
443+ }
444+
445+ finish ();
446+
447+ return ArgNo;
448+ }
449+
450+ private:
451+ void finish () {
452+ parameters.finish ();
453+ }
433454
434455 ManagedValue makeArgument (Type ty, bool isInOut, bool isNoImplicitCopy,
435456 LifetimeAnnotation lifetime, SILBasicBlock *parent,
@@ -845,13 +866,17 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
845866 bool throws,
846867 SourceLoc throwsLoc,
847868 Optional<AbstractionPattern> origClosureType) {
848- uint16_t ArgNo = emitBasicProlog (paramList, selfParam, resultType,
849- DC, throws, throwsLoc, origClosureType);
850-
851869 // Emit the capture argument variables. These are placed last because they
852870 // become the first curry level of the SIL function.
853871 assert (captureInfo.hasBeenComputed () &&
854872 " can't emit prolog of function with uncomputed captures" );
873+
874+ uint16_t ArgNo = emitBasicProlog (paramList, selfParam, resultType,
875+ DC, throws, throwsLoc,
876+ /* ignored parameters*/
877+ captureInfo.getCaptures ().size (),
878+ origClosureType);
879+
855880 for (auto capture : captureInfo.getCaptures ()) {
856881 if (capture.isDynamicSelfMetadata ()) {
857882 auto selfMetatype = MetatypeType::get (
@@ -1335,6 +1360,7 @@ uint16_t SILGenFunction::emitBasicProlog(ParameterList *paramList,
13351360 DeclContext *DC,
13361361 bool throws,
13371362 SourceLoc throwsLoc,
1363+ unsigned numIgnoredTrailingParameters,
13381364 Optional<AbstractionPattern> origClosureType) {
13391365 // Create the indirect result parameters.
13401366 auto genericSig = DC->getGenericSignatureOfContext ();
@@ -1348,18 +1374,12 @@ uint16_t SILGenFunction::emitBasicProlog(ParameterList *paramList,
13481374 emitIndirectResultParameters (*this , resultType, origResultType, DC);
13491375
13501376 // Emit the argument variables in calling convention order.
1351- ArgumentInitHelper emitter (*this , F, origClosureType);
1352-
1353- // Add the SILArguments and use them to initialize the local argument
1354- // values.
1355- if (paramList)
1356- for (auto *param : *paramList)
1357- emitter.emitParam (param);
1358- if (selfParam)
1359- emitter.emitParam (selfParam);
1377+ unsigned ArgNo =
1378+ ArgumentInitHelper (*this , F, origClosureType,
1379+ numIgnoredTrailingParameters)
1380+ .emitParams (paramList, selfParam);
13601381
13611382 // Record the ArgNo of the artificial $error inout argument.
1362- unsigned ArgNo = emitter.getNumArgs ();
13631383 if (throws) {
13641384 auto NativeErrorTy = SILType::getExceptionType (getASTContext ());
13651385 ManagedValue Undef = emitUndef (NativeErrorTy);
0 commit comments