Skip to content

Commit 140a151

Browse files
committed
ABI-checker: diagnose missing available attributes for members of extensions instead of the extensions themselves
rdar://61644469
1 parent 66ea6e6 commit 140a151

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

test/api-digester/Inputs/cake_current/cake.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,7 @@ open class AddingNewDesignatedInit {
241241
print(foo)
242242
}
243243
}
244+
245+
public extension Float {
246+
func floatHigher() {}
247+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ cake: Func C1.foo1() is now not static
6767
cake: Func C5.dy_foo() is now with dynamic
6868
cake: Func FinalFuncContainer.NewFinalFunc() is now with final
6969
cake: Func FinalFuncContainer.NoLongerFinalFunc() is now without final
70+
cake: Func Float.floatHigher() is a new API without @available attribute
7071
cake: Func HasMutatingMethodClone.foo() has self access kind changing from Mutating to NonMutating
7172
cake: Func RequiementChanges.addedFunc() is a new API without @available attribute
7273
cake: Func S1.foo1() has self access kind changing from NonMutating to Mutating

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,28 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
11121112
UpdateMap(Ctx.getNodeUpdateMap()),
11131113
ProtocolReqWhitelist(std::move(prWhitelist)) {}
11141114

1115+
void diagnoseMissingAvailable(SDKNodeDecl *D) {
1116+
// For extensions of external types, we diagnose individual member's missing
1117+
// available attribute instead of the extension itself.
1118+
// The reason is we may merge several extensions into a single one; some
1119+
// attributes are missing.
1120+
if (auto *DT = dyn_cast<SDKNodeDeclType>(D)) {
1121+
if (DT->isExtension()) {
1122+
for(auto MD: DT->getChildren()) {
1123+
diagnoseMissingAvailable(cast<SDKNodeDecl>(MD));
1124+
}
1125+
return;
1126+
}
1127+
}
1128+
// Diagnose the missing of @available attributes.
1129+
// Decls with @_alwaysEmitIntoClient aren't required to have an
1130+
// @available attribute.
1131+
if (!Ctx.getOpts().SkipOSCheck &&
1132+
!D->getIntroducingVersion().hasOSAvailability() &&
1133+
!D->hasDeclAttribute(DeclAttrKind::DAK_AlwaysEmitIntoClient)) {
1134+
D->emitDiag(D->getLoc(), diag::new_decl_without_intro);
1135+
}
1136+
}
11151137
void foundMatch(NodePtr Left, NodePtr Right, NodeMatchReason Reason) override {
11161138
if (options::DebugMapping)
11171139
debugMatch(Left, Right, Reason, llvm::errs());
@@ -1125,14 +1147,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
11251147
if (D->hasFixedBinaryOrder()) {
11261148
D->emitDiag(D->getLoc(), diag::decl_added);
11271149
}
1128-
// Diagnose the missing of @available attributes.
1129-
// Decls with @_alwaysEmitIntoClient aren't required to have an
1130-
// @available attribute.
1131-
if (!Ctx.getOpts().SkipOSCheck &&
1132-
!D->getIntroducingVersion().hasOSAvailability() &&
1133-
!D->hasDeclAttribute(DeclAttrKind::DAK_AlwaysEmitIntoClient)) {
1134-
D->emitDiag(D->getLoc(), diag::new_decl_without_intro);
1135-
}
1150+
diagnoseMissingAvailable(D);
11361151
}
11371152
}
11381153
// Complain about added protocol requirements

0 commit comments

Comments
 (0)