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

Segfault when trying to compile incorrect capabilities #4344

Open kylefurlong opened 1 year ago

kylefurlong commented 1 year ago
trait T
    fun some() =>
        "Do nothing"

class TClass is T
    let _l: String
    new create(l: String) =>
         _l = consume l
    fun some() =>
        "Do nothing"

actor Act
    let _c: T iso
    new create(c: T iso) =>
        _c = consume c

actor Main
    new create() => 
        let c: T iso = TClass.create(l)
        let a: Act   = Act.create(c)

Adding a ^to let c: T iso = ... causes a ponyc crash.

SeanTAllen commented 1 year ago

Please post the code that you are reporting. It's not completely clear what changes are required to replicate the issue.

kylefurlong commented 1 year ago

Hi Sean,

I'm somewhat flabbergasted. The posted code in the original comment crashes ponyc when adding a ^ to let c: T iso = ... at line 19. The code that crashes would read let c: T iso^ = ....

Hoping I'm not the crazy one!

Best, Kyle

SeanTAllen commented 1 year ago

Kyle can you please post the complete code that crashes rather than a description of changes to code that is required to cause the situation?

kylefurlong commented 1 year ago

Hi Sean,

It might sound crazy, but I actually did post the entire code that reproduces the issue in the first post. Any chance you can place the code in a test.pony file and try the edit I suggested?

redvers commented 1 year ago

No it doesn't…

actor Main
    new create() =>
        let c: T iso = TClass.create(l)
        let a: Act   = Act.create(c)
[red@apophenia:~/dd]$ ponyc
Building builtin -> /nix/store/nnvr2l04kdk62n633g74p0vdwf9bbrmy-ponyc-0.54.0/lib/pony/0.54.0/packages/builtin
Building . -> /home/red/dd
Error:
/home/red/dd/main.pony:19:38: can't find declaration of 'l'
        let c: T iso = TClass.create(l)
redvers commented 1 year ago

The code you originally posted doesn't compile. We can't correct it to make it compile to follow your suggested edit because your problem description is related to incorrect capabilities.

We need to know what you compiled.

Also - can you confirm which version of ponyc you're using please?

redvers commented 1 year ago

I also noticed that your constructor for Main isn't correct either:

actor Main
    new create() =>  // Should be new create(env: Env) =>
kylefurlong commented 1 year ago

Policing the code isn't helpful. Just run it.

(base) kylefurlong@Kyles-Mac-mini quanta % cat ~/crash.pony
trait T
    fun some() =>
        "Do nothing"

class TClass is T
    let _l: String
    new create(l: String) =>
         _l = consume l
    fun some() =>
        "Do nothing"

actor Act
    let _c: T iso
    new create(c: T iso) =>
        _c = consume c

actor Main
    new create() => 
        let c: T iso^ = TClass.create("")
        let a: Act   = Act.create(c) 
(base) kylefurlong@Kyles-Mac-mini quanta % ponyc ~
Building builtin -> /Users/kylefurlong/.local/share/ponyup/ponyc-release-0.53.0-arm64-darwin/packages/builtin
Building /Users/kylefurlong -> /Users/kylefurlong
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
zsh: segmentation fault  ponyc ~
redvers commented 1 year ago

It's not policing code when what you originally provided (after edit) is this:

let c: T iso^ = TClass.create(l)

Which gives me:

[nix-shell:~/dd]$ ponyc
Building builtin -> /nix/store/nnvr2l04kdk62n633g74p0vdwf9bbrmy-ponyc-0.54.0/lib/pony/0.54.0/packages/builtin
Building . -> /home/red/dd
Error:
/home/red/dd/main.pony:19:47: can't find declaration of 'l'
                let c: T iso^ = TClass.create(l)

Wheres in your last comment which actually illustrates the bug you have:

let c: T iso^ = TClass.create("")

So no, your original report, even after your requested edit did not replicate the compiler error.

However, your last comment (in which you actually provided the information we explicitly asked for - thank you) - did provide a version I could replicate the issue with.

So how about we take a step back from the inflammatory language and start again?

kylefurlong commented 1 year ago

Ah, I see the mistake. I apologize for the unforgiving attitude and unkind words. I should have read your first response more carefully and then I could have corrected the original.

SeanTAllen commented 1 year ago

@redvers can you post the complete code for this bug?

SeanTAllen commented 1 year ago

@redvers ping. see above.

nisanharamati commented 8 months ago

I stumbled on this while searching for clues on a similar (but unfortunately not identical) error. Here's the repro code and backtrace:

trait T
  fun some() =>
    "Do nothing"

class TClass is T
  let _l: String
  new create(l: String) =>
     _l = consume l
  fun some() =>
      "Do nothing"

actor Act
  let _c: T iso
  new create(c: T iso) =>
    _c = consume c

actor Main
  new create(env: Env) =>
    let c: T iso^ = TClass.create("")
    let a: Act = Act.create(consume c)

Fails with

# ponyc
Building builtin -> /usr/local/lib/pony/0.58.1-fe3895eb/packages/builtin
Building . -> /root/proj/scratch/pony/21-segfault
/root/proj/ponyc/src/libponyc/ast/ast.c:577: ast_id: Assertion `ast != NULL` failed.

Backtrace:
  ponyc(ponyint_assert_fail+0x9c) [0x89e49c]
  ponyc(ast_id+0x3b) [0x794a5b]
  ponyc(cap_fetch+0x15) [0x82c845]
  ponyc(expr_assign+0x244) [0x885714]
  ponyc(pass_expr+0x143) [0x7f6b53]
  ponyc(ast_visit+0x2aa) [0x7f78aa]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc(ast_visit+0x1e6) [0x7f77e6]
  ponyc() [0x7f83e6]
  ponyc() [0x7f7d75]
  ponyc(ast_passes_program+0x22) [0x7f7982]
  ponyc(program_load+0xbf) [0x81acef]
  ponyc() [0x793cf9]
  ponyc(main+0x270) [0x793b90]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f9cfc771083]
  ponyc(_start+0x2e) [0x79385e]
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Aborted

Using version 0.58.1-fe3895eb from the most recent release tag, running on Ubuntu 20.04 on Intel.

jemc commented 8 months ago

A more minimal repro:

actor Main
  new create() => 
    let c: String iso^ = String
jemc commented 8 months ago

There's two things wrong with the minimal code:

So for either of these problems in isolation, the compiler will give you error messages correctly. It's only the combination of the two that gives the assertion failure encountered in this ticket.

jasoncarr0 commented 8 months ago

@jemc Just a note, let c: String iso = String is fine due to Gordon's work https://github.com/ponylang/ponyc/pull/4124 My guess is that change could be one of the components involved plus my last changes to iso^.