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

support pub(restricted) in thread_local! #40984

Closed
wants to merge 4 commits into from

Conversation

durka
Copy link
Contributor

@durka durka commented Apr 1, 2017

pub(restricted) was stabilized in #40556 so let's go!

Here is a playground.

I changed the interface of __thread_local_inner!, which is supposedly unstable but this is not checked for macros (#34097 cc @petrochenkov @jseyfried), so this may be an issue.

@rust-highfive
Copy link
Collaborator

r? @brson

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

// rule 4: handle multiple restricted public declarations
($(#[$attr:meta])* pub $vis:tt static $name:ident: $t:ty = $init:expr) => (
__thread_local_inner!($(#[$attr])* [pub $vis] $name, $t, $init);
thread_local!($($rest)*);
Copy link
Contributor Author

@durka durka Apr 1, 2017

Choose a reason for hiding this comment

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

Please note these six rules can be reduced to two if we revive the $x:vis RFC.

@durka durka force-pushed the thread-local-pub-restricted branch 5 times, most recently from 6622a28 to 20a8799 Compare April 1, 2017 15:42
@durka
Copy link
Contributor Author

durka commented Apr 1, 2017

Github ate my comment, so just to reiterate: this PR is real, but also meant to demonstrate why we need a :vis macro matcher.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Apr 11, 2017
@alexcrichton
Copy link
Member

Discussed at the libs triage meeting the other day, our conclusion was that we should probably wait for #41012 to get merged, which looks like it's going to get merged.

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 14, 2017
@carols10cents
Copy link
Member

Labeling waiting on review since rereview might be needed once #41012 is in.

@arielb1
Copy link
Contributor

arielb1 commented Apr 18, 2017

#41012 has landed. @alexcrichton can you look at this?

@durka
Copy link
Contributor Author

durka commented Apr 18, 2017 via email

@alexcrichton
Copy link
Member

Ok thanks @durka!

@alexcrichton alexcrichton added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2017
@durka
Copy link
Contributor Author

durka commented Apr 19, 2017

Actually we can't use :vis until #41012 hits beta, right?

@sfackler
Copy link
Member

Seems like you can do it before then with #[cfg(stage0)] and #[cfg(not(stage0))] versions of the macro, right?

@durka durka force-pushed the thread-local-pub-restricted branch from 20a8799 to 8fffee0 Compare April 21, 2017 04:30
@durka durka force-pushed the thread-local-pub-restricted branch from 8fffee0 to 62e69cd Compare April 21, 2017 05:30
@durka
Copy link
Contributor Author

durka commented Apr 21, 2017

Hmm, this is odd:

[00:17:04] Building stage1 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
... snip ...
[00:17:20]    Compiling syntax_pos v0.0.0 (file:///checkout/src/libsyntax_pos)
[00:17:20] error: :vis fragment specifier is experimental and subject to change (see issue #41022)
[00:17:20]  --> <thread_local macros>:2:29
[00:17:20]   |
[00:17:20] 2 | $ ( # [ $ attr : meta ] ) * $ vis : vis static $ name : ident : $ t : ty = $
[00:17:20]   |                             ^^^^^^^^^^^
[00:17:20]   |
[00:17:20]   = help: add #![feature(macro_vis_matcher)] to the crate attributes to enable
[00:17:20] 
[00:17:20] error: :vis fragment specifier is experimental and subject to change (see issue #41022)
[00:17:20]  --> <thread_local macros>:6:29
[00:17:20]   |
[00:17:20] 6 | $ ( # [ $ attr : meta ] ) * $ vis : vis static $ name : ident : $ t : ty = $
[00:17:20]   |                             ^^^^^^^^^^^
[00:17:20]   |
[00:17:20]   = help: add #![feature(macro_vis_matcher)] to the crate attributes to enable

But I did add that attribute. Does it have to be added to crates that invoke the macro as well? That would be a problem. And it should be fine because thread_local! and __thread_local_inner! are marked #[allow_internal_unstable]. Perhaps fragment specifiers are not covered by that?

@alexcrichton
Copy link
Member

As the author of #41012, you're probably in the best position to answer that question :)

@durka
Copy link
Contributor Author

durka commented Apr 21, 2017

Good call :)

Can a commit fixing that go in this PR or should I separate it?

@durka durka force-pushed the thread-local-pub-restricted branch 2 times, most recently from 068b960 to 6174d01 Compare April 22, 2017 02:46
@jseyfried
Copy link
Contributor

jseyfried commented Apr 24, 2017

I've reached out to @jseyfried to see if this is fixable or not

I believe this is fixable, but I'm not sure exactly how -- I'll look into it when I get the time (probably a week or two).

@durka
Copy link
Contributor Author

durka commented Apr 25, 2017

OK, I did come up with a way to make it shorter, by having the macro munch attributes one at a time until it gets to the visibility specifier:

macro_rules! thread_local {
    // terminate recursion
    (@ [] -> $_x:tt) => {};
    
    // munch one attribute
    (@ [#[$attr:meta] $($rest:tt)*] -> [$(#[$attrs:meta])*]) => {
        thread_local!(@ [$($rest)*] -> [$(#[$attrs])* #[$attr]]);
    };
    
    // finish a static with no trailing semicolon (therefore there are no more)
    (@ [$vis:vis static $name:ident: $typ:ty = $init:expr] -> [$(#[$attrs:meta])*]) => {
        __thread_local_inner!(($(#[$attrs])*) $vis, $name, $typ, $init);
    };
    
    // finish a static with trailing semicolon and continue to parse more
    (@ [$vis:vis static $name:ident: $typ:ty = $init:expr; $($rest:tt)*] -> [$(#[$attrs:meta])*]) => {
        __thread_local_inner!(($(#[$attrs])*) $vis, $name, $typ, $init);
        thread_local!(@ [$($rest)*] -> []);
    };
    
    // public entry point
    ($($t:tt)*) => {
        thread_local!(@ [$($t)*] -> []);
    }
}

This business with the @ "private" rules could be pulled into a separate macro as well (e.g. __thread_local_collector!). If only that trailing semicolon was required, we could remove one more rule, oh well.

@alexcrichton
Copy link
Member

Yeah if we do add a macro implementation like that we'd want it to be an internal macro hidden away, but it seems reasonableto have such an implementation.

@alexcrichton
Copy link
Member

@durka to clarify, did you intend on landing that instantiation in this PR? Or waiting for a fix to the macros from @jseyfried?

@durka
Copy link
Contributor Author

durka commented May 4, 2017 via email

@alexcrichton
Copy link
Member

I'd ideally prefer to wait for :vis bugs to get fixed (or at least see if they're not fixable) but I also don't have a burning need for this change just yet. If there's some strong motivation I could see us landing this sooner rather than later.

@carols10cents
Copy link
Member

I'd ideally prefer to wait for :vis bugs to get fixed (or at least see if they're not fixable)

Are there issues/PRs for the :vis bugs that are blocking this PR that we could link to for status tracking purposes?

@durka
Copy link
Contributor Author

durka commented May 8, 2017

I think it is just #26444 (closed WONTFIX) unfortunately. But I could be wrong.

@alexcrichton
Copy link
Member

This was to a large degree the motivation for #41012, right? If so, it seems a shame if it's actually still difficult to leverage :(

@Mark-Simulacrum
Copy link
Member

@durka Could you give an update here? Looks like Travis is still failing -- @jseyfried, did you have a chance to take a look?

@durka
Copy link
Contributor Author

durka commented May 14, 2017

Status quo.

@bors
Copy link
Contributor

bors commented May 16, 2017

☔ The latest upstream changes (presumably #42038) made this pull request unmergeable. Please resolve the merge conflicts.

@durka
Copy link
Contributor Author

durka commented May 17, 2017

I'm going to close this for now and post in the :vis tracking issue. I'll resubmit once we decide on an approach, or if someone complains about thread_local! specifically.

@durka durka closed this May 17, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Jul 7, 2017
bors added a commit that referenced this pull request Jul 11, 2017
…seyfried

Only match a fragment specifier the if it starts with certain tokens.

When trying to match a fragment specifier, we first predict whether the current token can be matched at all. If it cannot be matched, don't bother to push the Earley item to `bb_eis`. This can fix a lot of issues which otherwise requires full backtracking (#42838).

In this PR the prediction treatment is not done for `:item`, `:stmt` and `:tt`, but it could be expanded in the future.

Fixes #24189.
Fixes #26444.
Fixes #27832.
Fixes #34030.
Fixes #35650.
Fixes #39964.
Fixes the 4th comment in #40569.
Fixes the issue blocking #40984.
@durka
Copy link
Contributor Author

durka commented Jul 12, 2017

Rebased and reopened now that #42913 got merged.

@Mark-Simulacrum
Copy link
Member

Looks like you'll need to open a new pull request -- GH is being annoying and not letting this one be reopened.

@durka
Copy link
Contributor Author

durka commented Jul 12, 2017

Resubmitted as #43185.

bors added a commit that referenced this pull request Jul 15, 2017
support pub(restricted) in thread_local! (round 2)

Resurrected #40984 now that the issue blocking it was fixed. Original description:

`pub(restricted)` was stabilized in #40556 so let's go!

Here is a [playground](https://play.rust-lang.org/?gist=f55f32f164a6ed18c219fec8f8293b98&version=nightly&backtrace=1).

I changed the interface of `__thread_local_inner!`, which is supposedly unstable but this is not checked for macros (#34097 cc @petrochenkov @jseyfried), so this may be an issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

10 participants