Skip to content

Commit e57b332

Browse files
committedAug 6, 2018
[TBDGen] Look for @_hasInitialValue on variables rather than an initializer expression.
The initializer expression is lost in the public interface (in Swift modules and the textual interface), but the attribute is preserved.
1 parent 7753383 commit e57b332

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed
 

‎lib/TBDGen/TBDGen.cpp

+11-15
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {
4141
return VD->isStatic() || VD->getDeclContext()->isModuleScopeContext();
4242
}
4343

44-
void TBDGenVisitor::visitPatternBindingDecl(PatternBindingDecl *PBD) {
45-
for (auto &entry : PBD->getPatternList()) {
46-
auto *var = entry.getAnchoringVarDecl();
47-
48-
// Non-global variables might have an explicit initializer symbol.
49-
if (entry.getNonLazyInit() && !isGlobalOrStaticVar(var)) {
50-
auto declRef =
51-
SILDeclRef(var, SILDeclRef::Kind::StoredPropertyInitializer);
52-
// Stored property initializers for public properties are currently
53-
// public.
54-
addSymbol(declRef);
55-
}
56-
}
57-
}
58-
5944
void TBDGenVisitor::addSymbol(SILDeclRef declRef) {
6045
auto linkage = effectiveLinkageForClassMember(
6146
declRef.getLinkage(ForDefinition),
@@ -169,6 +154,17 @@ void TBDGenVisitor::visitAbstractStorageDecl(AbstractStorageDecl *ASD) {
169154
}
170155

171156
void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
157+
// Non-global variables might have an explicit initializer symbol, in
158+
// non-resilient modules.
159+
if (VD->getAttrs().hasAttribute<HasInitialValueAttr>() &&
160+
SwiftModule->getResilienceStrategy() == ResilienceStrategy::Default &&
161+
!isGlobalOrStaticVar(VD)) {
162+
auto declRef = SILDeclRef(VD, SILDeclRef::Kind::StoredPropertyInitializer);
163+
// Stored property initializers for public properties are currently
164+
// public.
165+
addSymbol(declRef);
166+
}
167+
172168
// statically/globally stored variables have some special handling.
173169
if (VD->hasStorage() && isGlobalOrStaticVar(VD)) {
174170
if (getDeclLinkage(VD) == FormalLinkage::PublicUnique) {

‎lib/TBDGen/TBDGenVisitor.h

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9090
/// \brief Adds the global symbols associated with the first file.
9191
void addFirstFileSymbols();
9292

93-
void visitPatternBindingDecl(PatternBindingDecl *PBD);
94-
9593
void visitAbstractFunctionDecl(AbstractFunctionDecl *AFD);
9694

9795
void visitAccessorDecl(AccessorDecl *AD);

‎test/TBD/multi-file.swift

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public func function() {}
4343
public class Class {
4444
public var property: Int
4545

46+
public var propertyWithInit: Int = 0
47+
4648
public init() {
4749
property = 0
4850
}

‎test/TBD/struct.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s
2-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-resilience
3-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing
4-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-resilience -enable-testing
5-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -O
6-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-resilience -O
7-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing -O
8-
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-resilience -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-resilience
3+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing
4+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-resilience -enable-testing
5+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -O
6+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-resilience -O
7+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing -O
8+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-resilience -enable-testing -O
99

1010
public struct PublicNothing {}
1111

0 commit comments

Comments
 (0)
Please sign in to comment.