Skip to content

Commit 47228bc

Browse files
authored
swift-module-digester: remove unnecessary node annotations. NFC (#18975)
1 parent 2f08561 commit 47228bc

File tree

6 files changed

+61
-86
lines changed

6 files changed

+61
-86
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ NODE_ANNOTATION(TypeRewrittenRight)
5555
NODE_ANNOTATION(RemovedDecl)
5656
NODE_ANNOTATION(RenameOldName)
5757
NODE_ANNOTATION(RenameNewName)
58-
NODE_ANNOTATION(NowThrowing)
59-
NODE_ANNOTATION(NowMutating)
60-
NODE_ANNOTATION(StaticChange)
61-
NODE_ANNOTATION(OwnershipChange)
62-
NODE_ANNOTATION(ChangeObjC)
63-
NODE_ANNOTATION(ChangeFixedLayout)
64-
NODE_ANNOTATION(ChangeFrozen)
65-
NODE_ANNOTATION(ChangeDynamic)
66-
NODE_ANNOTATION(ChangeGenericSignature)
6758
NODE_ANNOTATION(RawTypeLeft)
6859
NODE_ANNOTATION(RawTypeRight)
6960

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct swift::ide::api::SDKNodeInitInfo {
6464

6565
SDKContext::SDKContext(CheckerOptions Opts): Diags(SourceMgr), Opts(Opts) {
6666
#define ADD(NAME) ABIAttrs.push_back({DeclAttrKind::DAK_##NAME, \
67-
NodeAnnotation::Change##NAME, getAttrName(DeclAttrKind::DAK_##NAME)});
67+
getAttrName(DeclAttrKind::DAK_##NAME)});
6868
ADD(ObjC)
6969
ADD(FixedLayout)
7070
ADD(Frozen)

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class UpdatedNodesMap {
130130
// attributes is considerred ABI-breaking.
131131
struct ABIAttributeInfo {
132132
const DeclAttrKind Kind;
133-
const NodeAnnotation Annotation;
134133
const StringRef Content;
135134
};
136135

tools/swift-api-digester/ModuleDiagsConsumer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ static StringRef getCategoryName(uint32_t ID) {
5454
}
5555

5656
swift::ide::api::
57-
ModuleDifferDiagsConsumer::ModuleDifferDiagsConsumer():
58-
PrintingDiagnosticConsumer(llvm::errs()) {
57+
ModuleDifferDiagsConsumer::ModuleDifferDiagsConsumer(bool DiagnoseModuleDiff):
58+
PrintingDiagnosticConsumer(llvm::errs()),
59+
DiagnoseModuleDiff(DiagnoseModuleDiff) {
5960
#define DIAG(KIND, ID, Options, Text, Signature) \
6061
auto ID = getCategoryName(LocalDiagID::ID); \
6162
assert(!ID.empty()); \
@@ -75,6 +76,8 @@ ModuleDifferDiagsConsumer::handleDiagnostic(SourceManager &SM, SourceLoc Loc,
7576
FormatArgs, Info);
7677
return;
7778
}
79+
if (!DiagnoseModuleDiff)
80+
return;
7881
llvm::SmallString<256> Text;
7982
{
8083
llvm::raw_svector_ostream Out(Text);

tools/swift-api-digester/ModuleDiagsConsumer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ namespace api {
3232

3333
/// \brief Diagnostic consumer that displays diagnostics to standard output.
3434
class ModuleDifferDiagsConsumer: public PrintingDiagnosticConsumer {
35+
bool DiagnoseModuleDiff;
3536
llvm::MapVector<StringRef, std::set<std::string>> AllDiags;
3637
public:
37-
ModuleDifferDiagsConsumer();
38+
ModuleDifferDiagsConsumer(bool DiagnoseModuleDiff);
3839
~ModuleDifferDiagsConsumer();
3940
void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
4041
DiagnosticKind Kind,

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 53 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,18 @@ class SDKTreeDiffPass {
638638
virtual ~SDKTreeDiffPass() {}
639639
};
640640

641-
static void detectFuncDeclChange(NodePtr L, NodePtr R) {
641+
static void detectFuncDeclChange(NodePtr L, NodePtr R, SDKContext &Ctx) {
642642
assert(L->getKind() == R->getKind());
643+
auto &Diags = Ctx.getDiags();
643644
if (auto LF = dyn_cast<SDKNodeDeclAbstractFunc>(L)) {
644645
auto RF = R->getAs<SDKNodeDeclAbstractFunc>();
645646
if (!LF->isThrowing() && RF->isThrowing()) {
646-
LF->annotate(NodeAnnotation::NowThrowing);
647+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, LF->getScreenInfo(),
648+
Ctx.buffer("throwing"));
647649
}
648650
if (!LF->isMutating() && RF->isMutating()) {
649-
LF->annotate(NodeAnnotation::NowMutating);
651+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, LF->getScreenInfo(),
652+
Ctx.buffer("mutating"));
650653
}
651654
}
652655
}
@@ -671,24 +674,48 @@ static bool isOwnershipEquivalent(ReferenceOwnership Left,
671674
return false;
672675
}
673676

674-
static void detectDeclChange(NodePtr L, NodePtr R) {
677+
static void detectDeclChange(NodePtr L, NodePtr R, SDKContext &Ctx) {
675678
assert(L->getKind() == R->getKind());
676-
auto &Ctx = L->getSDKContext();
679+
auto &Diags = Ctx.getDiags();
677680
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
678681
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.
681690
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+
}
692719
detectRename(L, R);
693720
}
694721
}
@@ -713,11 +740,11 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
713740
for (NodePtr R : RightToRemove)
714741
Right->removeChild(R);
715742
}
716-
743+
SDKContext &Ctx;
717744
UpdatedNodesMap &UpdateMap;
718745

719746
public:
720-
PrunePass(UpdatedNodesMap &UpdateMap) : UpdateMap(UpdateMap) {}
747+
PrunePass(SDKContext &Ctx): Ctx(Ctx), UpdateMap(Ctx.getNodeUpdateMap()) {}
721748

722749
void foundMatch(NodePtr Left, NodePtr Right, NodeMatchReason Reason) override {
723750
switch (Reason) {
@@ -755,8 +782,8 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
755782
SDKNodeKind Kind = Left->getKind();
756783
assert(Kind == SDKNodeKind::Root || *Left != *Right);
757784

758-
detectDeclChange(Left, Right);
759-
detectFuncDeclChange(Left, Right);
785+
detectDeclChange(Left, Right, Ctx);
786+
detectFuncDeclChange(Left, Right, Ctx);
760787

761788
switch(Kind) {
762789
case SDKNodeKind::Root:
@@ -1610,55 +1637,9 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
16101637
Count->getFullyQualifiedName()).str()));
16111638
return;
16121639
}
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:
16591641
return;
16601642
}
1661-
}
16621643
}
16631644

16641645
void DiagnosisEmitter::visitDecl(SDKNodeDecl *Node) {
@@ -1812,7 +1793,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
18121793
llvm::errs() << RightPath << " does not exist\n";
18131794
return 1;
18141795
}
1815-
ModuleDifferDiagsConsumer PDC;
1796+
ModuleDifferDiagsConsumer PDC(true);
18161797
SDKContext Ctx(Opts);
18171798
Ctx.getDiags().addConsumer(PDC);
18181799

@@ -1824,7 +1805,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
18241805
auto RightModule = RightCollector.getSDKRoot();
18251806
TypeAliasDiffFinder(LeftModule, RightModule,
18261807
Ctx.getTypeAliasUpdateMap()).search();
1827-
PrunePass Prune(Ctx.getNodeUpdateMap());
1808+
PrunePass Prune(Ctx);
18281809
Prune.pass(LeftModule, RightModule);
18291810
ChangeRefinementPass RefinementPass(Ctx.getNodeUpdateMap());
18301811
RefinementPass.pass(LeftModule, RightModule);
@@ -1869,7 +1850,7 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
18691850
}
18701851
llvm::errs() << "Diffing: " << LeftPath << " and " << RightPath << "\n";
18711852

1872-
ModuleDifferDiagsConsumer PDC;
1853+
ModuleDifferDiagsConsumer PDC(false);
18731854
SDKContext Ctx(Opts);
18741855
Ctx.getDiags().addConsumer(PDC);
18751856

@@ -1886,7 +1867,7 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
18861867
llvm::errs() << "Detecting type member diffs" << "\n";
18871868
findTypeMemberDiffs(LeftModule, RightModule, Ctx.getTypeMemberDiffs());
18881869

1889-
PrunePass Prune(Ctx.getNodeUpdateMap());
1870+
PrunePass Prune(Ctx);
18901871
Prune.pass(LeftModule, RightModule);
18911872
llvm::errs() << "Finished pruning" << "\n";
18921873
ChangeRefinementPass RefinementPass(Ctx.getNodeUpdateMap());

0 commit comments

Comments
 (0)