Skip to content

"let _ = foo();" is differently effectful from just "foo();" #2735

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

Closed
bblum opened this issue Jun 28, 2012 · 4 comments
Closed

"let _ = foo();" is differently effectful from just "foo();" #2735

bblum opened this issue Jun 28, 2012 · 4 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Milestone

Comments

@bblum
Copy link
Contributor

bblum commented Jun 28, 2012

See #2734. In that sample code, which segfaults, removing the characters "let _ =" causes it to no longer segfault. No idea why; maybe it causes it to optimise away the destructor call?

@ghost ghost assigned catamorphism Jul 5, 2012
@catamorphism
Copy link
Contributor

I'll see if this is still a bug now.

@bblum bblum reopened this Aug 2, 2012
@bblum
Copy link
Contributor Author

bblum commented Aug 2, 2012

This is still in the air. The following code prints "First" then "Second", but without the let _ =, it prints "Second" then "First".

class defer {
    f: fn@();
    new(f: fn@()) {
        self.f = f;
    }   
    drop { self.f(); }
}

fn main() {
    let _ = do defer {
        #error["Second"];
    };  
    #error["First"];
}

I'm not sure if the answer is "Well, too bad, there are no guarantees on when destructors get run", but I want to add this defer thing to libcore, and can't in good conscience as long as its behaviour is unpredictable.

@catamorphism
Copy link
Contributor

I have a fix for this, which I'm testing. However, for reference, what you want to do to get the behavior that bblum actually wanted was to write:

let _x = do ...

which means the destructor for the RHS won't run until the end of the enclosing scope, since _x is a perfectly cromulent identifier.

@catamorphism
Copy link
Contributor

My opinion is that let _ = e; should behave just like e; Feel free to argue about it, but for now I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

No branches or pull requests

2 participants