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

Fix compiler crash #4505

Merged
merged 6 commits into from
Apr 16, 2024
Merged

Fix compiler crash #4505

merged 6 commits into from
Apr 16, 2024

Conversation

ArthurPV
Copy link
Contributor

@ArthurPV ArthurPV commented Apr 14, 2024

Fix #4477

Before this PR this code didn't work and cause segmentation fault as reported in issue #4477:

struct FFIBytes
    var ptr: Pointer[U8 val] = Pointer[U8].create()
    var length: USize = 0

    fun iso string(): String val =>
        recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end

actor Main
    new create(env: Env) =>
        env.out.print("nothing to see here")

Now, with the changes in this PR, here's what the compiler generates as an error:

Building builtin -> /home/slacturyx/Programming/Personal/Github/ponyc/packages/builtin
Building ./app -> /home/slacturyx/Programming/Personal/Github/ponyc/app
Error:
/home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:46: You can't consume an expression that isn't local. More specifically, you can only consume a local variable (a single lowercase identifier, with no dots) or a field of this (this followed by a dot and a single lowercase identifier).
        recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end
                                             ^
Error:
/home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:38: consuming a field is only allowed if it is reassigned in the same expression
        recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end
                                     ^
Error:
/home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:68: You can't consume an expression that isn't local. More specifically, you can only consume a local variable (a single lowercase identifier, with no dots) or a field of this (this followed by a dot and a single lowercase identifier).
        recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end
                                                                   ^
Error:
/home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:60: consuming a field is only allowed if it is reassigned in the same expression
        recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 14, 2024
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Apr 14, 2024
@ponylang-main
Copy link
Contributor

Hi @ArthurPV,

The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 4505.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

.release-notes/4505.md Outdated Show resolved Hide resolved
.release-notes/4505.md Outdated Show resolved Hide resolved
@SeanTAllen
Copy link
Member

I've updated the release notes.

@SeanTAllen SeanTAllen changed the title Fix: Segmentation fault when ponyc compiles this code Fix compiler crash Apr 16, 2024
@jemc
Copy link
Member

jemc commented Apr 16, 2024

Thanks for doing this!

@SeanTAllen updated the release notes, and we'll merge it after the CI checks have all passed.

@SeanTAllen
Copy link
Member

Thanks @ArthurPV. This will get merged once CI passes.

@SeanTAllen SeanTAllen merged commit 82c5cf3 into ponylang:main Apr 16, 2024
22 checks passed
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Apr 16, 2024
github-actions bot pushed a commit that referenced this pull request Apr 16, 2024
github-actions bot pushed a commit that referenced this pull request Apr 16, 2024
@SeanTAllen
Copy link
Member

@ArthurPV this will be released at the end of the month. The weekend of the 27th/28th. It will be in tonight's nightly as well.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge discuss during sync Should be discussed during an upcoming sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when ponyc compiles this code
4 participants