Skip to content

Commit 843a584

Browse files
authored
Merge pull request #31091 from MForster/llvm-interleave
Move interleave(...) to the llvm namespace
2 parents cbeb758 + fae87c9 commit 843a584

25 files changed

+220
-205
lines changed

include/swift/AST/AutoDiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct SILAutoDiffIndices {
202202

203203
std::string mangle() const {
204204
std::string result = "src_" + llvm::utostr(source) + "_wrt_";
205-
interleave(
205+
llvm::interleave(
206206
parameters->getIndices(),
207207
[&](unsigned idx) { result += llvm::utostr(idx); },
208208
[&] { result += '_'; });

include/swift/Basic/STLExtras.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ struct function_traits<R (T::*)(Args...) const> {
6969
using argument_types = std::tuple<Args...>;
7070
};
7171

72+
} // end namespace swift
73+
74+
namespace llvm {
75+
7276
/// @{
7377

7478
/// An STL-style algorithm similar to std::for_each that applies a second
@@ -103,6 +107,11 @@ inline void interleave(const Container &c, UnaryFunctor each_fn,
103107
}
104108

105109
/// @}
110+
111+
} // end namespace llvm
112+
113+
namespace swift {
114+
106115
/// @{
107116

108117
/// The equivalent of std::for_each, but for two lists at once.

lib/AST/ASTPrinter.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,25 +1477,26 @@ void PrintAST::printSingleDepthOfGenericSignature(
14771477
if (printParams) {
14781478
// Print the generic parameters.
14791479
Printer << "<";
1480-
interleave(genericParams,
1481-
[&](GenericTypeParamType *param) {
1482-
if (!subMap.empty()) {
1483-
if (auto argTy = substParam(param))
1484-
printType(argTy);
1485-
else
1486-
printType(param);
1487-
} else if (auto *GP = param->getDecl()) {
1488-
Printer.callPrintStructurePre(
1489-
PrintStructureKind::GenericParameter, GP);
1490-
Printer.printName(GP->getName(),
1491-
PrintNameContext::GenericParameter);
1492-
Printer.printStructurePost(
1493-
PrintStructureKind::GenericParameter, GP);
1494-
} else {
1495-
printType(param);
1496-
}
1497-
},
1498-
[&] { Printer << ", "; });
1480+
llvm::interleave(
1481+
genericParams,
1482+
[&](GenericTypeParamType *param) {
1483+
if (!subMap.empty()) {
1484+
if (auto argTy = substParam(param))
1485+
printType(argTy);
1486+
else
1487+
printType(param);
1488+
} else if (auto *GP = param->getDecl()) {
1489+
Printer.callPrintStructurePre(PrintStructureKind::GenericParameter,
1490+
GP);
1491+
Printer.printName(GP->getName(),
1492+
PrintNameContext::GenericParameter);
1493+
Printer.printStructurePost(PrintStructureKind::GenericParameter,
1494+
GP);
1495+
} else {
1496+
printType(param);
1497+
}
1498+
},
1499+
[&] { Printer << ", "; });
14991500
}
15001501

15011502
if (printRequirements || printInherited) {
@@ -3025,7 +3026,7 @@ void PrintAST::visitEnumCaseDecl(EnumCaseDecl *decl) {
30253026
}
30263027
Printer << tok::kw_case << " ";
30273028

3028-
interleave(elems.begin(), elems.end(),
3029+
llvm::interleave(elems.begin(), elems.end(),
30293030
[&](EnumElementDecl *elt) {
30303031
printEnumElement(elt);
30313032
},
@@ -4438,9 +4439,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
44384439
if (!T->getSubstitutions().empty()) {
44394440
Printer << '<';
44404441
auto replacements = T->getSubstitutions().getReplacementTypes();
4441-
interleave(replacements.begin(), replacements.end(),
4442-
[&](Type t) { visit(t); },
4443-
[&] { Printer << ", "; });
4442+
llvm::interleave(
4443+
replacements.begin(), replacements.end(), [&](Type t) { visit(t); },
4444+
[&] { Printer << ", "; });
44444445
Printer << '>';
44454446
}
44464447
return;

lib/AST/ASTScopePrinting.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ void ASTScopeImpl::dumpOneScopeMapLocation(
6565
locScope->lookupLocalsOrMembers({this}, gatherer);
6666
if (!gatherer.getDecls().empty()) {
6767
llvm::errs() << "Local bindings: ";
68-
interleave(gatherer.getDecls().begin(), gatherer.getDecls().end(),
69-
[&](ValueDecl *value) { llvm::errs() << value->getFullName(); },
70-
[&]() { llvm::errs() << " "; });
68+
llvm::interleave(
69+
gatherer.getDecls().begin(), gatherer.getDecls().end(),
70+
[&](ValueDecl *value) { llvm::errs() << value->getFullName(); },
71+
[&]() { llvm::errs() << " "; });
7172
llvm::errs() << "\n";
7273
}
7374
}

lib/AST/GenericSignature.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
using namespace swift;
3030

3131
void ConformanceAccessPath::print(raw_ostream &out) const {
32-
interleave(begin(), end(),
33-
[&](const Entry &entry) {
34-
entry.first.print(out);
35-
out << ": " << entry.second->getName();
36-
}, [&] {
37-
out << " -> ";
38-
});
32+
llvm::interleave(
33+
begin(), end(),
34+
[&](const Entry &entry) {
35+
entry.first.print(out);
36+
out << ": " << entry.second->getName();
37+
},
38+
[&] { out << " -> "; });
3939
}
4040

4141
void ConformanceAccessPath::dump() const {

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,16 +2139,16 @@ void EquivalenceClass::dump(llvm::raw_ostream &out,
21392139
},
21402140
[&] { out << ", "; });
21412141
out << "\nSame-type constraints:";
2142-
interleave(sameTypeConstraints,
2143-
[&](const Constraint<Type> &constraint) {
2144-
out << "\n " << constraint.getSubjectDependentType({ })
2145-
<< " == " << constraint.value;
2146-
2147-
if (constraint.source->isDerivedRequirement())
2148-
out << " [derived]";
2149-
}, [&] {
2150-
out << ", ";
2151-
});
2142+
llvm::interleave(
2143+
sameTypeConstraints,
2144+
[&](const Constraint<Type> &constraint) {
2145+
out << "\n " << constraint.getSubjectDependentType({})
2146+
<< " == " << constraint.value;
2147+
2148+
if (constraint.source->isDerivedRequirement())
2149+
out << " [derived]";
2150+
},
2151+
[&] { out << ", "; });
21522152
if (concreteType)
21532153
out << "\nConcrete type: " << concreteType.getString();
21542154
if (superclass)
@@ -2922,15 +2922,15 @@ void RewritePath::print(llvm::raw_ostream &out) const {
29222922
if (!getPath().empty()) out << " -> ";
29232923
}
29242924

2925-
interleave(getPath().begin(), getPath().end(),
2926-
[&](AssociatedTypeDecl *assocType) {
2927-
out.changeColor(raw_ostream::BLUE);
2928-
out << assocType->getProtocol()->getName() << "."
2929-
<< assocType->getName();
2930-
out.resetColor();
2931-
}, [&] {
2932-
out << " -> ";
2933-
});
2925+
llvm::interleave(
2926+
getPath().begin(), getPath().end(),
2927+
[&](AssociatedTypeDecl *assocType) {
2928+
out.changeColor(raw_ostream::BLUE);
2929+
out << assocType->getProtocol()->getName() << "."
2930+
<< assocType->getName();
2931+
out.resetColor();
2932+
},
2933+
[&] { out << " -> "; });
29342934
out << "]";
29352935
}
29362936

lib/AST/IndexSubset.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ IndexSubset *IndexSubset::extendingCapacity(
8080

8181
void IndexSubset::print(llvm::raw_ostream &s) const {
8282
s << '{';
83-
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
84-
[&s] { s << ", "; });
83+
llvm::interleave(
84+
range(capacity), [this, &s](unsigned i) { s << contains(i); },
85+
[&s] { s << ", "; });
8586
s << '}';
8687
}
8788

lib/AST/Module.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,9 @@ void
14791479
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out,
14801480
StringRef delim) const {
14811481
SmallVector<StringRef, 8> elements(*this, {});
1482-
swift::interleave(llvm::reverse(elements),
1483-
[&out](StringRef next) { out << next; },
1484-
[&out, delim] { out << delim; });
1482+
llvm::interleave(
1483+
llvm::reverse(elements), [&out](StringRef next) { out << next; },
1484+
[&out, delim] { out << delim; });
14851485
}
14861486

14871487
void

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,9 @@ ClangImporter::create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
928928

929929
if (importerOpts.DumpClangDiagnostics) {
930930
llvm::errs() << "'";
931-
interleave(invocationArgStrs,
932-
[](StringRef arg) { llvm::errs() << arg; },
933-
[] { llvm::errs() << "' '"; });
931+
llvm::interleave(
932+
invocationArgStrs, [](StringRef arg) { llvm::errs() << arg; },
933+
[] { llvm::errs() << "' '"; });
934934
llvm::errs() << "'\n";
935935
}
936936

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -973,37 +973,32 @@ void SwiftLookupTable::dump(raw_ostream &os) const {
973973
printStoredContext(entry.Context, os);
974974
os << ": ";
975975

976-
interleave(entry.DeclsOrMacros.begin(), entry.DeclsOrMacros.end(),
977-
[this, &os](uint64_t entry) {
978-
printStoredEntry(this, entry, os);
979-
},
980-
[&os] {
981-
os << ", ";
982-
});
976+
llvm::interleave(
977+
entry.DeclsOrMacros.begin(), entry.DeclsOrMacros.end(),
978+
[this, &os](uint64_t entry) { printStoredEntry(this, entry, os); },
979+
[&os] { os << ", "; });
983980
os << "\n";
984981
}
985982
}
986983

987984
if (!Categories.empty()) {
988985
os << "Categories: ";
989-
interleave(Categories.begin(), Categories.end(),
990-
[&os](clang::ObjCCategoryDecl *category) {
991-
os << category->getClassInterface()->getName()
992-
<< "(" << category->getName() << ")";
993-
},
994-
[&os] {
995-
os << ", ";
996-
});
986+
llvm::interleave(
987+
Categories.begin(), Categories.end(),
988+
[&os](clang::ObjCCategoryDecl *category) {
989+
os << category->getClassInterface()->getName() << "("
990+
<< category->getName() << ")";
991+
},
992+
[&os] { os << ", "; });
997993
os << "\n";
998994
} else if (Reader && !Reader->categories().empty()) {
999995
os << "Categories: ";
1000-
interleave(Reader->categories().begin(), Reader->categories().end(),
1001-
[&os](clang::serialization::DeclID declID) {
1002-
os << "decl ID #" << declID;
1003-
},
1004-
[&os] {
1005-
os << ", ";
1006-
});
996+
llvm::interleave(
997+
Reader->categories().begin(), Reader->categories().end(),
998+
[&os](clang::serialization::DeclID declID) {
999+
os << "decl ID #" << declID;
1000+
},
1001+
[&os] { os << ", "; });
10071002
os << "\n";
10081003
}
10091004

@@ -1020,13 +1015,10 @@ void SwiftLookupTable::dump(raw_ostream &os) const {
10201015
os << ": ";
10211016

10221017
const auto &entries = GlobalsAsMembersIndex.find(context)->second;
1023-
interleave(entries.begin(), entries.end(),
1024-
[this, &os](uint64_t entry) {
1025-
printStoredEntry(this, entry, os);
1026-
},
1027-
[&os] {
1028-
os << ", ";
1029-
});
1018+
llvm::interleave(
1019+
entries.begin(), entries.end(),
1020+
[this, &os](uint64_t entry) { printStoredEntry(this, entry, os); },
1021+
[&os] { os << ", "; });
10301022
os << "\n";
10311023
}
10321024
}

lib/Demangling/NodePrinter.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -706,29 +706,29 @@ class NodePrinter {
706706
bool hasLabels = LabelList && LabelList->getNumChildren() > 0;
707707

708708
Printer << '(';
709-
interleave(Parameters->begin(), Parameters->end(),
710-
[&](NodePointer Param) {
711-
assert(Param->getKind() == Node::Kind::TupleElement);
712-
713-
if (hasLabels) {
714-
Printer << getLabelFor(Param, ParamIndex) << ':';
715-
} else if (!showTypes) {
716-
if (auto Label = getChildIf(Param,
717-
Node::Kind::TupleElementName))
718-
Printer << Label->getText() << ":";
719-
else
720-
Printer << "_:";
721-
}
722-
723-
if (hasLabels && showTypes)
724-
Printer << ' ';
725-
726-
++ParamIndex;
727-
728-
if (showTypes)
729-
print(Param);
730-
},
731-
[&]() { Printer << (showTypes ? ", " : ""); });
709+
llvm::interleave(
710+
Parameters->begin(), Parameters->end(),
711+
[&](NodePointer Param) {
712+
assert(Param->getKind() == Node::Kind::TupleElement);
713+
714+
if (hasLabels) {
715+
Printer << getLabelFor(Param, ParamIndex) << ':';
716+
} else if (!showTypes) {
717+
if (auto Label = getChildIf(Param, Node::Kind::TupleElementName))
718+
Printer << Label->getText() << ":";
719+
else
720+
Printer << "_:";
721+
}
722+
723+
if (hasLabels && showTypes)
724+
Printer << ' ';
725+
726+
++ParamIndex;
727+
728+
if (showTypes)
729+
print(Param);
730+
},
731+
[&]() { Printer << (showTypes ? ", " : ""); });
732732
Printer << ')';
733733
}
734734

lib/Driver/Driver.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,15 +2844,16 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
28442844
<< "\" - \"" << llvm::sys::path::filename(J->getExecutable())
28452845
<< "\", inputs: [";
28462846

2847-
interleave(InputActions.begin(), InputActions.end(),
2848-
[](const Action *A) {
2849-
auto Input = cast<InputAction>(A);
2850-
llvm::outs() << '"' << Input->getInputArg().getValue() << '"';
2851-
},
2852-
[] { llvm::outs() << ", "; });
2847+
llvm::interleave(
2848+
InputActions.begin(), InputActions.end(),
2849+
[](const Action *A) {
2850+
auto Input = cast<InputAction>(A);
2851+
llvm::outs() << '"' << Input->getInputArg().getValue() << '"';
2852+
},
2853+
[] { llvm::outs() << ", "; });
28532854
if (!InputActions.empty() && !J->getInputs().empty())
28542855
llvm::outs() << ", ";
2855-
interleave(
2856+
llvm::interleave(
28562857
J->getInputs().begin(), J->getInputs().end(),
28572858
[](const Job *Input) {
28582859
auto FileNames = Input->getOutput().getPrimaryOutputFilenames();
@@ -3305,9 +3306,10 @@ static unsigned printActions(const Action *A,
33053306
os << "\"" << IA->getInputArg().getValue() << "\"";
33063307
} else {
33073308
os << "{";
3308-
interleave(*cast<JobAction>(A),
3309-
[&](const Action *Input) { os << printActions(Input, Ids); },
3310-
[&] { os << ", "; });
3309+
llvm::interleave(
3310+
*cast<JobAction>(A),
3311+
[&](const Action *Input) { os << printActions(Input, Ids); },
3312+
[&] { os << ", "; });
33113313
os << "}";
33123314
}
33133315

0 commit comments

Comments
 (0)