Skip to content

Commit 92719d6

Browse files
committed
swift-api-digester: mark if a type declaration is pulled from an external module
To incorporate extensions to types from other modules, the tool sometimes needs to pull type declaration from external modules even though these modules are not under checking. We need a flag to explicitly mark such case.
1 parent 6e0d771 commit 92719d6

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ KEY_BOOL(HasDidset, hasDidset)
135135
KEY_BOOL(HasWillset, hasWillset)
136136
KEY_BOOL(ReqNewWitnessTableEntry, reqNewWitnessTableEntry)
137137
KEY_BOOL(IsABIPlaceholder, isABIPlaceholder)
138+
KEY_BOOL(IsExternal, isExternal)
138139

139140
KEY(kind)
140141

test/api-digester/Outputs/cake-abi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@
13291329
"declAttributes": [
13301330
"FixedLayout"
13311331
],
1332+
"isExternal": true,
13321333
"conformances": [
13331334
{
13341335
"kind": "Conformance",

test/api-digester/Outputs/cake.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@
12181218
"declAttributes": [
12191219
"FixedLayout"
12201220
],
1221+
"isExternal": true,
12211222
"conformances": [
12221223
{
12231224
"kind": "Conformance",

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ SDKNodeTypeAlias::SDKNodeTypeAlias(SDKNodeInitInfo Info):
110110
SDKNodeDeclType::SDKNodeDeclType(SDKNodeInitInfo Info):
111111
SDKNodeDecl(Info, SDKNodeKind::DeclType), SuperclassUsr(Info.SuperclassUsr),
112112
SuperclassNames(Info.SuperclassNames),
113-
EnumRawTypeName(Info.EnumRawTypeName) {}
113+
EnumRawTypeName(Info.EnumRawTypeName), IsExternal(Info.IsExternal) {}
114114

115115
SDKNodeConformance::SDKNodeConformance(SDKNodeInitInfo Info):
116116
SDKNode(Info, SDKNodeKind::Conformance),
@@ -1483,7 +1483,9 @@ SwiftDeclCollector::constructTypeDeclNode(NominalTypeDecl *NTD) {
14831483
SDKNode *swift::ide::api::
14841484
SwiftDeclCollector::constructExternalExtensionNode(NominalTypeDecl *NTD,
14851485
ArrayRef<ExtensionDecl*> AllExts) {
1486-
auto *TypeNode = SDKNodeInitInfo(Ctx, NTD).createSDKNode(SDKNodeKind::DeclType);
1486+
SDKNodeInitInfo initInfo(Ctx, NTD);
1487+
initInfo.IsExternal = true;
1488+
auto *TypeNode = initInfo.createSDKNode(SDKNodeKind::DeclType);
14871489
addConformancesToTypeDecl(cast<SDKNodeDeclType>(TypeNode), NTD);
14881490

14891491
bool anyConformancesAdded = false;
@@ -1785,6 +1787,7 @@ void SDKNodeDeclType::jsonize(json::Output &out) {
17851787
SDKNodeDecl::jsonize(out);
17861788
output(out, KeyKind::KK_superclassUsr, SuperclassUsr);
17871789
output(out, KeyKind::KK_enumRawTypeName, EnumRawTypeName);
1790+
output(out, KeyKind::KK_isExternal, IsExternal);
17881791
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_superclassNames).data(), SuperclassNames);
17891792
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_conformances).data(), Conformances);
17901793
}

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ class SDKNodeDeclType: public SDKNodeDecl {
469469
std::vector<StringRef> SuperclassNames;
470470
std::vector<SDKNode*> Conformances;
471471
StringRef EnumRawTypeName;
472+
// Check whether the type declaration is pulled from an external module so we
473+
// can incorporate extensions in the interested module.
474+
bool IsExternal;
472475
public:
473476
SDKNodeDeclType(SDKNodeInitInfo Info);
474477
static bool classof(const SDKNode *N);
@@ -477,6 +480,7 @@ class SDKNodeDeclType: public SDKNodeDecl {
477480
void addConformance(SDKNode *Conf);
478481
ArrayRef<SDKNode*> getConformances() const { return Conformances; }
479482
NodeVector getConformances() { return Conformances; }
483+
bool isExternal() const { return IsExternal; }
480484
StringRef getSuperClassName() const {
481485
return SuperclassNames.empty() ? StringRef() : SuperclassNames.front();
482486
};

0 commit comments

Comments
 (0)