mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Parser]: crash on variadic pack of memory type

Open soraros opened this issue 1 year ago • 10 comments

Bug description

As title. If the line with print is altered slightly, the problem goes away.

Steps to reproduce

Following is reduced code from the manual, unfortunately.

@value
struct S:
  var val: String

  fn __del__(owned self):
    print("", self.val)

System information

Mojo 0.6.0 on Docker, Intel Mac

soraros avatar Dec 05 '23 01:12 soraros

Thanks for opening the ticket! Could you please provide the "slightly altered" example that works?

laszlokindrat avatar Dec 11 '23 17:12 laszlokindrat

@laszlokindrat For instance, this works fine:

@value
struct S:
  var val: String

  fn __del__(owned self):
    print("")
    print(self.val)

soraros avatar Dec 12 '23 21:12 soraros

I did some superficial investigation and got this reproducer that doesn't use Strings:

struct Stuff:
    fn __del__(owned self): pass

fn foo[*Ts: AnyType](*rest: *Ts): pass

struct S:
  var val: Stuff

  fn __del__(owned self):
    foo(self.val)

The problem seems to be related to lifetime checking after a call to a function with variadic packs, but it's only crashing if the call happens in another destructor. CC: @lattner

laszlokindrat avatar Dec 14 '23 21:12 laszlokindrat

indeed, this is a compiler crash, thank you for catching this. i'll take a look soon

lattner avatar Jan 13 '24 07:01 lattner

Here‘s a simple test case, which can also reproduce the bug. Please confirm whether this is a duplicate of the issue. If not, I will open a new issue. Thanks.

$ cat test.mojo
fn a struct b : fn __copyinit__(inout c, d : Self) :

The crash info is following.

$ mojo test.mojo
/path/to/test.mojo:1:6: error: expected '(' for argument list
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^
/path/to/test.mojo:1:6: error: 'struct' statement must be on its own line
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^
/path/to/test.mojo:1:6: error: struct inside a function not supported here
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^
/path/to/test.mojo:1:17: error: 'fn' statement must be on its own line
fn a struct b : fn __copyinit__(inout c, d : Self) :
                ^
mojo: /__w/modular/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = M::KGEN::SymbolConstantAttr, From = mlir::TypedAttr]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
[30667:30667:20240123,195812.102283:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[30667:30667:20240123,195812.102386:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
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: mojo test.mojo
1.      Crash resolving decl body at loc("/path/to/test.mojo":1:6)
    >> fn a struct b : fn __copyinit__(inout c, d : Self) :
            ^..............................................
    >>
       <
 #0 0x000056162921aee7 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x60fee7)
 #1 0x0000561629218abe (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x60dabe)
 #2 0x000056162921b5bf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x6105bf)
 #3 0x00007f3402d15520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f3402d699fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f3402d15476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f3402cfb7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f3402cfb71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f3402d0ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000056162a8b16b0 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x1ca66b0)
#10 0x000056162968e785 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa83785)
#11 0x000056162968e2dc (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa832dc)
#12 0x00005616296a1c80 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa96c80)
#13 0x00005616296a23d8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa973d8)
#14 0x00005616296487f4 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa3d7f4)
#15 0x0000561629648b60 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa3db60)
#16 0x00005616291e37bf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d87bf)
#17 0x00005616291cfc6b (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5c4c6b)
#18 0x00005616291e28c9 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d78c9)
#19 0x00005616291c9352 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5be352)
#20 0x00007f3402cfcd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#21 0x00007f3402cfce40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#22 0x00005616291c892e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5bd92e)
Aborted

System information

- Ubuntu 22.04.3 LTS (WSL 2)
- mojo 0.6.3 (f58f8b94)
- modular 0.3.1 (589ce200)

junweizeng avatar Jan 23 '24 12:01 junweizeng

@jun-wei-zeng thank you for the crash, I don't think it is related, and it looks like it is fixed on top of tree:

t.mojo:2:6: error: expected '(' for argument list
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^
t.mojo:2:6: error: 'struct' statement must be on its own line
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^
t.mojo:2:6: error: struct inside a function not supported here
fn a struct b : fn __copyinit__(inout c, d : Self) :
     ^

lattner avatar Feb 04 '24 05:02 lattner

The original error and Laszlo's reduce testcase both still fail. They crash in CheckLifetimes, but it is actually a frontend problem: we're generating a load of a memory only type to form the pack, which can't work :-).

We have deeper problems with VariadicPacks, so I'll look into this when I can, thank you for the report!

lattner avatar Feb 04 '24 05:02 lattner

We now generate an unsupported error instead of a crash: cannot pass memory-only type 'String' through variadic packs yet but need to properly support this as well.

lattner avatar Feb 07 '24 22:02 lattner

@lattner This one strikes again in #2162. Also, I don't see the unsupported error.

soraros avatar Apr 03 '24 14:04 soraros

Another dup? https://github.com/modularml/mojo/issues/2054

ematejska avatar Apr 03 '24 17:04 ematejska

Very happy to say that this is fixed in next release. Variadic packs with memory types should be reliable now

lattner avatar Apr 04 '24 16:04 lattner