Ticket #203 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

Bug in optimization of range

Reported by: dagss Owned by: Prajwal Suhas P
Priority: critical Milestone: 0.11.1
Component: Python Semantics Keywords:
Cc:

Description

This:

   cdef int i, n
    n = 10
    for i in range(n):
        if i == 5: n *= 2
    print i

prints out 20.

Change History

Changed 6 years ago by dagss

It should print 9, I think

Changed 6 years ago by dagss

Note: This must be changed in the for in range-optimization, because "for 0 <= i < n" should have this semantics!

Changed 6 years ago by dagss

  • milestone changed from 0.11 to 0.11.1

Changed 6 years ago by dagss

  • owner changed from somebody to Prajwal Suhas P

Changed 6 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed

Works as expected. Committed  http://hg.cython.org/cython-devel/rev/620326b14c3f

This is another reason to keep the for...from syntax though.

Changed 6 years ago by robertwb

  • component changed from Optimization to Python Semantics

Changed 6 years ago by robertwb

This is a dupe of #196, the above commit was for #208.

Changed 6 years ago by dagss

  • status changed from closed to reopened
  • resolution fixed deleted

No, this is a different bug. Reopening.

Also note that this ticket is assigned to Prajwal Suhas P; see  http://thread.gmane.org/gmane.comp.python.cython.devel/4775

Magnus' patch was only for incrementing-one-to-far; this is about evaluating the endpoints to range once per loop.

Also consider this test case:

"""
 >>> f()
g called
0
1
2
2
"""

cdef int g():
     print "g called"
     return 3

def f():
     cdef int i
     for i in range(g()):
         print i
     print i

Changed 6 years ago by dagss

That is; I get:

Failed example:
    f()
Expected:
    g called
    0
    1
    2
    2
Got:
    g called
    0
    g called
    1
    g called
    2
    g called
    2

Changed 6 years ago by dagss

  • priority changed from major to critical

Changed 5 years ago by robertwb

  • status changed from reopened to closed
  • resolution set to fixed

Finally resolved by #243

Note: See TracTickets for help on using tickets.