Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Assertion on default argument assignment to ephemeral mutable type #4089

Open
ergl opened this issue Apr 6, 2022 · 4 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ergl
Copy link
Member

ergl commented Apr 6, 2022

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.

@ergl ergl added the bug Something isn't working label Apr 6, 2022
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 6, 2022
@ergl
Copy link
Member Author

ergl commented Apr 6, 2022

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

@SeanTAllen SeanTAllen added the help wanted Extra attention is needed label Apr 6, 2022
@ergl ergl changed the title Compiler Assertion on default argument to ephemeral mutable type Compiler Assertion on default argument assignment to ephemeral mutable type Apr 6, 2022
@jasoncarr0
Copy link
Contributor

jasoncarr0 commented Apr 8, 2022

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

@ergl
Copy link
Member Author

ergl commented Apr 8, 2022

@jemc
Copy link
Member

jemc commented Apr 12, 2022

Discussed on the sync call today.

The fastest fix seems to be removing the assert and changing the error string at

if(type == NULL)
{
// This should never happen. We've left this assert here for now because
// we're not sure it won't happen. If enough time passes and this hasn't
// triggered, we can remove it. -- February 2022
pony_assert(0);
ast_error_frame(&err2, type,
"invalid parameter type: %s",
ast_print_type(type));
errorframe_append(&err2, &err);
errorframe_report(&err2, opt->check.errors);
ok = false;
}

Jason also says it may be possible to just skip this case in hopes that a later check will catch the issue.

@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants