Skip to content

Commit 917b500

Browse files
author
Harlan Haskins
authored
Merge pull request swiftlang#21269 from harlanhaskins/what-does-pc-load-letter-even-mean
[ParseableInterface] Fix printing for properties with initializers and observers
2 parents d2da208 + 7fe74b2 commit 917b500

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ PrintOptions PrintOptions::printParseableInterfaceFile() {
104104
result.OmitNameOfInaccessibleProperties = true;
105105
result.FunctionDefinitions = true;
106106
result.CollapseSingleGetterProperty = false;
107+
result.VarInitializers = true;
107108

108109
result.FunctionBody = [](const ValueDecl *decl, ASTPrinter &printer) {
109110
auto AFD = dyn_cast<AbstractFunctionDecl>(decl);
@@ -2099,20 +2100,19 @@ void PrintAST::visitPatternBindingDecl(PatternBindingDecl *decl) {
20992100
}
21002101

21012102
if (Options.VarInitializers) {
2102-
// FIXME: Implement once we can pretty-print expressions.
2103-
}
2104-
2105-
auto vd = entry.getAnchoringVarDecl();
2106-
if (entry.hasInitStringRepresentation() &&
2107-
vd->isInitExposedToClients()) {
2108-
SmallString<128> scratch;
2109-
Printer << " = " << entry.getInitStringRepresentation(scratch);
2103+
auto vd = entry.getAnchoringVarDecl();
2104+
if (entry.hasInitStringRepresentation() &&
2105+
vd->isInitExposedToClients()) {
2106+
SmallString<128> scratch;
2107+
Printer << " = " << entry.getInitStringRepresentation(scratch);
2108+
}
21102109
}
21112110

2112-
// HACK: If we're just printing a single pattern and it has accessors,
2113-
// print the accessors here.
2114-
if (decl->getNumPatternEntries() == 1) {
2115-
printAccessors(vd);
2111+
// If we're just printing a single pattern and it has accessors,
2112+
// print the accessors here. It is an error to add accessors to a
2113+
// pattern binding with multiple entries.
2114+
if (auto var = decl->getSingleVar()) {
2115+
printAccessors(var);
21162116
}
21172117
}
21182118
}
@@ -3230,7 +3230,7 @@ bool Decl::shouldPrintInContext(const PrintOptions &PO) const {
32303230
// Stored variables in Swift source will be picked up by the
32313231
// PatternBindingDecl.
32323232
if (auto *VD = dyn_cast<VarDecl>(this)) {
3233-
if (!VD->hasClangNode() && VD->getImplInfo().isSimpleStored())
3233+
if (!VD->hasClangNode() && VD->hasStorage())
32343234
return false;
32353235
}
32363236

@@ -3241,7 +3241,7 @@ bool Decl::shouldPrintInContext(const PrintOptions &PO) const {
32413241
auto pattern =
32423242
pbd->getPatternList()[0].getPattern()->getSemanticsProvidingPattern();
32433243
if (auto named = dyn_cast<NamedPattern>(pattern)) {
3244-
if (!named->getDecl()->getImplInfo().isSimpleStored())
3244+
if (!named->getDecl()->hasStorage())
32453245
return false;
32463246
}
32473247
}

test/ParseableInterface/stored-properties-client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import StoredProperties
1717
// COMMON: %[[BAGOFVARIABLES:T16StoredProperties14BagOfVariablesV]] = type <{ %TSi, %TSb, [{{(3|7)}} x i8], %TSi }>
1818

1919
// This type is non-@_fixed_layout, so it becomes opaque in a resilient module
20-
// CHECK: %[[HASSTOREDPROPERTIES:T16StoredProperties03HasaB0V]] = type <{ %TSi, %TSi, %TSb, [{{(3|7)}} x i8], %TSi, %TSb }>
20+
// CHECK: %[[HASSTOREDPROPERTIES:T16StoredProperties03HasaB0V]] = type <{ %TSi, %TSi, %TSb, [{{(3|7)}} x i8], %TSi, %TSb, [{{3|7}} x i8], %TSi }>
2121
// RESILIENT: %[[HASSTOREDPROPERTIES:swift.opaque]] = type opaque
2222

2323
// COMMON: %[[HASSTOREDPROPERTIESFIXEDLAYOUT:T16StoredProperties03HasaB11FixedLayoutV]] = type <{ %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]] }>

test/ParseableInterface/stored-properties.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public struct HasStoredProperties {
5252
// CHECK: private var _: [[BOOL]]
5353
private var privateVar: Bool
5454

55+
// CHECK: @_hasStorage @_hasInitialValue public var storedWithObserversInitialValue: [[INT]] {
56+
// RESILIENT: {{^}} @_hasInitialValue public var storedWithObserversInitialValue: [[INT]] {
57+
// COMMON-NEXT: get
58+
// COMMON-NEXT: set
59+
// COMMON-NEXT: }
60+
public var storedWithObserversInitialValue: Int = 0 {
61+
didSet {}
62+
}
63+
5564
// COMMON: public init(){{$}}
5665
public init() {
5766
self.simpleStoredImmutable = 0

0 commit comments

Comments
 (0)