mojo
mojo copied to clipboard
[BUG] Defining a list-creating function causes stack dump
Bug description
I am trying to reshape a tensor.Tensor
based on a python tuple
. To this end, I've tried to convert the tuple
to a mojo List[Int]
that I can pass to tensor.TensorShape
. I've written a small function to do this, listed below. The compilation of the function alone is sufficient to cause a stack dump:
my-file.mojo:8:17: error: cannot call function that may raise in a context that cannot raise for item in iterable: ^~~~~~~~ my-file.mojo:8:17: note: try surrounding the call in a 'try' block for item in iterable: ^ my-file.mojo:5:4: note: or mark surrounding function as 'raises' fn list_int(iterable: PythonObject) -> List[Int]: ^ mojo: /__w/modular/modular/KGEN/include/KGEN/MojoParser/ExprEmitter.h:159: M::KGEN::LIT::ValueDest::~ValueDest(): Assertion `!isSpecified() && "ValueDest destroyed without being emitted into"' failed. Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes. Stack dump: 0. Program arguments: /path/to/.modular/pkg/packages.modular.com_mojo/bin/mojo my-file.mojo
Crash resolving decl body at loc("my-file.mojo":5:4)
fn list_int(iterable: PythonObject) -> List[Int]: ^............................................. """Convert iterable PythonObject of intergers to integer list.""" var out = ListInt for item in iterable: .........................<
Crash parsing statement at loc("my-file.mojo":8:5)
for item in iterable:
^....................<
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var
LLVM_SYMBOLIZER_PATH
to point to it): 0 mojo 0x0000583434f68f57 1 mojo 0x0000583434f66b2e 2 mojo 0x0000583434f695ef 3 libc.so.6 0x00007d3f39842990 4 libc.so.6 0x00007d3f39899a1b pthread_kill + 283 5 libc.so.6 0x00007d3f398428e6 raise + 22 6 libc.so.6 0x00007d3f398268b7 abort + 215 7 libc.so.6 0x00007d3f398267db 8 libc.so.6 0x00007d3f39839206 9 mojo 0x00005834353b656d 10 mojo 0x00005834353abe38 11 mojo 0x00005834353abce6 12 mojo 0x0000583435341a25 13 mojo 0x0000583435353f94 14 mojo 0x00005834353546a8 15 mojo 0x000058343535f2a2 16 mojo 0x000058343535f62d 17 mojo 0x0000583434e9f23c 18 mojo 0x0000583434e83111 19 mojo 0x0000583434e9e246 20 mojo 0x0000583434e7ccf4 21 libc.so.6 0x00007d3f39828150 22 libc.so.6 0x00007d3f39828209 __libc_start_main + 137 23 mojo 0x0000583434e7c42e 0x583437d65238 crashed! Please file a bug report. [1] 35926 IOT instruction (core dumped) '/path/to/.modular/pkg/packages.modular.com_mojo/bin/mojo'
Redefining the function using def
instead of fn
rescues the compilation.
Steps to reproduce
from collections import List
from python.object import PythonObject
fn list_int(iterable: PythonObject) -> List[Int]:
"""Convert iterable PythonObject of intergers to integer list."""
var out = List[Int]()
for item in iterable:
out.append(int(item))
return out
System information
OS: Ubuntu 23.10
`mojo -v`: mojo 24.2.1 (2f0dcf11)
`modular -v`: modular 0.7.2 (d0adc668)