Skip to content

Commit 6e0d771

Browse files
authored
Merge pull request #25039 from nkcsgexi/intro-json-file
api-digester: keep track of the introduced platforms and language versions for all APIs
2 parents f6ee2c7 + 7b445c3 commit 6e0d771

File tree

6 files changed

+127
-1
lines changed

6 files changed

+127
-1
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ KEY_STRING(EnumRawTypeName, enumRawTypeName)
148148
KEY_STRING(GenericSig, genericSig)
149149
KEY_STRING(FuncSelfKind, funcSelfKind)
150150
KEY_STRING(ParamValueOwnership, paramValueOwnership)
151+
KEY_STRING(IntromacOS, intro_Macosx)
152+
KEY_STRING(IntroiOS, intro_iOS)
153+
KEY_STRING(IntrotvOS, intro_tvOS)
154+
KEY_STRING(IntrowatchOS, intro_watchOS)
155+
KEY_STRING(Introswift, intro_swift)
151156

152157
KEY_STRING_ARR(SuperclassNames, superclassNames)
153158

test/api-digester/Inputs/cake.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,9 @@ public class FutureContainer {
117117
extension FutureContainer: P1 {}
118118

119119
extension FutureContainer: P2 {}
120+
121+
@available(macOS 10.1, iOS 10.2, tvOS 10.3, watchOS 3.4, *)
122+
public class PlatformIntroClass {}
123+
124+
@available(swift, introduced: 5)
125+
public class SwiftIntroClass {}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,10 @@
12031203
"usr": "s:4cake15FutureContainerC9futureFooyyF",
12041204
"moduleName": "cake",
12051205
"isABIPlaceholder": true,
1206+
"intro_Macosx": "9999",
1207+
"intro_iOS": "9999",
1208+
"intro_tvOS": "9999",
1209+
"intro_watchOS": "9999",
12061210
"declAttributes": [
12071211
"Available",
12081212
"Available",
@@ -1225,6 +1229,7 @@
12251229
"declKind": "Func",
12261230
"usr": "s:4cake15FutureContainerC12NotfutureFooyyF",
12271231
"moduleName": "cake",
1232+
"intro_Macosx": "9999",
12281233
"declAttributes": [
12291234
"Available"
12301235
],
@@ -1250,6 +1255,36 @@
12501255
}
12511256
]
12521257
},
1258+
{
1259+
"kind": "TypeDecl",
1260+
"name": "PlatformIntroClass",
1261+
"printedName": "PlatformIntroClass",
1262+
"declKind": "Class",
1263+
"usr": "s:4cake18PlatformIntroClassC",
1264+
"moduleName": "cake",
1265+
"intro_Macosx": "10.1",
1266+
"intro_iOS": "10.2",
1267+
"intro_tvOS": "10.3",
1268+
"intro_watchOS": "3.4",
1269+
"declAttributes": [
1270+
"Available",
1271+
"Available",
1272+
"Available",
1273+
"Available"
1274+
]
1275+
},
1276+
{
1277+
"kind": "TypeDecl",
1278+
"name": "SwiftIntroClass",
1279+
"printedName": "SwiftIntroClass",
1280+
"declKind": "Class",
1281+
"usr": "s:4cake15SwiftIntroClassC",
1282+
"moduleName": "cake",
1283+
"intro_swift": "5",
1284+
"declAttributes": [
1285+
"Available"
1286+
]
1287+
},
12531288
{
12541289
"kind": "TypeDecl",
12551290
"name": "Int",

test/api-digester/Outputs/cake.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@
10921092
"usr": "s:4cake15FutureContainerC9futureFooyyF",
10931093
"moduleName": "cake",
10941094
"isABIPlaceholder": true,
1095+
"intro_Macosx": "9999",
1096+
"intro_iOS": "9999",
1097+
"intro_tvOS": "9999",
1098+
"intro_watchOS": "9999",
10951099
"declAttributes": [
10961100
"Available",
10971101
"Available",
@@ -1114,6 +1118,7 @@
11141118
"declKind": "Func",
11151119
"usr": "s:4cake15FutureContainerC12NotfutureFooyyF",
11161120
"moduleName": "cake",
1121+
"intro_Macosx": "9999",
11171122
"declAttributes": [
11181123
"Available"
11191124
],
@@ -1139,6 +1144,36 @@
11391144
}
11401145
]
11411146
},
1147+
{
1148+
"kind": "TypeDecl",
1149+
"name": "PlatformIntroClass",
1150+
"printedName": "PlatformIntroClass",
1151+
"declKind": "Class",
1152+
"usr": "s:4cake18PlatformIntroClassC",
1153+
"moduleName": "cake",
1154+
"intro_Macosx": "10.1",
1155+
"intro_iOS": "10.2",
1156+
"intro_tvOS": "10.3",
1157+
"intro_watchOS": "3.4",
1158+
"declAttributes": [
1159+
"Available",
1160+
"Available",
1161+
"Available",
1162+
"Available"
1163+
]
1164+
},
1165+
{
1166+
"kind": "TypeDecl",
1167+
"name": "SwiftIntroClass",
1168+
"printedName": "SwiftIntroClass",
1169+
"declKind": "Class",
1170+
"usr": "s:4cake15SwiftIntroClassC",
1171+
"moduleName": "cake",
1172+
"intro_swift": "5",
1173+
"declAttributes": [
1174+
"Available"
1175+
]
1176+
},
11421177
{
11431178
"kind": "TypeDecl",
11441179
"name": "Int",

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
8989
IsOpen(Info.IsOpen),
9090
IsInternal(Info.IsInternal), IsABIPlaceholder(Info.IsABIPlaceholder),
9191
ReferenceOwnership(uint8_t(Info.ReferenceOwnership)),
92-
GenericSig(Info.GenericSig), FixedBinaryOrder(Info.FixedBinaryOrder) {}
92+
GenericSig(Info.GenericSig), FixedBinaryOrder(Info.FixedBinaryOrder),
93+
introVersions({Info.IntromacOS, Info.IntroiOS, Info.IntrotvOS,
94+
Info.IntrowatchOS, Info.Introswift}){}
9395

9496
SDKNodeType::SDKNodeType(SDKNodeInitInfo Info, SDKNodeKind Kind):
9597
SDKNode(Info, Kind), TypeAttributes(Info.TypeAttrs),
@@ -1134,6 +1136,28 @@ static bool isABIPlaceholderRecursive(Decl *D) {
11341136
return false;
11351137
}
11361138

1139+
StringRef SDKContext::getPlatformIntroVersion(Decl *D, PlatformKind Kind) {
1140+
for (auto *ATT: D->getAttrs()) {
1141+
if (auto *AVA = dyn_cast<AvailableAttr>(ATT)) {
1142+
if (AVA->Platform == Kind && AVA->Introduced) {
1143+
return buffer(AVA->Introduced->getAsString());
1144+
}
1145+
}
1146+
}
1147+
return StringRef();
1148+
}
1149+
1150+
StringRef SDKContext::getLanguageIntroVersion(Decl *D) {
1151+
for (auto *ATT: D->getAttrs()) {
1152+
if (auto *AVA = dyn_cast<AvailableAttr>(ATT)) {
1153+
if (AVA->isLanguageVersionSpecific() && AVA->Introduced) {
1154+
return buffer(AVA->Introduced->getAsString());
1155+
}
1156+
}
1157+
}
1158+
return StringRef();
1159+
}
1160+
11371161
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info) :
11381162
Ctx(Ctx), Name(getTypeName(Ctx, Ty, Info.IsImplicitlyUnwrappedOptional)),
11391163
PrintedName(getPrintedName(Ctx, Ty, Info.IsImplicitlyUnwrappedOptional)),
@@ -1152,6 +1176,11 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
11521176
Location(calculateLocation(Ctx, D)),
11531177
ModuleName(D->getModuleContext()->getName().str()),
11541178
GenericSig(printGenericSignature(Ctx, D)),
1179+
IntromacOS(Ctx.getPlatformIntroVersion(D, PlatformKind::OSX)),
1180+
IntroiOS(Ctx.getPlatformIntroVersion(D, PlatformKind::iOS)),
1181+
IntrotvOS(Ctx.getPlatformIntroVersion(D, PlatformKind::tvOS)),
1182+
IntrowatchOS(Ctx.getPlatformIntroVersion(D, PlatformKind::watchOS)),
1183+
Introswift(Ctx.getLanguageIntroVersion(D)),
11551184
IsImplicit(D->isImplicit()),
11561185
IsDeprecated(D->getAttrs().getDeprecated(D->getASTContext())),
11571186
IsABIPlaceholder(isABIPlaceholderRecursive(D)) {
@@ -1726,6 +1755,11 @@ void SDKNodeDecl::jsonize(json::Output &out) {
17261755
output(out, KeyKind::KK_isOpen, IsOpen);
17271756
output(out, KeyKind::KK_isInternal, IsInternal);
17281757
output(out, KeyKind::KK_isABIPlaceholder, IsABIPlaceholder);
1758+
output(out, KeyKind::KK_intro_Macosx, introVersions.macos);
1759+
output(out, KeyKind::KK_intro_iOS, introVersions.ios);
1760+
output(out, KeyKind::KK_intro_tvOS, introVersions.tvos);
1761+
output(out, KeyKind::KK_intro_watchOS, introVersions.watchos);
1762+
output(out, KeyKind::KK_intro_swift, introVersions.swift);
17291763
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_declAttributes).data(), DeclAttributes);
17301764
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_fixedbinaryorder).data(), FixedBinaryOrder);
17311765
// Strong reference is implied, no need for serialization.

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class SDKContext {
187187
DiagnosticEngine &getDiags() {
188188
return Diags;
189189
}
190+
StringRef getPlatformIntroVersion(Decl *D, PlatformKind Kind);
191+
StringRef getLanguageIntroVersion(Decl *D);
190192
bool isEqual(const SDKNode &Left, const SDKNode &Right);
191193
bool checkingABI() const { return Opts.ABI; }
192194
AccessLevel getAccessLevel(const ValueDecl *VD) const;
@@ -285,6 +287,14 @@ class SDKNode {
285287
}
286288
};
287289

290+
struct PlatformIntroVersion {
291+
StringRef macos;
292+
StringRef ios;
293+
StringRef tvos;
294+
StringRef watchos;
295+
StringRef swift;
296+
};
297+
288298
class SDKNodeDecl: public SDKNode {
289299
DeclKind DKind;
290300
StringRef Usr;
@@ -302,6 +312,7 @@ class SDKNodeDecl: public SDKNode {
302312
uint8_t ReferenceOwnership;
303313
StringRef GenericSig;
304314
Optional<uint8_t> FixedBinaryOrder;
315+
PlatformIntroVersion introVersions;
305316

306317
protected:
307318
SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind);

0 commit comments

Comments
 (0)