23
23
#include " swift/AST/ParameterList.h"
24
24
#include " swift/AST/PropertyWrappers.h"
25
25
#include " swift/Basic/Defer.h"
26
+ #include " swift/Basic/Generators.h"
26
27
#include " swift/SIL/SILArgument.h"
27
28
#include " swift/SIL/SILArgumentConvention.h"
28
29
#include " swift/SIL/SILInstruction.h"
@@ -76,22 +77,22 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
76
77
SILBasicBlock *parent;
77
78
SILLocation loc;
78
79
CanSILFunctionType fnTy;
79
- ArrayRef<SILParameterInfo> ¶meters;
80
+ ArrayRefGenerator< ArrayRef<SILParameterInfo> > ¶meters;
80
81
bool isNoImplicitCopy;
81
82
LifetimeAnnotation lifetimeAnnotation;
82
83
83
84
EmitBBArguments (SILGenFunction &sgf, SILBasicBlock *parent, SILLocation l,
84
85
CanSILFunctionType fnTy,
85
- ArrayRef<SILParameterInfo> ¶meters, bool isNoImplicitCopy,
86
+ ArrayRefGenerator<ArrayRef<SILParameterInfo>> ¶meters,
87
+ bool isNoImplicitCopy,
86
88
LifetimeAnnotation lifetimeAnnotation)
87
89
: SGF(sgf), parent(parent), loc(l), fnTy(fnTy), parameters(parameters),
88
90
isNoImplicitCopy (isNoImplicitCopy),
89
91
lifetimeAnnotation(lifetimeAnnotation) {}
90
92
91
93
ManagedValue claimNextParameter () {
92
94
// Pop the next parameter info.
93
- auto parameterInfo = parameters.front ();
94
- parameters = parameters.slice (1 );
95
+ auto parameterInfo = parameters.claimNext ();
95
96
96
97
auto paramType =
97
98
SGF.F .mapTypeIntoContext (SGF.getSILType (parameterInfo, fnTy));
@@ -408,28 +409,48 @@ namespace {
408
409
409
410
// / A helper for creating SILArguments and binding variables to the argument
410
411
// / names.
411
- struct ArgumentInitHelper {
412
+ class ArgumentInitHelper {
412
413
SILGenFunction &SGF;
413
414
SILFunction &f;
414
- SILGenBuilder &initB;
415
415
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;
419
417
uint16_t ArgNo = 0 ;
420
418
421
419
Optional<AbstractionPattern> OrigFnType;
422
420
421
+ public:
423
422
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),
426
426
parameters (
427
427
f.getLoweredFunctionTypeInContext(SGF.B.getTypeExpansionContext())
428
- ->getParameters()),
428
+ ->getParameters().drop_back(numIgnoredTrailingParameters) ),
429
429
OrigFnType(origFnType)
430
430
{}
431
431
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
+ }
433
454
434
455
ManagedValue makeArgument (Type ty, bool isInOut, bool isNoImplicitCopy,
435
456
LifetimeAnnotation lifetime, SILBasicBlock *parent,
@@ -845,13 +866,17 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
845
866
bool throws,
846
867
SourceLoc throwsLoc,
847
868
Optional<AbstractionPattern> origClosureType) {
848
- uint16_t ArgNo = emitBasicProlog (paramList, selfParam, resultType,
849
- DC, throws, throwsLoc, origClosureType);
850
-
851
869
// Emit the capture argument variables. These are placed last because they
852
870
// become the first curry level of the SIL function.
853
871
assert (captureInfo.hasBeenComputed () &&
854
872
" 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
+
855
880
for (auto capture : captureInfo.getCaptures ()) {
856
881
if (capture.isDynamicSelfMetadata ()) {
857
882
auto selfMetatype = MetatypeType::get (
@@ -1335,6 +1360,7 @@ uint16_t SILGenFunction::emitBasicProlog(ParameterList *paramList,
1335
1360
DeclContext *DC,
1336
1361
bool throws,
1337
1362
SourceLoc throwsLoc,
1363
+ unsigned numIgnoredTrailingParameters,
1338
1364
Optional<AbstractionPattern> origClosureType) {
1339
1365
// Create the indirect result parameters.
1340
1366
auto genericSig = DC->getGenericSignatureOfContext ();
@@ -1348,18 +1374,12 @@ uint16_t SILGenFunction::emitBasicProlog(ParameterList *paramList,
1348
1374
emitIndirectResultParameters (*this , resultType, origResultType, DC);
1349
1375
1350
1376
// 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);
1360
1381
1361
1382
// Record the ArgNo of the artificial $error inout argument.
1362
- unsigned ArgNo = emitter.getNumArgs ();
1363
1383
if (throws) {
1364
1384
auto NativeErrorTy = SILType::getExceptionType (getASTContext ());
1365
1385
ManagedValue Undef = emitUndef (NativeErrorTy);
0 commit comments