Skip to content

swift-api-digester: avoid diagnosing reference ownership changes from unowned to weak. #17837

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
Jul 9, 2018
Merged
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
14 changes: 13 additions & 1 deletion tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2387,13 +2387,25 @@ static void detectRename(NodePtr L, NodePtr R) {
}
}

static bool isOwnershipEquivalent(ReferenceOwnership Left,
ReferenceOwnership Right) {
if (Left == Right)
return true;
if (Left == ReferenceOwnership::Unowned && Right == ReferenceOwnership::Weak)
return true;
if (Left == ReferenceOwnership::Weak && Right == ReferenceOwnership::Unowned)
return true;
return false;
}

static void detectDeclChange(NodePtr L, NodePtr R) {
assert(L->getKind() == R->getKind());
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
auto *RD = R->getAs<SDKNodeDecl>();
if (LD->isStatic() ^ RD->isStatic())
L->annotate(NodeAnnotation::StaticChange);
if (LD->getReferenceOwnership() != RD->getReferenceOwnership())
if (!isOwnershipEquivalent(LD->getReferenceOwnership(),
RD->getReferenceOwnership()))
L->annotate(NodeAnnotation::OwnershipChange);
detectRename(L, R);
}
Expand Down