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.71k stars 415 forks source link

Compilation segfault #2740

Open Shorttail opened 6 years ago

Shorttail commented 6 years ago

Here's a minimal example.

actor Main
  new create(env: Env) =>
    foo()

  fun foo() =>
    @bar[None](addressof baz)

  fun baz() =>
    None

The error is the following:

Generating
 Reachability
c:\projects\ponyc\src\libponyc\type\cap.c:710: cap_view_upper: Assertion `0` failed.

Backtrace:
  () [00007FF72FDD375D]
  () [00007FF72FD8CE44]
  () [00007FF72FD8FE99]
  () [00007FF72FD8FA88]
  () [00007FF72FD8EE97]
  () [00007FF72FD8F844]
  () [00007FF72FD8F89D]
  () [00007FF72FD8869C]
  () [00007FF72FDA38D7]
  () [00007FF72FDA31CA]
  () [00007FF72FDA433C]
  () [00007FF72FDA4B73]
  () [00007FF72FDA4ED1]
  () [00007FF72FDA4ED1]
  () [00007FF72FDA548F]
  () [00007FF72FDAD342]
  () [00007FF72FD6C5FA]
  () [00007FF72FD3145F]
  () [00007FF72FD315E0]
  (pony_asio_event_set_writeable) [00007FF730E07A5C]
  (BaseThreadInitThunk) [00007FFE13E03034]
  (RtlUserThreadStart) [00007FFE141F1551]
This is an optimised version of ponyc: the backtrace may be imprecise or incorrect.
Use a debug version to get more meaningful information.

Moving the code from foo to create removes the segfault. Removing the addressof this.baz from the arguments also removes the segfault.

Edit: All edits to reduce example code size.

SeanTAllen commented 6 years ago

Can reproduce on OSX.

SeanTAllen commented 6 years ago

backtrace:

* thread #1: tid = 0x113a57, 0x00007fff8c223f06 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff8c223f06 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff8c223f06 <+10>: jae    0x7fff8c223f10            ; <+20>
    0x7fff8c223f08 <+12>: movq   %rax, %rdi
    0x7fff8c223f0b <+15>: jmp    0x7fff8c21e7cd            ; cerror_nocancel
    0x7fff8c223f10 <+20>: retq
(lldb) bt
* thread #1: tid = 0x113a57, 0x00007fff8c223f06 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff8c223f06 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff9a8224ec libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x00007fff8ab476df libsystem_c.dylib`abort + 129
    frame #3: 0x00000001001250f3 ponyc`ponyint_assert_fail(expr="0", file="src/libponyc/type/cap.c", line=710, func="cap_view_upper") + 403 at ponyassert.c:60
    frame #4: 0x0000000100100c61 ponyc`cap_view_upper(left_cap=TK_AT, left_eph=TK_NONE, right_cap=0x00007fff5fbfe5cc, right_eph=0x00007fff5fbfe5c8) + 753 at cap.c:710
    frame #5: 0x0000000100110884 ponyc`viewpoint_upper(type=0x0000000107efd040) + 660 at viewpoint.c:221
    frame #6: 0x0000000100110563 ponyc`viewpoint_type(l_type=0x0000000107effc00, r_type=0x0000000107efd080) + 1587 at viewpoint.c:135
    frame #7: 0x0000000100110f8d ponyc`replace_type(astp=0x00007fff5fbfe8c8, target=0x0000000107f01a00, with=0x0000000107efd0c0) + 717 at viewpoint.c:377
    frame #8: 0x0000000100110cae ponyc`viewpoint_replace(ast=0x0000000107efd180, target=0x0000000107f01a00, with=0x0000000107efd0c0, duplicate=false) + 158 at viewpoint.c:398
    frame #9: 0x0000000100111015 ponyc`viewpoint_replacethis(ast=0x0000000107efd180, with=0x0000000107efd0c0, duplicate=false) + 69 at viewpoint.c:405
    frame #10: 0x0000000100106343 ponyc`deferred_reify(deferred=0x0000000107efc300, ast=0x000000010a2de240, opt=0x00007fff5fbff7e0) + 67 at reify.c:296
    frame #11: 0x00000001000f8dd3 ponyc`set_method_types(r=0x00000001082a0100, m=0x0000000107ef6880, opt=0x00007fff5fbff7e0) + 195 at reach.c:192
    frame #12: 0x00000001000f6dc6 ponyc`add_rmethod(r=0x00000001082a0100, t=0x0000000107efa900, n=0x0000000107ef6800, cap=TK_AT, typeargs=0x0000000000000000, opt=0x00007fff5fbff7e0, internal=false) + 502 at reach.c:371
    frame #13: 0x00000001000f7681 ponyc`add_nominal(r=0x00000001082a0100, type=0x0000000107efc040, opt=0x00007fff5fbff7e0) + 1249 at reach.c:914
    frame #14: 0x00000001000f6a4a ponyc`add_type(r=0x00000001082a0100, type=0x0000000107efc040, opt=0x00007fff5fbff7e0) + 186 at reach.c:990
    frame #15: 0x00000001000fa26a ponyc`reachable_ffi(r=0x00000001082a0100, reify=0x0000000107efeb80, ast=0x000000010ab550c0, opt=0x00007fff5fbff7e0) + 586 at reach.c:1135
    frame #16: 0x00000001000f93f5 ponyc`reachable_expr(r=0x00000001082a0100, reify=0x0000000107efeb80, ast=0x000000010ab550c0, opt=0x00007fff5fbff7e0) + 597 at reach.c:1196
    frame #17: 0x00000001000f9a47 ponyc`reachable_expr(r=0x00000001082a0100, reify=0x0000000107efeb80, ast=0x000000010ab54bc0, opt=0x00007fff5fbff7e0) + 2215 at reach.c:1307
    frame #18: 0x00000001000f64ac ponyc`handle_method_stack(r=0x00000001082a0100, opt=0x00007fff5fbff7e0) + 108 at reach.c:1383
    frame #19: 0x00000001000f61b2 ponyc`reach(r=0x00000001082a0100, type=0x00000001082a3340, name="create", typeargs=0x0000000000000000, opt=0x00007fff5fbff7e0) + 82 at reach.c:1413
    frame #20: 0x000000010004f973 ponyc`genexe(c=0x00007fff5fbff2e8, program=0x000000010b1bfd40) + 435 at genexe.c:504
    frame #21: 0x000000010003dd2e ponyc`codegen(program=0x000000010b1bfd40, opt=0x00007fff5fbff7e0) + 302 at codegen.c:874
    frame #22: 0x00000001000cc013 ponyc`generate_passes(program=0x000000010b1bfd40, options=0x00007fff5fbff7e0) + 51 at pass.c:360
    frame #23: 0x0000000100001c91 ponyc`compile_package(path=".", opt=0x00007fff5fbff7e0, print_program_ast=false, print_package_ast=false) + 177 at main.c:67
    frame #24: 0x0000000100001abc ponyc`main(argc=1, argv=0x00007fff5fbff8d8) + 316 at main.c:108
    frame #25: 0x00007fff9e1ad5ad libdyld.dylib`start + 1
SeanTAllen commented 6 years ago

The following also compiles:

actor Main
  new create(env: Env) =>
    foo()

  fun foo() =>
    None

  fun baz() =>
    @bar[None](addressof baz)
jemc commented 6 years ago

Could be related to the deferred_reify changes that @Praetonus worked on somewhat recently?

SeanTAllen commented 6 years ago

Can someone test this with code prior to #2557 being merged to master? If using a release, that would be 0.21.3?

SeanTAllen commented 6 years ago

I tested this with 0.21.3 and it crashes as well, so not introduced by #2557.

SeanTAllen commented 4 years ago

Still present as of 0.37.0