Skip to content

[AutoDiff upstream] NFC: update IndexSubset print/dump utilities. #27775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions include/swift/AST/IndexSubset.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,10 @@ class IndexSubset : public llvm::FoldingSetNode {
id.AddInteger(index);
}

void print(llvm::raw_ostream &s = llvm::outs()) const {
s << '{';
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
[&s] { s << ", "; });
s << '}';
}

void dump(llvm::raw_ostream &s = llvm::errs()) const {
s << "(index_subset capacity=" << capacity << " indices=(";
interleave(getIndices(), [&s](unsigned i) { s << i; },
[&s] { s << ", "; });
s << "))";
}
void print(llvm::raw_ostream &s = llvm::outs()) const;
LLVM_ATTRIBUTE_DEPRECATED(void dump(llvm::raw_ostream &s = llvm::errs())
const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");

int findNext(int startIndex) const;
int findFirst() const { return findNext(-1); }
Expand Down
14 changes: 14 additions & 0 deletions lib/AST/IndexSubset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ IndexSubset *IndexSubset::extendingCapacity(
return IndexSubset::get(ctx, indices);
}

void IndexSubset::print(llvm::raw_ostream &s) const {
s << '{';
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
[&s] { s << ", "; });
s << '}';
}

void IndexSubset::dump(llvm::raw_ostream &s) const {
s << "(index_subset capacity=" << capacity << " indices=(";
interleave(getIndices(), [&s](unsigned i) { s << i; },
[&s] { s << ", "; });
s << "))\n";
}

int IndexSubset::findNext(int startIndex) const {
assert(startIndex < (int)capacity && "Start index cannot be past the end");
unsigned bitWordIndex = 0, offset = 0;
Expand Down