Skip to content

Commit 4e3f8f4

Browse files
committed
swift-module-digester: added protocol requirements can be source-breaking.
1 parent a64ae05 commit 4e3f8f4

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ ERROR(conformance_added,none,"%0 has added inherited protocol %1", (StringRef, S
6666

6767
ERROR(default_associated_type_removed,none,"%0 has removed default type %1", (StringRef, StringRef))
6868

69+
ERROR(protocol_req_added,none,"%0 has been added as a protocol requirement", (StringRef))
70+
6971
#ifndef DIAG_NO_UNDEF
7072
# if defined(DIAG)
7173
# undef DIAG

test/api-digester/Inputs/cake1.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ public class RemoveSetters {
8383
set(newValue) {}
8484
}
8585
}
86+
87+
public protocol RequiementChanges {
88+
func removedFunc()
89+
associatedtype removedType
90+
var removedVar: Int {get}
91+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ public class RemoveSetters {
9090
}
9191
}
9292

93+
public protocol RequiementChanges {
94+
associatedtype addedTypeWithDefault = Int
95+
associatedtype addedTypeWithoutDefault
96+
func addedFunc()
97+
var addedVar: Int { get }
98+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ cake1: Protocol P3 has generic signature change from <τ_0_0 : P1, τ_0_0 : P2>
66
/* RawRepresentable Changes */
77

88
/* Removed Decls */
9+
cake1: AssociatedType RequiementChanges.removedType has been removed
910
cake1: Constructor Somestruct2.init(_:) has been removed
1011
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1112
cake1: Func C4.foo() has been removed
13+
cake1: Func RequiementChanges.removedFunc() has been removed
1214
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1315
cake1: Var RemoveSetters.Value has removed its setter
16+
cake1: Var RequiementChanges.removedVar has been removed
1417

1518
/* Moved Decls */
1619

@@ -53,3 +56,6 @@ cake1: Struct fixedLayoutStruct has removed conformance to P1
5356

5457
/* Protocol Requirement Change */
5558
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
59+
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
60+
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
61+
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement

test/api-digester/Outputs/Cake.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ cake1: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <
66
/* RawRepresentable Changes */
77

88
/* Removed Decls */
9+
cake1: AssociatedType RequiementChanges.removedType has been removed
910
cake1: Constructor Somestruct2.init(_:) has been removed
1011
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1112
cake1: Func C4.foo() has been removed
13+
cake1: Func RequiementChanges.removedFunc() has been removed
1214
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1315
cake1: Var RemoveSetters.Value has removed its setter
16+
cake1: Var RequiementChanges.removedVar has been removed
1417

1518
/* Moved Decls */
1619

@@ -39,3 +42,6 @@ cake1: Struct fixedLayoutStruct has removed conformance to P1
3942

4043
/* Protocol Requirement Change */
4144
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
45+
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
46+
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
47+
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement

test/api-digester/source-stability.swift.expected

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,55 @@ Var Dictionary.values has declared type change from LazyMapCollection<[Key : Val
8484

8585

8686
/* Decl Attribute changes */
87+
88+
/* Protocol Requirement Changes */
89+
AssociatedType BidirectionalCollection.Element has been added as a protocol requirement
90+
AssociatedType BidirectionalCollection.Index has been added as a protocol requirement
91+
AssociatedType BidirectionalCollection.Indices has been added as a protocol requirement
92+
AssociatedType BidirectionalCollection.SubSequence has been added as a protocol requirement
93+
AssociatedType BinaryFloatingPoint.RawExponent has been added as a protocol requirement
94+
AssociatedType BinaryFloatingPoint.RawSignificand has been added as a protocol requirement
95+
AssociatedType BinaryInteger.Words has been added as a protocol requirement
96+
AssociatedType CaseIterable.AllCases has been added as a protocol requirement
97+
AssociatedType Collection.Element has been added as a protocol requirement
98+
AssociatedType Collection.Index has been added as a protocol requirement
99+
AssociatedType ExpressibleByArrayLiteral.ArrayLiteralElement has been added as a protocol requirement
100+
AssociatedType ExpressibleByBooleanLiteral.BooleanLiteralType has been added as a protocol requirement
101+
AssociatedType ExpressibleByDictionaryLiteral.Key has been added as a protocol requirement
102+
AssociatedType ExpressibleByDictionaryLiteral.Value has been added as a protocol requirement
103+
AssociatedType ExpressibleByExtendedGraphemeClusterLiteral.ExtendedGraphemeClusterLiteralType has been added as a protocol requirement
104+
AssociatedType ExpressibleByFloatLiteral.FloatLiteralType has been added as a protocol requirement
105+
AssociatedType ExpressibleByIntegerLiteral.IntegerLiteralType has been added as a protocol requirement
106+
AssociatedType ExpressibleByStringLiteral.StringLiteralType has been added as a protocol requirement
107+
AssociatedType ExpressibleByUnicodeScalarLiteral.UnicodeScalarLiteralType has been added as a protocol requirement
108+
AssociatedType FloatingPoint.Exponent has been added as a protocol requirement
109+
AssociatedType IteratorProtocol.Element has been added as a protocol requirement
110+
AssociatedType KeyedDecodingContainerProtocol.Key has been added as a protocol requirement
111+
AssociatedType KeyedEncodingContainerProtocol.Key has been added as a protocol requirement
112+
AssociatedType MutableCollection.Element has been added as a protocol requirement
113+
AssociatedType MutableCollection.Index has been added as a protocol requirement
114+
AssociatedType MutableCollection.SubSequence has been added as a protocol requirement
115+
AssociatedType Numeric.Magnitude has been added as a protocol requirement
116+
AssociatedType RandomAccessCollection.Element has been added as a protocol requirement
117+
AssociatedType RandomAccessCollection.Index has been added as a protocol requirement
118+
AssociatedType RandomAccessCollection.Indices has been added as a protocol requirement
119+
AssociatedType RandomAccessCollection.SubSequence has been added as a protocol requirement
120+
AssociatedType RangeExpression.Bound has been added as a protocol requirement
121+
AssociatedType RangeReplaceableCollection.SubSequence has been added as a protocol requirement
122+
AssociatedType RawRepresentable.RawValue has been added as a protocol requirement
123+
AssociatedType Sequence.Element has been added as a protocol requirement
124+
AssociatedType Sequence.Iterator has been added as a protocol requirement
125+
AssociatedType SetAlgebra.Element has been added as a protocol requirement
126+
AssociatedType Strideable.Stride has been added as a protocol requirement
127+
AssociatedType StringProtocol.UTF16View has been added as a protocol requirement
128+
AssociatedType StringProtocol.UTF8View has been added as a protocol requirement
129+
AssociatedType StringProtocol.UnicodeScalarView has been added as a protocol requirement
130+
AssociatedType _SequenceWrapper.Base has been added as a protocol requirement
131+
Func BinaryInteger.isMultiple(of:) has been added as a protocol requirement
132+
133+
// The subscript changes are bogus because we don't have subscript decls in the baseline.
134+
Subscript BidirectionalCollection.subscript(_:) has been added as a protocol requirement
135+
Subscript Collection.subscript(_:) has been added as a protocol requirement
136+
Subscript MutableCollection.subscript(_:) has been added as a protocol requirement
137+
Subscript RandomAccessCollection.subscript(_:) has been added as a protocol requirement
138+
Subscript RangeReplaceableCollection.subscript(_:) has been added as a protocol requirement

tools/swift-api-digester/ModuleDiagsConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static StringRef getCategoryName(uint32_t ID) {
5656
case LocalDiagID::conformance_removed:
5757
return "/* Protocol Conformance Change */";
5858
case LocalDiagID::default_associated_type_removed:
59+
case LocalDiagID::protocol_req_added:
5960
return "/* Protocol Requirement Change */";
6061
default:
6162
return StringRef();

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,20 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
813813
}
814814
}
815815
}
816+
// Complain about added protocol requirements
817+
if (auto *D = dyn_cast<SDKNodeDecl>(Right)) {
818+
if (D->isProtocolRequirement()) {
819+
bool ShouldComplain = true;
820+
// We should allow added associated types with default.
821+
if (auto ATD = dyn_cast<SDKNodeDeclAssociatedType>(D)) {
822+
if (ATD->getDefault())
823+
ShouldComplain = false;
824+
}
825+
if (ShouldComplain)
826+
Ctx.getDiags().diagnose(SourceLoc(), diag::protocol_req_added,
827+
D->getScreenInfo());
828+
}
829+
}
816830
return;
817831
case NodeMatchReason::Removed:
818832
assert(!Right);

0 commit comments

Comments
 (0)