Skip to content

Commit 7fe74b2

Browse files
author
Harlan Haskins
committed
[ParseableInterface] Go through pattern binding for all variables with storage
Instead of only printing through the pattern binding, and potentially missing stored properties with property observers, defer to the pattern binding for all stored properties, and print accessors if applicable while printing pattern bindings.
1 parent 579f018 commit 7fe74b2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)