Skip to content

Commit e606aad

Browse files
committed
SILGen: Remove uses of AbstractFunctionDecl::getParameterLists()
1 parent b0f59dc commit e606aad

File tree

8 files changed

+64
-62
lines changed

8 files changed

+64
-62
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,7 @@ emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
690690

691691
void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
692692
// Emit any default argument generators.
693-
if (!isa<DestructorDecl>(AFD)) {
694-
unsigned paramListIndex = AFD->getDeclContext()->isTypeContext() ? 1 : 0;
695-
auto *paramList = AFD->getParameterLists()[paramListIndex];
696-
emitDefaultArgGenerators(AFD, paramList);
697-
}
693+
emitDefaultArgGenerators(AFD, AFD->getParameters());
698694

699695
// If this is a function at global scope, it may close over a global variable.
700696
// If we're emitting top-level code, then emit a "mark_function_escape" that
@@ -1028,7 +1024,7 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
10281024
ASTContext &C = M.getASTContext();
10291025
auto *onceBuiltin =
10301026
cast<FuncDecl>(getBuiltinValueDecl(C, C.getIdentifier("once")));
1031-
auto blockParam = onceBuiltin->getParameterLists()[0]->get(1);
1027+
auto blockParam = onceBuiltin->getParameters()->get(1);
10321028
auto *type = blockParam->getType()->castTo<FunctionType>();
10331029
Type initType = FunctionType::get(TupleType::getEmpty(C),
10341030
TupleType::getEmpty(C), type->getExtInfo());

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,10 +4720,8 @@ static RValue emitApplyAllocatingInitializer(SILGenFunction &SGF,
47204720
bool requiresDowncast = false;
47214721
if (ctor->isRequired() && overriddenSelfType) {
47224722
CanType substResultType = substFormalType;
4723-
for (unsigned i : range(ctor->getNumParameterLists())) {
4724-
(void)i;
4725-
substResultType = cast<FunctionType>(substResultType).getResult();
4726-
}
4723+
substResultType = cast<FunctionType>(substResultType).getResult();
4724+
substResultType = cast<FunctionType>(substResultType).getResult();
47274725

47284726
if (!substResultType->isEqual(overriddenSelfType))
47294727
requiresDowncast = true;

lib/SILGen/SILGenBridging.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,24 +1601,6 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
16011601
}
16021602
ImportAsMemberStatus memberStatus = fd->getImportAsMemberStatus();
16031603

1604-
// Forward the arguments.
1605-
auto forwardedParameters = fd->getParameterLists();
1606-
1607-
// For allocating constructors, 'self' is a metatype, not the 'self' value
1608-
// formally present in the constructor body.
1609-
Type allocatorSelfType;
1610-
if (thunk.kind == SILDeclRef::Kind::Allocator) {
1611-
allocatorSelfType = forwardedParameters[0]
1612-
->getInterfaceType(getASTContext())
1613-
->getWithoutSpecifierType();
1614-
if (F.getGenericEnvironment())
1615-
allocatorSelfType = F.getGenericEnvironment()
1616-
->mapTypeIntoContext(allocatorSelfType);
1617-
forwardedParameters = forwardedParameters.slice(1);
1618-
}
1619-
1620-
SmallVector<SILValue, 8> params;
1621-
16221604
// Introduce indirect returns if necessary.
16231605
// TODO: Handle exploded results? We don't currently need to since the only
16241606
// bridged indirect type is Any.
@@ -1631,14 +1613,25 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
16311613
F.begin()->createFunctionArgument(nativeConv.getSingleSILResultType());
16321614
}
16331615

1634-
for (auto *paramList : reversed(forwardedParameters))
1635-
bindParametersForForwarding(paramList, params);
1616+
// Forward the arguments.
1617+
SmallVector<SILValue, 8> params;
1618+
1619+
bindParametersForForwarding(fd->getParameters(), params);
1620+
if (thunk.kind != SILDeclRef::Kind::Allocator)
1621+
if (auto *selfDecl = fd->getImplicitSelfDecl())
1622+
bindParameterForForwarding(selfDecl, params);
1623+
1624+
// For allocating constructors, 'self' is a metatype, not the 'self' value
1625+
// formally present in the constructor body.
1626+
Type allocatorSelfType;
1627+
if (thunk.kind == SILDeclRef::Kind::Allocator) {
1628+
auto *selfDecl = fd->getImplicitSelfDecl();
1629+
allocatorSelfType = F.mapTypeIntoContext(selfDecl->getInterfaceType());
16361630

1637-
if (allocatorSelfType) {
16381631
auto selfMetatype =
16391632
CanMetatypeType::get(allocatorSelfType->getCanonicalType());
16401633
auto selfArg = F.begin()->createFunctionArgument(
1641-
getLoweredLoadableType(selfMetatype), fd->getImplicitSelfDecl());
1634+
getLoweredLoadableType(selfMetatype), selfDecl);
16421635
params.push_back(selfArg);
16431636
}
16441637

lib/SILGen/SILGenConstructor.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
8686
RegularLocation Loc(ctor);
8787
Loc.markAutoGenerated();
8888
// FIXME: Handle 'self' along with the other arguments.
89-
auto *paramList = ctor->getParameterList(1);
89+
auto *paramList = ctor->getParameters();
9090
auto *selfDecl = ctor->getImplicitSelfDecl();
9191
auto selfTyCan = selfDecl->getType();
9292
auto selfIfaceTyCan = selfDecl->getInterfaceType();
@@ -231,7 +231,8 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
231231
SILValue selfLV = VarLocs[selfDecl].value;
232232

233233
// Emit the prolog.
234-
emitProlog(ctor->getParameterList(1),
234+
emitProlog(ctor->getParameters(),
235+
/*selfParam=*/nullptr,
235236
ctor->getResultInterfaceType(), ctor,
236237
ctor->hasThrows());
237238
emitConstructorMetatypeArg(*this, ctor);
@@ -464,7 +465,7 @@ void SILGenFunction::emitClassConstructorAllocator(ConstructorDecl *ctor) {
464465
// Forward the constructor arguments.
465466
// FIXME: Handle 'self' along with the other body patterns.
466467
SmallVector<SILValue, 8> args;
467-
bindParametersForForwarding(ctor->getParameterList(1), args);
468+
bindParametersForForwarding(ctor->getParameters(), args);
468469

469470
SILValue selfMetaValue = emitConstructorMetatypeArg(*this, ctor);
470471

@@ -595,7 +596,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
595596

596597
// Emit the prolog for the non-self arguments.
597598
// FIXME: Handle self along with the other body patterns.
598-
uint16_t ArgNo = emitProlog(ctor->getParameterList(1),
599+
uint16_t ArgNo = emitProlog(ctor->getParameters(), /*selfParam=*/nullptr,
599600
TupleType::getEmpty(F.getASTContext()), ctor,
600601
ctor->hasThrows());
601602

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4360,7 +4360,7 @@ static bool mayLieAboutNonOptionalReturn(SILModule &M, Expr *expr) {
43604360
// Only consider a full application of a method. Partial applications
43614361
// never lie.
43624362
if (auto func = dyn_cast<AbstractFunctionDecl>(fnRef->getDecl()))
4363-
if (func->getParameterLists().size() == 1)
4363+
if (func->getImplicitSelfDecl() == nullptr)
43644364
method = fnRef->getDecl();
43654365
}
43664366
if (method && mayLieAboutNonOptionalReturn(M, method))

lib/SILGen/SILGenFunction.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ SILGenFunction::emitClosureValue(SILLocation loc, SILDeclRef constant,
390390
void SILGenFunction::emitFunction(FuncDecl *fd) {
391391
MagicFunctionName = SILGenModule::getMagicFunctionName(fd);
392392

393-
emitProlog(fd, fd->getParameterLists(), fd->getResultInterfaceType(),
394-
fd->hasThrows());
393+
emitProlog(fd, fd->getParameters(), fd->getImplicitSelfDecl(),
394+
fd->getResultInterfaceType(), fd->hasThrows());
395395
Type resultTy = fd->mapTypeIntoContext(fd->getResultInterfaceType());
396396
prepareEpilog(resultTy, fd->hasThrows(), CleanupLocation(fd));
397397

@@ -405,8 +405,8 @@ void SILGenFunction::emitClosure(AbstractClosureExpr *ace) {
405405
MagicFunctionName = SILGenModule::getMagicFunctionName(ace);
406406

407407
auto resultIfaceTy = ace->getResultType()->mapTypeOutOfContext();
408-
emitProlog(ace, ace->getParameters(), resultIfaceTy,
409-
ace->isBodyThrowing());
408+
emitProlog(ace, ace->getParameters(), /*selfParam=*/nullptr,
409+
resultIfaceTy, ace->isBodyThrowing());
410410
prepareEpilog(ace->getResultType(), ace->isBodyThrowing(),
411411
CleanupLocation(ace));
412412
emitProfilerIncrement(ace);
@@ -631,7 +631,8 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value) {
631631

632632
auto *dc = function.getDecl()->getInnermostDeclContext();
633633
auto interfaceType = value->getType()->mapTypeOutOfContext();
634-
emitProlog({}, interfaceType, dc, false);
634+
emitProlog(/*paramList=*/nullptr, /*selfParam=*/nullptr, interfaceType,
635+
dc, false);
635636
prepareEpilog(value->getType(), false, CleanupLocation::get(Loc));
636637
emitReturnExpr(Loc, value);
637638
emitEpilog(Loc);

lib/SILGen/SILGenFunction.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,19 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
657657
/// emitProlog - Generates prolog code to allocate and clean up mutable
658658
/// storage for closure captures and local arguments.
659659
void emitProlog(AnyFunctionRef TheClosure,
660-
ArrayRef<ParameterList *> paramPatterns, Type resultType,
661-
bool throws);
660+
ParameterList *paramList, ParamDecl *selfParam,
661+
Type resultType, bool throws);
662662
/// returns the number of variables in paramPatterns.
663-
uint16_t emitProlog(ArrayRef<ParameterList *> paramPatterns, Type resultType,
664-
DeclContext *DeclCtx, bool throws);
663+
uint16_t emitProlog(ParameterList *paramList, ParamDecl *selfParam,
664+
Type resultType, DeclContext *DeclCtx, bool throws);
665+
666+
/// Create SILArguments in the entry block that bind a single value
667+
/// of the given parameter suitably for being forwarded.
668+
void bindParameterForForwarding(ParamDecl *param,
669+
SmallVectorImpl<SILValue> &parameters);
665670

666671
/// Create SILArguments in the entry block that bind all the values
667-
/// of the given pattern suitably for being forwarded.
672+
/// of the given parameter list suitably for being forwarded.
668673
void bindParametersForForwarding(const ParameterList *params,
669674
SmallVectorImpl<SILValue> &parameters);
670675

lib/SILGen/SILGenProlog.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,18 @@ static void makeArgument(Type ty, ParamDecl *decl,
335335
}
336336

337337

338+
void SILGenFunction::bindParameterForForwarding(ParamDecl *param,
339+
SmallVectorImpl<SILValue> &parameters) {
340+
Type type = (param->hasType()
341+
? param->getType()
342+
: F.mapTypeIntoContext(param->getInterfaceType()));
343+
makeArgument(type->eraseDynamicSelfType(), param, parameters, *this);
344+
}
345+
338346
void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
339347
SmallVectorImpl<SILValue> &parameters) {
340-
for (auto param : *params) {
341-
Type type = (param->hasType()
342-
? param->getType()
343-
: F.mapTypeIntoContext(param->getInterfaceType()));
344-
makeArgument(type->eraseDynamicSelfType(), param, parameters, *this);
345-
}
348+
for (auto param : *params)
349+
bindParameterForForwarding(param, parameters);
346350
}
347351

348352
static void emitCaptureArguments(SILGenFunction &SGF,
@@ -431,9 +435,10 @@ static void emitCaptureArguments(SILGenFunction &SGF,
431435
}
432436

433437
void SILGenFunction::emitProlog(AnyFunctionRef TheClosure,
434-
ArrayRef<ParameterList*> paramPatterns,
438+
ParameterList *paramList,
439+
ParamDecl *selfParam,
435440
Type resultType, bool throws) {
436-
uint16_t ArgNo = emitProlog(paramPatterns, resultType,
441+
uint16_t ArgNo = emitProlog(paramList, selfParam, resultType,
437442
TheClosure.getAsDeclContext(), throws);
438443

439444
// Emit the capture argument variables. These are placed last because they
@@ -485,8 +490,10 @@ static void emitIndirectResultParameters(SILGenFunction &SGF, Type resultType,
485490
(void)arg;
486491
}
487492

488-
uint16_t SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
489-
Type resultType, DeclContext *DC,
493+
uint16_t SILGenFunction::emitProlog(ParameterList *paramList,
494+
ParamDecl *selfParam,
495+
Type resultType,
496+
DeclContext *DC,
490497
bool throws) {
491498
// Create the indirect result parameters.
492499
auto *genericSig = DC->getGenericSignatureOfContext();
@@ -497,12 +504,13 @@ uint16_t SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
497504
// Emit the argument variables in calling convention order.
498505
ArgumentInitHelper emitter(*this, F);
499506

500-
for (ParameterList *paramList : reversed(paramLists)) {
501-
// Add the SILArguments and use them to initialize the local argument
502-
// values.
503-
for (auto &param : *paramList)
507+
// Add the SILArguments and use them to initialize the local argument
508+
// values.
509+
if (paramList)
510+
for (auto *param : *paramList)
504511
emitter.emitParam(param);
505-
}
512+
if (selfParam)
513+
emitter.emitParam(selfParam);
506514

507515
// Record the ArgNo of the artificial $error inout argument.
508516
unsigned ArgNo = emitter.getNumArgs();

0 commit comments

Comments
 (0)