Skip to content

[BEAM] &'static mut references to static variables and LLVM noalias #115

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
wants to merge 1 commit into from

Conversation

japaric
Copy link
Member

@japaric japaric commented Apr 14, 2019

Please read #111 first, if you haven't already.

Rendered discussion document

@comex
Copy link

comex commented Apr 15, 2019

noalias was originally used to implement C restrict and has roughly equivalent semantics. It basically means (slightly oversimplified): "as long as this pointer is in scope, I promise not to read or write the memory behind this pointer using anything but the pointer itself (or pointers derived from it)".

It's not UB to create a noalias pointer to a global variable. It's only UB if you refer to the original global variable a second time while the pointer is still in scope.

I think the example should also be fine under @RalfJung's proposed "stacked borrows" memory model for Rust, though he's the expert on that.

@RalfJung
Copy link
Member

RalfJung commented May 5, 2019

Meta-comment: in terms of process, "active_discussion" is for things in our current "area of discussion". The idea is to keep active discussion focused around one area or else we'll never get anywhere. What you posted as a PR here would, I think, make more sense as the body of an issue.

@RalfJung
Copy link
Member

RalfJung commented May 5, 2019

For your actual question, I concur with @comex: &'static mut T means "this is a unique pointer and no other pointer (not derived from this one) will be used to access said memory". It's a bit like Box<T> but without the heap/deallocation part. So, that seems to be exactly what you want.

noalias_pointer was derived from x in the implementation of BumpPointerAlloc, so that seems fine as well.

&mut *(alloc.alloc(Layout::from_size_align(4, 4)) as *mut u32)
};

loop {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an example for something that would not be okay here: even just reading from x or X will invalidate overlapping parts of noalias_pointer. So if the implementation of BumpPointerAlloc would do that, that would be a problem.

@RalfJung
Copy link
Member

Closing due to inactivity, see #169 for tracking.

@RalfJung RalfJung closed this Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants