Skip to content

Commit 171ff44

Browse files
authored
Remove swift::reversed in favor of llvm::reverse (swiftlang#27610)
The former predates the latter, but we don't need it anymore! The latter has more features anyway. No functionality change.
1 parent 4791af0 commit 171ff44

33 files changed

+48
-60
lines changed

include/swift/Basic/Range.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
/// This file provides classes and functions for conveniently working
1616
/// with ranges,
1717
///
18-
/// reversed returns an iterator_range out of the reverse iterators of a type.
19-
///
2018
/// map creates an iterator_range which applies a function to all the elements
2119
/// in another iterator_range.
2220
///
@@ -26,10 +24,6 @@
2624
/// indices returns the range of indices from [0..size()) on a
2725
/// subscriptable type.
2826
///
29-
/// Note that this is kept in Swift because it's really only useful in
30-
/// C++11, and there aren't any major open-source subprojects of LLVM
31-
/// that can use C++11 yet.
32-
///
3327
//===----------------------------------------------------------------------===//
3428

3529
#ifndef SWIFT_BASIC_RANGE_H
@@ -45,12 +39,6 @@
4539
namespace swift {
4640
using llvm::make_range;
4741

48-
template<typename T>
49-
inline auto reversed(T &&container)
50-
-> decltype(llvm::make_range(container.rbegin(), container.rend())) {
51-
return llvm::make_range(container.rbegin(), container.rend());
52-
}
53-
5442
// Wrapper for std::transform that creates a new back-insertable container
5543
// and transforms a range into it.
5644
template<typename T, typename InputRange, typename MapFn>
@@ -233,9 +221,9 @@ static inline IntRange<unsigned> range(unsigned end) {
233221

234222
/// Returns a reverse Int range (start, end].
235223
static inline auto reverse_range(unsigned start, unsigned end) ->
236-
decltype(reversed(range(start+1, end+1))) {
224+
decltype(llvm::reverse(range(start+1, end+1))) {
237225
assert(start <= end && "Invalid integral range");
238-
return reversed(range(start+1, end+1));
226+
return llvm::reverse(range(start+1, end+1));
239227
}
240228

241229
} // end namespace swift

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ GenericTypeParamType *ASTMangler::appendAssocType(DependentMemberType *DepTy,
11581158
}
11591159
if (auto gpRoot = dyn_cast<GenericTypeParamType>(base)) {
11601160
bool first = true;
1161-
for (auto *member : reversed(path)) {
1161+
for (auto *member : llvm::reverse(path)) {
11621162
appendAssociatedTypeName(member);
11631163
appendListSeparator(first);
11641164
}

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ createExtensionGenericParams(ASTContext &ctx,
11811181
});
11821182

11831183
GenericParamList *toParams = nullptr;
1184-
for (auto *gpList : reversed(allGenericParams)) {
1184+
for (auto *gpList : llvm::reverse(allGenericParams)) {
11851185
gpList->setOuterParameters(toParams);
11861186
toParams = gpList;
11871187
}

lib/AST/Evaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ bool Evaluator::checkDependency(const AnyRequest &request) {
9999

100100
void Evaluator::diagnoseCycle(const AnyRequest &request) {
101101
request.diagnoseCycle(diags);
102-
for (const auto &step : reversed(activeRequests)) {
102+
for (const auto &step : llvm::reverse(activeRequests)) {
103103
if (step == request) return;
104104

105105
step.noteCycleStep(diags);

lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ SourceRange TupleExpr::getSourceRange() const {
12701270
return { SourceLoc(), SourceLoc() };
12711271
} else {
12721272
// Scan backwards for a valid source loc.
1273-
for (Expr *expr : reversed(getElements())) {
1273+
for (Expr *expr : llvm::reverse(getElements())) {
12741274
end = expr->getEndLoc();
12751275
if (end.isValid()) {
12761276
break;

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ void
12311231
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out,
12321232
StringRef delim) const {
12331233
SmallVector<StringRef, 8> elements(*this, {});
1234-
swift::interleave(swift::reversed(elements),
1234+
swift::interleave(llvm::reverse(elements),
12351235
[&out](StringRef next) { out << next; },
12361236
[&out, delim] { out << delim; });
12371237
}

lib/AST/SwiftNameTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ getErrorDomainStringForObjC(const EnumDecl *ED) {
7272
}
7373

7474
std::string buffer = ED->getParentModule()->getNameStr();
75-
for (auto D : reversed(outerTypes)) {
75+
for (auto D : llvm::reverse(outerTypes)) {
7676
buffer += ".";
7777
buffer += D->getNameStr();
7878
}

lib/Basic/LangOptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ checkPlatformConditionSupported(PlatformConditionKind Kind, StringRef Value,
156156
StringRef
157157
LangOptions::getPlatformConditionValue(PlatformConditionKind Kind) const {
158158
// Last one wins.
159-
for (auto &Opt : reversed(PlatformConditionValues)) {
159+
for (auto &Opt : llvm::reverse(PlatformConditionValues)) {
160160
if (Opt.first == Kind)
161161
return Opt.second;
162162
}
@@ -169,7 +169,7 @@ checkPlatformCondition(PlatformConditionKind Kind, StringRef Value) const {
169169
if (Kind == PlatformConditionKind::OS && Value == "macOS")
170170
return checkPlatformCondition(Kind, "OSX");
171171

172-
for (auto &Opt : reversed(PlatformConditionValues)) {
172+
for (auto &Opt : llvm::reverse(PlatformConditionValues)) {
173173
if (Opt.first == Kind)
174174
if (Opt.second == Value)
175175
return true;

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ DefaultArgumentKind ClangImporter::Implementation::inferDefaultArgument(
17981798
const clang::EnumDecl *enumDef = enumTy->getDecl()->getDefinition();
17991799
if (enumDef && nameImporter.getEnumKind(enumDef) == EnumKind::Options) {
18001800
auto enumName = enumDef->getName();
1801-
for (auto word : reversed(camel_case::getWords(enumName))) {
1801+
for (auto word : llvm::reverse(camel_case::getWords(enumName))) {
18021802
if (camel_case::sameWordIgnoreFirstCase(word, "options"))
18031803
return DefaultArgumentKind::EmptyArray;
18041804
}
@@ -1820,7 +1820,7 @@ DefaultArgumentKind ClangImporter::Implementation::inferDefaultArgument(
18201820
emptyDictionaryKind = DefaultArgumentKind::NilLiteral;
18211821

18221822
bool sawInfo = false;
1823-
for (auto word : reversed(camel_case::getWords(searchStr))) {
1823+
for (auto word : llvm::reverse(camel_case::getWords(searchStr))) {
18241824
if (camel_case::sameWordIgnoreFirstCase(word, "options"))
18251825
return emptyDictionaryKind;
18261826

lib/IRGen/GenInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void TemporarySet::destroyAll(IRGenFunction &IGF) const {
8989
assert(!hasBeenCleared() && "destroying a set that's been cleared?");
9090

9191
// Deallocate all the temporaries.
92-
for (auto &temporary : reversed(Stack)) {
92+
for (auto &temporary : llvm::reverse(Stack)) {
9393
temporary.destroy(IGF);
9494
}
9595
}

0 commit comments

Comments
 (0)