ponyc
ponyc copied to clipboard
Expr pass: partial application of function with out-of-range literal in parenthesis causes core assertion error
Probably related to #3727, this code causes the compiler to crash:
primitive Foo
fun test(f: U8 = (256)) =>
None
actor Main
new create(env: Env) =>
Foo~test()
> ponyc -r expr examples/crash/
Building builtin -> /.../dev/ponyc/packages/builtin
Building examples/crash/ -> /...dev/ponyc/examples/crash
/.../dev/ponyc/src/libponyc/expr/literal.c:469: uifset: Assertion `0` failed.
Backtrace functionality not available.
Abort trap: 6
Pony version:
> ponyc --version
0.39.0-08187e28 [debug]
Compiled with: LLVM 9.0.1 -- AppleClang-11.0.0.11000033-x86_64
Defaults: pic=true
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="0", file="/Users/ryan/dev/ponyc/src/libponyc/expr/literal.c", line=469, func="uifset") at ponyassert.c:65:3
frame #4: 0x00000001000a0ad9 ponyc`uifset(opt=0x00007ffeefbff4c8, type=0x0000000109d60f80, chain=0x00007ffeefbfd418) at literal.c:469:7
frame #5: 0x00000001000a01e5 ponyc`uif_type(opt=0x00007ffeefbff4c8, literal=0x0000000109d60e80, type=0x0000000109d60f80, chain_head=0x00007ffeefbfd418, report_errors=true) at literal.c:483:11
frame #6: 0x000000010009fc3d ponyc`uif_type_from_chain(opt=0x00007ffeefbff4c8, literal=0x0000000109d60e80, target_type=0x0000000109d60f80, chain=0x00007ffeefbfd418, require_float=false, report_errors=true) at literal.c:550:9
frame #7: 0x000000010009ea4a ponyc`coerce_literal_to_type(astp=0x00007ffeefbfd498, target_type=0x0000000109d60f80, chain=0x00007ffeefbfd418, opt=0x00007ffeefbff4c8, report_errors=true) at literal.c:747:14
frame #8: 0x000000010009e613 ponyc`coerce_literals(astp=0x00007ffeefbfd498, target_type=0x0000000109d60f80, opt=0x00007ffeefbff4c8) at literal.c:846:10
frame #9: 0x000000010009716e ponyc`expr_seq(opt=0x00007ffeefbff4c8, ast=0x0000000109d60e00) at control.c:48:25
frame #10: 0x00000001000b2b63 ponyc`pass_expr(astp=0x00007ffeefbfd610, options=0x00007ffeefbff4c8) at expr.c:555:29
frame #11: 0x00000001000b6fe3 ponyc`ast_visit(ast=0x00007ffeefbfd610, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:457:12
frame #12: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfd6a0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #13: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfd730, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #14: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfd7c0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #15: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfd850, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #16: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfd8e0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #17: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfddf0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #18: 0x00000001000b7afa ponyc`visit_pass(astp=0x00007ffeefbfddf0, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR, out_r=0x00007ffeefbfd9e3, pass=PASS_EXPR, pre_fn=(ponyc`pass_pre_expr at expr.c:518), post_fn=(ponyc`pass_expr at expr.c:535)) at pass.c:176:6
frame #19: 0x00000001000b74d5 ponyc`ast_passes(astp=0x00007ffeefbfddf0, options=0x00007ffeefbff4c8, last=PASS_EXPR) at pass.c:269:7
frame #20: 0x00000001000b77f5 ponyc`ast_passes_type(astp=0x00007ffeefbfddf0, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR) at pass.c:339:13
frame #21: 0x000000010009cf00 ponyc`expr_object(opt=0x00007ffeefbff4c8, astp=0x00007ffeefbfef20) at lambda.c:825:7
frame #22: 0x00000001000b2e9e ponyc`pass_expr(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8) at expr.c:607:11
frame #23: 0x00000001000b6fe3 ponyc`ast_visit(ast=0x00007ffeefbfef20, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:457:12
frame #24: 0x00000001000b7afa ponyc`visit_pass(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR, out_r=0x00007ffeefbfe033, pass=PASS_EXPR, pre_fn=(ponyc`pass_pre_expr at expr.c:518), post_fn=(ponyc`pass_expr at expr.c:535)) at pass.c:176:6
frame #25: 0x00000001000b74d5 ponyc`ast_passes(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last=PASS_EXPR) at pass.c:269:7
frame #26: 0x00000001000b7873 ponyc`ast_passes_subtree(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR) at pass.c:351:10
frame #27: 0x000000010009a7ac ponyc`expr_lambda(opt=0x00007ffeefbff4c8, astp=0x00007ffeefbfef20) at lambda.c:455:10
frame #28: 0x00000001000b2ec4 ponyc`pass_expr(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8) at expr.c:613:11
frame #29: 0x00000001000b6fe3 ponyc`ast_visit(ast=0x00007ffeefbfef20, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:457:12
frame #30: 0x00000001000b7afa ponyc`visit_pass(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR, out_r=0x00007ffeefbfe5b3, pass=PASS_EXPR, pre_fn=(ponyc`pass_pre_expr at expr.c:518), post_fn=(ponyc`pass_expr at expr.c:535)) at pass.c:176:6
frame #31: 0x00000001000b74d5 ponyc`ast_passes(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last=PASS_EXPR) at pass.c:269:7
frame #32: 0x00000001000b7873 ponyc`ast_passes_subtree(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8, last_pass=PASS_EXPR) at pass.c:351:10
frame #33: 0x0000000100095191 ponyc`partial_application(opt=0x00007ffeefbff4c8, astp=0x00007ffeefbfef20) at call.c:922:10
frame #34: 0x000000010009227a ponyc`expr_call(opt=0x00007ffeefbff4c8, astp=0x00007ffeefbfef20) at call.c:990:14
frame #35: 0x00000001000b2c77 ponyc`pass_expr(astp=0x00007ffeefbfef20, options=0x00007ffeefbff4c8) at expr.c:569:29
frame #36: 0x00000001000b6fe3 ponyc`ast_visit(ast=0x00007ffeefbfef20, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:457:12
frame #37: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbfefb0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #38: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff040, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #39: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff0d0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #40: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff160, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #41: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff1f0, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #42: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff280, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #43: 0x00000001000b6f1c ponyc`ast_visit(ast=0x00007ffeefbff3b8, pre=(ponyc`pass_pre_expr at expr.c:518), post=(ponyc`pass_expr at expr.c:535), options=0x00007ffeefbff4c8, pass=PASS_EXPR) at pass.c:428:14
frame #44: 0x00000001000b7afa ponyc`visit_pass(astp=0x00007ffeefbff3b8, options=0x00007ffeefbff4c8, last_pass=PASS_ALL, out_r=0x00007ffeefbff383, pass=PASS_EXPR, pre_fn=(ponyc`pass_pre_expr at expr.c:518), post_fn=(ponyc`pass_expr at expr.c:535)) at pass.c:176:6
frame #45: 0x00000001000b74d5 ponyc`ast_passes(astp=0x00007ffeefbff3b8, options=0x00007ffeefbff4c8, last=PASS_ALL) at pass.c:269:7
frame #46: 0x00000001000b70e2 ponyc`ast_passes_program(ast=0x000000010afbfd00, options=0x00007ffeefbff4c8) at pass.c:318:10
frame #47: 0x00000001000dcbaf ponyc`program_load(path="examples/crash/", opt=0x00007ffeefbff4c8) at package.c:934:7
frame #48: 0x0000000100001f1f ponyc`compile_package(path="examples/crash/", opt=0x00007ffeefbff4c8, print_program_ast=false, print_package_ast=false) at main.c:56:20
frame #49: 0x0000000100001e3f ponyc`main(argc=2, argv=0x00007ffeefbff5d0) at main.c:112:15
frame #50: 0x00007fff725a93d5 libdyld.dylib`start + 1
As in #3727, the issue dissappears if we make don't use a partial function, so it seems that the desugaring process is faulty. The compiler should complain that 256 is an invalid value for U8:
Error:
/.../dev/ponyc/examples/crash/main.pony:2:21: Literal value is out of range for type (U8)
fun test(f: U8 = (256)) =>
^
It might be that 256 is not getting inferred as a nominal, and thus doesn't go through the regular out-of-range check in literal.c
I believe there's an issue that exists that looks a lot like this. That's my recollection.
Maybe. I tried looking for errors related to uifset but couldn't find any open issues.