mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #5560 from nkcsgexi/digester-ownership
This commit is contained in:
@@ -8,4 +8,6 @@ public struct S1 {
|
|||||||
public class C1 {
|
public class C1 {
|
||||||
public class func foo1() {}
|
public class func foo1() {}
|
||||||
public func foo2(_ : Int) {}
|
public func foo2(_ : Int) {}
|
||||||
|
public weak var CIIns1 : C1?
|
||||||
|
public var CIIns2 : C1?
|
||||||
}
|
}
|
||||||
@@ -8,4 +8,6 @@ public struct S1 {
|
|||||||
public class C1 {
|
public class C1 {
|
||||||
public func foo1() {}
|
public func foo1() {}
|
||||||
public func foo2(_ : ()->()) {}
|
public func foo2(_ : ()->()) {}
|
||||||
|
public var CIIns1 : C1?
|
||||||
|
public weak var CIIns2 : C1?
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,8 @@ Constructor S1.init(_:) has 1st parameter type change from Int to Double
|
|||||||
Func C1.foo2(_:) has 1st parameter type change from Int to () -> ()
|
Func C1.foo2(_:) has 1st parameter type change from Int to () -> ()
|
||||||
|
|
||||||
==================================================== Decl Attribute changes ====================================================
|
==================================================== Decl Attribute changes ====================================================
|
||||||
|
Var C1.CIIns1 changes from weak to strong
|
||||||
|
Var C1.CIIns2 changes from strong to weak
|
||||||
Func C1.foo1() is now not static
|
Func C1.foo1() is now not static
|
||||||
Func S1.foo3() is now static
|
Func S1.foo3() is now static
|
||||||
Func S1.foo1() is now mutating
|
Func S1.foo1() is now mutating
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ NODE_ANNOTATION(RenameNewName)
|
|||||||
NODE_ANNOTATION(NowThrowing)
|
NODE_ANNOTATION(NowThrowing)
|
||||||
NODE_ANNOTATION(NowMutating)
|
NODE_ANNOTATION(NowMutating)
|
||||||
NODE_ANNOTATION(StaticChange)
|
NODE_ANNOTATION(StaticChange)
|
||||||
|
NODE_ANNOTATION(OwnershipChange)
|
||||||
|
|
||||||
DECL_ATTR(deprecated)
|
DECL_ATTR(deprecated)
|
||||||
|
|
||||||
|
|||||||
@@ -889,6 +889,8 @@ bool SDKNode::operator==(const SDKNode &Other) const {
|
|||||||
auto Right = (&Other)->getAs<SDKNodeDecl>();
|
auto Right = (&Other)->getAs<SDKNodeDecl>();
|
||||||
if (Left->isStatic() ^ Right->isStatic())
|
if (Left->isStatic() ^ Right->isStatic())
|
||||||
return false;
|
return false;
|
||||||
|
if (Left->getOwnership() != Right->getOwnership())
|
||||||
|
return false;
|
||||||
SWIFT_FALLTHROUGH;
|
SWIFT_FALLTHROUGH;
|
||||||
}
|
}
|
||||||
case SDKNodeKind::Root:
|
case SDKNodeKind::Root:
|
||||||
@@ -1945,20 +1947,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void detectThrowing(NodePtr L, NodePtr R) {
|
static void detectFuncDeclChange(NodePtr L, NodePtr R) {
|
||||||
assert(L->getKind() == R->getKind());
|
assert(L->getKind() == R->getKind());
|
||||||
if (auto LF = dyn_cast<SDKNodeAbstractFunc>(L)) {
|
if (auto LF = dyn_cast<SDKNodeAbstractFunc>(L)) {
|
||||||
auto RF = R->getAs<SDKNodeAbstractFunc>();
|
auto RF = R->getAs<SDKNodeAbstractFunc>();
|
||||||
if (!LF->isThrowing() && RF->isThrowing()) {
|
if (!LF->isThrowing() && RF->isThrowing()) {
|
||||||
LF->annotate(NodeAnnotation::NowThrowing);
|
LF->annotate(NodeAnnotation::NowThrowing);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void detectMutating(NodePtr L, NodePtr R) {
|
|
||||||
assert(L->getKind() == R->getKind());
|
|
||||||
if (auto LF = dyn_cast<SDKNodeAbstractFunc>(L)) {
|
|
||||||
auto RF = R->getAs<SDKNodeAbstractFunc>();
|
|
||||||
if (!LF->isMutating() && RF->isMutating()) {
|
if (!LF->isMutating() && RF->isMutating()) {
|
||||||
LF->annotate(NodeAnnotation::NowMutating);
|
LF->annotate(NodeAnnotation::NowMutating);
|
||||||
}
|
}
|
||||||
@@ -1976,12 +1971,15 @@ static void detectRename(NodePtr L, NodePtr R) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void detectStaticUpdate(NodePtr L, NodePtr R) {
|
static void detectDeclChange(NodePtr L, NodePtr R) {
|
||||||
assert(L->getKind() == R->getKind());
|
assert(L->getKind() == R->getKind());
|
||||||
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
|
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
|
||||||
if (LD->isStatic() ^ R->getAs<SDKNodeDecl>()->isStatic()) {
|
auto *RD = R->getAs<SDKNodeDecl>();
|
||||||
|
if (LD->isStatic() ^ RD->isStatic())
|
||||||
L->annotate(NodeAnnotation::StaticChange);
|
L->annotate(NodeAnnotation::StaticChange);
|
||||||
}
|
if (LD->getOwnership() != RD->getOwnership())
|
||||||
|
L->annotate(NodeAnnotation::OwnershipChange);
|
||||||
|
detectRename(L, R);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2041,10 +2039,8 @@ public:
|
|||||||
Right->getKind() != SDKNodeKind::Nil);
|
Right->getKind() != SDKNodeKind::Nil);
|
||||||
assert(Kind == SDKNodeKind::Root || *Left != *Right);
|
assert(Kind == SDKNodeKind::Root || *Left != *Right);
|
||||||
|
|
||||||
detectRename(Left, Right);
|
detectDeclChange(Left, Right);
|
||||||
detectThrowing(Left, Right);
|
detectFuncDeclChange(Left, Right);
|
||||||
detectMutating(Left, Right);
|
|
||||||
detectStaticUpdate(Left, Right);
|
|
||||||
|
|
||||||
switch(Kind) {
|
switch(Kind) {
|
||||||
case SDKNodeKind::Root:
|
case SDKNodeKind::Root:
|
||||||
@@ -2756,9 +2752,14 @@ class DiagnosisEmitter : public SDKNodeVisitor {
|
|||||||
struct DeclAttrDiag {
|
struct DeclAttrDiag {
|
||||||
DeclKind Kind;
|
DeclKind Kind;
|
||||||
StringRef DeclName;
|
StringRef DeclName;
|
||||||
StringRef AttrName;
|
StringRef AttrBefore;
|
||||||
DeclAttrDiag(DeclKind Kind, StringRef DeclName, StringRef AttrName) :
|
StringRef AttrAfter;
|
||||||
Kind(Kind), DeclName(DeclName), AttrName(AttrName) {}
|
DeclAttrDiag(DeclKind Kind, StringRef DeclName, StringRef AttrBefore,
|
||||||
|
StringRef AttrAfter) : Kind(Kind), DeclName(DeclName),
|
||||||
|
AttrBefore(AttrBefore), AttrAfter(AttrAfter) {}
|
||||||
|
DeclAttrDiag(DeclKind Kind, StringRef DeclName, StringRef AttrAfter) :
|
||||||
|
DeclAttrDiag(Kind, DeclName, StringRef(), AttrAfter) {}
|
||||||
|
|
||||||
bool operator<(DeclAttrDiag Other) const;
|
bool operator<(DeclAttrDiag Other) const;
|
||||||
void output() const;
|
void output() const;
|
||||||
static void theme(raw_ostream &OS) { OS << "Decl Attribute changes"; };
|
static void theme(raw_ostream &OS) { OS << "Decl Attribute changes"; };
|
||||||
@@ -2888,8 +2889,12 @@ bool DiagnosisEmitter::DeclAttrDiag::operator<(DeclAttrDiag Other) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosisEmitter::DeclAttrDiag::output() const {
|
void DiagnosisEmitter::DeclAttrDiag::output() const {
|
||||||
llvm::outs() << Kind << " " << printName(DeclName) << " is now " <<
|
if (AttrBefore.empty())
|
||||||
printDiagKeyword(AttrName) << "\n";
|
llvm::outs() << Kind << " " << printName(DeclName) << " is now " <<
|
||||||
|
printDiagKeyword(AttrAfter)<< "\n";
|
||||||
|
else
|
||||||
|
llvm::outs() << Kind << " " << printName(DeclName) << " changes from " <<
|
||||||
|
printDiagKeyword(AttrBefore) << " to "<< printDiagKeyword(AttrAfter)<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
|
void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
|
||||||
@@ -2936,6 +2941,21 @@ void DiagnosisEmitter::visitDecl(SDKNodeDecl *Node) {
|
|||||||
Node->getFullyQualifiedName(),
|
Node->getFullyQualifiedName(),
|
||||||
InsertToBuffer(Node->isStatic() ? "not static" : "static"));
|
InsertToBuffer(Node->isStatic() ? "not static" : "static"));
|
||||||
}
|
}
|
||||||
|
if (Node->isAnnotatedAs(NodeAnnotation::OwnershipChange)) {
|
||||||
|
auto getOwnershipDescription = [](swift::Ownership O) {
|
||||||
|
switch (O) {
|
||||||
|
case Ownership::Strong: return InsertToBuffer("strong");
|
||||||
|
case Ownership::Weak: return InsertToBuffer("weak");
|
||||||
|
case Ownership::Unowned: return InsertToBuffer("unowned");
|
||||||
|
case Ownership::Unmanaged: return InsertToBuffer("unowned(unsafe)");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeDecl>();
|
||||||
|
AttrChangedDecls.Diags.emplace_back(Node->getDeclKind(),
|
||||||
|
Node->getFullyQualifiedName(),
|
||||||
|
getOwnershipDescription(Node->getOwnership()),
|
||||||
|
getOwnershipDescription(Count->getOwnership()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void DiagnosisEmitter::visitType(SDKNodeType *Node) {
|
void DiagnosisEmitter::visitType(SDKNodeType *Node) {
|
||||||
auto *Parent = Node->getParent()->getAs<SDKNodeDecl>();
|
auto *Parent = Node->getParent()->getAs<SDKNodeDecl>();
|
||||||
|
|||||||
Reference in New Issue
Block a user