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]: @parameter bound objects are incorrectly discarded #1404

Open
p88h opened this issue Dec 5, 2023 · 0 comments
Open

[BUG]: @parameter bound objects are incorrectly discarded #1404

p88h opened this issue Dec 5, 2023 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@p88h
Copy link

p88h commented Dec 5, 2023

Bug description

I suspect this may be a deeper issue. but the easy way to manifest that something is amiss is to create a 'memory-only' object, and then have a @parameter-bound callable use that. If the object is not referenced anywhere after the function call, you may 'get lucky' and Mojo decides to 'clean up' the object prior to actual use.
A smallest repro case is included below:

fn main():
    let simpler = String("I want you to hold this")

    @parameter
    fn doit():
        for i in range(len(simpler)-5):
            print(simpler[i:i+5])   

    doit()
    # If uncommented, this will actually work correctly
    #print(len(simpler))

Steps to reproduce

  • Anytime when you declare a non-trivial object and use it in @parameter bound function, the memory may be gone
  • This works with anything ranging from Strings to custom-allocated structs, through Pointers
  • Seems to be broken even if Pointer is purposefully not deallocated (does Mojo clean up unused Pointers? hard to say)

System information

- What OS did you do install Mojo on ?
Win 11 / WSL2 / Ubuntu 23.04
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 0.6.0 (d55c0025)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.2.2 (95d42445)
@p88h p88h added bug Something isn't working mojo Issues that are related to mojo labels Dec 5, 2023
@ematejska ematejska added the mojo-lang Tag for all issues related to language. label Dec 6, 2023
@linear linear bot removed mojo Issues that are related to mojo mojo-lang Tag for all issues related to language. labels Apr 29, 2024
@ematejska ematejska added the mojo-repo Tag all issues with this label label Apr 29, 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 mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants