ponyc
ponyc copied to clipboard
Compiler Assertion on default argument assignment to ephemeral mutable type
Starting with ponyc 0.49.1, the following Pony code:
class Foo
actor Main
fun apply(x: Foo iso^ = Foo) => None
new create(env: Env) =>
None
causes the compiler to crash with the following assertion error:
# ./build/debug/ponyc crash_examples
Building builtin -> ~/dev/ponylang/ponyc/packages/builtin
Building crash_examples -> ~/dev/ponylang/ponyc/crash_examples
~/../src/libponyc/expr/reference.c:178: expr_param: Assertion `0` failed.
Backtrace functionality not available.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Abort trap: 6
Changing x: Foo iso^ to x: Foo trn^ will also reproduce the issue.
This issue is related to #4018, as the above code compiled with ponyc 0.49.0.
This is the relevant backtrace:
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x000000018c760e28 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x000000018c79343c libsystem_pthread.dylib`pthread_kill + 292
frame #2: 0x000000018c6db454 libsystem_c.dylib`abort + 124
frame #3: 0x00000001001050a4 ponyc`ponyint_assert_fail(expr="0", file="/.../ponyc/src/libponyc/expr/reference.c", line=178, func="expr_param") at ponyassert.c:65:3
frame #4: 0x00000001000a0dc4 ponyc`expr_param(opt=0x000000016fdff4e0, ast=0x000000010be5ae00) at reference.c:178:7
frame #5: 0x00000001000aa2f8 ponyc`pass_expr(astp=0x000000016fdfefa0, options=0x000000016fdff4e0) at expr.c:564:29
frame #6: 0x00000001000ae250 ponyc`ast_visit(ast=0x000000016fdfefa0, pre=(ponyc`pass_pre_expr at expr.c:527), post=(ponyc`pass_expr at expr.c:548), options=0x000000016fdff4e0, pass=PASS_EXPR) at pass.c:466:12
This is the assert that we were uncertain about the possibility of triggering https://github.com/ponylang/ponyc/blame/main/src/libponyc/expr/reference.c#L175
Indeed, it seems that the NULL here comes from: https://github.com/ponylang/ponyc/blame/ebda8af80641bedd4723ac0b4dd2e336bd3dfa08/src/libponyc/type/alias.c#L205-L214
Discussed on the sync call today.
The fastest fix seems to be removing the assert and changing the error string at https://github.com/ponylang/ponyc/blob/deb1494a4ba423b5c46743062b00ccf5f4bf7942/src/libponyc/expr/reference.c#L173-L185
Jason also says it may be possible to just skip this case in hopes that a later check will catch the issue.