Skip to content

Commit d2fd347

Browse files
committed
Additional post-review fixes.
1 parent f249db3 commit d2fd347

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

include/swift/AST/Attr.h

+5
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,12 @@ class ImplementsAttr : public DeclAttribute {
17221722
DeclName MemberName);
17231723

17241724
ProtocolDecl *getProtocol(DeclContext *dc) const;
1725+
1726+
/// Returns the protocol declaration containing the requirement being
1727+
/// implemented by the attributed declaration if it has already been computed,
1728+
/// otherwise `nullopt`. This should only be used for dumping.
17251729
std::optional<ProtocolDecl *> getCachedProtocol(DeclContext *dc) const;
1730+
17261731
TypeRepr *getProtocolTypeRepr() const { return TyR; }
17271732

17281733
DeclName getMemberName() const { return MemberName; }

include/swift/Option/Options.td

+3-1
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,9 @@ def dump_ast : Flag<["-"], "dump-ast">,
13511351
HelpText<"Parse and type-check input file(s) and dump AST(s)">, ModeOpt,
13521352
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
13531353
def dump_ast_format : Separate<["-"], "dump-ast-format">,
1354-
HelpText<"Desired format for -dump-ast output ('default', 'json', or 'json-zlib')">,
1354+
HelpText<"Desired format for -dump-ast output "
1355+
"('default', 'json', or 'json-zlib'); no format is guaranteed "
1356+
"stable across different compiler versions">,
13551357
MetaVarName<"<format>">,
13561358
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
13571359
def emit_ast : Flag<["-"], "emit-ast">, Alias<dump_ast>,

lib/AST/ASTDumper.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -2227,12 +2227,12 @@ namespace {
22272227
if (Writer.isParsable()) {
22282228
// Parsable outputs are meant to be used for semantic analysis, so we
22292229
// want the full list of members, including macro-generated ones.
2230-
printList(IDC->getABIMembers(), [&](Decl *D, Label label) {
2230+
printList(IDC->getAllMembers(), [&](Decl *D, Label label) {
22312231
printRec(D, label);
22322232
}, Label::optional("members"));
22332233
} else {
22342234
auto members = ParseIfNeeded ? IDC->getMembers()
2235-
: IDC->getCurrentMembersWithoutLoading();
2235+
: IDC->getCurrentMembersWithoutLoading();
22362236
printList(members, [&](Decl *D, Label label) {
22372237
printRec(D, label);
22382238
}, Label::optional("members"));
@@ -4794,7 +4794,7 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
47944794

47954795
void visitExecutionAttr(ExecutionAttr *Attr, Label label) {
47964796
printCommon(Attr, "execution_attr", label);
4797-
printField(Attr->getBehavior(), "behavior");
4797+
printField(Attr->getBehavior(), Label::always("behavior"));
47984798
printFoot();
47994799
}
48004800
void visitABIAttr(ABIAttr *Attr, Label label) {
@@ -5869,14 +5869,15 @@ namespace {
58695869
#define VISIT_BINDABLE_NOMINAL_TYPE(TypeClass, Name) \
58705870
VISIT_NOMINAL_TYPE(TypeClass, Name) \
58715871
void visitBoundGeneric##TypeClass( \
5872-
BoundGeneric##TypeClass *T, StringRef label) { \
5872+
BoundGeneric##TypeClass *T, Label label) { \
58735873
printCommon("bound_generic_" #Name, label); \
5874-
printFieldQuoted(T->getDecl()->printRef(), "decl"); \
5874+
printFieldQuoted(T->getDecl()->printRef(), Label::always("decl")); \
58755875
printFlag(T->getDecl()->hasClangNode(), "foreign"); \
58765876
if (T->getParent()) \
5877-
printRec(T->getParent(), "parent"); \
5878-
for (auto arg : T->getGenericArgs()) \
5879-
printRec(arg); \
5877+
printRec(T->getParent(), Label::always("parent")); \
5878+
printList(T->getGenericArgs(), [&](auto arg, Label label) { \
5879+
printRec(arg, label); \
5880+
}, Label::optional("generic_args")); \
58805881
printFoot(); \
58815882
}
58825883

@@ -5919,7 +5920,7 @@ namespace {
59195920

59205921
void visitModuleType(ModuleType *T, Label label) {
59215922
printCommon("module_type", label);
5922-
printDeclNameField(T->getModule(), Label::always("module"));
5923+
printDeclName(T->getModule(), Label::always("module"));
59235924
printFlag(T->getModule()->isNonSwiftModule(), "foreign");
59245925
printFoot();
59255926
}
@@ -6042,7 +6043,7 @@ namespace {
60426043
void printAnyFunctionParamsRec(ArrayRef<AnyFunctionType::Param> params,
60436044
Label label) {
60446045
printRecArbitrary([&](Label label) {
6045-
printCommon("function_params", FieldLabelColor, label);
6046+
printHead("function_params", FieldLabelColor, label);
60466047

60476048
printField(params.size(), Label::always("num_params"));
60486049
printList(params, [&](const auto &param, Label label) {

test/Frontend/ast-dump-json-output-map.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: echo 'public func main() {a(); b()}' > %t/main.swift
55
// RUN: echo "{\"%/t/a.swift\": {\"ast-dump\": \"%/t/a.ast\"}, \"%/t/b.swift\": {\"ast-dump\": \"%/t/b.ast\"}, \"%/t/main.swift\": {\"ast-dump\": \"%/t/main.ast\"}}" > %t/outputs.json
66

7-
// RUN: %target-build-swift -dump-ast -dump-ast-format json -output-file-map %t/outputs.json %t/a.swift %t/b.swift %t/main.swift -module-name main
7+
// RUN: %target-build-swift -dump-ast -dump-ast-format json -output-file-map %t/outputs.json %/t/a.swift %/t/b.swift %/t/main.swift -module-name main
88
// RUN: %FileCheck -check-prefix A-AST %s < %t/a.ast
99
// RUN: %FileCheck -check-prefix B-AST %s < %t/b.ast
1010
// RUN: %FileCheck -check-prefix MAIN-AST %s < %t/main.ast

test/Frontend/dump-parse.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ struct SelfParam {
112112

113113
// CHECK-LABEL: (func_decl range=[{{.+}}] "createOptional()" static
114114
// CHECK-NEXT: (parameter "self")
115-
// CHECK-NEXT: (parameter_list range=[{{.+}}])
116115
// CHECK-NEXT: (result=type_optional
117116
// CHECK-NEXT: (type_unqualified_ident id="SelfParam" unbound))
117+
// CHECK-NEXT: (parameter_list range=[{{.+}}])
118118
static func createOptional() -> SelfParam? {
119119

120120
// CHECK-LABEL: (call_expr type="<null>"
@@ -125,8 +125,8 @@ struct SelfParam {
125125
}
126126

127127
// CHECK-LABEL: (func_decl range=[{{.+}}] "dumpMemberTypeRepr()"
128-
// CHECK-NEXT: (parameter_list range=[{{.+}}])
129128
// CHECK-NEXT: (result=type_qualified_ident id="Element" unbound
130129
// CHECK-NEXT: (type_unqualified_ident id="Array" unbound
131130
// CHECK-NEXT: (type_unqualified_ident id="Bool" unbound))
131+
// CHECK-NEXT: (parameter_list range=[{{.+}}])
132132
func dumpMemberTypeRepr() -> Array<Bool>.Element { true }

0 commit comments

Comments
 (0)