Skip to content

Keep killing multiple parameter lists #18102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
lhs = new (C) MemberRefExpr(lhs, SourceLoc(), anonymousInnerFieldDecl,
DeclNameLoc(), /*implicit*/true);

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

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

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

auto newValueRef = new (C) DeclRefExpr(newValueDecl, DeclNameLoc(),
/*implicit*/ true);
Expand Down Expand Up @@ -1463,8 +1463,7 @@ static ConstructorDecl *createRawValueBridgingConstructor(
/*wantBody=*/false);
// Insert our custom init body
if (wantBody) {
auto selfDecl = init->getParameterList(0)->get(0);

auto selfDecl = init->getImplicitSelfDecl();
auto storedType = storedRawValue->getInterfaceType();

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

// Construct right-hand side.
// FIXME: get the parameter from the init, and plug it in here.
auto *paramDecl = init->getParameterList(1)->get(0);
auto *paramDecl = init->getParameters()->get(0);
auto *paramRef = new (ctx) DeclRefExpr(
paramDecl, DeclNameLoc(), /*Implicit=*/true);
paramRef->setType(paramDecl->getType());
Expand Down Expand Up @@ -1672,7 +1671,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
//
// Build a setter thunk with the latter signature that maps to the
// former.
auto valueIndex = setter->getParameterList(1);
auto valueIndex = setter->getParameters();

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

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

Expand Down Expand Up @@ -6621,7 +6620,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
// Find the getter indices and make sure they match.
ParamDecl *getterIndex;
{
auto params = getter->getParameterList(1);
auto params = getter->getParameters();
if (params->size() != 1)
return nullptr;
getterIndex = params->get(0);
Expand All @@ -6630,11 +6629,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
// Compute the element type based on the getter, looking through
// the implicit 'self' parameter and the normal function
// parameters.
auto elementTy = getter->getInterfaceType()
->castTo<AnyFunctionType>()
->getResult()
->castTo<AnyFunctionType>()
->getResult();
auto elementTy = getter->getResultInterfaceType();
auto elementContextTy = getter->mapTypeIntoContext(elementTy);

// Local function to mark the setter unavailable.
Expand Down
8 changes: 2 additions & 6 deletions lib/PrintAsObjC/PrintAsObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,10 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,

os << ")";

auto paramLists = AFD->getParameterLists();
assert(paramLists.size() == 2 && "not an ObjC-compatible method");

auto selector = AFD->getObjCSelector();
ArrayRef<Identifier> selectorPieces = selector.getSelectorPieces();

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

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

assert(FD->getParameterLists().size() == 1 && "not a C-compatible func");
auto params = FD->getParameterLists().back();
auto params = FD->getParameters();
if (params->size()) {
interleave(*params,
[&](const ParamDecl *param) {
Expand Down
4 changes: 1 addition & 3 deletions lib/SIL/SILDeclRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc,
} else if (auto *ACE = baseLoc.dyn_cast<AbstractClosureExpr *>()) {
loc = ACE;
kind = Kind::Func;
assert(ACE->getParameterLists().size() >= 1 &&
"no param patterns for function?!");
} else {
llvm_unreachable("impossible SILDeclRef loc");
}
Expand Down Expand Up @@ -810,7 +808,7 @@ unsigned SILDeclRef::getParameterListCount() const {
auto *vd = getDecl();

if (auto *func = dyn_cast<AbstractFunctionDecl>(vd)) {
return func->getParameterLists().size();
return func->getImplicitSelfDecl() ? 2 : 1;
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) {
return ed->hasAssociatedValues() ? 2 : 1;
} else if (isa<ClassDecl>(vd)) {
Expand Down
8 changes: 2 additions & 6 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,7 @@ emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,

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

// If this is a function at global scope, it may close over a global variable.
// If we're emitting top-level code, then emit a "mark_function_escape" that
Expand Down Expand Up @@ -1028,7 +1024,7 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
ASTContext &C = M.getASTContext();
auto *onceBuiltin =
cast<FuncDecl>(getBuiltinValueDecl(C, C.getIdentifier("once")));
auto blockParam = onceBuiltin->getParameterLists()[0]->get(1);
auto blockParam = onceBuiltin->getParameters()->get(1);
auto *type = blockParam->getType()->castTo<FunctionType>();
Type initType = FunctionType::get(TupleType::getEmpty(C),
TupleType::getEmpty(C), type->getExtInfo());
Expand Down
6 changes: 2 additions & 4 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4720,10 +4720,8 @@ static RValue emitApplyAllocatingInitializer(SILGenFunction &SGF,
bool requiresDowncast = false;
if (ctor->isRequired() && overriddenSelfType) {
CanType substResultType = substFormalType;
for (unsigned i : range(ctor->getNumParameterLists())) {
(void)i;
substResultType = cast<FunctionType>(substResultType).getResult();
}
substResultType = cast<FunctionType>(substResultType).getResult();
substResultType = cast<FunctionType>(substResultType).getResult();

if (!substResultType->isEqual(overriddenSelfType))
requiresDowncast = true;
Expand Down
37 changes: 15 additions & 22 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,24 +1601,6 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
}
ImportAsMemberStatus memberStatus = fd->getImportAsMemberStatus();

// Forward the arguments.
auto forwardedParameters = fd->getParameterLists();

// For allocating constructors, 'self' is a metatype, not the 'self' value
// formally present in the constructor body.
Type allocatorSelfType;
if (thunk.kind == SILDeclRef::Kind::Allocator) {
allocatorSelfType = forwardedParameters[0]
->getInterfaceType(getASTContext())
->getWithoutSpecifierType();
if (F.getGenericEnvironment())
allocatorSelfType = F.getGenericEnvironment()
->mapTypeIntoContext(allocatorSelfType);
forwardedParameters = forwardedParameters.slice(1);
}

SmallVector<SILValue, 8> params;

// Introduce indirect returns if necessary.
// TODO: Handle exploded results? We don't currently need to since the only
// bridged indirect type is Any.
Expand All @@ -1631,14 +1613,25 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
F.begin()->createFunctionArgument(nativeConv.getSingleSILResultType());
}

for (auto *paramList : reversed(forwardedParameters))
bindParametersForForwarding(paramList, params);
// Forward the arguments.
SmallVector<SILValue, 8> params;

bindParametersForForwarding(fd->getParameters(), params);
if (thunk.kind != SILDeclRef::Kind::Allocator)
if (auto *selfDecl = fd->getImplicitSelfDecl())
bindParameterForForwarding(selfDecl, params);

// For allocating constructors, 'self' is a metatype, not the 'self' value
// formally present in the constructor body.
Type allocatorSelfType;
if (thunk.kind == SILDeclRef::Kind::Allocator) {
auto *selfDecl = fd->getImplicitSelfDecl();
allocatorSelfType = F.mapTypeIntoContext(selfDecl->getInterfaceType());

if (allocatorSelfType) {
auto selfMetatype =
CanMetatypeType::get(allocatorSelfType->getCanonicalType());
auto selfArg = F.begin()->createFunctionArgument(
getLoweredLoadableType(selfMetatype), fd->getImplicitSelfDecl());
getLoweredLoadableType(selfMetatype), selfDecl);
params.push_back(selfArg);
}

Expand Down
9 changes: 5 additions & 4 deletions lib/SILGen/SILGenConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
RegularLocation Loc(ctor);
Loc.markAutoGenerated();
// FIXME: Handle 'self' along with the other arguments.
auto *paramList = ctor->getParameterList(1);
auto *paramList = ctor->getParameters();
auto *selfDecl = ctor->getImplicitSelfDecl();
auto selfTyCan = selfDecl->getType();
auto selfIfaceTyCan = selfDecl->getInterfaceType();
Expand Down Expand Up @@ -231,7 +231,8 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
SILValue selfLV = VarLocs[selfDecl].value;

// Emit the prolog.
emitProlog(ctor->getParameterList(1),
emitProlog(ctor->getParameters(),
/*selfParam=*/nullptr,
ctor->getResultInterfaceType(), ctor,
ctor->hasThrows());
emitConstructorMetatypeArg(*this, ctor);
Expand Down Expand Up @@ -464,7 +465,7 @@ void SILGenFunction::emitClassConstructorAllocator(ConstructorDecl *ctor) {
// Forward the constructor arguments.
// FIXME: Handle 'self' along with the other body patterns.
SmallVector<SILValue, 8> args;
bindParametersForForwarding(ctor->getParameterList(1), args);
bindParametersForForwarding(ctor->getParameters(), args);

SILValue selfMetaValue = emitConstructorMetatypeArg(*this, ctor);

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

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

Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4360,7 +4360,7 @@ static bool mayLieAboutNonOptionalReturn(SILModule &M, Expr *expr) {
// Only consider a full application of a method. Partial applications
// never lie.
if (auto func = dyn_cast<AbstractFunctionDecl>(fnRef->getDecl()))
if (func->getParameterLists().size() == 1)
if (func->getImplicitSelfDecl() == nullptr)
method = fnRef->getDecl();
}
if (method && mayLieAboutNonOptionalReturn(M, method))
Expand Down
11 changes: 6 additions & 5 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ SILGenFunction::emitClosureValue(SILLocation loc, SILDeclRef constant,
void SILGenFunction::emitFunction(FuncDecl *fd) {
MagicFunctionName = SILGenModule::getMagicFunctionName(fd);

emitProlog(fd, fd->getParameterLists(), fd->getResultInterfaceType(),
fd->hasThrows());
emitProlog(fd, fd->getParameters(), fd->getImplicitSelfDecl(),
fd->getResultInterfaceType(), fd->hasThrows());
Type resultTy = fd->mapTypeIntoContext(fd->getResultInterfaceType());
prepareEpilog(resultTy, fd->hasThrows(), CleanupLocation(fd));

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

auto resultIfaceTy = ace->getResultType()->mapTypeOutOfContext();
emitProlog(ace, ace->getParameters(), resultIfaceTy,
ace->isBodyThrowing());
emitProlog(ace, ace->getParameters(), /*selfParam=*/nullptr,
resultIfaceTy, ace->isBodyThrowing());
prepareEpilog(ace->getResultType(), ace->isBodyThrowing(),
CleanupLocation(ace));
emitProfilerIncrement(ace);
Expand Down Expand Up @@ -631,7 +631,8 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value) {

auto *dc = function.getDecl()->getInnermostDeclContext();
auto interfaceType = value->getType()->mapTypeOutOfContext();
emitProlog({}, interfaceType, dc, false);
emitProlog(/*paramList=*/nullptr, /*selfParam=*/nullptr, interfaceType,
dc, false);
prepareEpilog(value->getType(), false, CleanupLocation::get(Loc));
emitReturnExpr(Loc, value);
emitEpilog(Loc);
Expand Down
15 changes: 10 additions & 5 deletions lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,19 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
/// emitProlog - Generates prolog code to allocate and clean up mutable
/// storage for closure captures and local arguments.
void emitProlog(AnyFunctionRef TheClosure,
ArrayRef<ParameterList *> paramPatterns, Type resultType,
bool throws);
ParameterList *paramList, ParamDecl *selfParam,
Type resultType, bool throws);
/// returns the number of variables in paramPatterns.
uint16_t emitProlog(ArrayRef<ParameterList *> paramPatterns, Type resultType,
DeclContext *DeclCtx, bool throws);
uint16_t emitProlog(ParameterList *paramList, ParamDecl *selfParam,
Type resultType, DeclContext *DeclCtx, bool throws);

/// Create SILArguments in the entry block that bind a single value
/// of the given parameter suitably for being forwarded.
void bindParameterForForwarding(ParamDecl *param,
SmallVectorImpl<SILValue> &parameters);

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

Expand Down
38 changes: 23 additions & 15 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,18 @@ static void makeArgument(Type ty, ParamDecl *decl,
}


void SILGenFunction::bindParameterForForwarding(ParamDecl *param,
SmallVectorImpl<SILValue> &parameters) {
Type type = (param->hasType()
? param->getType()
: F.mapTypeIntoContext(param->getInterfaceType()));
makeArgument(type->eraseDynamicSelfType(), param, parameters, *this);
}

void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
SmallVectorImpl<SILValue> &parameters) {
for (auto param : *params) {
Type type = (param->hasType()
? param->getType()
: F.mapTypeIntoContext(param->getInterfaceType()));
makeArgument(type->eraseDynamicSelfType(), param, parameters, *this);
}
for (auto param : *params)
bindParameterForForwarding(param, parameters);
}

static void emitCaptureArguments(SILGenFunction &SGF,
Expand Down Expand Up @@ -431,9 +435,10 @@ static void emitCaptureArguments(SILGenFunction &SGF,
}

void SILGenFunction::emitProlog(AnyFunctionRef TheClosure,
ArrayRef<ParameterList*> paramPatterns,
ParameterList *paramList,
ParamDecl *selfParam,
Type resultType, bool throws) {
uint16_t ArgNo = emitProlog(paramPatterns, resultType,
uint16_t ArgNo = emitProlog(paramList, selfParam, resultType,
TheClosure.getAsDeclContext(), throws);

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

uint16_t SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
Type resultType, DeclContext *DC,
uint16_t SILGenFunction::emitProlog(ParameterList *paramList,
ParamDecl *selfParam,
Type resultType,
DeclContext *DC,
bool throws) {
// Create the indirect result parameters.
auto *genericSig = DC->getGenericSignatureOfContext();
Expand All @@ -497,12 +504,13 @@ uint16_t SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
// Emit the argument variables in calling convention order.
ArgumentInitHelper emitter(*this, F);

for (ParameterList *paramList : reversed(paramLists)) {
// Add the SILArguments and use them to initialize the local argument
// values.
for (auto &param : *paramList)
// Add the SILArguments and use them to initialize the local argument
// values.
if (paramList)
for (auto *param : *paramList)
emitter.emitParam(param);
}
if (selfParam)
emitter.emitParam(selfParam);

// Record the ArgNo of the artificial $error inout argument.
unsigned ArgNo = emitter.getNumArgs();
Expand Down
Loading