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

Compiler crash with repeat until and error in else #3326

Open cvik opened 5 years ago

cvik commented 5 years ago

Compiling this:

actor Main                                                                       
  new create(env: Env) =>                                                        
    try let x: U8 = repeat 1 until false else error end end 

Results in a compiler crash. It's reproducable in the playground. Removing the else error and letting the alias type become (U8 | None) seem to fix it.

Compiler output:

Building builtin -> /usr/lib/pony/0.32.0/packages/builtin
Building . -> /home/cvi/src/pony/test
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
src/libponyc/ast/ast.c:421: ast_from: Assertion `ast != NULL` failed.

Backtrace:
  ponyc(ponyint_assert_fail+0x9e) [0x55b111c0ad6e]
  ponyc(ast_from+0x60) [0x55b111bacf00]
  ponyc(viewpoint_replacethis+0x1d) [0x55b111bb248d]
  ponyc(deferred_reify+0x2a) [0x55b111bb98ba]
  ponyc(gen_repeat+0x4af) [0x55b111bfde9f]
  ponyc(gen_expr+0x416) [0x55b111bf8696]
  ponyc(gen_assign+0x5b) [0x55b111c08dcb]
  ponyc(gen_expr+0x3ee) [0x55b111bf866e]
  ponyc(gen_seq+0x2c) [0x55b111bfc2ac]
  ponyc(gen_expr+0x23f) [0x55b111bf84bf]
  ponyc(gen_try+0xf7) [0x55b111bfc937]
  ponyc(gen_expr+0x134) [0x55b111bf83b4]
  ponyc(gen_seq+0x2c) [0x55b111bfc2ac]
  ponyc(gen_expr+0x23f) [0x55b111bf84bf]
  ponyc(genfun_method_bodies+0xb00) [0x55b111bf7ec0]
  ponyc(gentypes+0xd9e) [0x55b111bde18e]
  ponyc(genexe+0x13c) [0x55b111bf999c]
  ponyc(codegen+0x11e) [0x55b111b88c8e]
  ponyc(+0x26bb5) [0x55b111b67bb5]
  ponyc(main+0x1d0) [0x55b111b67750]
  /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7f33570d8153]
  ponyc(_start+0x2e) [0x55b111b67aae]
This is an optimised version of ponyc: the backtrace may be imprecise or incorrect.
Use a debug version to get more meaningful information.
Aborted (core dumped)

Compiler version:

0.32.0 [release]
compiled with: llvm 7.1.0 -- cc (GCC) 9.1.0
Defaults: pic=true
sylvanc commented 5 years ago

Looks like an implementation bug, not a type system bug.

aturley commented 5 years ago

@cvik would you have time to run this in a debugger and put the results in here?

cvik commented 5 years ago

I can try.

cvik commented 5 years ago

@aturley What particular output are you looking for from debugger?

aturley commented 5 years ago

@cvik I'm looking for the debugger backtrace here.

cvik commented 5 years ago

@aturley I compiled ponyc with debug options and ran it in gdb and ran bt after the crash, is this what you were after?

#0  0x00007f069466e428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007f069467002a in __GI_abort () at abort.c:89
#2  0x0000000000826756 in ponyint_assert_fail (expr=0x215c56f "ast != NULL", file=0x215c558 "src/libponyc/ast/ast.c", line=421, func=0x215d388 <__func__.7070> "ast_from")
    at src/libponyrt/platform/ponyassert.c:65
#3  0x00000000007855b3 in ast_from (ast=0x0, id=TK_THISTYPE) at src/libponyc/ast/ast.c:421
#4  0x000000000079abab in viewpoint_replacethis (ast=0x0, with=0x7f0690a61b00, duplicate=false) at src/libponyc/type/viewpoint.c:404
#5  0x00000000007993e1 in deferred_reify (deferred=0x7f0690a647c0, ast=0x0, opt=0x7ffd948cce70) at src/libponyc/type/reify.c:296
#6  0x000000000075a402 in gen_repeat (c=0x7ffd948cc9b0, ast=0x7f0693d28840) at src/libponyc/codegen/gencontrol.c:420
#7  0x00000000007512c1 in gen_expr (c=0x7ffd948cc9b0, ast=0x7f0693d28840) at src/libponyc/codegen/genexpr.c:79
#8  0x0000000000754901 in gen_assign (c=0x7ffd948cc9b0, ast=0x7f0693d28fc0) at src/libponyc/codegen/genoperator.c:914
#9  0x00000000007514a0 in gen_expr (c=0x7ffd948cc9b0, ast=0x7f0693d28fc0) at src/libponyc/codegen/genexpr.c:148
#10 0x0000000000758f9e in gen_seq (c=0x7ffd948cc9b0, ast=0x7f0693d28180) at src/libponyc/codegen/gencontrol.c:22
#11 0x000000000075119c in gen_expr (c=0x7ffd948cc9b0, ast=0x7f0693d28180) at src/libponyc/codegen/genexpr.c:26
#12 0x000000000075ad4c in gen_try (c=0x7ffd948cc9b0, ast=0x7f0693d29640) at src/libponyc/codegen/gencontrol.c:636
#13 0x00000000007512dd in gen_expr (c=0x7ffd948cc9b0, ast=0x7f0693d29640) at src/libponyc/codegen/genexpr.c:84
#14 0x0000000000758f9e in gen_seq (c=0x7ffd948cc9b0, ast=0x7f0693d28300) at src/libponyc/codegen/gencontrol.c:22
#15 0x000000000075119c in gen_expr (c=0x7ffd948cc9b0, ast=0x7f0693d28300) at src/libponyc/codegen/genexpr.c:26
#16 0x000000000076df01 in genfun_newbe (c=0x7ffd948cc9b0, t=0x7f0694056400, m=0x7f0693ea0980) at src/libponyc/codegen/genfun.c:599
#17 0x000000000076e8df in genfun_method (c=0x7ffd948cc9b0, t=0x7f0694056400, n=0x7f0693ea0900, m=0x7f0693ea0980) at src/libponyc/codegen/genfun.c:794
#18 0x000000000076edee in genfun_method_bodies (c=0x7ffd948cc9b0, t=0x7f0694056400) at src/libponyc/codegen/genfun.c:956
#19 0x0000000000765160 in gentypes (c=0x7ffd948cc9b0) at src/libponyc/codegen/gentype.c:857
#20 0x000000000076892d in genexe (c=0x7ffd948cc9b0, program=0x7f06945f8d00) at src/libponyc/codegen/genexe.c:552
#21 0x00000000007458ba in codegen (program=0x7f06945f8d00, opt=0x7ffd948cce70) at src/libponyc/codegen/codegen.c:880
#22 0x00000000007a7483 in generate_passes (program=0x7f06945f8d00, options=0x7ffd948cce70) at src/libponyc/pass/pass.c:360
#23 0x000000000073da7b in compile_package (path=0x21550a8 ".", opt=0x7ffd948cce70, print_program_ast=false, print_package_ast=false) at src/ponyc/main.c:67
#24 0x000000000073dbf9 in main (argc=1, argv=0x7ffd948cd038) at src/ponyc/main.c:109
aturley commented 5 years ago

@cvik Yeah, this is a good place for us to start, thanks!