Skip to content

Commit f745587

Browse files
authored
[AutoDiff] NFC: Clean up print/dump utility functions. (#27772)
All `dump` functions now print a newline at the end.
1 parent e9bfd14 commit f745587

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

include/swift/AST/AutoDiff.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,9 @@ struct SILAutoDiffIndices {
243243
parameters->contains(parameterIndex);
244244
}
245245

246-
void print(llvm::raw_ostream &s = llvm::outs()) const {
247-
s << "(source=" << source << " parameters=(";
248-
interleave(parameters->getIndices(),
249-
[&s](unsigned p) { s << p; }, [&s]{ s << ' '; });
250-
s << "))";
251-
}
246+
void print(llvm::raw_ostream &s = llvm::outs()) const;
247+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
248+
"only for use within the debugger");
252249

253250
std::string mangle() const {
254251
std::string result = "src_" + llvm::utostr(source) + "_wrt_";
@@ -279,6 +276,10 @@ struct AutoDiffConfig {
279276
GenericSignatureImpl *derivativeGenericSignature)
280277
: parameterIndices(parameterIndices), resultIndices(resultIndices),
281278
derivativeGenericSignature(derivativeGenericSignature) {}
279+
280+
void print(llvm::raw_ostream &s = llvm::outs()) const;
281+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
282+
"only for use within the debugger");
282283
};
283284

284285
/// In conjunction with the original function declaration, identifies an

include/swift/AST/IndexSubset.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,10 @@ class IndexSubset : public llvm::FoldingSetNode {
201201
id.AddInteger(index);
202202
}
203203

204-
void print(llvm::raw_ostream &s = llvm::outs()) const {
205-
s << '{';
206-
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
207-
[&s] { s << ", "; });
208-
s << '}';
209-
}
210-
211-
void dump(llvm::raw_ostream &s = llvm::errs()) const {
212-
s << "(index_subset capacity=" << capacity << " indices=(";
213-
interleave(getIndices(), [&s](unsigned i) { s << i; },
214-
[&s] { s << ", "; });
215-
s << "))";
216-
}
204+
void print(llvm::raw_ostream &s = llvm::outs()) const;
205+
LLVM_ATTRIBUTE_DEPRECATED(void dump(llvm::raw_ostream &s = llvm::errs())
206+
const LLVM_ATTRIBUTE_USED,
207+
"only for use within the debugger");
217208

218209
int findNext(int startIndex) const;
219210
int findFirst() const { return findNext(-1); }

lib/AST/AutoDiff.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,35 @@ LinearDifferentiableFunctionTypeComponent(StringRef string) {
8888
rawValue = *result;
8989
}
9090

91+
void SILAutoDiffIndices::print(llvm::raw_ostream &s) const {
92+
s << "(source=" << source << " parameters=(";
93+
interleave(parameters->getIndices(),
94+
[&s](unsigned p) { s << p; }, [&s]{ s << ' '; });
95+
s << "))";
96+
}
97+
98+
void SILAutoDiffIndices::dump() const {
99+
print(llvm::errs());
100+
llvm::errs() << '\n';
101+
}
102+
103+
void AutoDiffConfig::print(llvm::raw_ostream &s) const {
104+
s << "(parameters=";
105+
parameterIndices->print(s);
106+
s << " results=";
107+
resultIndices->print(s);
108+
if (derivativeGenericSignature) {
109+
s << " where=";
110+
derivativeGenericSignature->print(s);
111+
}
112+
s << ')';
113+
}
114+
115+
void AutoDiffConfig::dump() const {
116+
print(llvm::errs());
117+
llvm::errs() << '\n';
118+
}
119+
91120
// TODO(TF-874): This helper is inefficient and should be removed. Unwrapping at
92121
// most once (for curried method types) is sufficient.
93122
static void unwrapCurryLevels(AnyFunctionType *fnTy,

lib/AST/IndexSubset.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ IndexSubset *IndexSubset::extendingCapacity(
7979
return IndexSubset::get(ctx, indices);
8080
}
8181

82+
void IndexSubset::print(llvm::raw_ostream &s) const {
83+
s << '{';
84+
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
85+
[&s] { s << ", "; });
86+
s << '}';
87+
}
88+
89+
void IndexSubset::dump(llvm::raw_ostream &s) const {
90+
s << "(index_subset capacity=" << capacity << " indices=(";
91+
interleave(getIndices(), [&s](unsigned i) { s << i; },
92+
[&s] { s << ", "; });
93+
s << "))\n";
94+
}
95+
8296
int IndexSubset::findNext(int startIndex) const {
8397
assert(startIndex < (int)capacity && "Start index cannot be past the end");
8498
unsigned bitWordIndex = 0, offset = 0;

0 commit comments

Comments
 (0)