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] Mojo crashes when attempting run str() during compilation. #2779

Closed
thatstoasty opened this issue May 22, 2024 · 6 comments
Closed

[BUG] Mojo crashes when attempting run str() during compilation. #2779

thatstoasty opened this issue May 22, 2024 · 6 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@thatstoasty
Copy link
Contributor

thatstoasty commented May 22, 2024

Bug description

Running str() within in an alias causes the compiler to crash. I think we should be able to convert Stringables to String during compilation unless I'm missing something. Thanks!

Steps to reproduce

  • Include relevant code snippet or link to code that did not work as expected.
  • If applicable, add screenshots to help explain the problem.
  • 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.

Minimal example to reproduce the error:

fn main() -> None:
    alias s = str(1)

System information

- What OS did you do install Mojo on ? MacOS 14.4.1
- Provide version information for Mojo by pasting the output of `mojo -v` mojo 2024.5.2012 (fb60fe4f)
- Provide Modular CLI version by pasting the output of `modular -v` modular 0.7.1 (28ddab26)
@thatstoasty thatstoasty added bug Something isn't working mojo-repo Tag all issues with this label labels May 22, 2024
@JoeLoser
Copy link
Collaborator

FYI @laszlokindrat as we were talking about this last week if I recall correctly.

@laszlokindrat
Copy link
Contributor

@thatstoasty Thanks for opening the ticket! Can you please provide the error message or trace you are getting?

@thatstoasty
Copy link
Contributor Author

@laszlokindrat Sure! Here's the trace

/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: error: function instantiation failed
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: note:   call expansion failed - no concrete specializations
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:67:4: note:     function instantiation failed
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:82:14: note:       call expansion failed - no concrete specializations
/Users/mikhailtavarez/Git/mojo/mist/test.mojo:1:4: note:         function instantiation failed
fn main() -> None:
   ^
/Users/mikhailtavarez/Git/mojo/mist/test.mojo:2:5: note:           failed to evaluate 'apply'
    alias s = str(1)
    ^
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/str.mojo:134:4: note:             failed to interpret function @stdlib::builtin::str::str[stdlib::builtin::str::Stringable]($0),T=[index, {"__str__" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<(struct<(pointer<none>, index, index) memoryOnly>) memoryOnly>> byref_result) -> !kgen.none = @"stdlib::builtin::int::Int::__str__(stdlib::builtin::int::Int)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/str.mojo:146:25: note:               failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                 failed to interpret function @stdlib::builtin::int::Int::__str__(stdlib::builtin::int::Int)_thunk
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                   error recurses 1 times:
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                     failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:351:8: note:                       failed to interpret function @stdlib::builtin::int::Int::__str__(stdlib::builtin::int::Int)
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:358:38: note:                         failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/string.mojo:1108:8: note:                           failed to interpret function @stdlib::builtin::string::String::format_sequence[*stdlib::utils::_format::Formattable](*$0),Ts=[[index, {"format_to" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<((!kgen.pointer<none> borrow, !kgen.struct<(pointer<none>, index)> borrow) -> !kgen.none, pointer<none>) memoryOnly>> byref) -> !kgen.none = @"stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]]
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/string.mojo:1130:29: note:                             failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/builtin_list.mojo:635:8: note:                               failed to interpret function @stdlib::builtin::builtin_list::VariadicPack::each[fn[$2]($0, /) capturing -> None](stdlib::builtin::builtin_list::VariadicPack[$0, $1, $2, $3]),elt_is_mutable=0,lifetime={  },element_trait=type,element_types=[[index, {"format_to" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<((!kgen.pointer<none> borrow, !kgen.struct<(pointer<none>, index)> borrow) -> !kgen.none, pointer<none>) memoryOnly>> byref) -> !kgen.none = @"stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]],func=@"stdlib::builtin::string::String::format_sequence[*stdlib::utils::_format::Formattable](*$0)_write_arg[stdlib::utils::_format::Formattable]($0)"
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/builtin_list.mojo:649:41: note:                                 failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:30:4: note:                                   failed to interpret function @stdlib::utils::loop::unroll[fn[stdlib::builtin::int::Int]() capturing -> None,stdlib::builtin::int::Int](),func=@"stdlib::builtin::builtin_list::VariadicPack::each[fn[$2]($0, /) capturing -> None](stdlib::builtin::builtin_list::VariadicPack[$0, $1, $2, $3])_unrolled[stdlib::builtin::int::Int]()"<:type type, :variadic<type> [[index, {"format_to" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<((!kgen.pointer<none> borrow, !kgen.struct<(pointer<none>, index)> borrow) -> !kgen.none, pointer<none>) memoryOnly>> byref) -> !kgen.none = @"stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]], :<type>(!kgen.pointer<*(0,0)> borrow_in_mem) capturing -> !kgen.none @"stdlib::builtin::string::String::format_sequence[*stdlib::utils::_format::Formattable](*$0)_write_arg[stdlib::utils::_format::Formattable]($0)", ?>,count=1
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:44:16: note:                                     failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/builtin_list.mojo:646:12: note:                                       failed to interpret function @stdlib::builtin::builtin_list::VariadicPack::each[fn[$2]($0, /) capturing -> None](stdlib::builtin::builtin_list::VariadicPack[$0, $1, $2, $3])_unrolled[stdlib::builtin::int::Int](),element_trait=type,element_types=[[index, {"format_to" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<((!kgen.pointer<none> borrow, !kgen.struct<(pointer<none>, index)> borrow) -> !kgen.none, pointer<none>) memoryOnly>> byref) -> !kgen.none = @"stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]],func=@"stdlib::builtin::string::String::format_sequence[*stdlib::utils::_format::Formattable](*$0)_write_arg[stdlib::utils::_format::Formattable]($0)",i=0
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/builtin_list.mojo:647:17: note:                                         failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/string.mojo:1127:12: note:                                           failed to interpret function @stdlib::builtin::string::String::format_sequence[*stdlib::utils::_format::Formattable](*$0)_write_arg[stdlib::utils::_format::Formattable]($0),T=[index, {"format_to" : (!kgen.pointer<index> borrow_in_mem, !kgen.pointer<struct<((!kgen.pointer<none> borrow, !kgen.struct<(pointer<none>, index)> borrow) -> !kgen.none, pointer<none>) memoryOnly>> byref) -> !kgen.none = @"stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk", "__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::int::Int::__del__(stdlib::builtin::int::Int)_thunk"}]
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/string.mojo:1128:26: note:                                             failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                                               failed to interpret function @stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)_thunk
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                   remaining errors after:
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:241:8: note:                     failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:360:8: note:                       failed to interpret function @stdlib::builtin::int::Int::format_to(stdlib::builtin::int::Int,stdlib::utils::_format::Formatter&)
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/int.mojo:383:32: note:                         failed to evaluate call
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/io.mojo:136:4: note:                           failed to interpret function @stdlib::builtin::io::_snprintf[*stdlib::builtin::anytype::AnyType](stdlib::memory::unsafe_pointer::UnsafePointer[stdlib::builtin::simd::SIMD[{uint8}, {1}], {{0}}],stdlib::builtin::int::Int,stdlib::builtin::string_literal::StringLiteral,*$0),types=[[index, {"__del__" : (!kgen.pointer<index> owned_in_mem) -> !kgen.none = @"stdlib::builtin::_stubs::__MLIRType::__del__(stdlib::builtin::_stubs::__MLIRType[$0])_thunk"<:type index>}]]
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/io.mojo:162:49: note:                             failed to fold operation kgen.pack.load(#kgen.pack<2000000136> : !kgen.pack<[pointer<index>]>)
mojo: error: failed to run the pass manager

@laszlokindrat
Copy link
Contributor

@Mogball is this a potential issue with variadic packs in the compiler?

@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@zyx-billy
Copy link
Contributor

After fixing the issue with packs, evaluation still fails due to a dependency on an external call to snprintf in stdlib for formatting ints. So unfortunately this is not something that can be supported at compile-time unless the implementation no longer depends on the external call. Thanks for filing the issue though, it helped plug a hole with interpreting packs.

@thatstoasty
Copy link
Contributor Author

No problem, my use case will be covered once #1573 is resolved!

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

4 participants