Giter Club home page Giter Club logo

Comments (5)

oli-obk avatar oli-obk commented on July 20, 2024 2

Great analysis! I'll take this bug, drop code is my fault anyway ;)

from miri.

solson avatar solson commented on July 20, 2024

@oli-obk Weird... the closure body ought to explicitly drop the closure environment argument in MIR.

from miri.

solson avatar solson commented on July 20, 2024

I figured out the problem here.

move || { let _ = x; }; never by-value uses any of its captures, so it's a closure whose inherent signature is fn(&self). When we call it through FnOnce::call_once (in f(x)), it has to use a shim.

Our shim acts like the following function, where self is the closure type and body is the closure fn:

fn call_once_shim(self) {
    body(&self)
    // NOTE: self should be dropped at the end of scope, but Miri doesn't do it.
}

As you can see in the shim code I linked above, we do add this self to a vec of temporaries to be freed when the stack frame is freed, but we don't ever execute the drop glue for it. (It's freed here.)

from miri.

solson avatar solson commented on July 20, 2024

Note that if you force the closure to by-value use a separate value to remove Miri's use of the shim, then the closure's drop glue is properly called, as in this test I added.

EDIT: Actually I think in that case the closure body itself will drop x, since it's a fn(self) signature closure, responsible for freeing the by-value self argument which contains the capture x.

EDIT 2: ...which I guess means the closure body executes the closure's drop glue, so I wasn't wrong, just imprecise. :P

from miri.

solson avatar solson commented on July 20, 2024

It would also be fixed once @arielb1's rewrite of these shims into explicit MIR bodies is done in rustc, but I'm not sure about the timeline on that. If it's hard to fix in Miri we can wait, otherwise it's fine to do it now.

EDIT: relevant rustc PR is here.

from miri.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.