Skip to content

Commit 17169fc

Browse files
authored
Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2 parents c326016 + ffbe53e commit 17169fc

File tree

103 files changed

+426
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+426
-362
lines changed

docs/DebuggingTheCompiler.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ debugging press <CTRL>-C on the LLDB prompt.
214214
Note that this only works in Xcode if the PATH variable in the scheme's
215215
environment setting contains the path to the dot tool.
216216

217+
swift/Basic/Debug.h includes macros to help contributors declare these methods
218+
with the proper attributes to ensure they'll be available in the debugger. In
219+
particular, if you see ``SWIFT_DEBUG_DUMP`` in a class declaration, that class
220+
has a ``dump()`` method you can call.
221+
217222
Debugging and Profiling on SIL level
218223
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219224

include/swift/AST/ASTNode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_AST_AST_NODE_H
1919

2020
#include "llvm/ADT/PointerUnion.h"
21+
#include "swift/Basic/Debug.h"
2122
#include "swift/AST/TypeAlignments.h"
2223

2324
namespace llvm {
@@ -62,9 +63,7 @@ namespace swift {
6263
FUNC(Decl)
6364
#undef FUNC
6465

65-
LLVM_ATTRIBUTE_DEPRECATED(
66-
void dump() const LLVM_ATTRIBUTE_USED,
67-
"only for use within the debugger");
66+
SWIFT_DEBUG_DUMP;
6867
void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
6968

7069
/// Whether the AST node is implicit.

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/NameLookup.h" // for DeclVisibilityKind
3333
#include "swift/AST/SimpleRequest.h"
3434
#include "swift/Basic/Compiler.h"
35+
#include "swift/Basic/Debug.h"
3536
#include "swift/Basic/LLVM.h"
3637
#include "swift/Basic/NullablePtr.h"
3738
#include "swift/Basic/SourceManager.h"
@@ -330,8 +331,7 @@ class ASTScopeImpl {
330331
virtual NullablePtr<const void> addressForPrinting() const;
331332

332333
public:
333-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
334-
"only for use within the debugger");
334+
SWIFT_DEBUG_DUMP;
335335

336336
void dumpOneScopeMapLocation(std::pair<unsigned, unsigned> lineColumn);
337337

include/swift/AST/AccessScope.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/AST/AttrKind.h"
1717
#include "swift/AST/DeclContext.h"
18+
#include "swift/Basic/Debug.h"
1819
#include "llvm/ADT/PointerIntPair.h"
1920

2021
namespace swift {
@@ -87,7 +88,7 @@ class AccessScope {
8788
return None;
8889
}
8990

90-
void dump() const;
91+
SWIFT_DEBUG_DUMP;
9192
};
9293

9394
} // end namespace swift

include/swift/AST/AnyFunctionRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_AST_ANY_FUNCTION_REF_H
1515

1616
#include "swift/Basic/Compiler.h"
17+
#include "swift/Basic/Debug.h"
1718
#include "swift/Basic/LLVM.h"
1819
#include "swift/AST/Decl.h"
1920
#include "swift/AST/Expr.h"
@@ -177,8 +178,7 @@ class AnyFunctionRef {
177178
#pragma warning(push)
178179
#pragma warning(disable: 4996)
179180
#endif
180-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
181-
"only for use within the debugger") {
181+
SWIFT_DEBUG_DUMP {
182182
if (auto afd = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
183183
return afd->dump();
184184
}

include/swift/AST/Attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_ATTR_H
1818
#define SWIFT_ATTR_H
1919

20+
#include "swift/Basic/Debug.h"
2021
#include "swift/Basic/InlineBitfield.h"
2122
#include "swift/Basic/SourceLoc.h"
2223
#include "swift/Basic/UUID.h"
@@ -1583,7 +1584,7 @@ class DeclAttributes {
15831584
/// a declaration is deprecated on all deployment targets, or null otherwise.
15841585
const AvailableAttr *getDeprecated(const ASTContext &ctx) const;
15851586

1586-
void dump(const Decl *D = nullptr) const;
1587+
SWIFT_DEBUG_DUMPER(dump(const Decl *D = nullptr));
15871588
void print(ASTPrinter &Printer, const PrintOptions &Options,
15881589
const Decl *D = nullptr) const;
15891590
static void print(ASTPrinter &Printer, const PrintOptions &Options,

include/swift/AST/CaptureInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_CAPTURE_INFO_H
1414
#define SWIFT_AST_CAPTURE_INFO_H
1515

16+
#include "swift/Basic/Debug.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/OptionSet.h"
1819
#include "swift/Basic/SourceLoc.h"
@@ -219,7 +220,7 @@ class CaptureInfo {
219220
return StorageAndFlags.getPointer()->getOpaqueValue();
220221
}
221222

222-
void dump() const;
223+
SWIFT_DEBUG_DUMP;
223224
void print(raw_ostream &OS) const;
224225
};
225226

include/swift/AST/ConcreteDeclRef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_AST_CONCRETEDECLREF_H
1818
#define SWIFT_AST_CONCRETEDECLREF_H
1919

20+
#include "swift/Basic/Debug.h"
2021
#include "swift/Basic/LLVM.h"
2122
#include "swift/AST/SubstitutionMap.h"
2223
#include "swift/AST/TypeAlignments.h"
@@ -81,8 +82,8 @@ class ConcreteDeclRef {
8182
}
8283

8384
/// Dump a debug representation of this reference.
84-
void dump(raw_ostream &os);
85-
void dump() LLVM_ATTRIBUTE_USED;
85+
void dump(raw_ostream &os) const;
86+
SWIFT_DEBUG_DUMP;
8687
};
8788

8889
} // end namespace swift

include/swift/AST/Decl.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "swift/AST/Witness.h"
3636
#include "swift/Basic/ArrayRefView.h"
3737
#include "swift/Basic/Compiler.h"
38+
#include "swift/Basic/Debug.h"
3839
#include "swift/Basic/InlineBitfield.h"
3940
#include "swift/Basic/NullablePtr.h"
4041
#include "swift/Basic/OptionalEnum.h"
@@ -777,12 +778,8 @@ class alignas(1 << DeclAlignInBits) Decl {
777778

778779
SourceLoc TrailingSemiLoc;
779780

780-
LLVM_ATTRIBUTE_DEPRECATED(
781-
void dump() const LLVM_ATTRIBUTE_USED,
782-
"only for use within the debugger");
783-
LLVM_ATTRIBUTE_DEPRECATED(
784-
void dump(const char *filename) const LLVM_ATTRIBUTE_USED,
785-
"only for use within the debugger");
781+
SWIFT_DEBUG_DUMP;
782+
SWIFT_DEBUG_DUMPER(dump(const char *filename));
786783
void dump(raw_ostream &OS, unsigned Indent = 0) const;
787784

788785
/// Pretty-print the given declaration.
@@ -1203,9 +1200,7 @@ class RequirementRepr {
12031200
return repr->SecondType.getTypeRepr();
12041201
}
12051202

1206-
LLVM_ATTRIBUTE_DEPRECATED(
1207-
void dump() const LLVM_ATTRIBUTE_USED,
1208-
"only for use within the debugger");
1203+
SWIFT_DEBUG_DUMP;
12091204
void print(raw_ostream &OS) const;
12101205
void print(ASTPrinter &Printer) const;
12111206
};
@@ -1375,7 +1370,7 @@ class GenericParamList final :
13751370
GenericParamList *clone(DeclContext *dc) const;
13761371

13771372
void print(raw_ostream &OS) const;
1378-
void dump();
1373+
SWIFT_DEBUG_DUMP;
13791374
};
13801375

13811376
/// A trailing where clause.
@@ -2715,7 +2710,7 @@ class ValueDecl : public Decl {
27152710
void dumpRef(raw_ostream &os) const;
27162711

27172712
/// Dump a reference to the given declaration.
2718-
void dumpRef() const;
2713+
SWIFT_DEBUG_DUMPER(dumpRef());
27192714

27202715
/// Returns true if the declaration is a static member of a type.
27212716
///

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/LookupKinds.h"
2424
#include "swift/AST/ResilienceExpansion.h"
2525
#include "swift/AST/TypeAlignments.h"
26+
#include "swift/Basic/Debug.h"
2627
#include "swift/Basic/LLVM.h"
2728
#include "swift/Basic/STLExtras.h"
2829
#include "swift/Basic/SourceLoc.h"
@@ -597,7 +598,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
597598
/// \returns true if traversal was aborted, false otherwise.
598599
bool walkContext(ASTWalker &Walker);
599600

600-
void dumpContext() const;
601+
SWIFT_DEBUG_DUMPER(dumpContext());
601602
unsigned printContext(llvm::raw_ostream &OS, unsigned indent = 0,
602603
bool onlyAPartialLine = false) const;
603604

include/swift/AST/Evaluator.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "swift/AST/AnyRequest.h"
2222
#include "swift/Basic/AnyValue.h"
23+
#include "swift/Basic/Debug.h"
2324
#include "swift/Basic/Defer.h"
2425
#include "swift/Basic/Statistic.h"
2526
#include "llvm/ADT/DenseMap.h"
@@ -452,17 +453,13 @@ class Evaluator {
452453

453454
/// Dump the dependencies of the given request to the debugging stream
454455
/// as a tree.
455-
LLVM_ATTRIBUTE_DEPRECATED(
456-
void dumpDependencies(const AnyRequest &request) const LLVM_ATTRIBUTE_USED,
457-
"Only meant for use in the debugger");
456+
SWIFT_DEBUG_DUMPER(dumpDependencies(const AnyRequest &request));
458457

459458
/// Print all dependencies known to the evaluator as a single Graphviz
460459
/// directed graph.
461460
void printDependenciesGraphviz(llvm::raw_ostream &out) const;
462461

463-
LLVM_ATTRIBUTE_DEPRECATED(
464-
void dumpDependenciesGraphviz() const LLVM_ATTRIBUTE_USED,
465-
"Only meant for use in the debugger");
462+
SWIFT_DEBUG_DUMPER(dumpDependenciesGraphviz());
466463
};
467464

468465
template <typename Request>

include/swift/AST/ExperimentalDependencies.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_EXPERIMENTAL_DEPENDENCIES_H
1414
#define SWIFT_AST_EXPERIMENTAL_DEPENDENCIES_H
1515

16+
#include "swift/Basic/Debug.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/Range.h"
1819
#include "llvm/ADT/Hashing.h"
@@ -498,7 +499,8 @@ class DependencyKey {
498499

499500
std::string humanReadableName() const;
500501

501-
void dump() const { llvm::errs() << asString() << "\n"; }
502+
void dump(llvm::raw_ostream &os) const { os << asString() << "\n"; }
503+
SWIFT_DEBUG_DUMP { dump(llvm::errs()); }
502504

503505
/// For debugging, needed for \ref TwoStageMap::verify
504506
std::string asString() const;
@@ -609,7 +611,8 @@ class DepGraphNode {
609611
/// needs to set the fingerprint *after* the node has been created.
610612
void setFingerprint(Optional<std::string> fp) { fingerprint = fp; }
611613

612-
void dump() const;
614+
SWIFT_DEBUG_DUMP;
615+
void dump(llvm::raw_ostream &os) const;
613616

614617
std::string humanReadableName(StringRef where) const;
615618

@@ -685,7 +688,6 @@ class SourceFileDepGraphNode : public DepGraphNode {
685688
if (n != getSequenceNumber())
686689
defsIDependUpon.insert(n);
687690
}
688-
void dump() const { DepGraphNode::dump(); }
689691

690692
std::string humanReadableName() const {
691693
return DepGraphNode::humanReadableName("here");

include/swift/AST/Expr.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/TypeAlignments.h"
2828
#include "swift/AST/TypeLoc.h"
2929
#include "swift/AST/Availability.h"
30+
#include "swift/Basic/Debug.h"
3031
#include "swift/Basic/InlineBitfield.h"
3132
#include "llvm/Support/TrailingObjects.h"
3233
#include <utility>
@@ -540,9 +541,7 @@ class alignas(8) Expr {
540541
/// leaf node, etc.
541542
llvm::DenseMap<Expr *, unsigned> getPreorderIndexMap();
542543

543-
LLVM_ATTRIBUTE_DEPRECATED(
544-
void dump() const LLVM_ATTRIBUTE_USED,
545-
"only for use within the debugger");
544+
SWIFT_DEBUG_DUMP;
546545
void dump(raw_ostream &OS, unsigned Indent = 0) const;
547546
void dump(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
548547
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,

include/swift/AST/GenericEnvironment.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/GenericSignature.h"
2222
#include "swift/AST/GenericParamKey.h"
2323
#include "swift/Basic/Compiler.h"
24+
#include "swift/Basic/Debug.h"
2425
#include "llvm/ADT/ArrayRef.h"
2526
#include "llvm/Support/ErrorHandling.h"
2627
#include "llvm/Support/TrailingObjects.h"
@@ -160,7 +161,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
160161

161162
void dump(raw_ostream &os) const;
162163

163-
void dump() const;
164+
SWIFT_DEBUG_DUMP;
164165
};
165166

166167
} // end namespace swift

include/swift/AST/GenericSignature.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/Requirement.h"
2222
#include "swift/AST/Type.h"
2323
#include "swift/Basic/AnyValue.h"
24+
#include "swift/Basic/Debug.h"
2425
#include "llvm/ADT/ArrayRef.h"
2526
#include "llvm/ADT/FoldingSet.h"
2627
#include "llvm/ADT/SmallVector.h"
@@ -89,7 +90,7 @@ class ConformanceAccessPath {
8990

9091
void print(raw_ostream &OS) const;
9192

92-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const, "only for use in a debugger");
93+
SWIFT_DEBUG_DUMP;
9394
};
9495

9596
class GenericSignatureImpl;
@@ -136,7 +137,7 @@ class GenericSignature {
136137

137138
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
138139
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
139-
void dump() const;
140+
SWIFT_DEBUG_DUMP;
140141
std::string getAsString() const;
141142

142143
// Support for FoldingSet.
@@ -408,7 +409,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
408409

409410
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
410411
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
411-
void dump() const;
412+
SWIFT_DEBUG_DUMP;
412413
std::string getAsString() const;
413414
};
414415

0 commit comments

Comments
 (0)