Skip to content

Commit 5ff6286

Browse files
committed
[ASTDumper] Write inherited types correctly.
ASTDumper was never updated to print extra conformance information, like suppression, preconcurrency, etc. In default mode, we print it as a comma-delimited list of source-like strings. In JSON mode, we print objects containing flags.
1 parent c14561f commit 5ff6286

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,10 @@ struct InheritedEntry : public TypeLoc {
18591859
assert(!IsSuppressed && "setting suppressed again!?");
18601860
IsSuppressed = true;
18611861
}
1862+
1863+
void dump(raw_ostream &os) const;
1864+
1865+
SWIFT_DEBUG_DUMP;
18621866
};
18631867

18641868
/// A wrapper for the collection of inherited types for either a `TypeDecl` or

lib/AST/ASTDumper.cpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,16 @@ static StringRef getDumpString(ExecutionKind kind) {
624624
return "caller";
625625
}
626626
}
627+
static StringRef getDumpString(ExplicitSafety safety) {
628+
switch (safety) {
629+
case ExplicitSafety::Unspecified:
630+
return "unspecified";
631+
case ExplicitSafety::Safe:
632+
return "safe";
633+
case ExplicitSafety::Unsafe:
634+
return "unsafe";
635+
}
636+
}
627637
static StringRef getDumpString(StringRef s) {
628638
return s;
629639
}
@@ -1924,16 +1934,38 @@ namespace {
19241934
}
19251935

19261936
void printInherited(InheritedTypes Inherited) {
1927-
printStringListField(Inherited.getEntries(), [&](InheritedEntry Super) {
1928-
if (Writer.isParsable()) {
1929-
return typeUSR(Super.getType());
1930-
} else {
1931-
std::string value;
1932-
llvm::raw_string_ostream SOS(value);
1933-
Super.getType().print(SOS);
1934-
return value;
1935-
}
1936-
}, Label::always("inherits"), /*delimiter=*/ ", ");
1937+
if (Writer.isParsable()) {
1938+
printList(
1939+
Inherited.getEntries(),
1940+
[&](InheritedEntry Super, Label label) {
1941+
printRecArbitrary(
1942+
[&](Label label) {
1943+
printHead("inherited_entry", FieldLabelColor, label);
1944+
printTypeField(Super.getType(), Label::always("type"));
1945+
printFlag(Super.isPreconcurrency(), "preconcurrency");
1946+
printFlag(Super.isRetroactive(), "retroactive");
1947+
printFlag(Super.isSuppressed(), "suppressed");
1948+
printFlag(Super.isUnchecked(), "unchecked");
1949+
if (Super.getExplicitSafety() !=
1950+
ExplicitSafety::Unspecified)
1951+
printField(Super.getExplicitSafety(),
1952+
Label::always("safety"));
1953+
printFoot();
1954+
},
1955+
label);
1956+
},
1957+
Label::always("inherits"));
1958+
} else {
1959+
printStringListField(
1960+
Inherited.getEntries(),
1961+
[&](InheritedEntry Super) {
1962+
std::string value;
1963+
llvm::raw_string_ostream SOS(value);
1964+
Super.dump(SOS);
1965+
return value;
1966+
},
1967+
Label::always("inherits"), /*delimiter=*/", ");
1968+
}
19371969
}
19381970

19391971
void printImportPath(ImportDecl *ID, Label label) {
@@ -6504,3 +6536,19 @@ void SILResultInfo::dump() const {
65046536
print(llvm::errs());
65056537
llvm::errs() << '\n';
65066538
}
6539+
6540+
void InheritedEntry::dump(llvm::raw_ostream &os) const {
6541+
if (isPreconcurrency())
6542+
os << "@preconcurrency ";
6543+
if (isRetroactive())
6544+
os << "@retroactive ";
6545+
if (isUnchecked())
6546+
os << "@unchecked ";
6547+
if (getExplicitSafety() != ExplicitSafety::Unspecified)
6548+
os << '@' << getDumpString(getExplicitSafety()) << ' ';
6549+
if (isSuppressed())
6550+
os << "~";
6551+
getType().print(os);
6552+
}
6553+
6554+
void InheritedEntry::dump() const { dump(llvm::errs()); }

0 commit comments

Comments
 (0)