-
Notifications
You must be signed in to change notification settings - Fork 13.3k
More typesafe task-local data + LLVM shouldn't fold constants #3273
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
Comments
My preferred approach is to add 16 bytes of the type hash to the type descriptor and use the type as the key. Or don't add it to the type descriptor and make it an intrinsic to save space. |
On second thought, using the address of a
|
You would probably want to make TypeKey noncopyable. |
That would work as well. I think the problem back when I wrote this was that we didn't have static enum/newtype initializers. Why does noncopyable matter? |
cc #6004 and #3273 This is a rewrite of TLS to get towards not requiring `@` when using task local storage. Most of the rewrite is straightforward, although there are two caveats: 1. Changing `local_set` to not require `@` is blocked on #7673 2. The code in `local_pop` is some of the most unsafe code I've written. A second set of eyes should definitely scrutinize it... The public-facing interface currently hasn't changed, although it will have to change because `local_data::get` cannot return `Option<T>`, nor can it return `Option<&T>` (the lifetime isn't known). This will have to be changed to be given a closure which yield `&T` (or as an Option). I didn't do this part of the api rewrite in this pull request as I figured that it could wait until when `@` is fully removed. This also doesn't deal with the issue of using something other than functions as keys, but I'm looking into using static slices (as mentioned in the issues).
Fixed by #7677 |
No it wasn't. Misunderstood the github UI... I think. |
Yeah this wasn't fixed just yet, but this is coming very soon... |
Currently, task-local data (TLS) is implemented by keying off the code pointer of a closure that takes the desired type as its argument. You use it like this:
This has three known flaws:
An alternative proposal would be to key off the address of a global constant. A couple issues to address:
const my_key: &[my_type] = [];
static
region.type local_data_key<T> = &static/[T];
const key1: &[my_type] = [], key2: &[my_type] = [];
in order to have two different TLS slots to store the same type, then they shouldn't "accidentally" end up with the same data address and overwrite each other.This last, 3rd point is really the major thing blocking this bug being easy. May require a special attribute to tell llvm not to put it in rodata.
I wrote more about this here: http://bubblingbeebles.livejournal.com/111016.html
The text was updated successfully, but these errors were encountered: