Skip to content
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

upgrade thread_local! invocation syntax #34077

Merged
merged 1 commit into from
Jun 24, 2016
Merged

Conversation

durka
Copy link
Contributor

@durka durka commented Jun 4, 2016

Allows declaring multiple statics in one macro invocation, and supports attaching attributes to the generated items. In particular, #![forbid(missing_docs, unused)] is now tenable on a crate/module containing thread locals.

For an example see here. This change is fully backwards compatible as far as I can tell.

cc @frankmcsherry

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -106,12 +106,20 @@ pub struct LocalKey<T: 'static> {
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this attribute must be redundant since I was able to simply copy the macro into a playpen, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, it shouldn't be redundant because __thread_local_inner! is marked unstable, but something is failing to check that!

@durka
Copy link
Contributor Author

durka commented Jun 5, 2016

BTW, RFC 1422 pub(restricted) support can be added: https://is.gd/LnAsPq

However, as long as RFC 1575 languishes, it requires the ugly reparse trick.

@alexcrichton
Copy link
Member

It might be good to do a crater run just to be super sure this doesn't break anything, but otherwise this is a change in the API of the macro so I'm gonna tag with T-libs to ensure it receives discussion. There is some previous discussion about allowing attributes on thread locals but it ended up largely being inconclusive (and didn't happen despite the name of the PR and the merging of the PR).

@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 5, 2016
@alexcrichton
Copy link
Member

Oh and also, can you be sure to add tests which exercise this syntax as well?

@durka
Copy link
Contributor Author

durka commented Jun 5, 2016

I'll add tests and comments in the morning.

I just read that previous discussion and it seems to me to support this
change -- with thread_local not being able to take attributes it's still
incompatible with forbidden lints, because the thread locals can't be
documented.

The change to allow semicolons and multiple declarations is just sugar, but
it matches the API of similar macros like lazy_static, plus once you have a
doc comment + newline + declaration it looks super weird (IMO) to leave out
the semicolon.
On Jun 5, 2016 01:42, "Alex Crichton" notifications@github.com wrote:

Oh and also, can you be sure to add tests which exercise this syntax as
well?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAC3n_S3BedrZ9pWTLCQ2sSj5ryuMKgpks5qImHPgaJpZM4IuMuB
.

@durka
Copy link
Contributor Author

durka commented Jun 6, 2016

I think this is ready for cratering cc @brson

@brson
Copy link
Contributor

brson commented Jun 7, 2016

I'll start a crater run.

@brson
Copy link
Contributor

brson commented Jun 7, 2016

Here are the toolchain builds:

When these are done I can run the crate builds.

@brson
Copy link
Contributor

brson commented Jun 8, 2016

I've started the crate builds.

@brson
Copy link
Contributor

brson commented Jun 10, 2016

@durka
Copy link
Contributor Author

durka commented Jun 10, 2016

No regressions!

@aturon
Copy link
Member

aturon commented Jun 10, 2016

cc @rust-lang/libs Any concerns about this change? Passes crater with no regressions.

@sfackler
Copy link
Member

👍

);

// rule 2: handle a single private declaration
($(#[$attr:meta])* static $name:ident: $t:ty = $init:expr $(;)*) => (
Copy link
Member

Choose a reason for hiding this comment

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

This'll unfortunately accept syntax like:

thread_local!(static FOO: usize = 2 ;;;;;;;;;;;;;;;;;;;;;);

Although I'm not sure how much we can do about that.

@alexcrichton
Copy link
Member

I'd prefer to not accept the syntax I mentioned above, but I don't feel particularly strongly about that and would be fine landing.

@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 11, 2016
@brson
Copy link
Contributor

brson commented Jun 11, 2016

I don't have strong opinions about this.

@durka
Copy link
Contributor Author

durka commented Jun 11, 2016

@alexcrichton so add a one-or-none macro matcher :)
On Jun 10, 2016 9:08 PM, "Brian Anderson" notifications@github.com wrote:

I don't have strong opinions about this.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAC3n290RR7HfYktlzGx73tBo2WGnlksks5qKgqXgaJpZM4IuMuB
.

@durka
Copy link
Contributor Author

durka commented Jun 11, 2016

@alexcrichton fixed, at the expense of accepting thread_local!() (can be removed as well, but requires more code duplication)

@alexcrichton
Copy link
Member

Ok, thanks @durka! This does mean that thread_local!(); is valid, but that seems fine to me.

@alexcrichton alexcrichton removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 21, 2016
@alexcrichton
Copy link
Member

The libs team discussed this during triage today and the conclusion was to merge. Thanks again for the PR and the patience @durka! If you want to squash the commits I'll r+

@durka
Copy link
Contributor Author

durka commented Jun 22, 2016

🏁

@alexcrichton
Copy link
Member

Looks like the travis error is probably legit:

failures:

---- thread_local!_0 stdout ----
    <std macros>:13:1: 13:13 error: macro expansion ignores token `thread_local` and any following
<std macros>:13 thread_local ! ( $ ( $ rest ) * ) ; ) ; (
                ^~~~~~~~~~~~
<anon>:5:1: 10:2 note: caused by the macro expansion here; the usage of `thread_local!` is likely invalid in expression context
<anon>:5 thread_local! {
         ^
<std macros>:16:22: 16:25 error: expected expression, found keyword `pub`
<std macros>:16 $ ( # [ $ attr ] ) * pub static $ name : $ crate :: thread :: LocalKey < $ t >
                                     ^~~
thread 'thread_local!_0' panicked at 'Box<Any>', src/libsyntax/ext/tt/macro_rules.rs:71
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'thread_local!_0' panicked at 'couldn't compile the test', src/librustdoc/test.rs:287


failures:
    thread_local!_0

@durka
Copy link
Contributor Author

durka commented Jun 22, 2016

That's what I get for not testing my doc example! Though I did test it in
the playground. Not sure how it's getting evaluated in expression context
here...
On Jun 22, 2016 16:18, "Alex Crichton" notifications@github.com wrote:

Looks like the travis error is probably legit:

failures:

---- thread_local!_0 stdout ----
:13:1: 13:13 error: macro expansion ignores token thread_local and any following
:13 thread_local ! ( $ ( $ rest ) * ) ; ) ; (
^~~~~~~~~~~~
:5:1: 10:2 note: caused by the macro expansion here; the usage of thread_local! is likely invalid in expression context
:5 thread_local! {
^
:16:22: 16:25 error: expected expression, found keyword pub
:16 $ ( # [ $ attr ] ) * pub static $ name : $ crate :: thread :: LocalKey < $ t >
^~~
thread 'thread_local!_0' panicked at 'Box', src/libsyntax/ext/tt/macro_rules.rs:71
note: Run with RUST_BACKTRACE=1 for a backtrace.
thread 'thread_local!_0' panicked at 'couldn't compile the test', src/librustdoc/test.rs:287

failures:
thread_local!_0


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAC3n5_ojM93OI_lWNC-ReptgQVCi0_Cks5qOZitgaJpZM4IuMuB
.

Allows declaring multiple statics in one macro invocation, and supports attaching attributes to the generated items.
@durka
Copy link
Contributor Author

durka commented Jun 23, 2016

@alexcrichton OK, I think it's a bug and I filed #34418. Travis should pass now (if it fails again I'll relent and run the build locally).

@alexcrichton
Copy link
Member

@bors: r+ fc28ee2

@bors
Copy link
Contributor

bors commented Jun 23, 2016

⌛ Testing commit fc28ee2 with merge aeebcfd...

@bors
Copy link
Contributor

bors commented Jun 23, 2016

💔 Test failed - auto-mac-64-opt

@durka
Copy link
Contributor Author

durka commented Jun 23, 2016

Spurious failure, LLVM didn't build
On Jun 23, 2016 18:49, "bors" notifications@github.com wrote:

💔 Test failed - auto-mac-64-opt
http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/9564


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAC3n-CTE8CSahht9fj-2cr2MlxptiJKks5qOw10gaJpZM4IuMuB
.

@alexcrichton
Copy link
Member

@bors: retry

On Thu, Jun 23, 2016 at 4:19 PM, Alex Burka notifications@github.com
wrote:

Spurious failure, LLVM didn't build
On Jun 23, 2016 18:49, "bors" notifications@github.com wrote:

💔 Test failed - auto-mac-64-opt
http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/9564


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#34077 (comment),
or mute
the thread
<
https://github.com/notifications/unsubscribe/AAC3n-CTE8CSahht9fj-2cr2MlxptiJKks5qOw10gaJpZM4IuMuB

.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAD95JDiDvMYgepuAudiLs3OyPeVeuS8ks5qOxSHgaJpZM4IuMuB
.

@bors
Copy link
Contributor

bors commented Jun 23, 2016

⌛ Testing commit fc28ee2 with merge c7e8ee9...

@bors
Copy link
Contributor

bors commented Jun 23, 2016

💔 Test failed - auto-mac-cross-ios-opt

@alexcrichton
Copy link
Member

@bors: retry

On Thu, Jun 23, 2016 at 4:54 PM, bors notifications@github.com wrote:

💔 Test failed - auto-mac-cross-ios-opt
http://buildbot.rust-lang.org/builders/auto-mac-cross-ios-opt/builds/714


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34077 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAD95HLcwxtRlTLEYxtJCNvTFCSkCL0fks5qOxy1gaJpZM4IuMuB
.

@bors
Copy link
Contributor

bors commented Jun 24, 2016

⌛ Testing commit fc28ee2 with merge 4d9faf3...

bors added a commit that referenced this pull request Jun 24, 2016
upgrade thread_local! invocation syntax

Allows declaring multiple statics in one macro invocation, and supports attaching attributes to the generated items. In particular, `#![forbid(missing_docs, unused)]` is now tenable on a crate/module containing thread locals.

For an example see [here](https://is.gd/aVFZZF). This change is fully backwards compatible as far as I can tell.

cc @frankmcsherry
@bors bors merged commit fc28ee2 into rust-lang:master Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants