Skip to content

Commit 92b7a33

Browse files
committed
SILGen: Small cleanup for default argument emission
1 parent 400693b commit 92b7a33

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,10 @@ emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
649649

650650
void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
651651
// Emit any default argument generators.
652-
{
653-
auto paramLists = AFD->getParameterLists();
654-
if (AFD->getDeclContext()->isTypeContext())
655-
paramLists = paramLists.slice(1);
656-
emitDefaultArgGenerators(AFD, paramLists);
652+
if (!isa<DestructorDecl>(AFD)) {
653+
unsigned paramListIndex = AFD->getDeclContext()->isTypeContext() ? 1 : 0;
654+
auto *paramList = AFD->getParameterLists()[paramListIndex];
655+
emitDefaultArgGenerators(AFD, paramList);
657656
}
658657

659658
// If this is a function at global scope, it may close over a global variable.
@@ -1015,15 +1014,13 @@ void SILGenModule::emitGlobalGetter(VarDecl *global,
10151014
}
10161015

10171016
void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
1018-
ArrayRef<ParameterList*> paramLists) {
1017+
ParameterList *paramList) {
10191018
unsigned index = 0;
1020-
for (auto paramList : paramLists) {
1021-
for (auto param : *paramList) {
1022-
if (auto defaultArg = param->getDefaultValue())
1023-
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
1024-
defaultArg, param->getDefaultArgumentKind());
1025-
++index;
1026-
}
1019+
for (auto param : *paramList) {
1020+
if (auto defaultArg = param->getDefaultValue())
1021+
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
1022+
defaultArg, param->getDefaultArgumentKind());
1023+
++index;
10271024
}
10281025
}
10291026

lib/SILGen/SILGen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
271271
/// Emits the stored property initializer for the given pattern.
272272
void emitStoredPropertyInitialization(PatternBindingDecl *pd, unsigned i);
273273

274-
/// Emits the default argument generator for the given function.
274+
/// Emits default argument generators for the given parameter list.
275275
void emitDefaultArgGenerators(SILDeclRef::Loc decl,
276-
ArrayRef<ParameterList*> paramLists);
276+
ParameterList *paramList);
277277

278278
/// Emits the curry thunk between two uncurry levels of a function.
279279
void emitCurryThunk(SILDeclRef thunk);

0 commit comments

Comments
 (0)