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

Move static_assert! into librustc_data_structures #55805

Merged
merged 4 commits into from
Nov 14, 2018

Conversation

nnethercote
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(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 Nov 9, 2018
@Mark-Simulacrum
Copy link
Member

r? @Mark-Simulacrum

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 9, 2018

📌 Commit 87462067c91f8523689c8c6be516aa179c926f97 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2018
@pietroalbini
Copy link
Member

@bors r-

This is failing on dist-aarch64-linux:

[00:27:20] error[E0080]: could not evaluate static initializer
[00:27:20]    --> libsyntax/ast.rs:929:1
[00:27:20]     |
[00:27:20] 929 | static_assert!(EXPR_IS_AT_MOST_88_BYTES: std::mem::size_of::<Expr>() <= 88);
[00:27:20]     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1
[00:27:20]     = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[00:27:20] 
[00:27:20] error: aborting due to previous error

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2018
@nnethercote
Copy link
Contributor Author

@rust-lang/wg-compiler-performance: Does anybody know why mem::size_of::<Expr>() might be greater than 88 bytes on Aarch64 when it is 88 bytes on x64? I don't have access to an Aarch64 machine to investigate this, unfortunately.

@nagisa
Copy link
Member

nagisa commented Nov 11, 2018

Preferred alignment of u8 and u16 on AArch64 is 4 bytes.

@eddyb
Copy link
Member

eddyb commented Nov 11, 2018

@nagisa But that's not used for... pretty much anything, really.
Do we accidentally sort fields by it, somehow?

@nnethercote
Copy link
Contributor Author

Is there a #cfg qualifier for x64, so I can make the assertion conditional?

@nnethercote
Copy link
Contributor Author

#[cfg(target_arch = "x86_64")], looks like

@nagisa
Copy link
Member

nagisa commented Nov 11, 2018

As discussed on IRC, another difference is that i128 is 128-bit aligned on Aarch64 and 64-bit aligned on x86_64. That’s the most likely root cause.

@nnethercote
Copy link
Contributor Author

I changed the assertion to be x86_64-only.

@rust-highfive
Copy link
Collaborator

The job mingw-check 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:05e1a1fe:start=1541973404510982924,finish=1541973461716679789,duration=57205696865
$ 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
Setting environment variables from .travis.yml
$ export IMAGE=mingw-check
---
[00:08:06] configure: build.locked-deps    := True
[00:08:06] configure: llvm.ccache          := sccache
[00:08:06] configure: build.cargo-native-static := True
[00:08:06] configure: dist.missing-tools   := True
[00:08:06] configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
[00:08:06] configure: writing `config.toml` in current directory
[00:08:06] configure: 
[00:08:06] configure: run `python /checkout/x.py --help`
[00:08:06] configure: 
---
[00:10:34] 
[00:10:34] error: Could not compile `syntax`.
[00:10:34] 
[00:10:34] To learn more, run the command again with --verbose.
[00:10:34] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "i686-pc-windows-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:10:34] expected success, got: exit code: 101
[00:10:34] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1101:9
[00:10:34] travis_fold:end:stage0-rustc

[00:10:34] travis_time:end:stage0-rustc:start=1541974067580354422,finish=1541974106543297158,duration=38962942736

---
travis_time:end:2d625494:start=1541974107277136389,finish=1541974107282637430,duration=5501041
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1df19910
$ 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:0ebe3610
travis_time:start:0ebe3610
$ 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:0cc5a6f3
$ 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)

@nnethercote
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Nov 12, 2018

⌛ Trying commit 209f18aa8406ad3841700ac345f8a794f6ba4716 with merge 627a9b8857948721ee8a2eca7b33f36fced1a249...

@bors
Copy link
Contributor

bors commented Nov 12, 2018

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

// Note that the assertion is x86_64-only because the size is larger on
// AArch64.
#[cfg(target_arch = "x86_64")]
static_assert!(EXPR_IS_88_BYTES: std::mem::size_of::<Expr>() == 88);
Copy link
Member

Choose a reason for hiding this comment

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

It seems a bit incongruous that this assert is == whereas the Statement assert is <= -- I would think the same logic should apply to both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Statement assert is used on all platforms, which is why it's looser -- the size on 32-bit is different to the size on 64-bit, etc.

The Expr assert is x86_64-only, because the size on AArch64 is apparently greater than 88, and I didn't want to give unnecessary leeway on x86_64, which is probably the most important platform. So I took the opportunity to make it stronger, using equality. The advantage of this is that if somebody does shrink Expr, say to 80 bytes, they must update the assertion accordingly, and then we can't accidentally backslide back to 88 bytes. That's what the "And if it gets smaller, this assertion should be updated so it stays at that smaller size" part of the comment is trying to communicate.

So, options:

  • Accept the code as is.
  • Expand comments on one or both assertions.
  • Make the assertions more consistent, possibly by restricting the Statement assertion to x86_64-only.

@Mark-Simulacrum: which would you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

I think it probably makes sense to gate the Statement assert to x86_64 as well and make it ==.

@Mark-Simulacrum
Copy link
Member

r=me with the asserts modified to match or explanation

@nnethercote
Copy link
Contributor Author

@Mark-Simulacrum: I've made these changes:

  • They're now all x86_64-only.
  • They all use ==.
  • They have consistent naming of the static assert identifier (and that name doesn't mention the size, as future-proofing).
  • I added a fourth commit to do likewise to a couple more existing static assertions.

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 12, 2018

📌 Commit e01e0b0 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 12, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 12, 2018
…k-Simulacrum

Move `static_assert!` into librustc_data_structures
@rust-highfive
Copy link
Collaborator

The job mingw-check 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:059b8f8e:start=1542054305226581214,finish=1542054360174058919,duration=54947477705
$ 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
Setting environment variables from .travis.yml
$ export IMAGE=mingw-check
---
[00:07:49] configure: build.locked-deps    := True
[00:07:49] configure: llvm.ccache          := sccache
[00:07:49] configure: build.cargo-native-static := True
[00:07:49] configure: dist.missing-tools   := True
[00:07:49] configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
[00:07:49] configure: writing `config.toml` in current directory
[00:07:49] configure: 
[00:07:49] configure: run `python /checkout/x.py --help`
[00:07:49] configure: 
---
[00:10:20] 
[00:10:20] error: Could not compile `syntax`.
[00:10:20] 
[00:10:20] To learn more, run the command again with --verbose.
[00:10:20] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "i686-pc-windows-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:10:20] expected success, got: exit code: 101
[00:10:20] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1101:9
[00:10:20] travis_fold:end:stage0-rustc

[00:10:20] travis_time:end:stage0-rustc:start=1542054951066289044,finish=1542054989313037107,duration=38246748063

---
travis_time:end:02137488:start=1542054990028821192,finish=1542054990034044568,duration=5223376
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:066e1968
$ 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:0038c2c4
travis_time:start:0038c2c4
$ 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:00635646
$ 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)

// Use the bool to access an array such that if the bool is false, the access
// is out-of-bounds.
#[allow(dead_code)]
static $name: () = [()][!$test as usize];
Copy link
Member

Choose a reason for hiding this comment

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

(not really relevant to this PR) So I don't forget: this should have ($test: bool) to avoid accidentally allowing an integer expression (cc @oli-obk).

Copy link
Contributor

Choose a reason for hiding this comment

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

Just came across this, and I'm curious to know where I can follow the status of having types as macro input specifiers. This would be nice for my const_assert! macro.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what you mean. I am talking about writing [()][!($test: bool) as usize].

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah so this is just a matter of using type ascription anywhere. I was under the impression it was having bool instead of expr. It's still something I'll definitely be using when it stabilizes.

@pietroalbini
Copy link
Member

@bors r- (failed)

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 12, 2018
And make them x86_64-only so they can use `==` instead of `<=`.
@nnethercote
Copy link
Contributor Author

nnethercote commented Nov 13, 2018

I fixed the compile error, one of the use items needed to be conditional.

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Nov 13, 2018

📌 Commit 2bd4d5b has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Nov 13, 2018
…k-Simulacrum

Move `static_assert!` into librustc_data_structures
bors added a commit that referenced this pull request Nov 13, 2018
Rollup of 20 pull requests

Successful merges:

 - #55136 (Remove short doc where it starts with a codeblock)
 - #55711 (Format BtreeMap::range_mut example)
 - #55722 (impl_stable_hash_for: support enums and tuple structs with generic parameters)
 - #55754 (Avoid converting bytes to UTF-8 strings to print, just pass bytes to stdout/err)
 - #55804 (rustdoc: don't inline `pub use some_crate` unless directly asked to)
 - #55805 (Move `static_assert!` into librustc_data_structures)
 - #55837 (Make PhantomData #[structural_match])
 - #55840 (Fix TLS errors when downloading stage0)
 - #55843 (add FromIterator<A> to Box<[A]>)
 - #55858 (Small fixes on code blocks in rustdoc)
 - #55863 (Fix a typo in std::panic)
 - #55870 (Fix typos.)
 - #55874 (string: Add documentation for `From` impls)
 - #55879 (save-analysis: Don't panic for macro-generated use globs)
 - #55882 (Reference count `crate_inherent_impls`s return value.)
 - #55888 (miri: for uniformity, also move memory_deallocated to AllocationExtra)
 - #55889 (global allocators: add a few comments)
 - #55896 (Document optimizations enabled by FusedIterator)
 - #55905 (Change `Lit::short_name` to `Lit::literal_name`.)
 - #55908 (Fix their/there grammar nit)
@bors bors merged commit 2bd4d5b into rust-lang:master Nov 14, 2018
@nnethercote nnethercote deleted the mv-static_assert branch November 14, 2018 02:07
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.

9 participants