Skip to content

Commit 16fb73d

Browse files
authored
Merge pull request #18102 from slavapestov/keep-killing-parameter-lists
Keep killing multiple parameter lists
2 parents 1380590 + e606aad commit 16fb73d

36 files changed

+285
-351
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
838838
lhs = new (C) MemberRefExpr(lhs, SourceLoc(), anonymousInnerFieldDecl,
839839
DeclNameLoc(), /*implicit*/true);
840840

841-
auto newValueDecl = setterDecl->getParameterList(1)->get(0);
841+
auto newValueDecl = setterDecl->getParameters()->get(0);
842842

843843
auto rhs = new (C) DeclRefExpr(newValueDecl, DeclNameLoc(),
844844
/*implicit*/ true);
@@ -922,7 +922,7 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
922922
auto inoutSelf = new (C) InOutExpr(SourceLoc(), inoutSelfRef,
923923
importedUnionDecl->getDeclaredType(), /*implicit*/ true);
924924

925-
auto newValueDecl = setterDecl->getParameterList(1)->get(0);
925+
auto newValueDecl = setterDecl->getParameters()->get(0);
926926

927927
auto newValueRef = new (C) DeclRefExpr(newValueDecl, DeclNameLoc(),
928928
/*implicit*/ true);
@@ -1463,8 +1463,7 @@ static ConstructorDecl *createRawValueBridgingConstructor(
14631463
/*wantBody=*/false);
14641464
// Insert our custom init body
14651465
if (wantBody) {
1466-
auto selfDecl = init->getParameterList(0)->get(0);
1467-
1466+
auto selfDecl = init->getImplicitSelfDecl();
14681467
auto storedType = storedRawValue->getInterfaceType();
14691468

14701469
// Construct left-hand side.
@@ -1479,7 +1478,7 @@ static ConstructorDecl *createRawValueBridgingConstructor(
14791478

14801479
// Construct right-hand side.
14811480
// FIXME: get the parameter from the init, and plug it in here.
1482-
auto *paramDecl = init->getParameterList(1)->get(0);
1481+
auto *paramDecl = init->getParameters()->get(0);
14831482
auto *paramRef = new (ctx) DeclRefExpr(
14841483
paramDecl, DeclNameLoc(), /*Implicit=*/true);
14851484
paramRef->setType(paramDecl->getType());
@@ -1672,7 +1671,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
16721671
//
16731672
// Build a setter thunk with the latter signature that maps to the
16741673
// former.
1675-
auto valueIndex = setter->getParameterList(1);
1674+
auto valueIndex = setter->getParameters();
16761675

16771676
// 'self'
16781677
auto selfDecl = ParamDecl::createSelf(SourceLoc(), dc);
@@ -1728,7 +1727,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
17281727
/// Retrieve the element interface type and key param decl of a subscript
17291728
/// setter.
17301729
static std::pair<Type, ParamDecl *> decomposeSubscriptSetter(FuncDecl *setter) {
1731-
auto *PL = setter->getParameterList(1);
1730+
auto *PL = setter->getParameters();
17321731
if (PL->size() != 2)
17331732
return {nullptr, nullptr};
17341733

@@ -4810,8 +4809,8 @@ namespace {
48104809
// different (usually in something like nullability), but for Swift it's
48114810
// an AST invariant that's assumed and asserted elsewhere. If the type is
48124811
// different, just drop the setter, and leave the property as get-only.
4813-
assert(setter->getParameterLists().back()->size() == 1);
4814-
const ParamDecl *param = setter->getParameterLists().back()->get(0);
4812+
assert(setter->getParameters()->size() == 1);
4813+
const ParamDecl *param = setter->getParameters()->get(0);
48154814
if (!param->getInterfaceType()->isEqual(original->getInterfaceType()))
48164815
return;
48174816

@@ -6621,7 +6620,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
66216620
// Find the getter indices and make sure they match.
66226621
ParamDecl *getterIndex;
66236622
{
6624-
auto params = getter->getParameterList(1);
6623+
auto params = getter->getParameters();
66256624
if (params->size() != 1)
66266625
return nullptr;
66276626
getterIndex = params->get(0);
@@ -6630,11 +6629,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
66306629
// Compute the element type based on the getter, looking through
66316630
// the implicit 'self' parameter and the normal function
66326631
// parameters.
6633-
auto elementTy = getter->getInterfaceType()
6634-
->castTo<AnyFunctionType>()
6635-
->getResult()
6636-
->castTo<AnyFunctionType>()
6637-
->getResult();
6632+
auto elementTy = getter->getResultInterfaceType();
66386633
auto elementContextTy = getter->mapTypeIntoContext(elementTy);
66396634

66406635
// Local function to mark the setter unavailable.

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,10 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
590590

591591
os << ")";
592592

593-
auto paramLists = AFD->getParameterLists();
594-
assert(paramLists.size() == 2 && "not an ObjC-compatible method");
595-
596593
auto selector = AFD->getObjCSelector();
597594
ArrayRef<Identifier> selectorPieces = selector.getSelectorPieces();
598595

599-
const auto &params = paramLists[1]->getArray();
596+
const auto &params = AFD->getParameters()->getArray();
600597
unsigned paramIndex = 0;
601598
for (unsigned i = 0, n = selectorPieces.size(); i != n; ++i) {
602599
if (i > 0) os << ' ';
@@ -744,8 +741,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
744741

745742
os << ' ' << FD->getAttrs().getAttribute<CDeclAttr>()->Name << '(';
746743

747-
assert(FD->getParameterLists().size() == 1 && "not a C-compatible func");
748-
auto params = FD->getParameterLists().back();
744+
auto params = FD->getParameters();
749745
if (params->size()) {
750746
interleave(*params,
751747
[&](const ParamDecl *param) {

lib/SIL/SILDeclRef.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc,
145145
} else if (auto *ACE = baseLoc.dyn_cast<AbstractClosureExpr *>()) {
146146
loc = ACE;
147147
kind = Kind::Func;
148-
assert(ACE->getParameterLists().size() >= 1 &&
149-
"no param patterns for function?!");
150148
} else {
151149
llvm_unreachable("impossible SILDeclRef loc");
152150
}
@@ -810,7 +808,7 @@ unsigned SILDeclRef::getParameterListCount() const {
810808
auto *vd = getDecl();
811809

812810
if (auto *func = dyn_cast<AbstractFunctionDecl>(vd)) {
813-
return func->getParameterLists().size();
811+
return func->getImplicitSelfDecl() ? 2 : 1;
814812
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) {
815813
return ed->hasAssociatedValues() ? 2 : 1;
816814
} else if (isa<ClassDecl>(vd)) {

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
@@ -4352,7 +4352,7 @@ static bool mayLieAboutNonOptionalReturn(SILModule &M, Expr *expr) {
43524352
// Only consider a full application of a method. Partial applications
43534353
// never lie.
43544354
if (auto func = dyn_cast<AbstractFunctionDecl>(fnRef->getDecl()))
4355-
if (func->getParameterLists().size() == 1)
4355+
if (func->getImplicitSelfDecl() == nullptr)
43564356
method = fnRef->getDecl();
43574357
}
43584358
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)