Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] running Mojo code with run ownership parameter causes crash on Mac without LLVM installed #3231

Open
nzhang opened this issue Jul 13, 2024 · 2 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@nzhang
Copy link

nzhang commented Jul 13, 2024

Bug description

I tried to run the following example program with (intended) wrong ownership annotation of one of the parameter. It output the correct error message but followed by a crash. I then realized that I didn't have LLVM installed on my mac. After installing LLVM (and llvm-symbolizer) the crash went away. So it is possible that the crash is caused by the fact that llvm-symbolizer is not found.

Steps to reproduce

  • Include relevant code snippet or link to code that did not work as expected.
    =================== The source code: ===================
# @value
struct MyPet:
    var name: String
    var age: Int

    fn __init__(inout self, owned n: String, a: Int):
        self.name = n^
        self.age = a
        print(self.name,  ": ", self.age)

    fn __copyinit__(inout self, rhs: MyPet):
        self.name = rhs.name
        self.age = rhs.age

    fn __moveinit__(inout self, rhs: MyPet):
        self.name = rhs.name^
        self.age = rhs.age

    fn __del__(owned self):
        print("\tDestruct", self.name)

fn pets():
    var a = MyPet("Loki", 4)
    var b = MyPet("Sylvie", 2)
    print(a.name)
    # Zn: @value is a little confusing as it doe not mean immutable class. 
    # Zn: how to define a immutable struct in Mojo?
    a.name = "fake"
    # a.__del__() runs here for "Loki"

    a = MyPet("Charlie", 8)
    # a.__del__() runs immediately because "Charlie" is never used

    print(b.name)
    # b.__del__() runs here

fn main():
    pets()
  • If applicable, add screenshots to help explain the problem.
    ================ The error message: ===================
(base) nings-mbp:del ningzhang$ '/Users/ningzhang/.modular/pkg/packages.modular.com_max/bin/mojo' '/Users/ningzhang/test/mojo_max/del/del.mojo'
/Users/ningzhang/test/mojo_max/del/del.mojo:15:33: error: existing value argument must be passed as owned
    fn __moveinit__(inout self, rhs: MyPet):
                                ^
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: /Users/ningzhang/.modular/pkg/packages.modular.com_max/bin/mojo /Users/ningzhang/test/mojo_max/del/del.mojo
1.      Crash resolving decl body at loc("/Users/ningzhang/test/mojo_max/del/del.mojo":2:8)
    >> struct MyPet:
              ^.....
    >>     var name: String
    >>     var age: Int
    >> 
    >>     fn __init__(inout self, owned n: String, a: Int):
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                     0x0000000102f00c04 llvm_strlcpy   51480
1  mojo                     0x0000000102efeef0 llvm_strlcpy   44036
2  mojo                     0x0000000102f012a4 llvm_strlcpy   53176
3  libsystem_platform.dylib 0x000000019d58f584 _sigtramp   56
4  mojo                     0x0000000103244488 __jit_debug_register_code   709568
5  mojo                     0x0000000103244bbc __jit_debug_register_code   711412
6  mojo                     0x00000001031be52c __jit_debug_register_code   160868
7  mojo                     0x00000001031cacb0 __jit_debug_register_code   211944
8  mojo                     0x00000001031cb17c __jit_debug_register_code   213172
9  mojo                     0x00000001031d4788 __jit_debug_register_code   251584
10 mojo                     0x00000001031d49a8 __jit_debug_register_code   252128
11 mojo                     0x0000000102e4e8c8
12 mojo                     0x0000000102e606b0
13 mojo                     0x0000000102e49940
14 dyld                     0x000000019d1d60e0 start   2360
mojo crashed!
Please file a bug report.
[30546:4088829:20240712,155400.429252:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
Segmentation fault: 11
  • If using the Playground, name the pre-existing notebook that failed and the steps that led to failure.
  • Include anything else that might help us debug the issue.
    llvm (and llvm-symbolizer) was not installed when the crash happened.

System information

- What OS did you do install Mojo on ? 
macOSX
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 24.4.0 (59977802)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.8.0 (39a426b5)
@nzhang nzhang added bug Something isn't working mojo-repo Tag all issues with this label labels Jul 13, 2024
@soraros
Copy link
Contributor

soraros commented Jul 13, 2024

Might be related to #3099.

# Zn: @value is a little confusing as it doe not mean immutable class. 
# Zn: how to define a immutable struct in Mojo?

@value means "make it a value type", there is nothing about mutability. Also, there is no way to make an immutable structure in Mojo currently.

@nzhang
Copy link
Author

nzhang commented Jul 13, 2024

Thank you for the quick response @soraros , particularly answering my own questions while still learning the language :)

#3099 seems related but may not be exactly the same. The crash I got didn't need a @value decorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants