@@ -91,7 +91,12 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
91
91
@ GenerateNodeFactory
92
92
public abstract static class NextNode extends PythonUnaryBuiltinNode {
93
93
94
- @ Specialization
94
+ @ Specialization (guards = "self.isExhausted()" )
95
+ public Object exhausted (@ SuppressWarnings ("unused" ) PBuiltinIterator self ) {
96
+ throw raise (StopIteration );
97
+ }
98
+
99
+ @ Specialization (guards = "!self.isExhausted()" )
95
100
Object next (VirtualFrame frame , PArrayIterator self ,
96
101
@ Cached ("createClassProfile()" ) ValueProfile itemTypeProfile ,
97
102
@ Cached ("createNotNormalized()" ) SequenceStorageNodes .GetItemNode getItemNode ,
@@ -102,45 +107,47 @@ Object next(VirtualFrame frame, PArrayIterator self,
102
107
// types
103
108
return itemTypeProfile .profile (getItemNode .execute (frame , sequenceStorage , self .index ++));
104
109
}
110
+ self .setExhausted ();
105
111
throw raise (StopIteration );
106
112
}
107
113
108
- @ Specialization
114
+ @ Specialization ( guards = "!self.isExhausted()" )
109
115
int next (PIntegerSequenceIterator self ) {
110
- if (! self . isExhausted () && self .index < self .sequence .length ()) {
116
+ if (self .index < self .sequence .length ()) {
111
117
return self .sequence .getIntItemNormalized (self .index ++);
112
118
}
113
119
self .setExhausted ();
114
120
throw raise (StopIteration );
115
121
}
116
122
117
- @ Specialization
123
+ @ Specialization ( guards = "!self.isExhausted()" )
118
124
int next (PRangeIterator self ) {
119
125
if (self .hasNext ()) {
120
126
return self .next ();
121
127
}
128
+ self .setExhausted ();
122
129
throw raise (StopIteration );
123
130
}
124
131
125
- @ Specialization
132
+ @ Specialization ( guards = "!self.isExhausted()" )
126
133
double next (PDoubleSequenceIterator self ) {
127
- if (! self . isExhausted () && self .index < self .sequence .length ()) {
134
+ if (self .index < self .sequence .length ()) {
128
135
return self .sequence .getDoubleItemNormalized (self .index ++);
129
136
}
130
137
self .setExhausted ();
131
138
throw raise (StopIteration );
132
139
}
133
140
134
- @ Specialization
141
+ @ Specialization ( guards = "!self.isExhausted()" )
135
142
long next (PLongSequenceIterator self ) {
136
- if (! self . isExhausted () && self .index < self .sequence .length ()) {
143
+ if (self .index < self .sequence .length ()) {
137
144
return self .sequence .getLongItemNormalized (self .index ++);
138
145
}
139
146
self .setExhausted ();
140
147
throw raise (StopIteration );
141
148
}
142
149
143
- @ Specialization
150
+ @ Specialization ( guards = "!self.isExhausted()" )
144
151
public Object next (PBaseSetIterator self ,
145
152
@ Cached ("createBinaryProfile()" ) ConditionProfile sizeChanged ,
146
153
@ CachedLibrary (limit = "1" ) HashingStorageLibrary storageLibrary ) {
@@ -151,31 +158,33 @@ public Object next(PBaseSetIterator self,
151
158
}
152
159
return iterator .next ();
153
160
}
161
+ self .setExhausted ();
154
162
throw raise (StopIteration );
155
163
}
156
164
157
- @ Specialization (guards = {"self.isPSequence()" })
165
+ @ Specialization (guards = {"self.isPSequence()" , "!self.isExhausted()" })
158
166
public Object next (VirtualFrame frame , PSequenceIterator self ,
159
167
@ Cached SequenceNodes .GetSequenceStorageNode getStorage ,
160
168
@ Cached SequenceStorageNodes .LenNode lenNode ,
161
169
@ Cached ("createNotNormalized()" ) SequenceStorageNodes .GetItemNode getItemNode ) {
162
170
SequenceStorage s = getStorage .execute (self .getPSequence ());
163
- if (! self . isExhausted () && self .index < lenNode .execute (s )) {
171
+ if (self .index < lenNode .execute (s )) {
164
172
return getItemNode .execute (frame , s , self .index ++);
165
173
}
166
174
self .setExhausted ();
167
175
throw raise (StopIteration );
168
176
}
169
177
170
- @ Specialization
178
+ @ Specialization ( guards = "!self.isExhausted()" )
171
179
public Object next (PStringIterator self ) {
172
180
if (self .index < self .value .length ()) {
173
181
return Character .toString (self .value .charAt (self .index ++));
174
182
}
183
+ self .setExhausted ();
175
184
throw raise (StopIteration );
176
185
}
177
186
178
- @ Specialization
187
+ @ Specialization ( guards = "!self.isExhausted()" )
179
188
public Object next (PDictView .PBaseDictIterator <?> self ,
180
189
@ Cached ConditionProfile sizeChanged ,
181
190
@ CachedLibrary (limit = "3" ) HashingStorageLibrary storageLibrary ,
@@ -186,6 +195,7 @@ public Object next(PDictView.PBaseDictIterator<?> self,
186
195
}
187
196
return self .next (factory ());
188
197
}
198
+ self .setExhausted ();
189
199
throw raise (PythonErrorType .StopIteration );
190
200
}
191
201
@@ -197,6 +207,7 @@ public Object next(VirtualFrame frame, PSequenceIterator self,
197
207
return callGetItem .executeObject (frame , self .getObject (), self .index ++);
198
208
} catch (PException e ) {
199
209
e .expectIndexError (profile );
210
+ self .setExhausted ();
200
211
throw raise (StopIteration );
201
212
}
202
213
}
@@ -329,7 +340,7 @@ public Object reduceNonSeq(VirtualFrame frame, PSequenceIterator self,
329
340
@ CachedContext (PythonLanguage .class ) PythonContext context ,
330
341
@ Cached ("create(__REDUCE__)" ) LookupAndCallUnaryNode callUnaryNode ,
331
342
@ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
332
- Object reduce = pol .lookupAttribute (self .getPSequence (), __REDUCE__ );
343
+ Object reduce = pol .lookupAttribute (self .getObject (), __REDUCE__ );
333
344
Object content = callUnaryNode .executeObject (frame , reduce );
334
345
return reduceInternal (content , self .index , context , pol );
335
346
}
0 commit comments