@@ -3125,100 +3125,49 @@ dummy_func(
31253125 }
31263126
31273127 replaced op (_FOR_ITER , (iter , null_or_index -- iter , null_or_index , next )) {
3128- /* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
3129- PyObject * iter_o = PyStackRef_AsPyObjectBorrow (iter );
3130- if (PyStackRef_IsTaggedInt (null_or_index )) {
3131- next = _PyForIter_NextWithIndex (iter_o , null_or_index );
3132- if (PyStackRef_IsNull (next )) {
3133- JUMPBY (oparg + 1 );
3134- DISPATCH ();
3135- }
3136- null_or_index = PyStackRef_IncrementTaggedIntNoOverflow (null_or_index );
3137- }
3138- else {
3139- PyObject * next_o = (* Py_TYPE (iter_o )-> tp_iternext )(iter_o );
3140- if (next_o == NULL ) {
3141- if (_PyErr_Occurred (tstate )) {
3142- int matches = _PyErr_ExceptionMatches (tstate , PyExc_StopIteration );
3143- if (!matches ) {
3144- ERROR_NO_POP ();
3145- }
3146- _PyEval_MonitorRaise (tstate , frame , this_instr );
3147- _PyErr_Clear (tstate );
3148- }
3149- /* iterator ended normally */
3150- assert (next_instr [oparg ].op .code == END_FOR ||
3151- next_instr [oparg ].op .code == INSTRUMENTED_END_FOR );
3152- /* Jump forward oparg, then skip following END_FOR */
3153- JUMPBY (oparg + 1 );
3154- DISPATCH ();
3128+ _PyStackRef item = _PyForIter_VirtualIteratorNext (tstate , frame , iter , & null_or_index );
3129+ if (!PyStackRef_IsValid (item )) {
3130+ if (PyStackRef_IsError (item )) {
3131+ ERROR_NO_POP ();
31553132 }
3156- next = PyStackRef_FromPyObjectSteal (next_o );
3133+ // Jump forward by oparg and skip the following END_FOR
3134+ JUMPBY (oparg + 1 );
3135+ DISPATCH ();
31573136 }
3137+ next = item ;
31583138 }
31593139
31603140 op (_FOR_ITER_TIER_TWO , (iter , null_or_index -- iter , null_or_index , next )) {
3161- /* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
3162- PyObject * iter_o = PyStackRef_AsPyObjectBorrow (iter );
3163- EXIT_IF (!PyStackRef_IsNull (null_or_index ));
3164- PyObject * next_o = (* Py_TYPE (iter_o )-> tp_iternext )(iter_o );
3165- if (next_o == NULL ) {
3166- if (_PyErr_Occurred (tstate )) {
3167- int matches = _PyErr_ExceptionMatches (tstate , PyExc_StopIteration );
3168- if (!matches ) {
3169- ERROR_NO_POP ();
3170- }
3171- _PyEval_MonitorRaise (tstate , frame , frame -> instr_ptr );
3172- _PyErr_Clear (tstate );
3141+ _PyStackRef item = _PyForIter_VirtualIteratorNext (tstate , frame , iter , & null_or_index );
3142+ if (!PyStackRef_IsValid (item )) {
3143+ if (PyStackRef_IsError (item )) {
3144+ ERROR_NO_POP ();
31733145 }
31743146 /* iterator ended normally */
31753147 /* The translator sets the deopt target just past the matching END_FOR */
31763148 EXIT_IF (true);
31773149 }
3178- next = PyStackRef_FromPyObjectSteal (next_o );
3179- // Common case: no jump, leave it to the code generator
3150+ next = item ;
31803151 }
31813152
3153+
31823154 macro (FOR_ITER ) = _SPECIALIZE_FOR_ITER + _FOR_ITER ;
31833155
31843156
31853157 inst (INSTRUMENTED_FOR_ITER , (unused /1 , iter , null_or_index -- iter , null_or_index , next )) {
3186- PyObject * iter_o = PyStackRef_AsPyObjectBorrow (iter );
3187- if (PyStackRef_IsTaggedInt (null_or_index )) {
3188- next = _PyForIter_NextWithIndex (iter_o , null_or_index );
3189- if (PyStackRef_IsNull (next )) {
3190- JUMPBY (oparg + 1 );
3191- DISPATCH ();
3192- }
3193- null_or_index = PyStackRef_IncrementTaggedIntNoOverflow (null_or_index );
3194- INSTRUMENTED_JUMP (this_instr , next_instr , PY_MONITORING_EVENT_BRANCH_LEFT );
3195- }
3196- else {
3197- PyObject * next_o = (* Py_TYPE (iter_o )-> tp_iternext )(iter_o );
3198- if (next_o != NULL ) {
3199- next = PyStackRef_FromPyObjectSteal (next_o );
3200- INSTRUMENTED_JUMP (this_instr , next_instr , PY_MONITORING_EVENT_BRANCH_LEFT );
3201- }
3202- else {
3203- if (_PyErr_Occurred (tstate )) {
3204- int matches = _PyErr_ExceptionMatches (tstate , PyExc_StopIteration );
3205- if (!matches ) {
3206- ERROR_NO_POP ();
3207- }
3208- _PyEval_MonitorRaise (tstate , frame , this_instr );
3209- _PyErr_Clear (tstate );
3210- }
3211- /* iterator ended normally */
3212- assert (next_instr [oparg ].op .code == END_FOR ||
3213- next_instr [oparg ].op .code == INSTRUMENTED_END_FOR );
3214- /* Skip END_FOR */
3215- JUMPBY (oparg + 1 );
3216- DISPATCH ();
3158+ _PyStackRef item = _PyForIter_VirtualIteratorNext (tstate , frame , iter , & null_or_index );
3159+ if (!PyStackRef_IsValid (item )) {
3160+ if (PyStackRef_IsError (item )) {
3161+ ERROR_NO_POP ();
32173162 }
3163+ // Jump forward by oparg and skip the following END_FOR
3164+ JUMPBY (oparg + 1 );
3165+ DISPATCH ();
32183166 }
3167+ next = item ;
3168+ INSTRUMENTED_JUMP (this_instr , next_instr , PY_MONITORING_EVENT_BRANCH_LEFT );
32193169 }
32203170
3221-
32223171 op (_ITER_CHECK_LIST , (iter , null_or_index -- iter , null_or_index )) {
32233172 PyObject * iter_o = PyStackRef_AsPyObjectBorrow (iter );
32243173 EXIT_IF (Py_TYPE (iter_o ) != & PyList_Type );
0 commit comments