Long Viper Function Hangs #17923
Unanswered
samneggs
asked this question in
RP2040 / Pico
Replies: 3 comments 12 replies
-
Something you can share or point to? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I tested 1.26 with unhealthy long viper functions. Works fine. Even with 5000 lines in a loop. #!/micropython
# -*- coding: UTF-8 -*-
# vim: fileencoding=utf-8: ts=4: sw=4: expandtab:
#┌────────────────────────────────────────────────────────────────────────────┒
#│ Test long viper functions ┃
#┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
from array import array
from random import randint
sz_arr = 1000
arr = array('I', (randint(0,2**31-1) for _ in range(sz_arr)))
cols = array('I', (0, 2147483647, 1131376761, 410151271, 157840433,
58548857, 21521774, 8810089, 3501671, 1355339, 543749, 213331,
84801, 27901, 11969, 4711, 1968, 815, 271, 111, 41, 13, 4, 1))
cols[0] = len(cols) # length ──▶ item[0], data ──▶ item[1:]
head = '''@micropython.viper
def protosort(arr: ptr32, n: int, cols: ptr32):
i: int
j: int
k: int
h: int
t: int
loops: int = 5
while loops:
'''
sortblock = ''' # ascending
k = 1
while k < cols[0]:
h = cols[k]
i = h
while i < n:
t = arr[i]
j = i
while j >= h and arr[j-h] > t:
arr[j] = arr[j-h]
j = j - h
arr[j] = t
i += 1
k += 1
# descending
k = 1
while k < cols[0]:
h = cols[k]
i = h
while i < n:
t = arr[i]
j = i
while j >= h and arr[j-h] < t:
arr[j] = arr[j-h]
j = j - h
arr[j] = t
i += 1
k += 1
'''
tail = ''' loops -= 1
return
'''
TEST_WITH_NUMSORTBLOCKS = 50
f_proto = head
for i in range(TEST_WITH_NUMSORTBLOCKS):
f_proto += sortblock
f_proto += tail
exec(f_proto)
protosort(arr, len(arr), cols)
for item in arr:
print(f'{item:20}')
print(f'{len(f_proto.split())} lines in function') |
Beta Was this translation helpful? Give feedback.
5 replies
-
This should be fixed in #17946, by the way :) |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a ~170 line viper function that locks up a Pico2. If I remark any random section to reduce the size, it runs fine.
In the past it may have generated an error but with the recent change in v1.26 maybe something is up:
There are quite a few if statements so maybe the >12 bit long jumps happen in those.
I'm assuming it should work on my hardware:
MicroPython v1.26.0 on 2025-08-09; Raspberry Pi Pico2 with RP2350
Beta Was this translation helpful? Give feedback.
All reactions