@@ -638,15 +638,18 @@ class SDKTreeDiffPass {
638
638
virtual ~SDKTreeDiffPass () {}
639
639
};
640
640
641
- static void detectFuncDeclChange (NodePtr L, NodePtr R) {
641
+ static void detectFuncDeclChange (NodePtr L, NodePtr R, SDKContext &Ctx ) {
642
642
assert (L->getKind () == R->getKind ());
643
+ auto &Diags = Ctx.getDiags ();
643
644
if (auto LF = dyn_cast<SDKNodeDeclAbstractFunc>(L)) {
644
645
auto RF = R->getAs <SDKNodeDeclAbstractFunc>();
645
646
if (!LF->isThrowing () && RF->isThrowing ()) {
646
- LF->annotate (NodeAnnotation::NowThrowing);
647
+ Diags.diagnose (SourceLoc (), diag::decl_new_attr, LF->getScreenInfo (),
648
+ Ctx.buffer (" throwing" ));
647
649
}
648
650
if (!LF->isMutating () && RF->isMutating ()) {
649
- LF->annotate (NodeAnnotation::NowMutating);
651
+ Diags.diagnose (SourceLoc (), diag::decl_new_attr, LF->getScreenInfo (),
652
+ Ctx.buffer (" mutating" ));
650
653
}
651
654
}
652
655
}
@@ -671,24 +674,48 @@ static bool isOwnershipEquivalent(ReferenceOwnership Left,
671
674
return false ;
672
675
}
673
676
674
- static void detectDeclChange (NodePtr L, NodePtr R) {
677
+ static void detectDeclChange (NodePtr L, NodePtr R, SDKContext &Ctx ) {
675
678
assert (L->getKind () == R->getKind ());
676
- auto &Ctx = L-> getSDKContext ();
679
+ auto &Diags = Ctx. getDiags ();
677
680
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
678
681
auto *RD = R->getAs <SDKNodeDecl>();
679
- if (LD->isStatic () ^ RD->isStatic ())
680
- L->annotate (NodeAnnotation::StaticChange);
682
+
683
+ // Diagnose static attribute change.
684
+ if (LD->isStatic () ^ RD->isStatic ()) {
685
+ Diags.diagnose (SourceLoc (), diag::decl_new_attr, LD->getScreenInfo (),
686
+ Ctx.buffer (LD->isStatic () ? " not static" : " static" ));
687
+ }
688
+
689
+ // Diagnose ownership change.
681
690
if (!isOwnershipEquivalent (LD->getReferenceOwnership (),
682
- RD->getReferenceOwnership ()))
683
- L->annotate (NodeAnnotation::OwnershipChange);
684
- // Check if some attributes with ABI-impact have been added/removed.
685
- for (auto &Info: Ctx.getABIAttributeInfo ()) {
686
- if (LD->hasDeclAttribute (Info.Kind ) != RD->hasDeclAttribute (Info.Kind ))
687
- L->annotate (Info.Annotation );
688
- }
689
- // Mark generic signature change
690
- if (LD->getGenericSignature () != RD->getGenericSignature ())
691
- L->annotate (NodeAnnotation::ChangeGenericSignature);
691
+ RD->getReferenceOwnership ())) {
692
+ auto getOwnershipDescription = [&](swift::ReferenceOwnership O) {
693
+ if (O == ReferenceOwnership::Strong)
694
+ return Ctx.buffer (" strong" );
695
+ return keywordOf (O);
696
+ };
697
+ Diags.diagnose (SourceLoc (), diag::decl_attr_change, LD->getScreenInfo (),
698
+ getOwnershipDescription (LD->getReferenceOwnership ()),
699
+ getOwnershipDescription (RD->getReferenceOwnership ()));
700
+ }
701
+ if (options::Abi) {
702
+ // Check if some attributes with ABI-impact have been added/removed.
703
+ for (auto &Info: Ctx.getABIAttributeInfo ()) {
704
+ if (LD->hasDeclAttribute (Info.Kind ) != RD->hasDeclAttribute (Info.Kind )) {
705
+ auto Desc = LD->hasDeclAttribute (Info.Kind ) ?
706
+ Ctx.buffer ((llvm::Twine (" without " ) + Info.Content ).str ()):
707
+ Ctx.buffer ((llvm::Twine (" with " ) + Info.Content ).str ());
708
+ Diags.diagnose (SourceLoc (), diag::decl_new_attr, LD->getScreenInfo (),
709
+ Desc);
710
+ }
711
+ }
712
+ }
713
+
714
+ // Diagnose generic signature change
715
+ if (LD->getGenericSignature () != RD->getGenericSignature ()) {
716
+ Diags.diagnose (SourceLoc (), diag::generic_sig_change, LD->getScreenInfo (),
717
+ LD->getGenericSignature (), RD->getGenericSignature ());
718
+ }
692
719
detectRename (L, R);
693
720
}
694
721
}
@@ -713,11 +740,11 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
713
740
for (NodePtr R : RightToRemove)
714
741
Right->removeChild (R);
715
742
}
716
-
743
+ SDKContext &Ctx;
717
744
UpdatedNodesMap &UpdateMap;
718
745
719
746
public:
720
- PrunePass (UpdatedNodesMap &UpdateMap) : UpdateMap( UpdateMap) {}
747
+ PrunePass (SDKContext &Ctx): Ctx(Ctx), UpdateMap(Ctx.getNodeUpdateMap() ) {}
721
748
722
749
void foundMatch (NodePtr Left, NodePtr Right, NodeMatchReason Reason) override {
723
750
switch (Reason) {
@@ -755,8 +782,8 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
755
782
SDKNodeKind Kind = Left->getKind ();
756
783
assert (Kind == SDKNodeKind::Root || *Left != *Right);
757
784
758
- detectDeclChange (Left, Right);
759
- detectFuncDeclChange (Left, Right);
785
+ detectDeclChange (Left, Right, Ctx );
786
+ detectFuncDeclChange (Left, Right, Ctx );
760
787
761
788
switch (Kind) {
762
789
case SDKNodeKind::Root:
@@ -1610,55 +1637,9 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
1610
1637
Count->getFullyQualifiedName ()).str ()));
1611
1638
return ;
1612
1639
}
1613
- case NodeAnnotation::NowMutating: {
1614
- Diags.diagnose (SourceLoc (), diag::decl_new_attr, Node->getScreenInfo (),
1615
- Ctx.buffer (" mutating" ));
1616
- return ;
1617
- }
1618
- case NodeAnnotation::NowThrowing: {
1619
- Diags.diagnose (SourceLoc (), diag::decl_new_attr, Node->getScreenInfo (),
1620
- Ctx.buffer (" throwing" ));
1621
- return ;
1622
- }
1623
- case NodeAnnotation::StaticChange: {
1624
- Diags.diagnose (SourceLoc (), diag::decl_new_attr, Node->getScreenInfo (),
1625
- Ctx.buffer (Node->isStatic () ? " not static" : " static" ));
1626
- return ;
1627
- }
1628
- case NodeAnnotation::OwnershipChange: {
1629
- auto getOwnershipDescription = [&](swift::ReferenceOwnership O) {
1630
- if (O == ReferenceOwnership::Strong)
1631
- return Ctx.buffer (" strong" );
1632
- return keywordOf (O);
1633
- };
1634
- auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>();
1635
- Diags.diagnose (SourceLoc (), diag::decl_attr_change, Node->getScreenInfo (),
1636
- getOwnershipDescription (Node->getReferenceOwnership ()),
1637
- getOwnershipDescription (Count->getReferenceOwnership ()));
1638
- return ;
1639
- }
1640
- case NodeAnnotation::ChangeGenericSignature: {
1641
- Diags.diagnose (SourceLoc (), diag::generic_sig_change, Node->getScreenInfo (),
1642
- Node->getGenericSignature (), UpdateMap.findUpdateCounterpart (Node)->
1643
- getAs<SDKNodeDecl>()->getGenericSignature ());
1644
- return ;
1645
- }
1646
-
1647
- default : {
1648
- // Diagnose the addition/removal of attributes with ABI impact.
1649
- auto Infos = Ctx.getABIAttributeInfo ();
1650
- auto It = std::find_if (Infos.begin (), Infos.end (),
1651
- [&](const ABIAttributeInfo &I) { return I.Annotation == Anno; });
1652
- if (It == Infos.end ())
1653
- return ;
1654
- auto Desc = Node->hasDeclAttribute (It->Kind ) ?
1655
- Ctx.buffer ((llvm::Twine (" without " ) + It->Content ).str ()):
1656
- Ctx.buffer ((llvm::Twine (" with " ) + It->Content ).str ());
1657
- if (options::Abi)
1658
- Diags.diagnose (SourceLoc (), diag::decl_new_attr, Node->getScreenInfo (), Desc);
1640
+ default :
1659
1641
return ;
1660
1642
}
1661
- }
1662
1643
}
1663
1644
1664
1645
void DiagnosisEmitter::visitDecl (SDKNodeDecl *Node) {
@@ -1812,7 +1793,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
1812
1793
llvm::errs () << RightPath << " does not exist\n " ;
1813
1794
return 1 ;
1814
1795
}
1815
- ModuleDifferDiagsConsumer PDC;
1796
+ ModuleDifferDiagsConsumer PDC ( true ) ;
1816
1797
SDKContext Ctx (Opts);
1817
1798
Ctx.getDiags ().addConsumer (PDC);
1818
1799
@@ -1824,7 +1805,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
1824
1805
auto RightModule = RightCollector.getSDKRoot ();
1825
1806
TypeAliasDiffFinder (LeftModule, RightModule,
1826
1807
Ctx.getTypeAliasUpdateMap ()).search ();
1827
- PrunePass Prune (Ctx. getNodeUpdateMap () );
1808
+ PrunePass Prune (Ctx);
1828
1809
Prune.pass (LeftModule, RightModule);
1829
1810
ChangeRefinementPass RefinementPass (Ctx.getNodeUpdateMap ());
1830
1811
RefinementPass.pass (LeftModule, RightModule);
@@ -1869,7 +1850,7 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
1869
1850
}
1870
1851
llvm::errs () << " Diffing: " << LeftPath << " and " << RightPath << " \n " ;
1871
1852
1872
- ModuleDifferDiagsConsumer PDC;
1853
+ ModuleDifferDiagsConsumer PDC ( false ) ;
1873
1854
SDKContext Ctx (Opts);
1874
1855
Ctx.getDiags ().addConsumer (PDC);
1875
1856
@@ -1886,7 +1867,7 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
1886
1867
llvm::errs () << " Detecting type member diffs" << " \n " ;
1887
1868
findTypeMemberDiffs (LeftModule, RightModule, Ctx.getTypeMemberDiffs ());
1888
1869
1889
- PrunePass Prune (Ctx. getNodeUpdateMap () );
1870
+ PrunePass Prune (Ctx);
1890
1871
Prune.pass (LeftModule, RightModule);
1891
1872
llvm::errs () << " Finished pruning" << " \n " ;
1892
1873
ChangeRefinementPass RefinementPass (Ctx.getNodeUpdateMap ());
0 commit comments