-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Check that nested statics in thread locals are duplicated per thread. #123362
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Check that we forbid nested statics in `thread_local` statics. | ||
|
||
#![feature(const_refs_to_cell)] | ||
#![feature(thread_local)] | ||
|
||
#[thread_local] | ||
static mut FOO: &u32 = { | ||
//~^ ERROR: does not support implicit nested statics | ||
// Prevent promotion (that would trigger on `&42` as an expression) | ||
let x = 42; | ||
&{ x } | ||
}; | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead | ||
--> $DIR/nested_thread_local.rs:7:1 | ||
| | ||
LL | static mut FOO: &u32 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to extract a more exact span from the allocation? Specifically, I'd like a label on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Miri extends the interpreter with more detailed tracking of where each allocation comes from, but so far the compile-time interpreter does not have that information. Maybe we should add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just wondering about that when I saw this error. We can see how perf is affected, but it would be really nice for many diagnostics There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... but in a separate PR, please. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lmao yes |
||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not also affect
thread_local!()
macro invokations? It should, since those just desugar to#[thread_local]
internally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but those always desugar to a
Key<StaticsType>
, which is always initialized withNone
internally, and then set toSome
by computing a value at runtime at thread start.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at the implementation of
thread_local_inner
inlibrary/std/src/sys/thread_local/fast_local.rs
, which initializes:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice
INIT_EXPR
, not$init_expr
. It is first stored in aconst
and then assigned here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 of course!