Skip to content

Commit dc0805b

Browse files
authored
Merge pull request swiftlang#26492 from slavapestov/tbdgen-enum-element-default-arg
TBD: Be sure to visit enum element default arguments
2 parents 64d0c42 + c3fefc0 commit dc0805b

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ static bool shouldUseAllocatorMangling(const AbstractFunctionDecl *afd) {
183183
constructor->isConvenienceInit();
184184
}
185185

186+
void TBDGenVisitor::visitDefaultArguments(ValueDecl *VD, ParameterList *PL) {
187+
auto publicDefaultArgGenerators = SwiftModule->isTestingEnabled() ||
188+
SwiftModule->arePrivateImportsEnabled();
189+
if (!publicDefaultArgGenerators)
190+
return;
191+
192+
// In Swift 3 (or under -enable-testing), default arguments (of public
193+
// functions) are public symbols, as the default values are computed at the
194+
// call site.
195+
auto index = 0;
196+
for (auto *param : *PL) {
197+
if (param->isDefaultArgument())
198+
addSymbol(SILDeclRef::getDefaultArgGenerator(VD, index));
199+
index++;
200+
}
201+
}
202+
186203
void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
187204
// A @_silgen_name("...") function without a body only exists
188205
// to forward-declare a symbol from another library.
@@ -199,7 +216,6 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
199216
AFD, useAllocator));
200217
addSymbol(
201218
LinkEntity::forDynamicallyReplaceableFunctionKey(AFD, useAllocator));
202-
203219
}
204220
if (AFD->getAttrs().hasAttribute<DynamicReplacementAttr>()) {
205221
bool useAllocator = shouldUseAllocatorMangling(AFD);
@@ -215,20 +231,7 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
215231
addSymbol(SILDeclRef(AFD).asForeign());
216232
}
217233

218-
auto publicDefaultArgGenerators = SwiftModule->isTestingEnabled() ||
219-
SwiftModule->arePrivateImportsEnabled();
220-
if (!publicDefaultArgGenerators)
221-
return;
222-
223-
// In Swift 3 (or under -enable-testing), default arguments (of public
224-
// functions) are public symbols, as the default values are computed at the
225-
// call site.
226-
auto index = 0;
227-
for (auto *param : *AFD->getParameters()) {
228-
if (param->isDefaultArgument())
229-
addSymbol(SILDeclRef::getDefaultArgGenerator(AFD, index));
230-
index++;
231-
}
234+
visitDefaultArguments(AFD, AFD->getParameters());
232235
}
233236

234237
void TBDGenVisitor::visitFuncDecl(FuncDecl *FD) {
@@ -559,12 +562,12 @@ void TBDGenVisitor::visitEnumDecl(EnumDecl *ED) {
559562

560563
if (!ED->isResilient())
561564
return;
565+
}
562566

563-
// Emit resilient tags.
564-
for (auto *elt : ED->getAllElements()) {
565-
auto entity = LinkEntity::forEnumCase(elt);
566-
addSymbol(entity);
567-
}
567+
void TBDGenVisitor::visitEnumElementDecl(EnumElementDecl *EED) {
568+
addSymbol(LinkEntity::forEnumCase(EED));
569+
if (auto *PL = EED->getParameterList())
570+
visitDefaultArguments(EED, PL);
568571
}
569572

570573
void TBDGenVisitor::addFirstFileSymbols() {

lib/TBDGen/TBDGenVisitor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9191
/// Adds the global symbols associated with the first file.
9292
void addFirstFileSymbols();
9393

94+
void visitDefaultArguments(ValueDecl *VD, ParameterList *PL);
95+
9496
void visitAbstractFunctionDecl(AbstractFunctionDecl *AFD);
9597

9698
void visitAccessorDecl(AccessorDecl *AD);
@@ -115,6 +117,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
115117

116118
void visitEnumDecl(EnumDecl *ED);
117119

120+
void visitEnumElementDecl(EnumElementDecl *EED);
121+
118122
void visitDecl(Decl *D) {}
119123
};
120124
} // end namespace tbdgen

test/TBD/enum.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
// Swift 3:
21
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s
32
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s
43
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -O
54
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -O
6-
// Swift 4:
7-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4
8-
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4
9-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -O
10-
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -O
115

126
// With -enable-testing:
13-
// Swift 3:
147
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing
158
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing
169
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing -O
1710
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing -O
18-
// Swift 4:
19-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing
20-
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing
21-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing -O
22-
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing -O
2311

2412
// RUN: %empty-directory(%t)
2513
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
@@ -71,3 +59,11 @@ public enum OneCase {
7159
public enum OneCasePayload {
7260
case a(C)
7361
}
62+
63+
public enum PublicEnumDefaultArgument {
64+
case first(_: Int = 123)
65+
}
66+
67+
internal enum InternalEnumDefaultArgument {
68+
case first(_: Int = 123)
69+
}

test/TBD/function.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s
2-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -enable-testing
3-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -O
4-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -enable-testing -O
1+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s
2+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing
3+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -O
4+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing -O
55

66
// RUN: %empty-directory(%t)
77
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd

0 commit comments

Comments
 (0)