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

Monomorphisation panic #190

Open
sullyj3 opened this issue Feb 23, 2024 · 3 comments
Open

Monomorphisation panic #190

sullyj3 opened this issue Feb 23, 2024 · 3 comments

Comments

@sullyj3
Copy link

sullyj3 commented Feb 23, 2024

The code:

fizzbuzz_loop n = 
  loop (i = 1) ->

    if i % 3 == 0 and i % 5 == 0 then
      print "FizzBuzz"
    else if i % 3 == 0 then
      print "Fizz"
    else if i % 5 == 0 then
      print "Buzz"
    else
      print i

    if i == n then 
      () 
    else 
      recur (i + 1)

fizzbuzz_loop 30

Fails with:

⮞ env RUST_BACKTRACE=1 ante fizzbuzz.an
thread 'main' panicked at src/hir/monomorphisation.rs:826:17:
internal error: entered unreachable code: Cannot monomorphise from a TraitDefinition.
No cached impl for '%' 39: (I32 - I32 -> I32 can 600)
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: ante::hir::monomorphisation::Context::monomorphise_definition_id
   3: ante::hir::monomorphisation::Context::monomorphise
   4: ante::hir::monomorphisation::Context::monomorphise_call
   5: ante::hir::monomorphisation::Context::monomorphise_call
   6: ante::hir::monomorphisation::Context::monomorphise
   7: ante::hir::monomorphisation::Context::monomorphise
   8: ante::hir::monomorphisation::Context::monomorphise
   9: ante::hir::monomorphisation::Context::monomorphise
  10: ante::hir::monomorphisation::Context::monomorphise_definition_id
  11: ante::hir::monomorphisation::Context::monomorphise
  12: ante::hir::monomorphisation::Context::monomorphise_call
  13: ante::hir::monomorphisation::Context::monomorphise
  14: ante::hir::monomorphisation::Context::monomorphise
  15: ante::hir::monomorphisation::Context::monomorphise
  16: ante::hir::monomorphisation::Context::monomorphise_definition_id
  17: ante::hir::monomorphisation::Context::monomorphise
  18: ante::hir::monomorphisation::Context::monomorphise_call
  19: ante::hir::monomorphisation::Context::monomorphise
  20: ante::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fish: Job 1, 'env RUST_BACKTRACE=1 ante fizzb…' terminated by signal SIGABRT (Abort)
@jfecher
Copy link
Owner

jfecher commented Feb 23, 2024

Looks like it failed to find the monomorphized trait impl. Odd, I'd think you'd need a more complex example to trigger this bug. Thanks for the issue, I'll take a look.

@jfecher
Copy link
Owner

jfecher commented Feb 23, 2024

Also - in case you or anyone else reading is looking for a workaround using explicit, non-polymorphic types for fizzbuzz_loop will fix the bug:

fizzbuzz_loop (n: U32) = 
  loop (i = 1) ->
    if i % 3 == 0 and i % 5 == 0 then
      print "FizzBuzz"
    else if i % 3 == 0 then
      print "Fizz"
    else if i % 5 == 0 then
      print "Buzz"
    else
      print i

    if i != n then
      recur (i + 1)

fizzbuzz_loop 30

@sullyj3
Copy link
Author

sullyj3 commented Feb 23, 2024

Nice, thank you. (And for the implicit tip about if)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants