Skip to content

Range optimization has semantical issues #565

Closed
@pfalcon

Description

@pfalcon

Here's example:

n = 20

for i in range(n):
    if i == 3:
        n = 1
    print(i)

On uPy, this ends loop prematurely, while expected semantics of range is that it captures value it was initialized with, not reference to variable.

But what really made me look into this is the gross performance difference of using range with constant expression vs one with var as arg. My guess proper semantics would be to load the end value on stack at the beginning of iteration and use that afterwards...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions