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

Add #[allow_internal_unstable] to track stability for macros better. #22899

Merged
merged 4 commits into from
Mar 6, 2015

Conversation

huonw
Copy link
Member

@huonw huonw commented Feb 28, 2015

Unstable items used in a macro expansion will now always trigger
stability warnings, unless the unstable items are directly inside a
macro marked with #[allow_internal_unstable]. IOW, the compiler warns
unless the span of the unstable item is a subspan of the definition of a
macro marked with that attribute.

E.g.

#[allow_internal_unstable]
macro_rules! foo {
    ($e: expr) => {{
        $e;
        unstable(); // no warning
        only_called_by_foo!();
    }}
}

macro_rules! only_called_by_foo {
    () => { unstable() } // warning
}

foo!(unstable()) // warning

The unstable inside foo is fine, due to the attribute. But the
unstable inside only_called_by_foo is not, since that macro doesn't
have the attribute, and the unstable passed into foo is also not
fine since it isn't contained in the macro itself (that is, even though
it is only used directly in the macro).

In the process this makes the stability tracking much more precise,
e.g. previously println!("{}", unstable()) got no warning, but now it
does. As such, this is a bug fix that may cause [breaking-change]s.

The attribute is definitely feature gated, since it explicitly allows
side-stepping the feature gating system.


This updates thread_local! macro to use the attribute, since it uses
unstable features internally (initialising a struct with unstable
fields).

@rust-highfive
Copy link
Collaborator

r? @kmcallister

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

@huonw
Copy link
Member Author

huonw commented Feb 28, 2015

r? @alexcrichton, @aturon

@alexcrichton this is the fix for the macro issues we were discussing on IRC a few days ago.

@aturon
Copy link
Member

aturon commented Feb 28, 2015

🏆

@alexcrichton
Copy link
Member

Nice! This looks pretty great to me. Can this de-stabilize all of the internal fields of the thread local structs as well? (now that they can explicitly be left as unstable)

@huonw
Copy link
Member Author

huonw commented Mar 1, 2015

Updated, destabilising essentially everything in thread_local other than the main macro and the Key type.

@alexcrichton
Copy link
Member

@bors: r+ 5ea24dd

@Manishearth
Copy link
Member

This is awesome :D

@bors
Copy link
Contributor

bors commented Mar 1, 2015

⌛ Testing commit 5ea24dd with merge 2196aa3...

@bors
Copy link
Contributor

bors commented Mar 1, 2015

💔 Test failed - auto-mac-32-opt

@Manishearth
Copy link
Member

run-pass/macro-attributes.rs needs a #![feature(custom_attribute)]

@huonw
Copy link
Member Author

huonw commented Mar 2, 2015

@bors r=alexcrichton 49ef

@bors
Copy link
Contributor

bors commented Mar 2, 2015

⌛ Testing commit 49ef199 with merge 29c07e2...

@bors
Copy link
Contributor

bors commented Mar 2, 2015

💔 Test failed - auto-mac-32-opt

@Manishearth
Copy link
Member


---- [run-pass] run-pass-fulldeps/plugin-args-1.rs stdout ----

error: auxiliary build of "/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs" failed to compile: 
status: exit code: 101
command: i686-apple-darwin/stage2/bin/rustc /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs -L i686-apple-darwin/test/run-pass-fulldeps --target=i686-apple-darwin --crate-type=dylib -L i686-apple-darwin/test/run-pass-fulldeps/plugin-args-1.stage2-i686-apple-darwinlibaux -C prefer-dynamic --out-dir i686-apple-darwin/test/run-pass-fulldeps/plugin-args-1.stage2-i686-apple-darwinlibaux --cfg rtopt --cfg debug -O -L i686-apple-darwin/rt
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49:9: 49:53 error: this function takes 3 parameters but 2 parameters were supplied [E0061]
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49         NormalTT(box Expander { args: args, }, None));
                                                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

------------------------------------------

thread '[run-pass] run-pass-fulldeps/plugin-args-1.rs' panicked at 'explicit panic', /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/compiletest/runtest.rs:1466


---- [run-pass] run-pass-fulldeps/plugin-args-2.rs stdout ----

error: auxiliary build of "/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs" failed to compile: 
status: exit code: 101
command: i686-apple-darwin/stage2/bin/rustc /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs -L i686-apple-darwin/test/run-pass-fulldeps --target=i686-apple-darwin --crate-type=dylib -L i686-apple-darwin/test/run-pass-fulldeps/plugin-args-2.stage2-i686-apple-darwinlibaux -C prefer-dynamic --out-dir i686-apple-darwin/test/run-pass-fulldeps/plugin-args-2.stage2-i686-apple-darwinlibaux --cfg rtopt --cfg debug -O -L i686-apple-darwin/rt
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49:9: 49:53 error: this function takes 3 parameters but 2 parameters were supplied [E0061]
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49         NormalTT(box Expander { args: args, }, None));
                                                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

------------------------------------------

thread '[run-pass] run-pass-fulldeps/plugin-args-2.rs' panicked at 'explicit panic', /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/compiletest/runtest.rs:1466


---- [run-pass] run-pass-fulldeps/plugin-args-3.rs stdout ----

error: auxiliary build of "/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs" failed to compile: 
status: exit code: 101
command: i686-apple-darwin/stage2/bin/rustc /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs -L i686-apple-darwin/test/run-pass-fulldeps --target=i686-apple-darwin --crate-type=dylib -L i686-apple-darwin/test/run-pass-fulldeps/plugin-args-3.stage2-i686-apple-darwinlibaux -C prefer-dynamic --out-dir i686-apple-darwin/test/run-pass-fulldeps/plugin-args-3.stage2-i686-apple-darwinlibaux --cfg rtopt --cfg debug -O -L i686-apple-darwin/rt
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49:9: 49:53 error: this function takes 3 parameters but 2 parameters were supplied [E0061]
/Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/auxiliary/plugin_args.rs:49         NormalTT(box Expander { args: args, }, None));
                                                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

------------------------------------------

thread '[run-pass] run-pass-fulldeps/plugin-args-3.rs' panicked at 'explicit panic', /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/compiletest/runtest.rs:1466



failures:
    [run-pass] run-pass-fulldeps/plugin-args-1.rs
    [run-pass] run-pass-fulldeps/plugin-args-2.rs
    [run-pass] run-pass-fulldeps/plugin-args-3.rs

@bors
Copy link
Contributor

bors commented Mar 3, 2015

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

@huonw
Copy link
Member Author

huonw commented Mar 4, 2015

Updated; I've modified the approach and several extra commits (the fixup! ... one are intended as a corrections to the earlier commit, preserved for to allow you to see what changed. I'll rebase and squash post review).

I've had to add another feature gating pass, because the post-expansion feature-gating pass ran before the second configuration pass, and so would miss custom attributes inserted by cfg_attr's inside macro expansion: huonw@e397c4a. (I'm sure this can be done in a more rigorous way, but, it seems sensible to run feature gating on exactly the AST we compile, which this extra pass does.)

@alexcrichton
Copy link
Member

This looks good to me, r=me.

Could you also knock out some #[stable] attributes in sys_common::thread_local as well as part of this PR? They're reexported through std::thread_local::__imp currently.

@theemathas
Copy link
Contributor

What about select! {}?

@huonw
Copy link
Member Author

huonw commented Mar 5, 2015

select! is unstable.

Unstable items used in a macro expansion will now always trigger
stability warnings, *unless* the unstable items are directly inside a
macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns
unless the span of the unstable item is a subspan of the definition of a
macro marked with that attribute.

E.g.

    #[allow_internal_unstable]
    macro_rules! foo {
        ($e: expr) => {{
            $e;
            unstable(); // no warning
            only_called_by_foo!();
        }}
    }

    macro_rules! only_called_by_foo {
        () => { unstable() } // warning
    }

    foo!(unstable()) // warning

The unstable inside `foo` is fine, due to the attribute. But the
`unstable` inside `only_called_by_foo` is not, since that macro doesn't
have the attribute, and the `unstable` passed into `foo` is also not
fine since it isn't contained in the macro itself (that is, even though
it is only used directly in the macro).

In the process this makes the stability tracking much more precise,
e.g. previously `println!("{}", unstable())` got no warning, but now it
does. As such, this is a bug fix that may cause [breaking-change]s.

The attribute is definitely feature gated, since it explicitly allows
side-stepping the feature gating system.
This destabilises all the implementation details of `thread_local!`,
since they do not *need* to be stable with the new attribute.
This ensures we catch everything; previously, an unknown attribute
inserted by #[cfg_attr(...)] in a macro expansion would not be detected.
@huonw
Copy link
Member Author

huonw commented Mar 5, 2015

@bors r=alexcrichton b5c6

@bors
Copy link
Contributor

bors commented Mar 5, 2015

⌛ Testing commit b5c6ab2 with merge ffb90ea...

@bors
Copy link
Contributor

bors commented Mar 5, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member

@bors: retry

1 similar comment
@alexcrichton
Copy link
Member

@bors: retry

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 6, 2015
 Unstable items used in a macro expansion will now always trigger
stability warnings, *unless* the unstable items are directly inside a
macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns
unless the span of the unstable item is a subspan of the definition of a
macro marked with that attribute.

E.g.

    #[allow_internal_unstable]
    macro_rules! foo {
        ($e: expr) => {{
            $e;
            unstable(); // no warning
            only_called_by_foo!();
        }}
    }

    macro_rules! only_called_by_foo {
        () => { unstable() } // warning
    }

    foo!(unstable()) // warning

The unstable inside `foo` is fine, due to the attribute. But the
`unstable` inside `only_called_by_foo` is not, since that macro doesn't
have the attribute, and the `unstable` passed into `foo` is also not
fine since it isn't contained in the macro itself (that is, even though
it is only used directly in the macro).

In the process this makes the stability tracking much more precise,
e.g. previously `println!(\"{}\", unstable())` got no warning, but now it
does. As such, this is a bug fix that may cause [breaking-change]s.

The attribute is definitely feature gated, since it explicitly allows
side-stepping the feature gating system.

---

This updates `thread_local!` macro to use the attribute, since it uses
unstable features internally (initialising a struct with unstable
fields).
@bors
Copy link
Contributor

bors commented Mar 6, 2015

⌛ Testing commit b5c6ab2 with merge 1fe8f22...

bors added a commit that referenced this pull request Mar 6, 2015
Unstable items used in a macro expansion will now always trigger
stability warnings, *unless* the unstable items are directly inside a
macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns
unless the span of the unstable item is a subspan of the definition of a
macro marked with that attribute.

E.g.

    #[allow_internal_unstable]
    macro_rules! foo {
        ($e: expr) => {{
            $e;
            unstable(); // no warning
            only_called_by_foo!();
        }}
    }

    macro_rules! only_called_by_foo {
        () => { unstable() } // warning
    }

    foo!(unstable()) // warning

The unstable inside `foo` is fine, due to the attribute. But the
`unstable` inside `only_called_by_foo` is not, since that macro doesn't
have the attribute, and the `unstable` passed into `foo` is also not
fine since it isn't contained in the macro itself (that is, even though
it is only used directly in the macro).

In the process this makes the stability tracking much more precise,
e.g. previously `println!("{}", unstable())` got no warning, but now it
does. As such, this is a bug fix that may cause [breaking-change]s.

The attribute is definitely feature gated, since it explicitly allows
side-stepping the feature gating system.

---

This updates `thread_local!` macro to use the attribute, since it uses
unstable features internally (initialising a struct with unstable
fields).
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.

8 participants