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

[BUG] Top-level code isn't enforcing ownership and mutability #15

Open
nmsmith opened this issue May 4, 2023 · 3 comments
Open

[BUG] Top-level code isn't enforcing ownership and mutability #15

nmsmith opened this issue May 4, 2023 · 3 comments
Labels
bug Something isn't working Initiative: REPL/Jupyter mojo Issues that are related to mojo mojo-repo Tag all issues with this label

Comments

@nmsmith
Copy link
Contributor

nmsmith commented May 4, 2023

Bug Description

The program below crashes with a double-free error.

Steps to Reproduce

Run the following program in a notebook:

from String import String

struct Foo:
    var x: String
    fn __init__(self&, owned x: String):
        self.x = x
    fn __moveinit__(self&, owned existing: Self):
        self.x = existing.x

fn bar(owned foo: Foo) -> Int:
    return 2

let foo = Foo("test")
print(bar(foo^))
print(bar(foo^))

Context

Click to expand 11:freezer:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 10:pids:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 9:hugetlb:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 8:net_cls,net_prio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 7:blkio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 6:cpu,cpuacct:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 5:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 4:devices:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 3:perf_event:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 2:memory:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod58ead308_6b5e_4f48_a483_33eff7b8c09b.slice/cri-containerd-bf25cf0ee968cddde56ce666988b8ec79651ef4adadc6ffc15ae99baf64d98d8.scope 0::/
@nmsmith nmsmith changed the title A struct can be moved twice, causing a double free(). A struct can be moved twice, causing a double free() May 4, 2023
@Mogball
Copy link

Mogball commented May 4, 2023

Thanks for the bug report! This seems specifically like a notebook environment bug, as it is occurring in top-level code (trying to do the same inside a function definition will cause a compilation error). @River707 I guess we need to track liveliness?

@Mogball Mogball added bug Something isn't working playground label to tag playground environment related issues. labels May 4, 2023
@lattner
Copy link
Collaborator

lattner commented May 4, 2023

Yep, this is workbook toplevel code specific, thanks for reporting it!

@lattner lattner changed the title A struct can be moved twice, causing a double free() [Notebook] Top-level code isn't enforcing ownership correctly, causing a double free May 4, 2023
@goldiegadde goldiegadde added mojo-external notebook Tag for issues related to Jupyter Notebooks or enviornment and removed playground label to tag playground environment related issues. labels May 6, 2023
@Mogball Mogball changed the title [Notebook] Top-level code isn't enforcing ownership correctly, causing a double free [BUG] Top-level code isn't enforcing ownership correctly, causing a double free May 10, 2023
@Mogball Mogball changed the title [BUG] Top-level code isn't enforcing ownership correctly, causing a double free [BUG] Top-level code isn't enforcing ownership and mutability May 11, 2023
@ematejska ematejska added mojo Issues that are related to mojo mojo-tooling Tag for all issues related to repl, lldb, lsp, vscode extension. labels Sep 7, 2023
@gabrieldemarmiesse
Copy link
Contributor

gabrieldemarmiesse commented Mar 3, 2024

Doing some triaging here, with Mojo 2024.1.0. I updated the example to reproduce the bug to the latest syntax:

struct Foo:
    var x: String
    fn __init__(inout self, owned x: String):
        self.x = x
    fn __moveinit__(inout self, owned existing: Self):
        self.x = existing.x

fn bar(owned foo: Foo) -> Int:
    return 2

var foo = Foo(String("test"))
print(bar(foo^))
print(bar(foo^))

We now get this output:

error: Expression [1]:12:14: cannot consume indirect references to values
print(bar(foo^))
             ^

error: Expression [1]:13:14: cannot consume indirect references to values
print(bar(foo^))
             ^

2
2

So we're getting errors in the output, but the notebook cell is still considered successful and the code is still executed. That's a different bug, but still a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Initiative: REPL/Jupyter mojo Issues that are related to mojo mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

6 participants