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

resolve: Future proof resolutions for potentially built-in attributes #53913

Merged
merged 4 commits into from
Sep 12, 2018

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Sep 3, 2018

This is not full "pass all attributes through name resolution", but a more conservative solution.
If built-in attribute is ambiguous with any other macro in scope, then an error is reported.

What complications arise with the full solution - #53913 (comment).

cc #50911 (comment)
cc #52269
Closes #53531

@rust-highfive
Copy link
Collaborator

r? @estebank

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2018
@petrochenkov
Copy link
Contributor Author

r? @alexcrichton

This needs a check-only crater run before proceeding.
@bors try

@bors
Copy link
Contributor

bors commented Sep 3, 2018

⌛ Trying commit bc49117 with merge ad43424...

bors added a commit that referenced this pull request Sep 3, 2018
resolve: Future proof resolutions for potentially built-in attributes

Based on #53778

This is not full "pass all attributes through name resolution", but a more conservative solution.
If built-in attribute is ambiguous with any other macro in scope, then an error is reported.
TODO: Explain what complications arise with the full solution.
@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:20:41]    Compiling libc v0.0.0 (file:///checkout/src/rustc/libc_shim)
[00:20:41]    Compiling alloc v0.0.0 (file:///checkout/src/liballoc)
[00:20:42]    Compiling alloc_system v0.0.0 (file:///checkout/src/liballoc_system)
[00:20:42]    Compiling panic_abort v0.0.0 (file:///checkout/src/libpanic_abort)
[00:20:49] error[E0659]: `thread_local` is ambiguous
[00:20:49]      |
[00:20:49] 179  |                   #[thread_local]
[00:20:49]      |                     ^^^^^^^^^^^^
[00:20:49]      | 
[00:20:49]      | 
[00:20:49]     ::: libstd/collections/hash/map.rs:2609:9
[00:20:49]      |
[00:20:49] 2609 | /         thread_local!(static KEYS: Cell<(u64, u64)> = {
[00:20:49] 2610 | |             Cell::new(sys::hashmap_random_keys())
[00:20:49] 2611 | |         });
[00:20:49]      |
[00:20:49]      |
[00:20:49] note: `thread_local` could refer to the name defined here
[00:20:49]      |
[00:20:49]      |
[00:20:49] 142  | / macro_rules! thread_38;5;12m| }
[00:20:49]     | |_- in this macro invocation
[00:20:49]     |
[00:20:49] note: `thread_local` could refer to the name defined here
[00:20:49]     |
[00:20:49] 142 | / macro_rules! thread_local {
[00:20:49] 143 | |     // empty (base case for the recursion)
[00:20:49] 144 | |     () => {};
[00:20:49] 144 | |     () => {};
[00:20:49] 145 | |
[00:20:49] ...   |
[00:20:49] 155 | |     );
[00:20:49] 156 | | }
[00:20:49]     | |_^
[00:20:49] note: `thread_local` could also refer to the name defined here
[00:20:49]     |
[00:20:49] 179 |                   #[thread_local]
[00:20:49]     |                     ^^^^^^^^^^^^
[00:20:49]     | 
[00:20:49]     | 
[00:20:49]    ::: libstd/io/stdio.rs:23:1
[00:20:49]     |
[00:20:49] 23  | / thread_local! {
[00:20:49] 24  | |     static LOCAL_STDOUT: RefCell<Option<Box<dyn Write + Send>>> = {
[00:20:49] 25  | |         RefCell::new(None)
[00:20:49] 27  | | }
[00:20:49]     | |_- in this macro invocation
[00:20:49] 
[00:20:49] 
[00:20:49] error[E0659]: `thread_local` is ambiguous
[00:20:49]     |
[00:20:49] 179 |                   #[thread_local]
[00:20:49]     |                     ^^^^^^^^^^^^
[00:20:49]     | 
[00:20:49]     | 
[00:20:49]    ::: libstd/future.rs:53:1
[00:20:49]     |
[00:20:49] 53  | / thread_local! {
[00:20:49] 54  | |     static TLS_CX: Cell<Option<NonNull<task::Context<'static>>>> = Cell::new(None);
[00:20:49]     | |_- in this macro invocation
[00:20:49]     |
[00:20:49]     |
[00:20:49] note: `thread_local` could refer to the name defined here
[00:20:49]     |
[00:20:49] 142 | / macro_rules! thread_local {
[00:20:49] 143 | |     // empty (base case for the recursion)
[00:20:49] 144 | |     () => {};
---
[00:20:49]     |                     ^^^^^^^^^^^^
[00:20:49]     | 
[00:20:49]    ::: libstd/panicking.rs:38:1
[00:20:49]     |
[00:20:49] 38  | / thread_local! {
[00:20:49] 39  | |     pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
[00:20:49] 40  | |         RefCell::new(None)
[00:20:49] 42  | | }
[00:20:49]     | |_- in this macro invocation
[00:20:49]     |
[00:20:49]     |
[00:20:49] note: `thread_local` could refer to the name defined here
[00:20:49]     |
[00:20:49] 142 | / macro_rules! thread_local {
[00:20:49] 143 | |     // empty (base case for the recursion)
[00:20:49] 144 | |     () => {};
[00:20:49] 144 | |     () => {};
[00:20:49] 145 | |
[00:20:49] ...   |
[00:20:49] 155 | |     );
[00:20:49] 156 | | }
[00:20:49]     | |_^
[00:20:49] note: `thread_local` could also refer to the name defined here
[00:20:49]     |
[00:20:49] 179 |                   #[thread_local]
[00:20:49]     |                     ^^^^^^^^^^^^
[00:20:49]     | 
[00:20:49]     | 
[00:20:49]    ::: libstd/panicking.rs:38:1
[00:20:49]     |
[00:20:49] 38  | / thread_local! {
[00:20:49] 39  | |     pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
[00:20:49] 40  | m|
[00:20:49] 142 | / macro_rules! thread_local {
[00:20:49] 143 | |     // empty (base case for the recursion)
[00:20:49] 144 | |     () => {};
[00:20:49] ...   |
[00:20:49] 155 | |     );
[00:20:49] 156 | | }
[00:20:49]     | |_^
[00:20:49]     | |_^
[00:20:49] note: `thread_local` could also refer to the name defined here
[00:20:49]     |
[00:20:49] 179 |                 #[thread_local]
[00:20:49]     |                   ^^^^^^^^^^^^
[00:20:49]     | 
[00:20:49]     | 
[00:20:49]    ::: libstd/panicking.rs:238:5
[00:20:49]     |
[00:20:49] 238 |     thread_local! { static PANIC_COUNT: Cell<usize> = Cell::new(0) }
[00:20:49] 
[00:20:52] error: aborting due to 6 previous errors
[00:20:52] 
[00:20:52] For more information about this error, try `rustc --explain E0659`.
[00:20:52] For more information about this error, try `rustc --explain E0659`.
[00:20:52] error: Could not compile `std`.
[00:20:52] 
[00:20:52] Caused by:
[00:20:52]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name std libstd/lib.rs --color always --error-format json --crate-type dylib --crate-type rlib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 --cfg 'feature="alloc_jemalloc"' --cfg 'feature="backtrace"' --cfg 'feature="jemalloc"' --cfg 'feature="panic-unwind"' --cfg 'feature="panic_unwind"' -C metadata=d36e1a231adc37cd -C extra-filename=-d36e1a231adc37cd --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-c653c24a5aa8b822.rlib --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-c9c5677c39e3582f.rlib --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-03fd58e3ea6b5474.rlib --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/def68b0

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Sep 3, 2018

💔 Test failed - status-travis

@rust-highfive
Copy link
Collaborator

The job dist-x86_64-linux of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_fold:end:services

travis_fold:start:git.checkout
travis_time:start:00756921
$ git clone --depth=2 --branch=try https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:51:28]    Compiling alloc v0.0.0 (file:///checkout/src/liballoc)
[00:51:30]    Compiling alloc_system v0.0.0 (file:///checkout/src/liballoc_system)
[00:51:31]    Compiling panic_abort v0.0.0 (file:///checkout/src/libpanic_abort)
[00:51:35]    Compiling panic_unwind v0.0.0 (file:///checkout/src/libpanic_unwind)
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]      |
[00:51:40] 179  |                   #[thread_local]
[00:51:40]      |                     ^^^^^^^^^^^^
[00:51:40]      | 
[00:51:40]      | 
[00:51:40]     ::: libstd/collections/hash/map.rs:2609:9
[00:51:40]      |
[00:51:40] 2609 | /         thread_local!(static KEYS: Cell<(u64, u64)> = {
[00:51:40] 2610 | |             Cell::new(sys::hashmap_random_keys())
[00:51:40] 2611 | |         });
[00:51:40]      |
[00:51:40]      |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]      |
[00:51:40] 142  | / macro_rules! thread_local {
[00:51:40] 143  | |     // empty (base case for the recursion)
[00:51:40] 144  | |     () => {};
[00:51:40] 144  | |     () => {};
[00:51:40] 145  | |
[00:51:40] ...    |
[00:51:40] 155  | |     );
[00:51:40] 156  | | }
[00:51:40]      | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]      |
[00:51:40] 179  |                   #[thread_local]
[00:51:40]      |                     ^^^^^^^^^^^^
[00:51:40]      | 
[00:51:40]      | 
[00:51:40]     ::: libstd/collections/hash/map.rs:2609:9
[00:51:40]      |
[00:51:40] 2609 | /         thread_local!(static KEYS: Cell<(u64, u64)> = {
[00:51:40] 2610 | |             Cell::new(sys::hashmap_random_keys())
[00:51:40] 2611 | |         });
[00:51:40] 
[00:51:40] 
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/io/stdio.rs:23:1
[00:51:40]     |
[00:51:40] 23  | / thread_local! {
[00:51:40] 24  | |     static LOCAL_STDOUT: RefCell<Option<Box<dyn Write + Send>>> = {
[00:51:40] 25  | |         RefCell::new(None)
[00:51:40] 27  | | }
[00:51:40]     | |_- in this macro invocation
[00:51:40]     |
[00:51:40]     |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]     |
[00:51:40] 142 | / macro_rules! thread_local {
[00:51:40] 143 | |     // empty (base case for the recursion)
[00:51:40] 144 | |     () => {};
[00:51:40] 144 | |     () => {};
[00:51:40] 145 | |
[00:51:40] ...   |
[00:51:40] 155 | |     );
[00:51:40] 156 | | }
[00:51:40]     | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/io/stdio.rs:23:1
[00:51:40]     |
[00:51:40] 23  | / thread_local! {
[00:51:40] 24  | |     static LOCAL_STDOUT: RefCell<Option<Box<dyn Write + Send>>> = {
[00:51:40] 25  | |         RefCell::new(None)
[00:51:40] 27  | | }
[00:51:40]     | |_- in this macro invocation
[00:51:40] 
[00:51:40] 
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/future.rs:53:1
[00:51:40]     |
[00:51:40] 53  | / thread_local! {
[00:51:40] 54  | |     static TLS_CX: Cell<Option<NonNull<task::Context<'static>>>> = Cell::new(None);
[00:51:40]     | |_- in this macro invocation
[00:51:40]     |
[00:51:40]     |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]     |
[00:51:40] 142 | / macro_rules! thread_local {
[00:51:40] 143 | |     // empty (base case for the recursion)
[00:51:40] 144 | |     () => {};
[00:51:40] 144 | |     () => {};
[00:51:40] 145 | |
[00:51:40] ...   |
[00:51:40] 155 | |     );
[00:51:40] 156 | | }
[00:51:40]     | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/future.rs:53:1
[00:51:40]     |
[00:51:40] 53  | / thread_local! {
[00:51:40] 54  | |     static TLS_CX: Cell<Option<NonNull<task::Context<'static>>>> = Cell::new(None);
[00:51:40]     | |_- in this macro invocation
[00:51:40] 
[00:51:40] 
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]     |
[00:51:40] 179 |                 #[thread_local]
[00:51:40]     |                   ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/sys_common/thread_info.rs:22:1
[00:51:40]     |
[00:51:40] 22  | thread_local! { static THREAD_INFO: RefCell<Option<ThreadInfo>> = RefCell::new(None) }
[00:51:40]     | -------------------------------------------------------------------------------------- in this macro invocation
[00:51:40]     |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]     |
[00:51:40] 142 | / macro_rules! thread_local {
[00:51:40] 143 | |     // empty (base case for the recursion)
[00:51:40] 144 | |     () => {};
[00:51:40] 144 | |     () => {};
[00:51:40] 145 | |
[00:51:40] ...   |
[00:51:40] 155 | |     );
[00:51:40] 156 | | }
[00:51:40]     | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]     |
[00:51:40] 179 |                 #[thread_local]
[00:51:40]     |                   ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/sys_common/thread_info.rs:22:1
[00:51:40]     |
[00:51:40] 22  | thread_local! { static THREAD_INFO: RefCell<Option<ThreadInfo>> = RefCell::new(None) }
[00:51:40]     | -------------------------------------------------------------------------------------- in this macro invocation
[00:51:40] 
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/panicking.rs:38:1
[00:51:40]     |
[00:51:40] 38  | / thread_local! {
[00:51:40] 39  | |     pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
[00:51:40] 40  | |         RefCell::new(None)
[00:51:40] 42  | | }
[00:51:40]     | |_- in this macro invocation
[00:51:40]     |
[00:51:40]     |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]     |
[00:51:40] 142 | / macro_rules! thread_local {
[00:51:40] 143 | |     // empty (base case for the recursion)
[00:51:40] 144 | |     () => {};
[00:51:40] 144 | |     () => {};
[00:51:40] 145 | |
[00:51:40] ...   |
[00:51:40] 155 | |     );
[00:51:40] 156 | | }
[00:51:40]     | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]     |
[00:51:40] 179 |                   #[thread_local]
[00:51:40]     |                     ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/panicking.rs:38:1
[00:51:40]     |
[00:51:40] 38  | / thread_local! {
[00:51:40] 39  | |     pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
[00:51:40] 40  | |         RefCell::new(None)
[00:51:40] 42  | | }
[00:51:40]     | |_- in this macro invocation
[00:51:40] 
[00:51:40] 
[00:51:40] error[E0659]: `thread_local` is ambiguous
[00:51:40]     |
[00:51:40] 179 |                 #[thread_local]
[00:51:40]     |                   ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/panicking.rs:238:5
[00:51:40]     |
[00:51:40] 238 |     thread_local! { static PANIC_COUNT: Cell<usize> = Cell::new(0) }
[00:51:40]     |
[00:51:40]     |
[00:51:40] note: `thread_local` could refer to the name defined here
[00:51:40]     |
[00:51:40] 142 | / macro_rules! thread_local {
[00:51:40] 143 | |     // empty (base case for the recursion)
[00:51:40] 144 | |     () => {};
[00:51:40] 144 | |     () => {};
[00:51:40] 145 | |
[00:51:40] ...   |
[00:51:40] 155 | |     );
[00:51:40] 156 | | }
[00:51:40]     | |_^
[00:51:40] note: `thread_local` could also refer to the name defined here
[00:51:40]     |
[00:51:40] 179 |                 #[thread_local]
[00:51:40]     |                   ^^^^^^^^^^^^
[00:51:40]     | 
[00:51:40]     | 
[00:51:40]    ::: libstd/panicking.rs:238:5
[00:51:40]     |
[00:51:40] 238 |     thread_local! { static PANIC_COUNT: Cell<usize> = Cell::new(0) }
[00:51:40] 
[00:51:45] error: aborting due to 6 previous errors
[00:51:45] 
[00:51:45] For more information about this error, try `rustc --explain E0659`.
[00:51:45] For more information about this error, try `rustc --explain E0659`.
[00:51:45] error: Could not compile `std`.
[00:51:45] 
[00:51:45] Caused by:
[00:51:45]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name std libstd/lib.rs --color always --error-format json --crate-type dylib --crate-type rlib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 --cfg 'feature="alloc_jemalloc"' --cfg 'feature="backtrace"' --cfg 'feature="jemalloc"' --cfg 'feature="panic-unwind"' --cfg 'feature="panic_unwind"' --cfg 'feature="profiler"' --cfg 'feature="profiler_builtins"' -C metadata=d879867f50afc8df -C extra-filename=-d879867f50afc8df --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=clang -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-381ef4303a4b8d72.rlib --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-157ed363282e1456.rlib --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-75d7082732f6c6fc.rlib --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-0e27b5e72d396482.rlib --extern core=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-6b88aff5affc9853.rlib --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liblibc-f41d7104b4e208fd.rlib --extern panic_abort=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_abort-86caad002ed4f9b7.rlib --extern panic_unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-6f01c2159763e870.rlib --extern profiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libprofiler_builtins-90288e148285012a.rlib --extern rustc_asan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_asan-10443f513b1a041a.rlib --extern rustc_lsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_lsan-0a53eb9e15b2b139.rlib --extern rustc_msan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_msan-f9732fb739f53137.rlib --extern rustc_tsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_tsan-c3842baa2002649a.rlib --extern unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libunwind-7eda5676ba5b12b7.rlib -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/libbacktrace/ -l static=backtrace -l dl -l rt -l pthread -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/build/compiler_builtins-35d02304dcd871b8/out -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/jemalloc/lib -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/build/profiler_builtins-d0dc0cd9b3a831c7/out -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/linux -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/lsan/build/lib/linux -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/msan/build/lib/linux -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/tsan/build/lib/linux` (exit code: 1)
[00:51:45] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace profiler" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:51:45] expected success, got: exit code: 101
[00:51:45] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1155:9
[00:51:45] travis_fold:end:stage1-std

[00:51:45] travis_time:end:stage1-std:start=1535944530166167759,finish=1535944613136543403,duration=82970375644

---
travis_time:end:0ffd8956:start=1535944614373784555,finish=1535944614381228261,duration=7443706
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:026761d4
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:10d03180
travis_time:start:10d03180
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:1d4dae14
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors bors 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-crater Status: Waiting on a crater run to be completed. labels Sep 3, 2018
@petrochenkov
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 3, 2018

⌛ Trying commit ebb7a7b with merge 5fe695a...

bors added a commit that referenced this pull request Sep 3, 2018
resolve: Future proof resolutions for potentially built-in attributes

Based on #53778

This is not full "pass all attributes through name resolution", but a more conservative solution.
If built-in attribute is ambiguous with any other macro in scope, then an error is reported.
TODO: Explain what complications arise with the full solution.

cc #50911 (comment)
Closes #53531
@bors
Copy link
Contributor

bors commented Sep 3, 2018

☀️ Test successful - status-travis
State: approved= try=True

@petrochenkov
Copy link
Contributor Author

@craterbot run start=master#2687112ea6a8701cbf36e6dd4d77d64694cf93d8 end=try#5fe695a3844714c70e8f7731a553f7947987a68a mode=check-only

@craterbot
Copy link
Collaborator

👌 Experiment pr-53913 created and queued.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 3, 2018
@craterbot
Copy link
Collaborator

🚧 Experiment pr-53913 is now running on agent crater-2.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@petrochenkov
Copy link
Contributor Author

Why passing all attributes through name resolution / expansion is not so simple.

It's actually easy to pass all attributes through name resolution / expansion, it's much harder to fight the consequences.

If some attribute may be a macro and goes through the process of determining whether it's a macro or not, then... it's target becomes potentially macro-expanded (e.g. coming from an expansion).
In this example

#[inline]
fn f() {}

f is macro expanded and is not planted into its parent module until #[inline] is trivially expanded (added to the list of processed attributes and just left on the item).

For most items it doesn't pose any problems. Actually, most of structs/enums are already macro-expanded due to derives on them, however it poses a problem for attributes on macros (and also modules and imports).
Macro paths are resolved early when crate structure (modules, scopes) is still changing, so they have some shadowing restrictions on them for the resolution to be sound. Those shadowing restrictions make macro-expanded macros somewhat limited.

Now imagine if built-in attributes on macros start going through resolution/expansion.
#[macro_export] macro_rules! ... - macro-expanded, #[stable(...)] macro_rules! ... - macro-expanded, #[macro_use] mod m { macro_rules! ... } - macro-expanded!
Long story short - even libstd doesn't build due to ambiguities between two panics caused by restricted shadowing.

So, even if attributes on non-macros/modules/imports go through usual macro expansion, attributes on macros/modules/imports still need immediate built-in attribute resolution and, as a consequence, stricter ambiguity checking - exactly what this PR does.
So I just implemented this stricter ambiguity checking for all items as a first step.

Other uncovered issues with the full solution (I also didn't want to deal with all them in the limited time until beta):

@alexcrichton
Copy link
Member

This sounds like a solid approach to me and the tests look amazingly comprehensive, thanks so much for taking this on @petrochenkov! I think I'm a bit out of my depth reviewing the internals of this PR, but with a "green enough" crater run I'd be comfortable r+'ing

@craterbot
Copy link
Collaborator

🎉 Experiment pr-53913 is completed!
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Sep 5, 2018
@petrochenkov
Copy link
Contributor Author

@bors p=1
This needs to be merged before beta (which is in a few days), or backported, but #54069 needs to be landed first.

Invocation/expansion ID (aka `Mark`) is not really necessary for resolving a macro path.
What is really necessary is its parent module, parent expansion and parent legacy scope.
This is required for validation resolutions of built-in attributes, which don't get their own `Mark`s
@petrochenkov
Copy link
Contributor Author

@alexcrichton
I've updated this PR with a mini-version of #54069 that affects only the built-in attribute check and nothing else, so this is now unblocked.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. P-high High priority and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Sep 10, 2018
@alexcrichton
Copy link
Member

@bors: r+

@petrochenkov petrochenkov added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed P-high High priority S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 11, 2018
@petrochenkov
Copy link
Contributor Author

@bors are you here?
@bors r=alexcrichton

@bors
Copy link
Contributor

bors commented Sep 11, 2018

📌 Commit de153d6 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Sep 11, 2018

⌛ Testing commit de153d6 with merge 5806389...

bors added a commit that referenced this pull request Sep 11, 2018
resolve: Future proof resolutions for potentially built-in attributes

This is not full "pass all attributes through name resolution", but a more conservative solution.
If built-in attribute is ambiguous with any other macro in scope, then an error is reported.

What complications arise with the full solution - #53913 (comment).

cc #50911 (comment)
cc #52269
Closes #53531
@bors
Copy link
Contributor

bors commented Sep 12, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 5806389 to master...

@bors bors merged commit de153d6 into rust-lang:master Sep 12, 2018
bors added a commit that referenced this pull request Sep 14, 2018
resolve: Introduce two sub-namespaces in macro namespace

Two sub-namespaces are introduced in the macro namespace - one for bang macros and one for attribute-like macros (attributes, derives).

"Sub-namespace" means this is not a newly introduced full namespace, the single macro namespace is still in place.
I.e. you still can't define/import two macros with the same name in a single module, `use` imports still import only one name in macro namespace (from any sub-namespace) and not possibly two.

However, when we are searching for a name used in a `!` macro call context (`my_macro!()`) we skip attribute names in scope, and when we are searching for a name used in attribute context (`#[my_macro]`/`#[derive(my_macro)]`) we are skipping bang macro names in scope.
In other words, bang macros cannot shadow attribute macros and vice versa.

For a non-macro analogy, we could e.g. skip non-traits when searching for `MyTrait` in `impl MyTrait for Type { ... }`.
However we do not do it in non-macro namespaces because we don't have practical issues with e.g. non-traits shadowing traits with the same name, but with macros we do, especially after macro modularization.

For `#[test]` and `#[bench]` we have a hack in the compiler right now preventing their shadowing by `macro_rules! test` and similar things. This hack was introduced after making `#[test]`/`#[bench]` built-in macros instead of built-in attributes (#53410), something that needed to be done from the start since they are "active" attributes transforming their inputs.
Now they are passed through normal name resolution and can be shadowed, but that's a breaking change, so we have  a special hack basically applying this PR for `#[test]` and `#[bench]` only.

Soon all potentially built-in attributes will be passed through normal name resolution (#53913) and that uncovers even more cases where the strict "macro namespace is a single namespace" rule needs to be broken.
For example, with strict rules, built-in macro `cfg!(...)` would shadow built-in attribute `#[cfg]` (they are different things), standard library macro `thread_local!(...)` would shadow built-in attribute `#[thread_local]` - both of these cases are covered by special hacks in #53913 as well.
Crater run uncovered more cases of attributes being shadowed by user-defined macros (`warn`, `doc`, `main`, even `deprecated`), we cannot add exceptions in the compiler for all of them.

Regressions with user-defined attributes like #53583 and #53898 also appeared after enabling macro modularization.

People are also usually confused (#53205 (comment), #53583 (comment)) when they see conflicts between attributes and non-attribute macros for the first time.

So my proposed solution is to solve this issue by introducing two sub-namespaces and thus skipping resolutions of the wrong kind and preventing more error-causing cases of shadowing.

Fixes #53583
@petrochenkov petrochenkov deleted the biattr4 branch June 5, 2019 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants