Skip to content

Commit 209cd2e

Browse files
authored
Merge pull request #13922 from rudkx/iuo-update-api-digester
IUO: Update swift-api-digester for the removal of IUOs from the type …
2 parents dc1dac6 + 4a91351 commit 209cd2e

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ struct SDKNodeInitInfo {
302302
StringRef SuperclassUsr;
303303
SDKNodeInitInfo(SDKContext &Ctx) : Ctx(Ctx) {}
304304
SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD);
305-
SDKNodeInitInfo(SDKContext &Ctx, Type Ty);
305+
SDKNodeInitInfo(SDKContext &Ctx, Type Ty,
306+
bool IsImplicitlyUnwrappedOptional =false);
306307
SDKNode* createSDKNode(SDKNodeKind Kind);
307308
};
308309

@@ -1029,16 +1030,21 @@ class SDKNodeDumpVisitor : public SDKNodeVisitor {
10291030
SDKNodeDumpVisitor() {};
10301031
};
10311032

1032-
static StringRef getPrintedName(SDKContext &Ctx, Type Ty) {
1033+
static StringRef getPrintedName(SDKContext &Ctx, Type Ty,
1034+
bool IsImplicitlyUnwrappedOptional) {
10331035
std::string S;
10341036
llvm::raw_string_ostream OS(S);
10351037
PrintOptions PO;
10361038
PO.SkipAttributes = true;
1039+
if (IsImplicitlyUnwrappedOptional)
1040+
PO.PrintOptionalAsImplicitlyUnwrapped = true;
1041+
10371042
Ty.print(OS, PO);
10381043
return Ctx.buffer(OS.str());
10391044
}
10401045

1041-
static StringRef getTypeName(SDKContext &Ctx, Type Ty) {
1046+
static StringRef getTypeName(SDKContext &Ctx, Type Ty,
1047+
bool IsImplicitlyUnwrappedOptional) {
10421048
if (Ty->getKind() == TypeKind::Paren) {
10431049
return Ctx.buffer("Paren");
10441050
}
@@ -1049,6 +1055,10 @@ static StringRef getTypeName(SDKContext &Ctx, Type Ty) {
10491055
return NAT->getDecl()->getNameStr();
10501056
}
10511057
if (Ty->getAnyNominal()) {
1058+
if (IsImplicitlyUnwrappedOptional) {
1059+
assert(Ty->getAnyOptionalObjectType());
1060+
return StringRef("ImplicitlyUnwrappedOptional");
1061+
}
10521062
return Ty->getAnyNominal()->getNameStr();
10531063
}
10541064
#define TYPE(id, parent) \
@@ -1159,8 +1169,10 @@ static Ownership getOwnership(ValueDecl *VD) {
11591169
return Ownership::Strong;
11601170
}
11611171

1162-
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty) :
1163-
Ctx(Ctx), Name(getTypeName(Ctx, Ty)), PrintedName(getPrintedName(Ctx, Ty)) {
1172+
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty,
1173+
bool IsImplicitlyUnwrappedOptional) :
1174+
Ctx(Ctx), Name(getTypeName(Ctx, Ty, IsImplicitlyUnwrappedOptional)),
1175+
PrintedName(getPrintedName(Ctx, Ty, IsImplicitlyUnwrappedOptional)) {
11641176
if (isFunctionTypeNoEscape(Ty))
11651177
TypeAttrs.push_back(TypeAttrKind::TAK_noescape);
11661178
}
@@ -1196,8 +1208,10 @@ case SDKNodeKind::X: \
11961208

11971209
// Recursively construct a node that represents a type, for instance,
11981210
// representing the return value type of a function decl.
1199-
static SDKNode *constructTypeNode(SDKContext &Ctx, Type T) {
1200-
SDKNode* Root = SDKNodeInitInfo(Ctx, T).createSDKNode(SDKNodeKind::TypeNominal);
1211+
static SDKNode *constructTypeNode(SDKContext &Ctx, Type T,
1212+
bool IsImplicitlyUnwrappedOptional =false) {
1213+
SDKNode* Root = SDKNodeInitInfo(Ctx, T, IsImplicitlyUnwrappedOptional)
1214+
.createSDKNode(SDKNodeKind::TypeNominal);
12011215

12021216
if (auto NAT = dyn_cast<NameAliasType>(T.getPointer())) {
12031217
SDKNode* Root = SDKNodeInitInfo(Ctx, T).createSDKNode(SDKNodeKind::TypeNameAlias);
@@ -1245,11 +1259,20 @@ static SDKNode *constructTypeNode(SDKContext &Ctx, Type T) {
12451259
static SDKNode *constructFunctionNode(SDKContext &Ctx, FuncDecl* FD,
12461260
SDKNodeKind Kind) {
12471261
auto Func = SDKNodeInitInfo(Ctx, FD).createSDKNode(Kind);
1248-
Func->addChild(constructTypeNode(Ctx, FD->getResultInterfaceType()));
1262+
bool resultIsImplicitlyUnwrappedOptional = false;
1263+
if (FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
1264+
resultIsImplicitlyUnwrappedOptional = true;
1265+
Func->addChild(constructTypeNode(Ctx, FD->getResultInterfaceType(),
1266+
resultIsImplicitlyUnwrappedOptional));
12491267
for (auto *paramList : FD->getParameterLists()) {
12501268
for (auto param : *paramList) {
1269+
bool paramIsImplicitlyUnwrappedOptional = false;
1270+
if (param->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
1271+
paramIsImplicitlyUnwrappedOptional = true;
1272+
12511273
if (!param->isSelfParameter())
1252-
Func->addChild(constructTypeNode(Ctx, param->getInterfaceType()));
1274+
Func->addChild(constructTypeNode(Ctx, param->getInterfaceType(),
1275+
paramIsImplicitlyUnwrappedOptional));
12531276
}
12541277
}
12551278
return Func;
@@ -1321,7 +1344,11 @@ static SDKNode *constructTypeDeclNode(SDKContext &Ctx, NominalTypeDecl *NTD) {
13211344

13221345
static SDKNode *constructVarNode(SDKContext &Ctx, ValueDecl *VD) {
13231346
auto Var = SDKNodeInitInfo(Ctx, VD).createSDKNode(SDKNodeKind::Var);
1324-
Var->addChild(constructTypeNode(Ctx, VD->getInterfaceType()));
1347+
auto isImplicitlyUnwrappedOptional = false;
1348+
if (VD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
1349+
isImplicitlyUnwrappedOptional = true;
1350+
Var->addChild(constructTypeNode(Ctx, VD->getInterfaceType(),
1351+
isImplicitlyUnwrappedOptional));
13251352
if (auto VAD = dyn_cast<AbstractStorageDecl>(VD)) {
13261353
if (auto Getter = VAD->getGetter())
13271354
Var->addChild(constructFunctionNode(Ctx, Getter, SDKNodeKind::Getter));

0 commit comments

Comments
 (0)