Skip to content

Commit 55f194b

Browse files
committed
api-digester: in module dump, record whether a func decl is mutating.
1 parent ab9b035 commit 55f194b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
public struct S1 {
22
public func foo1() {}
3-
public func foo2() {}
3+
mutating public func foo2() {}
44
}

test/api-digester/Outputs/cake.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"usr": "s:FV4cake2S14foo2FT_T_",
3737
"location": "",
3838
"moduleName": "cake",
39+
"mutating": true,
3940
"children": [
4041
{
4142
"kind": "TypeNominal",

tools/swift-api-digester/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ KEY(children)
6666
KEY(printedName)
6767
KEY(moduleName)
6868
KEY(throwing)
69+
KEY(mutating)
6970
KEY(typeAttributes)
7071
KEY(declAttributes)
7172
KEY(declKind)

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct SDKNodeInitInfo {
261261
StringRef Location;
262262
StringRef ModuleName;
263263
bool IsThrowing = false;
264+
bool IsMutating = false;
264265
Optional<uint8_t> SelfIndex;
265266
std::vector<SDKDeclAttrKind> DeclAttrs;
266267
std::vector<TypeAttrKind> TypeAttrs;
@@ -683,15 +684,18 @@ class SDKNodeVar : public SDKNodeDecl {
683684

684685
class SDKNodeAbstractFunc : public SDKNodeDecl {
685686
const bool IsThrowing;
687+
const bool IsMutating;
686688
const Optional<uint8_t> SelfIndex;
687689

688690
protected:
689691
SDKNodeAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind) :
690692
SDKNodeDecl(Info, Kind),
691693
IsThrowing(Info.IsThrowing),
694+
IsMutating(Info.IsMutating),
692695
SelfIndex(Info.SelfIndex){}
693696
public:
694697
bool isThrowing() const { return IsThrowing; }
698+
bool isMutating() const { return IsMutating; }
695699
uint8_t getSelfIndex() const { return SelfIndex.getValue(); }
696700
Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
697701
bool hasSelfIndex() const { return SelfIndex.hasValue(); }
@@ -800,6 +804,8 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
800804
Info.ModuleName = GetScalarString(Pair.getValue());
801805
} else if (Key == Key_throwing) {
802806
Info.IsThrowing = true;
807+
} else if (Key == Key_mutating) {
808+
Info.IsMutating = true;
803809
} else if (Key == Key_typeAttributes) {
804810
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue());
805811
for (auto It = Seq->begin(); It != Seq->end(); ++ It) {
@@ -946,6 +952,13 @@ static bool isFuncThrowing(ValueDecl *VD) {
946952
return false;
947953
}
948954

955+
static bool isFuncMutating(ValueDecl *VD) {
956+
if (auto AF = dyn_cast<FuncDecl>(VD)) {
957+
return AF->isMutating();
958+
}
959+
return false;
960+
}
961+
949962
static Optional<uint8_t> getSelfIndex(ValueDecl *VD) {
950963
if (auto AF = dyn_cast<AbstractFunctionDecl>(VD)) {
951964
if (AF->isImportAsInstanceMember())
@@ -965,7 +978,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(ValueDecl *VD) :
965978
PrintedName(getPrintedName(VD)), DKind(VD->getKind()),
966979
USR(calculateUsr(VD)), Location(calculateLocation(VD)),
967980
ModuleName(VD->getModuleContext()->getName().str()),
968-
IsThrowing(isFuncThrowing(VD)), SelfIndex(getSelfIndex(VD)) {
981+
IsThrowing(isFuncThrowing(VD)), IsMutating(isFuncMutating(VD)),
982+
SelfIndex(getSelfIndex(VD)) {
969983
if (VD->getAttrs().getDeprecated(VD->getASTContext()))
970984
DeclAttrs.push_back(SDKDeclAttrKind::DAK_deprecated);
971985
}
@@ -1296,6 +1310,8 @@ namespace swift {
12961310
if (auto F = dyn_cast<SDKNodeAbstractFunc>(value.get())) {
12971311
if (bool isThrowing = F->isThrowing())
12981312
out.mapRequired(Key_throwing, isThrowing);
1313+
if (bool isMutating = F->isMutating())
1314+
out.mapRequired(Key_mutating, isMutating);
12991315
if (F->hasSelfIndex()) {
13001316
auto Index = F->getSelfIndex();
13011317
out.mapRequired(Key_selfIndex, Index);

0 commit comments

Comments
 (0)