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