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 unstable cfg_if! macro to libcore #59443

Closed
wants to merge 12 commits into from

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Mar 26, 2019

This PR adds the cfg_if! macro to libcore and exposes it behind the cfg_if feature-gate.

Is this macro useful ? It has >140 reverse dependencies on crates.io.

Pros of exposing it from libcore: in libcore we can't use the crates.io version unless we stabilize the no_core feature, which is something we might not want to do. The macro is already there - in fact, it's there twice (once in internal_macros, once as part of core::arch) - so we might as well expose it once, so that everybody can just easily use it. Note that even though libstd can technically use cfg_if from crates.io, to minimize external dependencies, the macro is copy-pasted another 3-4 times (std_arch, std_detect, hashbrown, libstd-itself, ...).

Cons of exposing it from libcore: extra maintenance burden, if we were to stabilize no_core, libcore could just use a dependency from crates.io, the cost of copy-pasting it N times and maintaining the copies is less work than exposing it from libcore. Also, it might well be that some day we might want to solve this problem using language features (e.g. allowing people to programatically create their own cfgs, etc.). If that ever happens, we can just deprecate it.

r? @SimonSapin cc @rust-lang/libs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 26, 2019
///
/// # fn main() {}
/// ```
#[macro_export(local_inner_macros)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Use $crate:: instead?

@SimonSapin
Copy link
Contributor

Thanks @gnzlbg! I’m in favor of this PR, and there’s precedent for accepting unstable APIs without an RFC. However this adds a new macro to the libcore prelude, so it deserves special attention from @rust-lang/libs. In any case, we’ll at least do a FCP before stabilizing.

Given there there is no concrete proposal so far for stabilizing no_core and that IMO it would only have very limited usefulness (cfg-if is the only crate I can think of), I don’t think it’s worth making hypothetical scenarios based on this.

Cons of exposing it from libcore: extra maintenance burden

On the contrary I think we can reduce maintenance burden by having fewer copies of the macro. Could you add commits to this PR to remove the ones in src/libstd/macros.rs, src/libpanic_unwind/macros.rs, and src/libunwind/macros.rs? Maybe also changing the librustc_data_structures and libsyntax_pos crates to use it from libcore rather than crates.io (on cfg(not(stage0))).

It’d also be nice to either add a new test or point to an existing test to show that when an unstable macro is in the prelude, it can be shadowed by a stable macro with the same name from another crate without the crate using the macro opting into any feature gate. (The case relevant here is using crates.io’s cfg-if in Rust 1.35 on the Stable channel.)

Finally, it looks like the multiple existing implementations of this macro are not identical. Could you say if the differences are significant, and why pick this one?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 26, 2019

Could you add commits to this PR to remove the ones in src/libstd/macros.rs, src/libpanic_unwind/macros.rs, and src/libunwind/macros.rs?

Is that also ok if I do this once this lands in the next bootstrap compiler? Otherwise one probably still needs to keep the older macros around, at least for bootstraping right ?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 26, 2019

Finally, it looks like the multiple existing implementations of this macro are not identical. Could you say if the differences are significant, and why pick this one?

Older ones are probably copy-pastes from older versions of the cfg-if crate (at least that's the case for the libstd and stdsimd ones). I am not sure what bugs the different releases of cfg-if have fixed, but this implementation is the one from its latest release.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 26, 2019

It’d also be nice to either add a new test or point to an existing test to show that when an unstable macro is in the prelude, it can be shadowed by a stable macro with the same name from another crate without the crate using the macro opting into any feature gate. (The case relevant here is using crates.io’s cfg-if in Rust 1.35 on the Stable channel.)

I'll add such a test to this PR :)

@SimonSapin
Copy link
Contributor

Otherwise one probably still needs to keep the older macros around, at least for bootstraping right ?

I think not: all crates in the repo are compiled against libcore in the repo.

It’s only standard library crates, in stage 0, that are compiled against the bootstrap compiler. So they may need #[cfg]s for lang item changes. I believe this is the current status, until something like #49119 lands. Try it?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:09c5f8b0:start=1553617825696510208,finish=1553617826712589117,duration=1016078909
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
travis_time:start:test_assembly
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:19:17] 
[01:19:17] running 9 tests
[01:19:17] iiiiiiiii
[01:19:17] 
[01:19:17]  finished in 0.160
[01:19:17] travis_fold:end:test_assembly

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:19:34] 
[01:19:34] running 120 tests
[01:20:02] .iiiii...i.....i..i...i..i.i...i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i.i 100/120
[01:20:07] .i......iii.i.....ii
[01:20:07] 
[01:20:07]  finished in 33.358
[01:20:07] travis_fold:end:test_debuginfo

---
[01:31:09] ....iiiii........................................................................................... 100/2298
[01:31:22] ......................................................................ii............................ 200/2298
[01:31:36] ..........................................................................................i......... 300/2298
[01:31:53] .................................................................................................... 400/2298
[01:32:05] ......................i..i....F..................................................................... 500/2298
[01:32:31] .................................................................................................... 700/2298
[01:32:44] .................................................................................................... 800/2298
[01:32:57] .................................................................................................... 900/2298
[01:33:10] .................................................................................................... 1000/2298
---
[01:36:11] 
[01:36:11] error: test failed, to rerun pass '--doc'
[01:36:11] 
[01:36:11] 
[01:36:11] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:36:11] 
[01:36:11] 
[01:36:11] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:36:11] Build completed unsuccessfully in 0:29:14
[01:36:11] Build completed unsuccessfully in 0:29:14
[01:36:11] make: *** [check] Error 1
[01:36:11] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:19c0f4b2
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Tue Mar 26 18:06:49 UTC 2019

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)

@alexcrichton
Copy link
Member

@SimonSapin should be correct in that all the existing cfg_if definitions throughout the codebase should be safely deletable, no bootstrap concerns necessary.

@SimonSapin as to the litany of definitions most of them probably stem from me as I've copied it to various places over time as I got fed up with the jungle of #[cfg] mainenance. Changes to the macro itself over time have been, I think in order:

  1. Macro was incepted
  2. Final else { ... } block was made optional
  3. Compatibility importing the macro through the module system and the 2018 edition
  4. Adding coments explaining what's going on

Each of the macros may represent some snapshot in time amongst all those, but the general gist is that it's basically been the same over time, the surface syntax never changing except for a final else becoming optional.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:0e7e85f6:start=1553625605446000477,finish=1553625609002737208,duration=3556736731
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
travis_time:end:1f7fca90:start=1553625771444529523,finish=1553625771451101601,duration=6572078
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:15ab4c98
$ 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 --batch -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:031d51cf
travis_time:start:031d51cf
$ 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:0393f1b0
$ 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)

src/libcore/tests/cfg_if_override.rs Outdated Show resolved Hide resolved
src/libstd/lib.rs Show resolved Hide resolved
src/libcore/macros.rs Outdated Show resolved Hide resolved
src/libcore/Cargo.toml Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:15e90df1:start=1553626110383034384,finish=1553626112712768838,duration=2329734454
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
travis_time:end:29488647:start=1553626266064728111,finish=1553626266070837034,duration=6108923
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:005d47b0
$ 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 --batch -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:2c56e3be
travis_time:start:2c56e3be
$ 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:01a169c0
$ 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)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:00473d78:start=1553626662724647100,finish=1553626665183227254,duration=2458580154
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
############################################################              83.9%
######################################################################## 100.0%
[00:01:45] extracting /checkout/obj/build/cache/2019-03-20/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
[00:01:45]     Updating crates.io index
[00:01:59] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:59]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:59]   location searched: crates.io index
[00:01:59] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:59] Build completed unsuccessfully in 0:00:28
[00:01:59] make: *** [prepare] Error 1
[00:01:59] Makefile:69: recipe for target 'prepare' failed
[00:02:00] Command failed. Attempt 2/5:
[00:02:00] Command failed. Attempt 2/5:
[00:02:00]     Updating crates.io index
[00:02:00] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:02:00]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:02:00]   location searched: crates.io index
[00:02:00] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:02:00] Build completed unsuccessfully in 0:00:00
[00:02:00] make: *** [prepare] Error 1
[00:02:00] Makefile:69: recipe for target 'prepare' failed
[00:02:02] Command failed. Attempt 3/5:
[00:02:02] Command failed. Attempt 3/5:
[00:02:02]     Updating crates.io index
[00:02:03] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:02:03]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:02:03]   location searched: crates.io index
[00:02:03] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:02:03] Build completed unsuccessfully in 0:00:00
[00:02:03] make: *** [prepare] Error 1
[00:02:03] Makefile:69: recipe for target 'prepare' failed
[00:02:06] Command failed. Attempt 4/5:
[00:02:06] Command failed. Attempt 4/5:
[00:02:06]     Updating crates.io index
[00:02:08] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:02:08]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:02:08]   location searched: crates.io index
[00:02:08] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:02:08] Build completed unsuccessfully in 0:00:01
[00:02:08] make: *** [prepare] Error 1
[00:02:08] Makefile:69: recipe for target 'prepare' failed
[00:02:12] Command failed. Attempt 5/5:
[00:02:12] Command failed. Attempt 5/5:
[00:02:12]     Updating crates.io index
[00:02:13] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:02:13]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:02:13]   location searched: crates.io index
[00:02:13] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:02:13] Build completed unsuccessfully in 0:00:01
[00:02:13] make: *** [prepare] Error 1
[00:02:13] Makefile:69: recipe for target 'prepare' failed
[00:02:13] The command has failed after 5 attempts.
---
travis_time:end:0fc28472:start=1553626811290366903,finish=1553626811301308339,duration=10941436
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0accb844
$ 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 --batch -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:0058a2a0
travis_time:start:0058a2a0
$ 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:2a424300
$ 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)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:089adce6:start=1553627451320244568,finish=1553627453709124590,duration=2388880022
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
[00:01:33] 
######################################################################## 100.0%
[00:01:33] extracting /checkout/obj/build/cache/2019-03-20/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
[00:01:33]     Updating crates.io index
[00:01:47] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:47]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:47]   location searched: crates.io index
[00:01:47] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:47] Build completed unsuccessfully in 0:00:28
[00:01:47] make: *** [prepare] Error 1
[00:01:47] Makefile:69: recipe for target 'prepare' failed
[00:01:48] Command failed. Attempt 2/5:
[00:01:48] Command failed. Attempt 2/5:
[00:01:48]     Updating crates.io index
[00:01:48] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:48]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:48]   location searched: crates.io index
[00:01:48] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:48] Build completed unsuccessfully in 0:00:00
[00:01:48] Makefile:69: recipe for target 'prepare' failed
[00:01:48] make: *** [prepare] Error 1
[00:01:50] Command failed. Attempt 3/5:
[00:01:50] Command failed. Attempt 3/5:
[00:01:51]     Updating crates.io index
[00:01:51] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:51]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:51]   location searched: crates.io index
[00:01:51] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:51] Build completed unsuccessfully in 0:00:00
[00:01:51] make: *** [prepare] Error 1
[00:01:51] Makefile:69: recipe for target 'prepare' failed
[00:01:54] Command failed. Attempt 4/5:
[00:01:54] Command failed. Attempt 4/5:
[00:01:54]     Updating crates.io index
[00:01:54] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:54]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:54]   location searched: crates.io index
[00:01:54] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:54] Build completed unsuccessfully in 0:00:00
[00:01:54] Makefile:69: recipe for target 'prepare' failed
[00:01:54] make: *** [prepare] Error 1
[00:01:58] Command failed. Attempt 5/5:
[00:01:58] Command failed. Attempt 5/5:
[00:01:59]     Updating crates.io index
[00:01:59] error: failed to select a version for the requirement `cfg-if = "^1.0"`
[00:01:59]   candidate versions found which didn't match: 0.1.7, 0.1.6, 0.1.5, ...
[00:01:59]   location searched: crates.io index
[00:01:59] required by package `core v0.0.0 (/checkout/src/libcore)`
[00:01:59] Build completed unsuccessfully in 0:00:00
[00:01:59] Makefile:69: recipe for target 'prepare' failed
[00:01:59] make: *** [prepare] Error 1
[00:01:59] The command has failed after 5 attempts.
---
travis_time:end:163194c4:start=1553627586646013821,finish=1553627586652613202,duration=6599381
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:216fa77c
$ 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 --batch -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:02b6feba
travis_time:start:02b6feba
$ 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:35472941
$ 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)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.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.
travis_time:end:03a931ac:start=1553635940783833375,finish=1553636015703039459,duration=74919206084
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
[00:01:23] 
######################################################################## 100.0%
[00:01:24] extracting /checkout/obj/build/cache/2019-03-20/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
[00:01:24]     Updating crates.io index
[00:01:41] error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
[00:01:41] Build completed unsuccessfully in 0:00:30
[00:01:41] make: *** [prepare] Error 1
[00:01:41] Makefile:69: recipe for target 'prepare' failed
[00:01:42] Command failed. Attempt 2/5:
[00:01:42] Command failed. Attempt 2/5:
[00:01:43] error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
[00:01:43] Build completed unsuccessfully in 0:00:00
[00:01:43] Makefile:69: recipe for target 'prepare' failed
[00:01:43] make: *** [prepare] Error 1
[00:01:45] Command failed. Attempt 3/5:
[00:01:45] Command failed. Attempt 3/5:
[00:01:45] error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
[00:01:45] Build completed unsuccessfully in 0:00:00
[00:01:45] make: *** [prepare] Error 1
[00:01:45] Makefile:69: recipe for target 'prepare' failed
[00:01:48] Command failed. Attempt 4/5:
[00:01:48] Command failed. Attempt 4/5:
[00:01:48] error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
[00:01:48] Build completed unsuccessfully in 0:00:00
[00:01:48] make: *** [prepare] Error 1
[00:01:48] Makefile:69: recipe for target 'prepare' failed
[00:01:52] Command failed. Attempt 5/5:
[00:01:52] Command failed. Attempt 5/5:
[00:01:53] error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
[00:01:53] Build completed unsuccessfully in 0:00:00
[00:01:53] make: *** [prepare] Error 1
[00:01:53] Makefile:69: recipe for target 'prepare' failed
[00:01:53] The command has failed after 5 attempts.
---
travis_time:end:194bf8f0:start=1553636140644617158,finish=1553636140650910067,duration=6292909
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:04829846
$ 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 --batch -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:101ccf66
travis_time:start:101ccf66
$ 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:02c33262
$ 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
Copy link
Contributor

bors commented Mar 28, 2019

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

@eaglgenes101
Copy link

eaglgenes101 commented Mar 30, 2019

I would argue that a cfg_match! macro makes more sense, as it would parallel its base syntax better than cfg_if, which, because macros' inability to look ahead outside of its own body, requires a second layer of expressions for the actual conditional compilation functionality:

cfg_match! {
    #[cfg(unix)] => { fn foo() { /* unix specific functionality */ } },
    #[cfg(target_pointer_width = "32")] => { fn foo() { /* non-unix, 32-bit functionality */ } }, 
    _ => { fn foo() { /* fallback implementation */ } }
}

@Centril
Copy link
Contributor

Centril commented Mar 30, 2019

@eaglgenes101 Oooh! I had thought of suggesting that also. Cool.

One thing I dislike about cfg_if! { ... } is that it looks like cfg_if! { if <-- see the two ifs repeated? That's quite awkward.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 30, 2019 via email

@faern
Copy link
Contributor

faern commented Apr 4, 2019

Regarding the cfg_match! syntax mentioned above. It got me thinking. It would be extremely handy if the macro could support single expression match arms, like normal matches. So it can be used much more compact with oneliners, like this:

const PLATFORM_NAME: &str = cfg_match! {
    #[cfg(unix)] => "*nix",
    #[cfg(windows)] => "Win",
    _ => compile_error!("Unsupported platform!"),
};

That would reduce sooo much duplication and risk for mistakes by not having to repeat const PLATFORM_NAME: &str =

@Dylan-DPC-zz
Copy link

ping from triage @gnzlbg you have failing tests to resolve. Any updates?

@Dylan-DPC-zz Dylan-DPC-zz 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 15, 2019
@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 10, 2019
@jonas-schievink
Copy link
Contributor

Ping from triage @gnzlbg, this needs merge conflicts to be resolved. I'm not sure what the status of this is – does this still need an RFC/FCP, or is cfg_match! clearly a better alternative? cc @rust-lang/libs

@alexcrichton
Copy link
Member

I've opened #61720 to separate out the question of adding an unstable macro from the internal refactorings done here.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 11, 2019

does this still need an RFC/FCP, or is cfg_match! clearly a better alternative?

That question is still unresolved.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 11, 2019

Also, resolving this question would require for somebody to implement a cfg_match! macro that works. AFAICT this is not possible in Rust today with macro rules, because _ is a pseudo-identifier, and meta matches it (see #59881), so you can't properly tell #[cfg(foo)] => {...} from _ => { ... } appart (can be kind of hacked though).

So this is kind of blocked on whether we can improve the macro system to support _ properly, and then blocked on whether use such improved macro system can be used to implement a cfg_match crate properly. And if we ever have that, on whether such a cfg_match macro is better in all possible ways than cfg_if!, or on whether both macros should be added.

@jonas-schievink jonas-schievink added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 11, 2019
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 21, 2019

@rust-lang/libs should decide what to do here. Should this be closed until either someone builds a good cfg_match! library or that's proven impossible ? Should we proceed with adding cfg_if! to libcore ? Even if its kept perma unstable forever at least it can be reused throughout the internal crates.

@jonas-schievink jonas-schievink added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jun 21, 2019
@alexcrichton
Copy link
Member

I would personally prefer that we not take this route. I don't think a libs team decision should be guided by internal implementation details, and for example there are now currently no duplications of the cfg_if macro definition in this codebase. While I do think this is a very useful macro it has nowhere near the number of reverse dependencies of a crate like serde, so I don't think it's really that ubiquitous. For that reason I think it's fine to leave to an external crate for now.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 21, 2019

Does core::arch now get cfg_if! from libcore somehow, or how does that work?

@alexcrichton
Copy link
Member

It does not get it because libcore doesn't have a definition. It also doesn't currently use it.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 21, 2019

Indeed, only std_detect needs it but that can be fetched from crates.io.

@gnzlbg gnzlbg closed this Jun 21, 2019
@BurntSushi
Copy link
Member

BurntSushi commented Jun 21, 2019

While I do think this is a very useful macro it has nowhere near the number of reverse dependencies of a crate like serde

FWIW, there have been at least a few occasions where I would have used cfg_if! in a library if it were provided by std, but have consciously chosen to avoid using it just to avoid bringing in another dep.

(I'm not saying this should necessarily change anything here, but this is one of those things that falls into the category of "really nice if it's available, but maybe not worth the trouble of bringing in another dep in less complex scenarios.")

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 22, 2019

@BurntSushi When I opened this the reason to not go through an RFC was that the design here was small and constrained enough that a tracking issue / FCP might be enough. Some people have raised the issue that a cfg_match! would be a better fit, which kind of shows that the design space here is larger than at least I originally thought, and maye that means that adding a macro like this to libcore should go through the RFC process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). 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.