Skip to content

Commit 26952f7

Browse files
committed
ABI checker: include a field to indicate whether a decl is from extension
1 parent ee312bc commit 26952f7

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace api {
6363
///
6464
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
6565
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
66-
const uint8_t DIGESTER_JSON_VERSION = 7; // push SDKNodeRoot to lower-level
66+
const uint8_t DIGESTER_JSON_VERSION = 8; // add isFromExtension
6767
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.
6868
const StringRef ABIRootKey = "ABIRoot";
6969
const StringRef ConstValuesKey = "ConstValues";
@@ -354,6 +354,7 @@ class SDKNodeDecl: public SDKNode {
354354
bool IsOpen;
355355
bool IsInternal;
356356
bool IsABIPlaceholder;
357+
bool IsFromExtension;
357358
uint8_t ReferenceOwnership;
358359
StringRef GenericSig;
359360
// In ABI mode, this field is populated as a user-friendly version of GenericSig.
@@ -392,6 +393,7 @@ class SDKNodeDecl: public SDKNode {
392393
bool isOpen() const { return IsOpen; }
393394
bool isInternal() const { return IsInternal; }
394395
bool isABIPlaceholder() const { return IsABIPlaceholder; }
396+
bool isFromExtension() const { return IsFromExtension; }
395397
StringRef getGenericSignature() const { return GenericSig; }
396398
StringRef getSugaredGenericSignature() const { return SugaredGenericSig; }
397399
StringRef getScreenInfo() const;

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ KEY_BOOL(IsExternal, isExternal)
136136
KEY_BOOL(IsEnumExhaustive, isEnumExhaustive)
137137
KEY_BOOL(HasMissingDesignatedInitializers, hasMissingDesignatedInitializers)
138138
KEY_BOOL(InheritsConvenienceInitializers, inheritsConvenienceInitializers)
139+
KEY_BOOL(IsFromExtension, isFromExtension)
139140

140141
KEY(kind)
141142

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
109109
IsOverriding(Info.IsOverriding),
110110
IsOpen(Info.IsOpen),
111111
IsInternal(Info.IsInternal), IsABIPlaceholder(Info.IsABIPlaceholder),
112+
IsFromExtension(Info.IsFromExtension),
112113
ReferenceOwnership(uint8_t(Info.ReferenceOwnership)),
113114
GenericSig(Info.GenericSig),
114115
SugaredGenericSig(Info.SugaredGenericSig),
@@ -1376,6 +1377,13 @@ StringRef SDKContext::getInitKind(Decl *D) {
13761377
return StringRef();
13771378
}
13781379

1380+
static bool isDeclaredInExtension(Decl *D) {
1381+
if (auto *DC = D->getDeclContext()->getAsDecl()) {
1382+
return isa<ExtensionDecl>(DC);
1383+
}
1384+
return false;
1385+
}
1386+
13791387
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
13801388
Ctx(Ctx), DKind(D->getKind()), Loc(D->getLoc()),
13811389
Location(calculateLocation(Ctx, D)),
@@ -1394,6 +1402,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
13941402
IsImplicit(D->isImplicit()),
13951403
IsDeprecated(D->getAttrs().getDeprecated(D->getASTContext())),
13961404
IsABIPlaceholder(isABIPlaceholderRecursive(D)),
1405+
IsFromExtension(isDeclaredInExtension(D)),
13971406
DeclAttrs(collectDeclAttributes(D)) {}
13981407

13991408
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *OD):
@@ -2040,6 +2049,7 @@ void SDKNodeDecl::jsonize(json::Output &out) {
20402049
uint8_t Raw = uint8_t(getReferenceOwnership());
20412050
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_ownership).data(), Raw);
20422051
}
2052+
output(out, KeyKind::KK_isFromExtension, IsFromExtension);
20432053
}
20442054

20452055
void SDKNodeDeclAbstractFunc::jsonize(json::Output &out) {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"genericSig": "<τ_0_0 where τ_0_0 : cake.P1>",
6565
"sugared_genericSig": "<Self where Self : cake.P1>",
6666
"static": true,
67+
"isFromExtension": true,
6768
"funcSelfKind": "NonMutating"
6869
}
6970
],
@@ -219,6 +220,7 @@
219220
"moduleName": "cake",
220221
"genericSig": "<τ_0_0, τ_0_1, τ_0_2 where τ_0_0 == cake.S1, τ_0_1 == cake.S1, τ_0_2 == cake.S1>",
221222
"sugared_genericSig": "<T1, T2, T3 where T1 == cake.S1, T2 == cake.S1, T3 == cake.S1>",
223+
"isFromExtension": true,
222224
"funcSelfKind": "NonMutating"
223225
},
224226
{
@@ -238,6 +240,7 @@
238240
"moduleName": "cake",
239241
"genericSig": "<τ_0_0, τ_0_1, τ_0_2>",
240242
"sugared_genericSig": "<T1, T2, T3>",
243+
"isFromExtension": true,
241244
"funcSelfKind": "NonMutating"
242245
}
243246
],
@@ -1021,6 +1024,7 @@
10211024
"moduleName": "cake",
10221025
"genericSig": "<τ_0_0 where τ_0_0 : cake.ProWithAssociatedType>",
10231026
"sugared_genericSig": "<Self where Self : cake.ProWithAssociatedType>",
1027+
"isFromExtension": true,
10241028
"funcSelfKind": "NonMutating"
10251029
},
10261030
{
@@ -1039,6 +1043,7 @@
10391043
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
10401044
"mangledName": "$s4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
10411045
"moduleName": "cake",
1046+
"isFromExtension": true,
10421047
"accessors": [
10431048
{
10441049
"kind": "Accessor",
@@ -1058,6 +1063,7 @@
10581063
"moduleName": "cake",
10591064
"genericSig": "<τ_0_0 where τ_0_0 : cake.ProWithAssociatedType>",
10601065
"sugared_genericSig": "<Self where Self : cake.ProWithAssociatedType>",
1066+
"isFromExtension": true,
10611067
"accessorKind": "get"
10621068
}
10631069
]
@@ -1305,6 +1311,7 @@
13051311
"moduleName": "cake",
13061312
"genericSig": "<τ_0_0 where τ_0_0 : cake.PSuper>",
13071313
"sugared_genericSig": "<Self where Self : cake.PSuper>",
1314+
"isFromExtension": true,
13081315
"funcSelfKind": "NonMutating"
13091316
}
13101317
],
@@ -1648,6 +1655,7 @@
16481655
"usr": "s:Si4cakeE3fooyyF",
16491656
"mangledName": "$sSi4cakeE3fooyyF",
16501657
"moduleName": "cake",
1658+
"isFromExtension": true,
16511659
"funcSelfKind": "NonMutating"
16521660
},
16531661
{
@@ -1665,6 +1673,7 @@
16651673
"usr": "s:Si4cakeE3baryyF",
16661674
"mangledName": "$sSi4cakeE3baryyF",
16671675
"moduleName": "cake",
1676+
"isFromExtension": true,
16681677
"funcSelfKind": "NonMutating"
16691678
}
16701679
],
@@ -2008,6 +2017,6 @@
20082017
]
20092018
}
20102019
],
2011-
"json_format_version": 7
2020+
"json_format_version": 8
20122021
}
20132022
}

test/api-digester/Outputs/cake.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"moduleName": "cake",
6464
"genericSig": "<Self where Self : cake.P1>",
6565
"static": true,
66+
"isFromExtension": true,
6667
"funcSelfKind": "NonMutating"
6768
}
6869
],
@@ -223,6 +224,7 @@
223224
"mangledName": "$s4cake2C0CA2A2S1VRszAERs_AERs0_rlE17conditionalFooExtyyF",
224225
"moduleName": "cake",
225226
"genericSig": "<T1, T2, T3 where T1 == cake.S1, T2 == cake.S1, T3 == cake.S1>",
227+
"isFromExtension": true,
226228
"funcSelfKind": "NonMutating"
227229
},
228230
{
@@ -241,6 +243,7 @@
241243
"mangledName": "$s4cake2C0C19unconditionalFooExtyyF",
242244
"moduleName": "cake",
243245
"genericSig": "<T1, T2, T3>",
246+
"isFromExtension": true,
244247
"funcSelfKind": "NonMutating"
245248
}
246249
],
@@ -921,6 +924,7 @@
921924
"mangledName": "$s4cake21ProWithAssociatedTypePAAE10NonReqFuncyyF",
922925
"moduleName": "cake",
923926
"genericSig": "<Self where Self : cake.ProWithAssociatedType>",
927+
"isFromExtension": true,
924928
"funcSelfKind": "NonMutating"
925929
},
926930
{
@@ -939,6 +943,7 @@
939943
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
940944
"mangledName": "$s4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
941945
"moduleName": "cake",
946+
"isFromExtension": true,
942947
"accessors": [
943948
{
944949
"kind": "Accessor",
@@ -957,6 +962,7 @@
957962
"mangledName": "$s4cake21ProWithAssociatedTypePAAE9NonReqVarSivg",
958963
"moduleName": "cake",
959964
"genericSig": "<Self where Self : cake.ProWithAssociatedType>",
965+
"isFromExtension": true,
960966
"accessorKind": "get"
961967
}
962968
]
@@ -977,7 +983,8 @@
977983
"usr": "s:4cake21ProWithAssociatedTypePAAE11NonReqAliasa",
978984
"mangledName": "$s4cake21ProWithAssociatedTypePAAE11NonReqAliasa",
979985
"moduleName": "cake",
980-
"genericSig": "<Self where Self : cake.ProWithAssociatedType>"
986+
"genericSig": "<Self where Self : cake.ProWithAssociatedType>",
987+
"isFromExtension": true
981988
}
982989
],
983990
"declKind": "Protocol",
@@ -1187,6 +1194,7 @@
11871194
"mangledName": "$s4cake6PSuperPAAE9futureFooyyF",
11881195
"moduleName": "cake",
11891196
"genericSig": "<Self where Self : cake.PSuper>",
1197+
"isFromExtension": true,
11901198
"funcSelfKind": "NonMutating"
11911199
}
11921200
],
@@ -1508,6 +1516,7 @@
15081516
"usr": "s:Si4cakeE3fooyyF",
15091517
"mangledName": "$sSi4cakeE3fooyyF",
15101518
"moduleName": "cake",
1519+
"isFromExtension": true,
15111520
"funcSelfKind": "NonMutating"
15121521
},
15131522
{
@@ -1525,6 +1534,7 @@
15251534
"usr": "s:Si4cakeE3baryyF",
15261535
"mangledName": "$sSi4cakeE3baryyF",
15271536
"moduleName": "cake",
1537+
"isFromExtension": true,
15281538
"funcSelfKind": "NonMutating"
15291539
}
15301540
],
@@ -1868,6 +1878,6 @@
18681878
]
18691879
}
18701880
],
1871-
"json_format_version": 7
1881+
"json_format_version": 8
18721882
}
18731883
}

test/api-digester/Outputs/empty-baseline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"kind": "Root",
44
"name": "TopLevel",
55
"printedName": "TopLevel",
6-
"json_format_version": 7
6+
"json_format_version": 8
77
}
88
}

0 commit comments

Comments
 (0)