ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.74k stars 415 forks source link

Unexpected GEN_NOTNEEDED in partial application in constructor #3584

Open ergl opened 4 years ago

ergl commented 4 years ago

The following code causes a compiler error on ponyc 0.35.1-57947572

actor Main
  new create(env: Env) =>
    Herp~create(where env=env)(Derp)

actor Herp
  new create(derp: Derp, env: Env) =>
    env.out.print("hooray!")

class iso Derp

Pony version:

$ ponyc --version
0.35.1-57947572 [release]
Compiled with: LLVM 9.0.1 -- AppleClang-11.0.3.11030032-x86_64
Defaults: pic=true
$ ponyc .
Building builtin -> ~/.local/share/ponyup/ponyc-release-0.35.1-x86_64-darwin/packages/builtin
Building . -> ~/test
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
.../src/libponyc/codegen/genexpr.c:310: gen_assign_cast: Assertion `r_value != GEN_NOTNEEDED` failed.

Backtrace functionality not available.
Abort trap: 6

Can reproduce on the playground: https://playground.ponylang.io/?gist=04897bac813bf7fed2f2639eccb4a88d

I don't have a debug version of ponyc right now, but this is the backtrace with lldb:

$ lldb -- ponyc
(lldb) target create "ponyc"
Current executable set to 'ponyc' (x86_64).
(lldb) run
Process 10108 launched: '~/.local/share/ponyup/bin/ponyc' (x86_64)
Building builtin -> ~/.local/share/ponyup/ponyc-release-0.35.1-x86_64-darwin/packages/builtin
Building . -> ~/test
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
.../src/libponyc/codegen/genexpr.c:310: gen_assign_cast: Assertion `r_value != GEN_NOTNEEDED` failed.

Backtrace functionality not available.
Process 10108 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff7976d2c2 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff7976d2c2 <+10>: jae    0x7fff7976d2cc            ; <+20>
    0x7fff7976d2c4 <+12>: movq   %rax, %rdi
    0x7fff7976d2c7 <+15>: jmp    0x7fff79767453            ; cerror_nocancel
    0x7fff7976d2cc <+20>: retq
Target 0: (ponyc) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff7976d2c2 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff79828bf1 libsystem_pthread.dylib`pthread_kill + 284
    frame #2: 0x00007fff796d76a6 libsystem_c.dylib`abort + 127
    frame #3: 0x000000010152492e ponyc`ponyint_assert_fail + 142
    frame #4: 0x000000010004d1ed ponyc`gen_assign_cast + 221
    frame #5: 0x0000000100046138 ponyc`gen_call + 3336
    frame #6: 0x000000010004cc64 ponyc`gen_expr + 532
    frame #7: 0x0000000100045a16 ponyc`gen_call + 1510
    frame #8: 0x000000010004cc64 ponyc`gen_expr + 532
    frame #9: 0x000000010004824b ponyc`gen_seq + 59
    frame #10: 0x000000010004cd69 ponyc`gen_expr + 793
    frame #11: 0x000000010004e7c1 ponyc`genfun_method_bodies + 1137
    frame #12: 0x000000010006420c ponyc`gentypes + 3628
    frame #13: 0x000000010004c679 ponyc`genexe + 457
    frame #14: 0x0000000100041b5b ponyc`codegen + 219
    frame #15: 0x0000000100002083 ponyc`main + 403
    frame #16: 0x00007fff796323d5 libdyld.dylib`start + 1
jemc commented 4 years ago

Info for whomever wants to look at this: this kind of assertion error means there's a mismatch between one part of the code that thinks the expression value is used, and another part of the code that thinks the expression value is not used.

ergl commented 3 years ago

Further comments, this happens during the ir pass of the compiler, and a minimal example:

class Foo
  new create() => None

actor Main
  new create(env: Env) =>
    Foo~create()

Debug backtrace:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff726e42c2 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff7279fbf1 libsystem_pthread.dylib`pthread_kill + 284
    frame #2: 0x00007fff7264e6a6 libsystem_c.dylib`abort + 127
    frame #3: 0x0000000100114e0d ponyc`ponyint_assert_fail(expr="r_value != GEN_NOTNEEDED", file="/Users/ryan/dev/ponyc/src/libponyc/codegen/genexpr.c", line=310, func="gen_assign_cast") at ponyassert.c:65:3
    frame #4: 0x000000010004bfa7 ponyc`gen_assign_cast(c=0x00007ffeefbfeff8, l_type=0x0000000104004500, r_value=0x0000000000000002, type=0x000000010626e780) at genexpr.c:310:3
    frame #5: 0x0000000100041e1b ponyc`gen_call(c=0x00007ffeefbfeff8, ast=0x000000010b56a040) at gencall.c:877:17
    frame #6: 0x000000010004b885 ponyc`gen_expr(c=0x00007ffeefbfeff8, ast=0x000000010b56a040) at genexpr.c:92:13
    frame #7: 0x0000000100045864 ponyc`gen_seq(c=0x00007ffeefbfeff8, ast=0x000000010bee5dc0) at gencontrol.c:22:13
    frame #8: 0x000000010004b759 ponyc`gen_expr(c=0x00007ffeefbfeff8, ast=0x000000010bee5dc0) at genexpr.c:26:13
    frame #9: 0x000000010004e577 ponyc`genfun_newbe(c=0x00007ffeefbfeff8, t=0x000000010c213d00, m=0x000000010c05e900) at genfun.c:589:24
    frame #10: 0x000000010004d70f ponyc`genfun_method(c=0x00007ffeefbfeff8, t=0x000000010c213d00, n=0x000000010c05e880, m=0x000000010c05e900) at genfun.c:784:15
    frame #11: 0x000000010004d542 ponyc`genfun_method_bodies(c=0x00007ffeefbfeff8, t=0x000000010c213d00) at genfun.c:946:11
    frame #12: 0x000000010006a096 ponyc`gentypes(c=0x00007ffeefbfeff8) at gentype.c:861:9
    frame #13: 0x000000010004b07c ponyc`genexe(c=0x00007ffeefbfeff8, program=0x000000010c7bfd00) at genexe.c:561:7
    frame #14: 0x000000010003ca7a ponyc`codegen(program=0x000000010c7bfd00, opt=0x00007ffeefbff4c8) at codegen.c:923:10
    frame #15: 0x00000001000b78b3 ponyc`generate_passes(program=0x000000010c7bfd00, options=0x00007ffeefbff4c8) at pass.c:360:10
    frame #16: 0x0000000100001fa1 ponyc`compile_package(path="examples/crash/", opt=0x00007ffeefbff4c8, print_program_ast=false, print_package_ast=false) at main.c:67:13
    frame #17: 0x0000000100001e3f ponyc`main(argc=2, argv=0x00007ffeefbff5d0) at main.c:112:15
    frame #18: 0x00007fff725a93d5 libdyld.dylib`start + 1