Skip to content

ABI-checker: diagnose missing available attributes for members of extensions instead of the extensions themselves #30983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/api-digester/Inputs/cake_current/cake.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,7 @@ open class AddingNewDesignatedInit {
print(foo)
}
}

public extension Float {
func floatHigher() {}
}
1 change: 1 addition & 0 deletions test/api-digester/Outputs/Cake-abi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cake: Func C1.foo1() is now not static
cake: Func C5.dy_foo() is now with dynamic
cake: Func FinalFuncContainer.NewFinalFunc() is now with final
cake: Func FinalFuncContainer.NoLongerFinalFunc() is now without final
cake: Func Float.floatHigher() is a new API without @available attribute
cake: Func HasMutatingMethodClone.foo() has self access kind changing from Mutating to NonMutating
cake: Func RequiementChanges.addedFunc() is a new API without @available attribute
cake: Func S1.foo1() has self access kind changing from NonMutating to Mutating
Expand Down
31 changes: 23 additions & 8 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,28 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
UpdateMap(Ctx.getNodeUpdateMap()),
ProtocolReqWhitelist(std::move(prWhitelist)) {}

void diagnoseMissingAvailable(SDKNodeDecl *D) {
// For extensions of external types, we diagnose individual member's missing
// available attribute instead of the extension itself.
// The reason is we may merge several extensions into a single one; some
// attributes are missing.
if (auto *DT = dyn_cast<SDKNodeDeclType>(D)) {
if (DT->isExtension()) {
for(auto MD: DT->getChildren()) {
diagnoseMissingAvailable(cast<SDKNodeDecl>(MD));
}
return;
}
}
// Diagnose the missing of @available attributes.
// Decls with @_alwaysEmitIntoClient aren't required to have an
// @available attribute.
if (!Ctx.getOpts().SkipOSCheck &&
!D->getIntroducingVersion().hasOSAvailability() &&
!D->hasDeclAttribute(DeclAttrKind::DAK_AlwaysEmitIntoClient)) {
D->emitDiag(D->getLoc(), diag::new_decl_without_intro);
}
}
void foundMatch(NodePtr Left, NodePtr Right, NodeMatchReason Reason) override {
if (options::DebugMapping)
debugMatch(Left, Right, Reason, llvm::errs());
Expand All @@ -1125,14 +1147,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
if (D->hasFixedBinaryOrder()) {
D->emitDiag(D->getLoc(), diag::decl_added);
}
// Diagnose the missing of @available attributes.
// Decls with @_alwaysEmitIntoClient aren't required to have an
// @available attribute.
if (!Ctx.getOpts().SkipOSCheck &&
!D->getIntroducingVersion().hasOSAvailability() &&
!D->hasDeclAttribute(DeclAttrKind::DAK_AlwaysEmitIntoClient)) {
D->emitDiag(D->getLoc(), diag::new_decl_without_intro);
}
diagnoseMissingAvailable(D);
}
}
// Complain about added protocol requirements
Expand Down