Skip to content

Commit f72620c

Browse files
committed
swift-module-digester: removing setter from a property is API breaking.
1 parent 15377ec commit f72620c

File tree

9 files changed

+43
-3
lines changed

9 files changed

+43
-3
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ ERROR(raw_type_change,none,"%0(%1) is now %2 representable", (StringRef, StringR
4242

4343
ERROR(removed_decl,none,"%0 has been removed%select{| (deprecated)}1", (StringRef, bool))
4444

45+
ERROR(removed_setter,none,"%0 has removed its setter", (StringRef))
46+
4547
ERROR(moved_decl,none,"%0 has been moved to %1", (StringRef, StringRef))
4648

4749
ERROR(renamed_decl,none,"%0 has been renamed to %1", (StringRef, StringRef))

test/api-digester/Inputs/cake1.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@ public protocol AssociatedTypePro {
7575
associatedtype T2
7676
associatedtype T3 = C1
7777
}
78+
79+
public class RemoveSetters {
80+
public var Value = 4
81+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ public protocol AssociatedTypePro {
8282
associatedtype T2
8383
associatedtype T3 = C6
8484
}
85+
86+
public class RemoveSetters {
87+
public private(set) var Value = 4
88+
}
89+

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cake1: Protocol P3 has generic signature change from <τ_0_0 : P1, τ_0_0 : P2>
99
cake1: Constructor Somestruct2.init(_:) has been removed
1010
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1111
cake1: Func C4.foo() has been removed
12+
cake1: Var RemoveSetters.Value has removed its setter
1213

1314
/* Moved Decls */
1415

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cake1: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <
99
cake1: Constructor Somestruct2.init(_:) has been removed
1010
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1111
cake1: Func C4.foo() has been removed
12+
cake1: Var RemoveSetters.Value has removed its setter
1213

1314
/* Moved Decls */
1415

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ StringRef SDKNodeDecl::getHeaderName() const {
144144
return llvm::sys::path::filename(Location.split(":").first);
145145
}
146146

147+
SDKNodeDeclGetter *SDKNodeDeclVar::getGetter() const {
148+
if (getChildrenCount() > 1)
149+
return cast<SDKNodeDeclGetter>(childAt(1));
150+
return nullptr;
151+
}
152+
153+
SDKNodeDeclSetter *SDKNodeDeclVar::getSetter() const {
154+
if (getChildrenCount() > 2)
155+
return cast<SDKNodeDeclSetter>(childAt(2));
156+
return nullptr;
157+
}
158+
159+
SDKNodeType *SDKNodeDeclVar::getType() const {
160+
return cast<SDKNodeType>(childAt(0));
161+
}
162+
147163
NodePtr UpdatedNodesMap::findUpdateCounterpart(const SDKNode *Node) const {
148164
assert(Node->isAnnotatedAs(NodeAnnotation::Updated) && "Not update operation.");
149165
auto FoundPair = std::find_if(MapImpl.begin(), MapImpl.end(),

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ enum class KnownProtocolKind: uint8_t {
207207
};
208208

209209
class SDKNodeRoot;
210-
210+
class SDKNodeDeclGetter;
211+
class SDKNodeDeclSetter;
211212
struct SDKNodeInitInfo;
212213

213214
class SDKNode {
@@ -456,6 +457,9 @@ class SDKNodeDeclVar : public SDKNodeDecl {
456457
static bool classof(const SDKNode *N);
457458
bool hasFixedBinaryOrder() const { return FixedBinaryOrder.hasValue(); }
458459
unsigned getFixedBinaryOrder() const { return *FixedBinaryOrder; }
460+
SDKNodeDeclGetter *getGetter() const;
461+
SDKNodeDeclSetter *getSetter() const;
462+
SDKNodeType *getType() const;
459463
};
460464

461465
class SDKNodeDeclAbstractFunc : public SDKNodeDecl {

tools/swift-api-digester/ModuleDiagsConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum LocalDiagID : uint32_t {
3333
static StringRef getCategoryName(uint32_t ID) {
3434
switch(ID) {
3535
case LocalDiagID::removed_decl:
36+
case LocalDiagID::removed_setter:
3637
return "/* Removed Decls */";
3738
case LocalDiagID::moved_decl:
3839
return "/* Moved Decls */";

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,16 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
886886
}
887887

888888
case SDKNodeKind::DeclVar: {
889-
auto LC = Left->getChildren()[0];
890-
auto RC = Right->getChildren()[0];
889+
auto LVar = cast<SDKNodeDeclVar>(Left);
890+
auto RVar = cast<SDKNodeDeclVar>(Right);
891+
auto LC = LVar->getType();
892+
auto RC = RVar->getType();
891893
if (!(*LC == *RC))
892894
foundMatch(LC, RC, NodeMatchReason::Sequential);
895+
if (LVar->getSetter() && !RVar->getSetter()) {
896+
Ctx.getDiags().diagnose(SourceLoc(), diag::removed_setter,
897+
LVar->getScreenInfo());
898+
}
893899
break;
894900
}
895901
}

0 commit comments

Comments
 (0)