def foo():
a = [1, 2, 3]
exhit = iter(a)
for _ in exhit:
pass
a.append("this should'be in exhit")
print(f"got {list(exhit)}, should be []")
foo()
foo()
foo()
foo()
foo()
foo()
Output:
got [], should be []
got [], should be []
got [], should be []
got [], should be []
got [], should be []
got ["this should'be in exhit"], should be []
I guess the culprit is there. If we remove the _GUARD_NOT_EXHAUSTED_LIST from is_for_iter_test, the problem will go away (although it can still be reproduced in other ways using other (range, tuple) iterators).
This is a tier two thing, not a JIT thing. Let's reserve the topic-JIT label for issues that reproduce with --enable-experimental-jit (but not--enable-experimental-jit=interpreter).
Bug report
Bug description:
Reproducer:
Output:
Obviously, the last line is incorrect.
Output with a
PYTHON_LLTRACE=2
env:It's definitely related to this part of code: https://github.com/python/cpython/blob/e4a97a7fb1c03d3b6ec6efbeff553a0230e003c7/Python/optimizer.c#L1027-L1033
I guess the culprit is there. If we remove the
_GUARD_NOT_EXHAUSTED_LIST
fromis_for_iter_test
, the problem will go away (although it can still be reproduced in other ways using other (range, tuple) iterators).CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux, macOS