Skip to content

ABIChecker: include import decls in the intermediate JSON file #38943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/swift/APIDigester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ class SDKNodeDeclAccessor: public SDKNodeDeclAbstractFunc {
void jsonize(json::Output &Out) override;
};

class SDKNodeDeclImport: public SDKNodeDecl {
public:
SDKNodeDeclImport(SDKNodeInitInfo Info);
static bool classof(const SDKNode *N);
};

// The additional information we need for a type node in the digest.
// We use type node to represent entities more than types, e.g. parameters, so
// this struct is necessary to pass down to create a type node.
Expand Down
1 change: 1 addition & 0 deletions include/swift/IDE/DigesterEnums.def
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ NODE_KIND(DeclOperator, OperatorDecl)
NODE_KIND(DeclType, TypeDecl)
NODE_KIND(DeclVar, Var)
NODE_KIND(DeclTypeAlias, TypeAlias)
NODE_KIND(DeclImport, Import)
NODE_KIND(DeclAssociatedType, AssociatedType)
NODE_KIND_RANGE(Decl, DeclFunction, DeclAssociatedType)

Expand Down
20 changes: 20 additions & 0 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct swift::ide::api::SDKNodeInitInfo {
SDKNodeInitInfo(SDKContext &Ctx, Decl *D);
SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD);
SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *D);
SDKNodeInitInfo(SDKContext &Ctx, ImportDecl *ID);
SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformance *Conform);
SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info = TypeInitInfo());
SDKNode* createSDKNode(SDKNodeKind Kind);
Expand Down Expand Up @@ -80,6 +81,9 @@ void SDKNodeRoot::registerDescendant(SDKNode *D) {
// Operator doesn't have usr
if (isa<SDKNodeDeclOperator>(D))
return;
// Import doesn't have usr
if (isa<SDKNodeDeclImport>(D))
return;
if (auto DD = dyn_cast<SDKNodeDecl>(D)) {
assert(!DD->getUsr().empty());
DescendantDeclTable[DD->getUsr()].insert(DD);
Expand Down Expand Up @@ -166,6 +170,9 @@ SDKNodeDeclAccessor::SDKNodeDeclAccessor(SDKNodeInitInfo Info):
SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclAccessor),
AccKind(Info.AccKind) {}

SDKNodeDeclImport::SDKNodeDeclImport(SDKNodeInitInfo Info):
SDKNodeDecl(Info, SDKNodeKind::DeclImport) {}

SDKNodeDeclAssociatedType::SDKNodeDeclAssociatedType(SDKNodeInitInfo Info):
SDKNodeDecl(Info, SDKNodeKind::DeclAssociatedType) {};

Expand Down Expand Up @@ -375,6 +382,7 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
case SDKNodeKind::DeclType:
case SDKNodeKind::DeclOperator:
case SDKNodeKind::Conformance:
case SDKNodeKind::DeclImport:
llvm_unreachable("Type Parent is wrong");
case SDKNodeKind::DeclFunction:
case SDKNodeKind::DeclConstructor:
Expand Down Expand Up @@ -940,6 +948,7 @@ static bool isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R)
}
case SDKNodeKind::Conformance:
case SDKNodeKind::TypeWitness:
case SDKNodeKind::DeclImport:
case SDKNodeKind::Root: {
return L.getPrintedName() == R.getPrintedName() &&
L.hasSameChildren(R);
Expand Down Expand Up @@ -1358,6 +1367,13 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *OD):
PrintedName = OD->getName().str();
}

SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ImportDecl *ID):
SDKNodeInitInfo(Ctx, cast<Decl>(ID)) {
std::string content;
llvm::raw_string_ostream OS(content);
ID->getModulePath().print(OS);
Name = PrintedName = Ctx.buffer(content);
}

SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformance *Conform):
SDKNodeInitInfo(Ctx, Conform->getProtocol()) {
Expand Down Expand Up @@ -1888,6 +1904,10 @@ void SwiftDeclCollector::processDecl(Decl *D) {
if (auto *OD = dyn_cast<OperatorDecl>(D)) {
RootNode->addChild(constructOperatorDeclNode(OD));
}
if (auto *IM = dyn_cast<ImportDecl>(D)) {
RootNode->addChild(SDKNodeInitInfo(Ctx, IM)
.createSDKNode(SDKNodeKind::DeclImport));
}
}

void SwiftDeclCollector::processValueDecl(ValueDecl *VD) {
Expand Down
1 change: 1 addition & 0 deletions lib/DriverTool/swift_api_digester_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
case SDKNodeKind::DeclAccessor:
case SDKNodeKind::DeclConstructor:
case SDKNodeKind::DeclTypeAlias:
case SDKNodeKind::DeclImport:
case SDKNodeKind::TypeFunc:
case SDKNodeKind::TypeNominal:
case SDKNodeKind::TypeAlias: {
Expand Down
1 change: 1 addition & 0 deletions test/api-digester/Outputs/apinotes-diags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ APINotesTest(APINotesTest.h): TypeAlias CatAttributeName has been removed
APINotesTest(APINotesTest.h): Protocol SwiftTypeWithMethodLeft has been renamed to Protocol SwiftTypeWithMethodRight
APINotesTest(APINotesTest.h): Var OldType.oldMember has been renamed to Var NewType.newMember
APINotesTest(APINotesTest.h): Var globalAttributeName has been renamed to Var AnimalAttributeName.globalAttributeName
APINotesTest: Import Foundation has been renamed to Import objc_generics

/* Type Changes */
APINotesTest(APINotesTest.h): Constructor Cat.init(name:) has return type change from APINotesTest.Cat to APINotesTest.Cat?
Expand Down
11 changes: 11 additions & 0 deletions test/api-digester/Outputs/apinotes-migrator-gen-revert.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Import",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "",
"LeftComment": "objc_generics",
"RightUsr": "",
"RightComment": "Foundation",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Var",
Expand Down
11 changes: 11 additions & 0 deletions test/api-digester/Outputs/apinotes-migrator-gen.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Import",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "",
"LeftComment": "Foundation",
"RightUsr": "",
"RightComment": "objc_generics",
"ModuleName": "APINotesTest"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Var",
Expand Down
24 changes: 24 additions & 0 deletions test/api-digester/Outputs/cake-abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
"name": "TopLevel",
"printedName": "TopLevel",
"children": [
{
"kind": "Import",
"name": "SwiftOnoneSupport",
"printedName": "SwiftOnoneSupport",
"declKind": "Import",
"moduleName": "cake"
},
{
"kind": "Import",
"name": "_Concurrency",
"printedName": "_Concurrency",
"declKind": "Import",
"moduleName": "cake"
},
{
"kind": "Import",
"name": "cake",
"printedName": "cake",
"declKind": "Import",
"moduleName": "cake",
"declAttributes": [
"Exported"
]
},
{
"kind": "TypeDecl",
"name": "P1",
Expand Down
24 changes: 24 additions & 0 deletions test/api-digester/Outputs/cake.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
"name": "TopLevel",
"printedName": "TopLevel",
"children": [
{
"kind": "Import",
"name": "SwiftOnoneSupport",
"printedName": "SwiftOnoneSupport",
"declKind": "Import",
"moduleName": "cake"
},
{
"kind": "Import",
"name": "_Concurrency",
"printedName": "_Concurrency",
"declKind": "Import",
"moduleName": "cake"
},
{
"kind": "Import",
"name": "cake",
"printedName": "cake",
"declKind": "Import",
"moduleName": "cake",
"declAttributes": [
"Exported"
]
},
{
"kind": "TypeDecl",
"name": "P1",
Expand Down
10 changes: 10 additions & 0 deletions test/api-digester/Outputs/clang-module-dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"name": "TopLevel",
"printedName": "TopLevel",
"children": [
{
"kind": "Import",
"name": "ObjectiveC",
"printedName": "ObjectiveC",
"declKind": "Import",
"moduleName": "Foo",
"declAttributes": [
"Exported"
]
},
{
"kind": "TypeDecl",
"name": "AnotherObjcProt",
Expand Down