Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Clarify when StorageLive is legal #39

Closed
RalfJung opened this issue Jun 6, 2017 · 5 comments
Closed

Clarify when StorageLive is legal #39

RalfJung opened this issue Jun 6, 2017 · 5 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 6, 2017

StorageLive compiles to llvm.lifetime.start. It is an open question whether it is allowed to call StorageLive on a local that has already been marked as live. Currently, rustc emits code that relies on this being okay.
To account for some optimizations that LLVM has been caught performing, at the very least, we have to declare that StorageLive resets the contents of a local back to Undef. It seems this is consistent with what rustc currently emits.

See rust-lang/rust#42371 for more details.

@strega-nil
Copy link

Is this an official part of Rust? It seems weird to define a memory model for a non-rust language.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 6, 2017

StorageLive/StorageDead are in MIR; so I'd say they are as official as it gets. If we want their translation to LLVM to be sound, we better make them have a semantics that rules out everything LLVM forbids (and maybe more).

@strega-nil
Copy link

@RalfJung I've never thought of MIR as an "official" part of Rust - just an implementation detail. See mrustc, which doesn't use the same MIR.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 6, 2017

Fair enough.

The road I am pursuing (and there's hopefully going to be a blog post with more details) is to develop a spec for MIR, and then specify Rust by translation to MIR. I feel that makes sense because MIR is a very nice "core" language without all the redundancy of surface Rust.

That doesn't mean all compilers have to use MIR; it just means that the behavior of Rust code is defined by means of what the corresponding MIR code does.

EDIT: I realized I actually laid out this strategy in https://www.ralfj.de/blog/2017/05/23/internship-starting.html, so I just extended that post a little to cover your objection about not all compilers using MIR.

@RalfJung
Copy link
Member Author

This issue moved to rust-lang/unsafe-code-guidelines#129.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants