Skip to content

memory issues with expect #7799

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

Open
Anton-4 opened this issue May 19, 2025 · 7 comments
Open

memory issues with expect #7799

Anton-4 opened this issue May 19, 2025 · 7 comments
Labels
intermediate issue Likely good for someone who has completed a few other issues

Comments

@Anton-4
Copy link
Collaborator

Anton-4 commented May 19, 2025

It's quite easy to hit a segmentation fault when using the expect keyword.

Example:

app [main!] {
    cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}

import cli.Stdout

main! = |_args|
    Stdout.line!("ignore me")

expect
    actual = 1.0
    expected = 2.0
    actual == expected

Output:

$ roc test repro.roc
Segmentation fault (core dumped)
@Anton-4
Copy link
Collaborator Author

Anton-4 commented May 19, 2025

This is happening because we're sharing memory between processes in a brittle way.
We used to do this the same way for the dbg keyword, we modernized that but did not yet perform similar changes for expect.
Relevant links for the changes to dbg:

The core team is mostly occupied with working on the new compiler (which will also fix this issue) but a motivated individual could probably land this fix in the old compiler.

@Anton-4
Copy link
Collaborator Author

Anton-4 commented May 19, 2025

@Anton-4 Anton-4 added the intermediate issue Likely good for someone who has completed a few other issues label May 19, 2025
@Anton-4
Copy link
Collaborator Author

Anton-4 commented May 19, 2025

@Anton-4
Copy link
Collaborator Author

Anton-4 commented May 19, 2025

Workaround for this issue; write your own inline test function like err_on_false here:

app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }

import pf.Stdout
import pf.Url
import pf.Arg exposing [Arg]

main! : List Arg => Result {} _
main! = |_args|
    Stdout.line!("Testing Url module functions...")?

    # Test Url.from_str and Url.to_str
    Stdout.line!("\nTesting Url.from_str and Url.to_str:")?
    url = Url.from_str("https://example.com")
    Stdout.line!("Created URL: ${Url.to_str(url)}")?
    err_on_false(Url.to_str(url) == "https://example.com")?

    Ok({})

err_on_false : Bool -> Result {} [StrErr Str]
err_on_false = |bool|
    if bool then
        Ok({})
    else
        Err(StrErr("Test failed"))

@Anton-4
Copy link
Collaborator Author

Anton-4 commented May 19, 2025

Would you be interested in taking a look at this @lukewilliamboswell? It may not be a lot of work, no promises though :p

@lukewilliamboswell
Copy link
Collaborator

@Anton-4 -- I'm not particularly motivated to look at this. I've spent a lot of time poking around in the shared memory stuff and it's a bit wild and difficult for me to debug anything.

I'm glad we had identified a workaround for now. If @kili-ilo needs help I could look into a more specific issue and try to help find another workaround.

@kili-ilo
Copy link
Collaborator

I'm not currently inconvenienced by this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intermediate issue Likely good for someone who has completed a few other issues
Projects
None yet
Development

No branches or pull requests

3 participants