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

Disable field reordering for repr(int). #56887

Merged
merged 2 commits into from Dec 22, 2018

Conversation

Projects
None yet
8 participants
@emilio
Copy link
Contributor

emilio commented Dec 16, 2018

This fixes the problem that the test in #56619 uncovers.

Closes #56619.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Dec 16, 2018

r? @petrochenkov

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

@emilio

This comment has been minimized.

Copy link
Contributor

emilio commented Dec 16, 2018

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned petrochenkov Dec 16, 2018

@emilio

This comment has been minimized.

Copy link
Contributor

emilio commented Dec 16, 2018

The order of commits is the opposite github shows because github doesn't show the topological order... :(

Anyway. cc @BorisChiou, I think this is the problem you hit with cbindgen that time.

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 16, 2018

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.
travis_time:end:10ff2c21:start=1544987564767243025,finish=1544987565864410530,duration=1097167505
$ 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=x86_64-gnu-llvm-5.0
---

[00:02:45] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:02:45] tidy error: /checkout/src/test/run-pass/structs-enums/enum-non-c-like-repr-int.rs:24: line longer than 100 chars
[00:02:45] tidy error: /checkout/src/test/run-pass/structs-enums/enum-non-c-like-repr-c-and-int.rs:24: line longer than 100 chars
[00:02:45] tidy error: /checkout/src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs:24: line longer than 100 chars
[00:02:46] 
[00:02:46] 
[00:02:46] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:02:46] 
[00:02:46] 
[00:02:46] some tidy checks failed
[00:02:46] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:02:46] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:02:46] Build completed unsuccessfully in 0:00:42
[00:02:46] Makefile:79: recipe for target 'tidy' failed
[00:02:46] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:12002c22
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Dec 16 19:15:41 UTC 2018
---
travis_time:end:30102b58:start=1544987742178921394,finish=1544987742183753548,duration=4832154
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:19106a24
$ 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:30f5cc2e
travis_time:start:30f5cc2e
$ 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:055b81c8
$ 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)

Add test to check order of repr(int) enum fields
RFC #2195 specifies that a repr(int) enum such as:

    #[repr(u8)]
    enum MyEnum {
        B { x: u8, y: i16, z: u8 },
    }

has a layout that is equivalent to:

    #[repr(C)]
    enum MyEnumVariantB { tag: u8, x: u8, y: i16, z: u8 },

However this isn't actually implemented, with the actual layout being
roughly equivalent to:

    union MyEnumPayload {
        B { x: u8, y: i16, z: u8 },
    }

    #[repr(packed)]
    struct MyEnum {
        tag: u8,
        payload: MyEnumPayload,
    }

Thus the variant payload is *not* subject to repr(C) ordering rules, and
gets re-ordered as `{ x: u8, z: u8, z: i16 }`

The existing tests added in pull-req #45688 fail to catch this as the
repr(C) ordering just happens to match the current Rust ordering in this
case; adding a third field reveals the problem.

@emilio emilio force-pushed the emilio:enum-field-reordering branch from c5dbc0a to d84bdba Dec 16, 2018

pub fn inhibit_struct_field_reordering_opt(&self) -> bool {
!(self.flags & ReprFlags::IS_UNOPTIMISABLE).is_empty() || (self.pack == 1)
self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.pack == 1 ||
self.int.is_some()

This comment has been minimized.

@eddyb

eddyb Dec 19, 2018

Member

cc @rkruppe @nagisa This seems somewhat fragile (I mean the pre-existing code).
The check for pack == 1 means things will still be reordered with #[repr(packed(N))], is that intentional?
Also, it seems to me that inhibit_enum_layout_opt is a subset of this function and maybe we should have just one function that checks all conditions?

This comment has been minimized.

@nagisa

nagisa Dec 19, 2018

Contributor

The repr RFC does not specify any behaviour /wrt repr(packed(N)) for enums and I’m not sure I recall us guaranteeing that repr(packed) specifies any representation and the reference seems to agree.

This comment has been minimized.

@nagisa

nagisa Dec 19, 2018

Contributor

In fact as per strict reading of the reference, self.pack == 1 inhibiting reordering would be somewhat wrong, as it should cause "packing" for the original ordering, but since the "default" ordering is not specified, it seems to be fine either way...

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Dec 19, 2018

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 19, 2018

📌 Commit d84bdba has been approved by eddyb

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 20, 2018

Rollup merge of rust-lang#56887 - emilio:enum-field-reordering, r=eddyb
Disable field reordering for repr(int).

This fixes the problem that the test in rust-lang#56619 uncovers.

Closes rust-lang#56619.

bors added a commit that referenced this pull request Dec 20, 2018

Auto merge of #57005 - pietroalbini:rollup, r=pietroalbini
Rollup of 19 pull requests

Successful merges:

 - #56842 (Add unstable VecDeque::rotate_{left|right})
 - #56843 (Add a note describing the type of the non-Copy moved variable)
 - #56845 (Don't render const keyword on stable)
 - #56862 (stop treating trait objects from #[fundamental] traits as fundamental)
 - #56869 (Reduce search-index.js size)
 - #56887 (Disable field reordering for repr(int).)
 - #56892 (rustc: Update Clang used to build LLVM on Linux)
 - #56906 (Issue #56905)
 - #56909 (static eval: Do not ICE on layout size overflow)
 - #56914 (Ignore ui/target-feature-gate on sparc, sparc64, powerpc, powerpc64 and powerpc64le)
 - #56916 (Fix a recently introduced regression)
 - #56919 (Remove a wrong multiplier on relocation offset computation)
 - #56933 (Add --progress to git submodule commands in x.py)
 - #56954 (Add dist builder for Armv8-M Mainline)
 - #56970 (Mem uninit doc ptr drop)
 - #56973 (make basic CTFE tracing available on release builds)
 - #56979 (Adding unwinding support for x86_64_fortanix_unknown_sgx target.)
 - #56984 (A few tweaks to dropck_outlives)
 - #56989 (Fix compiletest `trim` deprecation warnings)

Failed merges:

r? @ghost

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Dec 21, 2018

Rollup merge of rust-lang#56887 - emilio:enum-field-reordering, r=eddyb
Disable field reordering for repr(int).

This fixes the problem that the test in rust-lang#56619 uncovers.

Closes rust-lang#56619.

bors added a commit that referenced this pull request Dec 21, 2018

Auto merge of #57022 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 22 pull requests

Successful merges:

 - #55798 (Add version display for associated consts)
 - #56802 (Add DoubleEndedIterator::nth_back)
 - #56824 (rustdoc: display rustc_private APIs as "Internal")
 - #56862 (stop treating trait objects from #[fundamental] traits as fundamental)
 - #56887 (Disable field reordering for repr(int).)
 - #56892 (rustc: Update Clang used to build LLVM on Linux)
 - #56906 (Issue #56905)
 - #56914 (Ignore ui/target-feature-gate on sparc, sparc64, powerpc, powerpc64 and powerpc64le)
 - #56919 (Remove a wrong multiplier on relocation offset computation)
 - #56933 (Add --progress to git submodule commands in x.py)
 - #56939 (Pin stabilization)
 - #56941 (deny intra-doc link resolution failures in libstd)
 - #56953 (Mark tuple structs as live if their constructors are used)
 - #56954 (Add dist builder for Armv8-M Mainline)
 - #56970 (Mem uninit doc ptr drop)
 - #56973 (make basic CTFE tracing available on release builds)
 - #56979 (Adding unwinding support for x86_64_fortanix_unknown_sgx target.)
 - #56981 (miri: allocation is infallible)
 - #56984 (A few tweaks to dropck_outlives)
 - #56989 (Fix compiletest `trim` deprecation warnings)
 - #56992 (suggest similar lint names for unknown lints)
 - #57002 (Stabilize Vec(Deque)::resize_with)

Failed merges:

r? @ghost

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 21, 2018

Rollup merge of rust-lang#56887 - emilio:enum-field-reordering, r=eddyb
Disable field reordering for repr(int).

This fixes the problem that the test in rust-lang#56619 uncovers.

Closes rust-lang#56619.

bors added a commit that referenced this pull request Dec 21, 2018

Auto merge of #57025 - pietroalbini:rollup, r=pietroalbini
Rollup of 21 pull requests

Successful merges:

 - #56802 (Add DoubleEndedIterator::nth_back)
 - #56842 (Add unstable VecDeque::rotate_{left|right})
 - #56869 (Reduce search-index.js size)
 - #56887 (Disable field reordering for repr(int).)
 - #56892 (rustc: Update Clang used to build LLVM on Linux)
 - #56909 (static eval: Do not ICE on layout size overflow)
 - #56914 (Ignore ui/target-feature-gate on sparc, sparc64, powerpc, powerpc64 and powerpc64le)
 - #56917 (Simplify MIR generation for logical operations)
 - #56919 (Remove a wrong multiplier on relocation offset computation)
 - #56933 (Add --progress to git submodule commands in x.py)
 - #56941 (deny intra-doc link resolution failures in libstd)
 - #56954 (Add dist builder for Armv8-M Mainline)
 - #56964 (Remove `TokenStream::JointTree`.)
 - #56970 (Mem uninit doc ptr drop)
 - #56973 (make basic CTFE tracing available on release builds)
 - #56979 (Adding unwinding support for x86_64_fortanix_unknown_sgx target.)
 - #56981 (miri: allocation is infallible)
 - #56984 (A few tweaks to dropck_outlives)
 - #56989 (Fix compiletest `trim` deprecation warnings)
 - #56992 (suggest similar lint names for unknown lints)
 - #57002 (Stabilize Vec(Deque)::resize_with)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Dec 21, 2018

Auto merge of #57025 - pietroalbini:rollup, r=pietroalbini
Rollup of 20 pull requests

Successful merges:

 - #56802 (Add DoubleEndedIterator::nth_back)
 - #56842 (Add unstable VecDeque::rotate_{left|right})
 - #56869 (Reduce search-index.js size)
 - #56887 (Disable field reordering for repr(int).)
 - #56892 (rustc: Update Clang used to build LLVM on Linux)
 - #56909 (static eval: Do not ICE on layout size overflow)
 - #56914 (Ignore ui/target-feature-gate on sparc, sparc64, powerpc, powerpc64 and powerpc64le)
 - #56917 (Simplify MIR generation for logical operations)
 - #56919 (Remove a wrong multiplier on relocation offset computation)
 - #56933 (Add --progress to git submodule commands in x.py)
 - #56941 (deny intra-doc link resolution failures in libstd)
 - #56964 (Remove `TokenStream::JointTree`.)
 - #56970 (Mem uninit doc ptr drop)
 - #56973 (make basic CTFE tracing available on release builds)
 - #56979 (Adding unwinding support for x86_64_fortanix_unknown_sgx target.)
 - #56981 (miri: allocation is infallible)
 - #56984 (A few tweaks to dropck_outlives)
 - #56989 (Fix compiletest `trim` deprecation warnings)
 - #56992 (suggest similar lint names for unknown lints)
 - #57002 (Stabilize Vec(Deque)::resize_with)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Dec 21, 2018

Auto merge of #57025 - pietroalbini:rollup, r=pietroalbini
Rollup of 20 pull requests

Successful merges:

 - #56802 (Add DoubleEndedIterator::nth_back)
 - #56842 (Add unstable VecDeque::rotate_{left|right})
 - #56869 (Reduce search-index.js size)
 - #56887 (Disable field reordering for repr(int).)
 - #56892 (rustc: Update Clang used to build LLVM on Linux)
 - #56909 (static eval: Do not ICE on layout size overflow)
 - #56914 (Ignore ui/target-feature-gate on sparc, sparc64, powerpc, powerpc64 and powerpc64le)
 - #56917 (Simplify MIR generation for logical operations)
 - #56919 (Remove a wrong multiplier on relocation offset computation)
 - #56933 (Add --progress to git submodule commands in x.py)
 - #56941 (deny intra-doc link resolution failures in libstd)
 - #56964 (Remove `TokenStream::JointTree`.)
 - #56970 (Mem uninit doc ptr drop)
 - #56973 (make basic CTFE tracing available on release builds)
 - #56979 (Adding unwinding support for x86_64_fortanix_unknown_sgx target.)
 - #56981 (miri: allocation is infallible)
 - #56984 (A few tweaks to dropck_outlives)
 - #56989 (Fix compiletest `trim` deprecation warnings)
 - #56992 (suggest similar lint names for unknown lints)
 - #57002 (Stabilize Vec(Deque)::resize_with)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Dec 22, 2018

Rollup merge of rust-lang#56887 - emilio:enum-field-reordering, r=eddyb
Disable field reordering for repr(int).

This fixes the problem that the test in rust-lang#56619 uncovers.

Closes rust-lang#56619.
@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Dec 22, 2018

@bors p=30

(rollup fairness)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 22, 2018

⌛️ Testing commit d84bdba with merge 2d3e909...

bors added a commit that referenced this pull request Dec 22, 2018

Auto merge of #56887 - emilio:enum-field-reordering, r=eddyb
Disable field reordering for repr(int).

This fixes the problem that the test in #56619 uncovers.

Closes #56619.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 22, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 2d3e909 to master...

@bors bors merged commit d84bdba into rust-lang:master Dec 22, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment