Skip to content

Commit 958832d

Browse files
authored
Merge pull request #62095 from eeckstein/deprecate-iterator
Remove uses of `std::iterator` and `llvm::empty`
2 parents f588672 + e0c862f commit 958832d

File tree

11 files changed

+70
-25
lines changed

11 files changed

+70
-25
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,16 @@ class SDKNodeVectorViewer {
520520
ViewerIterator end();
521521
};
522522

523-
class SDKNodeVectorViewer::ViewerIterator :
524-
public std::iterator<std::input_iterator_tag, VectorIt> {
523+
class SDKNodeVectorViewer::ViewerIterator {
525524
SDKNodeVectorViewer &Viewer;
526525
VectorIt P;
527526
public:
527+
using iterator_category = std::forward_iterator_tag;
528+
using value_type = VectorIt;
529+
using difference_type = std::ptrdiff_t;
530+
using pointer = value_type*;
531+
using reference = value_type&;
532+
528533
ViewerIterator(SDKNodeVectorViewer &Viewer, VectorIt P) : Viewer(Viewer), P(P) {}
529534
ViewerIterator(const ViewerIterator& mit) : Viewer(mit.Viewer), P(mit.P) {}
530535
ViewerIterator& operator++();

include/swift/AST/Attr.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,9 +2377,15 @@ class DeclAttributes {
23772377
const Decl *D = nullptr);
23782378

23792379
template <typename T, typename DERIVED>
2380-
class iterator_base : public std::iterator<std::forward_iterator_tag, T *> {
2380+
class iterator_base {
23812381
T *Impl;
23822382
public:
2383+
using iterator_category = std::forward_iterator_tag;
2384+
using value_type = T*;
2385+
using difference_type = std::ptrdiff_t;
2386+
using pointer = value_type*;
2387+
using reference = value_type&;
2388+
23832389
explicit iterator_base(T *Impl) : Impl(Impl) {}
23842390
DERIVED &operator++() { Impl = Impl->Next; return (DERIVED&)*this; }
23852391
bool operator==(const iterator_base &X) const { return X.Impl == Impl; }
@@ -2678,11 +2684,16 @@ class TypeAttributes {
26782684
}
26792685

26802686
// Iterator for the custom type attributes.
2681-
class iterator
2682-
: public std::iterator<std::forward_iterator_tag, CustomAttr *> {
2687+
class iterator {
26832688
CustomAttr *attr;
26842689

26852690
public:
2691+
using iterator_category = std::forward_iterator_tag;
2692+
using value_type = CustomAttr*;
2693+
using difference_type = std::ptrdiff_t;
2694+
using pointer = value_type*;
2695+
using reference = value_type&;
2696+
26862697
iterator() : attr(nullptr) { }
26872698
explicit iterator(CustomAttr *attr) : attr(attr) { }
26882699

include/swift/Basic/FrozenMultiMap.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ class FrozenMultiMap {
143143
unsigned size() const { return storage.size(); }
144144
bool empty() const { return storage.empty(); }
145145

146-
struct iterator
147-
: std::iterator<std::forward_iterator_tag,
148-
std::pair<Key, Optional<PairToSecondEltRange>>> {
146+
struct iterator {
147+
using iterator_category = std::forward_iterator_tag;
148+
using value_type = std::pair<Key, Optional<PairToSecondEltRange>>;
149+
using difference_type = std::ptrdiff_t;
150+
using pointer = value_type*;
151+
using reference = value_type&;
149152
using base_iterator = typename decltype(storage)::iterator;
150153

151154
FrozenMultiMap &map;

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ class ReflectionSection {
8787
};
8888

8989
template<typename Self, typename Descriptor>
90-
class ReflectionSectionIteratorBase
91-
: public std::iterator<std::forward_iterator_tag, Descriptor> {
90+
class ReflectionSectionIteratorBase {
9291
uint64_t OriginalSize;
9392
protected:
9493
Self &asImpl() {
9594
return *static_cast<Self *>(this);
9695
}
9796
public:
97+
using iterator_category = std::forward_iterator_tag;
98+
using value_type = Descriptor;
99+
using difference_type = std::ptrdiff_t;
100+
using pointer = value_type*;
101+
using reference = value_type&;
102+
98103
RemoteRef<void> Cur;
99104
uint64_t Size;
100105
std::string Name;

include/swift/SIL/DebugUtils.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ inline void deleteAllDebugUses(SILInstruction *inst) {
6565
/// of uses, provided by the underlying ValueBaseUseIterator.
6666
/// If \p nonDebugInsts is true, then the iterator provides a view to all non-
6767
/// debug instructions. Otherwise it provides a view ot all debug-instructions.
68-
template <bool nonDebugInsts> class DebugUseIterator
69-
: public std::iterator<std::forward_iterator_tag, Operand *, ptrdiff_t> {
70-
68+
template <bool nonDebugInsts> class DebugUseIterator {
69+
public:
70+
using iterator_category = std::forward_iterator_tag;
71+
using value_type = Operand*;
72+
using difference_type = std::ptrdiff_t;
73+
using pointer = value_type*;
74+
using reference = value_type&;
75+
76+
private:
7177
ValueBaseUseIterator BaseIterator;
7278

7379
// Skip any debug or non-debug instructions (depending on the nonDebugInsts

include/swift/SIL/SILValue.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,11 +1160,16 @@ inline SILValue getSILValueType(const Operand &op) {
11601160
using OperandValueArrayRef = ArrayRefView<Operand, SILValue, getSILValueType>;
11611161

11621162
/// An iterator over all uses of a ValueBase.
1163-
class ValueBaseUseIterator : public std::iterator<std::forward_iterator_tag,
1164-
Operand*, ptrdiff_t> {
1163+
class ValueBaseUseIterator {
11651164
protected:
11661165
Operand *Cur;
11671166
public:
1167+
using iterator_category = std::forward_iterator_tag;
1168+
using value_type = Operand*;
1169+
using difference_type = std::ptrdiff_t;
1170+
using pointer = value_type*;
1171+
using reference = value_type&;
1172+
11681173
ValueBaseUseIterator() = default;
11691174
explicit ValueBaseUseIterator(Operand *cur) : Cur(cur) {}
11701175
Operand *operator->() const { return Cur; }

include/swift/SILOptimizer/Analysis/ClosureScope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class ClosureFunctionOrder {
173173

174174
ArrayRef<SILFunction *> getTopDownFunctions() const {
175175
assert(!topDownFunctions.empty()
176-
|| llvm::empty(csa->getModule()->getFunctions()));
176+
|| csa->getModule()->getFunctions().empty());
177177
return topDownFunctions;
178178
}
179179

include/swift/SILOptimizer/Analysis/LoopRegionAnalysis.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ class LoopRegion {
237237

238238
/// An iterator that knows how to iterate over the subregion indices of a
239239
/// region.
240-
class subregion_iterator :
241-
public std::iterator<std::bidirectional_iterator_tag, unsigned> {
240+
class subregion_iterator {
242241
friend struct SubregionData;
243242
llvm::SmallVectorImpl<SubregionID>::const_iterator InnerIter;
244243
const llvm::SmallVectorImpl<std::pair<unsigned, unsigned>> *Subloops;
@@ -323,8 +322,7 @@ class LoopRegion {
323322

324323
/// An iterator that knows how to iterate over the backedge indices of a
325324
/// region.
326-
class backedge_iterator
327-
: public std::iterator<std::bidirectional_iterator_tag, unsigned> {
325+
class backedge_iterator {
328326
friend struct SubregionData;
329327
using InnerIterTy = llvm::SmallVectorImpl<unsigned>::const_iterator;
330328
llvm::Optional<InnerIterTy> InnerIter;

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,15 @@ void insertDeallocOfCapturedArguments(
288288
/// users of the looked through builtin expect instruction i.e it presents a
289289
/// view that shows all users as if there were no builtin expect instructions
290290
/// interposed.
291-
class IgnoreExpectUseIterator
292-
: public std::iterator<std::forward_iterator_tag, Operand *, ptrdiff_t> {
291+
class IgnoreExpectUseIterator {
292+
public:
293+
using iterator_category = std::forward_iterator_tag;
294+
using value_type = Operand*;
295+
using difference_type = std::ptrdiff_t;
296+
using pointer = value_type*;
297+
using reference = value_type&;
298+
299+
private:
293300
ValueBaseUseIterator origUseChain;
294301
ValueBaseUseIterator currentIter;
295302

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static void printDifferentiableAttrArguments(
689689
return false;
690690
return true;
691691
});
692-
if (!llvm::empty(requirementsToPrint)) {
692+
if (!requirementsToPrint.empty()) {
693693
if (!isLeadingClause)
694694
stream << ' ';
695695
stream << "where ";

0 commit comments

Comments
 (0)