@@ -210,6 +210,12 @@ struct ASTContext::Implementation {
210
210
// / The declaration of 'AsyncSequence.makeAsyncIterator()'.
211
211
FuncDecl *MakeAsyncIterator = nullptr ;
212
212
213
+ // / The declaration of 'IteratorProtocol.next()'.
214
+ FuncDecl *IteratorNext = nullptr ;
215
+
216
+ // / The declaration of 'AsyncIteratorProtocol.next()'.
217
+ FuncDecl *AsyncIteratorNext = nullptr ;
218
+
213
219
// / The declaration of Swift.Optional<T>.Some.
214
220
EnumElementDecl *OptionalSomeDecl = nullptr ;
215
221
@@ -779,31 +785,40 @@ FuncDecl *ASTContext::getPlusFunctionOnString() const {
779
785
return getImpl ().PlusFunctionOnString ;
780
786
}
781
787
782
- FuncDecl *ASTContext::getSequenceMakeIterator () const {
783
- if (getImpl ().MakeIterator ) {
784
- return getImpl ().MakeIterator ;
785
- }
786
-
787
- auto proto = getProtocol (KnownProtocolKind::Sequence);
788
- if (!proto)
789
- return nullptr ;
790
-
791
- for (auto result : proto->lookupDirect (Id_makeIterator)) {
788
+ static FuncDecl *lookupRequirement (ProtocolDecl *proto,
789
+ Identifier requirement) {
790
+ for (auto result : proto->lookupDirect (requirement)) {
792
791
if (result->getDeclContext () != proto)
793
792
continue ;
794
793
795
794
if (auto func = dyn_cast<FuncDecl>(result)) {
796
795
if (func->getParameters ()->size () != 0 )
797
796
continue ;
798
797
799
- getImpl ().MakeIterator = func;
800
798
return func;
801
799
}
802
800
}
803
801
804
802
return nullptr ;
805
803
}
806
804
805
+ FuncDecl *ASTContext::getSequenceMakeIterator () const {
806
+ if (getImpl ().MakeIterator ) {
807
+ return getImpl ().MakeIterator ;
808
+ }
809
+
810
+ auto proto = getProtocol (KnownProtocolKind::Sequence);
811
+ if (!proto)
812
+ return nullptr ;
813
+
814
+ if (auto *func = lookupRequirement (proto, Id_makeIterator)) {
815
+ getImpl ().MakeIterator = func;
816
+ return func;
817
+ }
818
+
819
+ return nullptr ;
820
+ }
821
+
807
822
FuncDecl *ASTContext::getAsyncSequenceMakeAsyncIterator () const {
808
823
if (getImpl ().MakeAsyncIterator ) {
809
824
return getImpl ().MakeAsyncIterator ;
@@ -813,17 +828,43 @@ FuncDecl *ASTContext::getAsyncSequenceMakeAsyncIterator() const {
813
828
if (!proto)
814
829
return nullptr ;
815
830
816
- for (auto result : proto->lookupDirect (Id_makeAsyncIterator)) {
817
- if (result->getDeclContext () != proto)
818
- continue ;
831
+ if (auto *func = lookupRequirement (proto, Id_makeAsyncIterator)) {
832
+ getImpl ().MakeAsyncIterator = func;
833
+ return func;
834
+ }
819
835
820
- if (auto func = dyn_cast<FuncDecl>(result)) {
821
- if (func->getParameters ()->size () != 0 )
822
- continue ;
836
+ return nullptr ;
837
+ }
823
838
824
- getImpl ().MakeAsyncIterator = func;
825
- return func;
826
- }
839
+ FuncDecl *ASTContext::getIteratorNext () const {
840
+ if (getImpl ().IteratorNext ) {
841
+ return getImpl ().IteratorNext ;
842
+ }
843
+
844
+ auto proto = getProtocol (KnownProtocolKind::IteratorProtocol);
845
+ if (!proto)
846
+ return nullptr ;
847
+
848
+ if (auto *func = lookupRequirement (proto, Id_next)) {
849
+ getImpl ().IteratorNext = func;
850
+ return func;
851
+ }
852
+
853
+ return nullptr ;
854
+ }
855
+
856
+ FuncDecl *ASTContext::getAsyncIteratorNext () const {
857
+ if (getImpl ().AsyncIteratorNext ) {
858
+ return getImpl ().AsyncIteratorNext ;
859
+ }
860
+
861
+ auto proto = getProtocol (KnownProtocolKind::AsyncIteratorProtocol);
862
+ if (!proto)
863
+ return nullptr ;
864
+
865
+ if (auto *func = lookupRequirement (proto, Id_next)) {
866
+ getImpl ().AsyncIteratorNext = func;
867
+ return func;
827
868
}
828
869
829
870
return nullptr ;
0 commit comments