Stream: t-compiler/help

Topic: Missing (?) StorageLive/Dead statements?

Edd Barrett (Aug 03 2020 at 10:44, on Zulip):


I'd always assumed that the compiler would insert StorageLive/StorageDead statements into MIR when a variable comes in and out of "scope".

In this example however, the result of the calls to checked_add are never marked live or dead.

I was wondering why that is?

(Why am I asking? In our Rust JIT, we were hoping to use StorageLive/Dead as hints to the register allocator).



Jonas Schievink (Aug 03 2020 at 10:46, on Zulip):

temporaries might not get them

bjorn3 (Aug 03 2020 at 10:54, on Zulip):

Also on the cleanup path no variables get Storage{Live,Dead}.

oli (Aug 03 2020 at 10:55, on Zulip):

we're considering scrapping these annotations entirely and computing them on the fly for each statement

Edd Barrett (Aug 03 2020 at 11:03, on Zulip):

Thanks for your replies!

It's looking less likely that we can rely on StorageLive/StorageDead for our (niche) purposes.

I've just had a prod around in the compiler. It's not clear to me how a temporary is different from short-lived local. Is there a definition somewhere?

oli (Aug 03 2020 at 11:17, on Zulip):

you can rely on them, but if they aren't there, you need to assume the thing lives for the entire function

oli (Aug 03 2020 at 11:18, on Zulip):

this is how miri does it

oli (Aug 03 2020 at 11:19, on Zulip):

Edd Barrett (Aug 03 2020 at 11:19, on Zulip):

I see. Thanks.

And when does the compiler use these temporaries?

oli (Aug 03 2020 at 14:56, on Zulip):

I don't understand the question. Are you asking when the code being compiled uses these temporaries? That would be "anywhere within the function, we don't know unless we check the body"

Edd Barrett (Aug 03 2020 at 15:07, on Zulip):

In other wording: when does the compiler opt to use a temporary variable instead of a regular local variable? It's not clear to me the difference between a temporary variable and a normal one.


Jonas Schievink (Aug 03 2020 at 15:14, on Zulip):

There is not really a difference on the MIR level. It just uses a "internal" variables that aren't present in surface Rust to implement checked arithmetic and drop flags, and those don't get storage statements (maybe there's a few other cases?).

oli (Aug 03 2020 at 15:51, on Zulip):

bodies of constants and statics also don't use StorageDead and StorageLive

Jonas Schievink (Aug 03 2020 at 15:52, on Zulip):

I'm pretty sure they do? I saw a comment in rustc claiming they didn't, but --emit=mir says otherwise.

Edd Barrett (Aug 03 2020 at 15:54, on Zulip):

variables that aren't present in surface Rust

^ Ah ha! That's the detail I was missing. Thanks!

oli (Aug 03 2020 at 16:51, on Zulip):

ah, then it's probably just all the temporary variables that go into the return value of a constant or static that don't have storage statements, but there it makes a lot of sense, because these values are leaked to static memory

Last update: Sep 27 2020 at 13:00UTC