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

Segfault when trying to compile incorrect capabilities #4344

Open
kylefurlong opened this issue Apr 20, 2023 · 16 comments
Open

Segfault when trying to compile incorrect capabilities #4344

kylefurlong opened this issue Apr 20, 2023 · 16 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kylefurlong
Copy link

kylefurlong commented Apr 20, 2023

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.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 20, 2023
@SeanTAllen
Copy link
Member

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

@kylefurlong
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Contributor

redvers commented Apr 20, 2023

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
Copy link
Contributor

redvers commented Apr 20, 2023

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
Copy link
Contributor

redvers commented Apr 20, 2023

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

actor Main
    new create() =>  // Should be new create(env: Env) =>

@kylefurlong
Copy link
Author

kylefurlong commented Apr 20, 2023

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
Copy link
Contributor

redvers commented Apr 20, 2023

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
Copy link
Author

kylefurlong commented Apr 20, 2023

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
Copy link
Member

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

@SeanTAllen SeanTAllen added bug Something isn't working needs investigation This needs to be looked into before its "ready for work" labels Apr 25, 2023
@SeanTAllen
Copy link
Member

@redvers ping. see above.

@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label May 30, 2023
@nisanharamati
Copy link
Contributor

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.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 19, 2024
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Feb 20, 2024
@jemc
Copy link
Member

jemc commented Feb 20, 2024

A more minimal repro:

actor Main
  new create() => 
    let c: String iso^ = String

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 20, 2024
@jemc
Copy link
Member

jemc commented Feb 20, 2024

There's two things wrong with the minimal code:

  • 1️⃣ The String constructor returns ref, not iso - you'd need to wrap it in a recover to get an iso
  • 2️⃣ iso^ is not a valid ref cap for a local variable (which the compiler rightly tells if you if you fix the above issue by wrapping in a recover block)

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.

@SeanTAllen SeanTAllen added help wanted Extra attention is needed good first issue Good for newcomers and removed needs investigation This needs to be looked into before its "ready for work" discuss during sync Should be discussed during an upcoming sync labels Feb 20, 2024
@jasoncarr0
Copy link
Contributor

jasoncarr0 commented Feb 20, 2024

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

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 20, 2024
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants