Skip to content

swift-api-digester: diagnose removal/addition of dynamic attribute under abi mode. #18775

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 2 commits into from
Aug 17, 2018
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
1 change: 1 addition & 0 deletions include/swift/IDE/DigesterEnums.def
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ NODE_ANNOTATION(OwnershipChange)
NODE_ANNOTATION(ChangeObjC)
NODE_ANNOTATION(ChangeFixedLayout)
NODE_ANNOTATION(ChangeFrozen)
NODE_ANNOTATION(ChangeDynamic)
NODE_ANNOTATION(ChangeGenericSignature)
NODE_ANNOTATION(RawTypeLeft)
NODE_ANNOTATION(RawTypeRight)
Expand Down
5 changes: 4 additions & 1 deletion test/api-digester/Inputs/cake1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class C4: OldType {
}

@objc
public class C5 {}
public class C5 {
@objc
public func dy_foo() {}
}

public struct C6 {}

Expand Down
5 changes: 4 additions & 1 deletion test/api-digester/Inputs/cake2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public struct NSSomestruct2 {

public class C4: NewType {}

public class C5 {}
public class C5 {
@objc
public dynamic func dy_foo() {}
}

@_fixed_layout
public struct C6 {}
Expand Down
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 @@ -26,5 +26,6 @@ cake1: Class C5 is now without @objc
cake1: Var C1.CIIns1 changes from weak to strong
cake1: Var C1.CIIns2 changes from strong to weak
cake1: Func C1.foo1() is now not static
cake1: Func C5.dy_foo() is now with dynamic
cake1: Func S1.foo1() is now mutating
cake1: Func S1.foo3() is now static
46 changes: 4 additions & 42 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ class SDKContext {

static StringRef getAttrName(DeclAttrKind Kind) {
switch (Kind) {
#define DECL_ATTR(NAME, CLASS, ...) case DAK_##CLASS: return "@"#NAME;
#define DECL_ATTR(NAME, CLASS, ...) \
case DAK_##CLASS: \
return DeclAttribute::isDeclModifier(DAK_##CLASS) ? #NAME : "@"#NAME;
#include "swift/AST/Attr.def"
case DAK_Count:
llvm_unreachable("unrecognized attribute kind.");
Expand All @@ -287,6 +289,7 @@ class SDKContext {
ADD(ObjC)
ADD(FixedLayout)
ADD(Frozen)
ADD(Dynamic)
#undef ADD
}
llvm::BumpPtrAllocator &allocator() {
Expand Down Expand Up @@ -3765,47 +3768,6 @@ class NoEscapingFuncEmitter : public SDKNodeVisitor {
SDKNode::postorderVisit(Root, Emitter);
}
};

class OverloadMemberFunctionEmitter : public SDKNodeVisitor {

std::vector<OverloadedFuncInfo> &AllItems;

void visit(NodePtr Node) override {
if (Node->getKind() != SDKNodeKind::DeclFunction)
return;
auto Parent = Node->getParent();
if (Parent->getKind() != SDKNodeKind::DeclType)
return;
DeclNameViewer CurrentViewer(Node->getPrintedName());
if (CurrentViewer.args().empty())
return;
for (auto &C : Parent->getChildren()) {
if (C == Node)
continue;
if (C->getKind() != SDKNodeKind::DeclFunction)
continue;
DeclNameViewer ChildViewer(C->getPrintedName());
if (ChildViewer.args().empty())
continue;
if (CurrentViewer.commonPartsCount(ChildViewer) >=
CurrentViewer.partsCount() - 1) {
AllItems.emplace_back(Node->getAs<SDKNodeDecl>()->getUsr());
return;
}
}
}

OverloadMemberFunctionEmitter(std::vector<OverloadedFuncInfo> &AllItems) :
AllItems(AllItems) {}

public:
static void collectDiffItems(NodePtr Root,
std::vector<OverloadedFuncInfo> &AllItems) {
OverloadMemberFunctionEmitter Emitter(AllItems);
SDKNode::postorderVisit(Root, Emitter);
}
};

} // end anonymous namespace

namespace fs = llvm::sys::fs;
Expand Down