@@ -888,6 +888,8 @@ bool SDKNode::operator==(const SDKNode &Other) const {
888
888
auto Right = (&Other)->getAs <SDKNodeDecl>();
889
889
if (Left->isStatic () ^ Right->isStatic ())
890
890
return false ;
891
+ if (Left->getOwnership () != Right->getOwnership ())
892
+ return false ;
891
893
SWIFT_FALLTHROUGH;
892
894
}
893
895
case SDKNodeKind::Root:
@@ -1944,20 +1946,13 @@ class UpdatedNodesMap : public MatchedNodeListener {
1944
1946
}
1945
1947
};
1946
1948
1947
- static void detectThrowing (NodePtr L, NodePtr R) {
1949
+ static void detectFuncDeclChange (NodePtr L, NodePtr R) {
1948
1950
assert (L->getKind () == R->getKind ());
1949
1951
if (auto LF = dyn_cast<SDKNodeAbstractFunc>(L)) {
1950
1952
auto RF = R->getAs <SDKNodeAbstractFunc>();
1951
1953
if (!LF->isThrowing () && RF->isThrowing ()) {
1952
1954
LF->annotate (NodeAnnotation::NowThrowing);
1953
1955
}
1954
- }
1955
- }
1956
-
1957
- static void detectMutating (NodePtr L, NodePtr R) {
1958
- assert (L->getKind () == R->getKind ());
1959
- if (auto LF = dyn_cast<SDKNodeAbstractFunc>(L)) {
1960
- auto RF = R->getAs <SDKNodeAbstractFunc>();
1961
1956
if (!LF->isMutating () && RF->isMutating ()) {
1962
1957
LF->annotate (NodeAnnotation::NowMutating);
1963
1958
}
@@ -1975,12 +1970,15 @@ static void detectRename(NodePtr L, NodePtr R) {
1975
1970
}
1976
1971
}
1977
1972
1978
- static void detectStaticUpdate (NodePtr L, NodePtr R) {
1973
+ static void detectDeclChange (NodePtr L, NodePtr R) {
1979
1974
assert (L->getKind () == R->getKind ());
1980
1975
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
1981
- if (LD->isStatic () ^ R->getAs <SDKNodeDecl>()->isStatic ()) {
1976
+ auto *RD = R->getAs <SDKNodeDecl>();
1977
+ if (LD->isStatic () ^ RD->isStatic ())
1982
1978
L->annotate (NodeAnnotation::StaticChange);
1983
- }
1979
+ if (LD->getOwnership () != RD->getOwnership ())
1980
+ L->annotate (NodeAnnotation::OwnershipChange);
1981
+ detectRename (L, R);
1984
1982
}
1985
1983
}
1986
1984
@@ -2040,10 +2038,8 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
2040
2038
Right->getKind () != SDKNodeKind::Nil);
2041
2039
assert (Kind == SDKNodeKind::Root || *Left != *Right);
2042
2040
2043
- detectRename (Left, Right);
2044
- detectThrowing (Left, Right);
2045
- detectMutating (Left, Right);
2046
- detectStaticUpdate (Left, Right);
2041
+ detectDeclChange (Left, Right);
2042
+ detectFuncDeclChange (Left, Right);
2047
2043
2048
2044
switch (Kind) {
2049
2045
case SDKNodeKind::Root:
@@ -2755,9 +2751,14 @@ class DiagnosisEmitter : public SDKNodeVisitor {
2755
2751
struct DeclAttrDiag {
2756
2752
DeclKind Kind;
2757
2753
StringRef DeclName;
2758
- StringRef AttrName;
2759
- DeclAttrDiag (DeclKind Kind, StringRef DeclName, StringRef AttrName) :
2760
- Kind (Kind), DeclName(DeclName), AttrName(AttrName) {}
2754
+ StringRef AttrBefore;
2755
+ StringRef AttrAfter;
2756
+ DeclAttrDiag (DeclKind Kind, StringRef DeclName, StringRef AttrBefore,
2757
+ StringRef AttrAfter) : Kind(Kind), DeclName(DeclName),
2758
+ AttrBefore (AttrBefore), AttrAfter(AttrAfter) {}
2759
+ DeclAttrDiag (DeclKind Kind, StringRef DeclName, StringRef AttrAfter) :
2760
+ DeclAttrDiag(Kind, DeclName, StringRef(), AttrAfter) {}
2761
+
2761
2762
bool operator <(DeclAttrDiag Other) const ;
2762
2763
void output () const ;
2763
2764
static void theme (raw_ostream &OS) { OS << " Decl Attribute changes" ; };
@@ -2887,8 +2888,12 @@ bool DiagnosisEmitter::DeclAttrDiag::operator<(DeclAttrDiag Other) const {
2887
2888
}
2888
2889
2889
2890
void DiagnosisEmitter::DeclAttrDiag::output () const {
2890
- llvm::outs () << Kind << " " << printName (DeclName) << " is now " <<
2891
- printDiagKeyword (AttrName) << " \n " ;
2891
+ if (AttrBefore.empty ())
2892
+ llvm::outs () << Kind << " " << printName (DeclName) << " is now " <<
2893
+ printDiagKeyword (AttrAfter)<< " \n " ;
2894
+ else
2895
+ llvm::outs () << Kind << " " << printName (DeclName) << " changes from " <<
2896
+ printDiagKeyword (AttrBefore) << " to " << printDiagKeyword (AttrAfter)<< " \n " ;
2892
2897
}
2893
2898
2894
2899
void DiagnosisEmitter::diagnosis (NodePtr LeftRoot, NodePtr RightRoot,
@@ -2935,6 +2940,21 @@ void DiagnosisEmitter::visitDecl(SDKNodeDecl *Node) {
2935
2940
Node->getFullyQualifiedName (),
2936
2941
InsertToBuffer (Node->isStatic () ? " not static" : " static" ));
2937
2942
}
2943
+ if (Node->isAnnotatedAs (NodeAnnotation::OwnershipChange)) {
2944
+ auto getOwnershipDescription = [](swift::Ownership O) {
2945
+ switch (O) {
2946
+ case Ownership::Strong: return InsertToBuffer (" strong" );
2947
+ case Ownership::Weak: return InsertToBuffer (" weak" );
2948
+ case Ownership::Unowned: return InsertToBuffer (" unowned" );
2949
+ case Ownership::Unmanaged: return InsertToBuffer (" unowned(unsafe)" );
2950
+ }
2951
+ };
2952
+ auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>();
2953
+ AttrChangedDecls.Diags .emplace_back (Node->getDeclKind (),
2954
+ Node->getFullyQualifiedName (),
2955
+ getOwnershipDescription (Node->getOwnership ()),
2956
+ getOwnershipDescription (Count->getOwnership ()));
2957
+ }
2938
2958
}
2939
2959
void DiagnosisEmitter::visitType (SDKNodeType *Node) {
2940
2960
auto *Parent = Node->getParent ()->getAs <SDKNodeDecl>();
0 commit comments