Remove the old AST-based backend from rustc_trans. #35764

Merged
merged 4 commits into from Aug 25, 2016

Conversation

Projects
None yet
8 participants
@eddyb
Member

eddyb commented Aug 17, 2016

Starting with Rust 1.13, --disable-orbit , -Z orbit=off and #[rustc_no_mir] have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), #[unsafe_no_drop_flag] and associated unstable APIs are gone.
Implementing Drop doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use Option::None and/or mem::forget if you are unsure about your ability to prevent/control the drop of a value. In the future, union will be usable in some such cases.

NOTE: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as unions, safe use of #[packed] or new type layout optimizations, not to mention many other experiments.

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Aug 17, 2016

Collaborator

r? @nrc

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

Collaborator

rust-highfive commented Aug 17, 2016

r? @nrc

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

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton Aug 17, 2016

Member

Dat diff.

Member

alexcrichton commented Aug 17, 2016

Dat diff.

@retep998

This comment has been minimized.

Show comment
Hide comment
@retep998

retep998 Aug 17, 2016

Member

Praise be, the world will no longer be blocked on MIR, and development of new features can finally take place!

Member

retep998 commented Aug 17, 2016

Praise be, the world will no longer be blocked on MIR, and development of new features can finally take place!

@nrc

This comment has been minimized.

Show comment
Hide comment
@nrc

nrc Aug 17, 2016

Member

Much as I'd love to r+ this, r? @nikomatsakis

Member

nrc commented Aug 17, 2016

Much as I'd love to r+ this, r? @nikomatsakis

src/librustc_trans/adt.rs
-fn dtor_to_init_u8(dtor: bool) -> u8 {
- if dtor { 1 } else { 0 }
-}
-
pub trait GetDtorType<'tcx> { fn dtor_type(self) -> Ty<'tcx>; }

This comment has been minimized.

@jld

jld Aug 18, 2016

Contributor

It looks like this trait can also be deleted?

@jld

jld Aug 18, 2016

Contributor

It looks like this trait can also be deleted?

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 18, 2016

Contributor

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

Contributor

bors commented Aug 18, 2016

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

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 18, 2016

Member

FWIW, this appears to fix #35408 locally, possibly due to P::map not using memset with 0x1d to prevent drop on panic, allowing LLVM to optimize the moves in the AST folder better.

Member

eddyb commented Aug 18, 2016

FWIW, this appears to fix #35408 locally, possibly due to P::map not using memset with 0x1d to prevent drop on panic, allowing LLVM to optimize the moves in the AST folder better.

src/liballoc/arc.rs
// see comments above for why this check is here
- if thin as usize == mem::POST_DROP_USIZE {
- return;
+ #[cfg(stage0)] {

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

this is nifty

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

this is nifty

- /// Rust moves to non-zeroing dynamic drop (and thus removes the
- /// embedded drop flags that are being established by this
- /// intrinsic).
- pub fn init_dropped<T>() -> T;

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

buh-bye 👋

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

buh-bye 👋

src/libcore/mem.rs
-#[allow(missing_docs)]
-pub const POST_DROP_USIZE: usize = POST_DROP_U16 as usize;
-#[cfg(target_pointer_width = "32")]
+// TODO HACK FIXME(eddyb) !!! Remove POST_DROP_* after beta branches off.

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

I'm confused --- what makes this a hack?

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

I'm confused --- what makes this a hack?

This comment has been minimized.

@eddyb

eddyb Aug 19, 2016

Member

That's just an anti-tidy marker so we remove that stuff before merging. Which is why we need to update the stage0 first.

@eddyb

eddyb Aug 19, 2016

Member

That's just an anti-tidy marker so we remove that stuff before merging. Which is why we need to update the stage0 first.

- value: Int(I8),
- non_zero: false
- })).into_iter(), ty)?;
- }

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

🐊 tears

@nikomatsakis

nikomatsakis Aug 19, 2016

Contributor

🐊 tears

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
Contributor

nikomatsakis commented Aug 23, 2016

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 23, 2016

Contributor

📌 Commit 9a9cd63 has been approved by nikomatsakis

Contributor

bors commented Aug 23, 2016

📌 Commit 9a9cd63 has been approved by nikomatsakis

@eddyb eddyb referenced this pull request Aug 23, 2016

Closed

Rollup of 15 pull requests #35944

eddyb added a commit to eddyb/rust that referenced this pull request Aug 23, 2016

Rollup merge of #35764 - eddyb:byegone, r=nikomatsakis
Remove the old AST-based backend from rustc_trans.

Starting with Rust 1.13, `--disable-orbit` , `-Z orbit=off` and `#[rustc_no_mir]` have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), `#[unsafe_no_drop_flag]` and associated unstable APIs are gone.
Implementing `Drop` doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use `Option::None` and/or `mem::forget` if you are unsure about your ability to prevent/control the drop of a value. In the future, `union` will be usable in some such cases.

**NOTE**: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as `union`s, safe use of `#[packed]` or new type layout optimizations, not to mention many other experiments.

@eddyb eddyb referenced this pull request Aug 23, 2016

Closed

Rollup of 13 pull requests #35945

bors added a commit that referenced this pull request Aug 23, 2016

Auto merge of #35945 - eddyb:rollup, r=eddyb
Rollup of 13 pull requests

- Successful merges: #35704, #35718, #35764, #35883, #35884, #35885, #35910, #35912, #35913, #35916, #35920, #35936, #35939
- Failed merges: #35854, #35909

bors added a commit that referenced this pull request Aug 23, 2016

Auto merge of #35945 - eddyb:rollup, r=eddyb
Rollup of 13 pull requests

- Successful merges: #35704, #35718, #35764, #35883, #35884, #35885, #35910, #35912, #35913, #35916, #35920, #35936, #35939
- Failed merges: #35854, #35909
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 23, 2016

Contributor

⌛️ Testing commit 9a9cd63 with merge 91aadff...

Contributor

bors commented Aug 23, 2016

⌛️ Testing commit 9a9cd63 with merge 91aadff...

bors added a commit that referenced this pull request Aug 23, 2016

Auto merge of #35764 - eddyb:byegone, r=nikomatsakis
Remove the old AST-based backend from rustc_trans.

Starting with Rust 1.13, `--disable-orbit` , `-Z orbit=off` and `#[rustc_no_mir]` have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), `#[unsafe_no_drop_flag]` and associated unstable APIs are gone.
Implementing `Drop` doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use `Option::None` and/or `mem::forget` if you are unsure about your ability to prevent/control the drop of a value. In the future, `union` will be usable in some such cases.

**NOTE**: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as `union`s, safe use of `#[packed]` or new type layout optimizations, not to mention many other experiments.
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 23, 2016

Contributor

💔 Test failed - auto-linux-cross-opt

Contributor

bors commented Aug 23, 2016

💔 Test failed - auto-linux-cross-opt

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 23, 2016

Member

@bors retry

Member

eddyb commented Aug 23, 2016

@bors retry

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 23, 2016

Contributor

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

Contributor

bors commented Aug 23, 2016

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

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 24, 2016

Member

@bors r=nikomatsakis p=3 The sooner the better for everyone.

Member

eddyb commented Aug 24, 2016

@bors r=nikomatsakis p=3 The sooner the better for everyone.

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

📌 Commit a624c44 has been approved by nikomatsakis

Contributor

bors commented Aug 24, 2016

📌 Commit a624c44 has been approved by nikomatsakis

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

⌛️ Testing commit a624c44 with merge df69368...

Contributor

bors commented Aug 24, 2016

⌛️ Testing commit a624c44 with merge df69368...

bors added a commit that referenced this pull request Aug 24, 2016

Auto merge of #35764 - eddyb:byegone, r=nikomatsakis
Remove the old AST-based backend from rustc_trans.

Starting with Rust 1.13, `--disable-orbit` , `-Z orbit=off` and `#[rustc_no_mir]` have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), `#[unsafe_no_drop_flag]` and associated unstable APIs are gone.
Implementing `Drop` doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use `Option::None` and/or `mem::forget` if you are unsure about your ability to prevent/control the drop of a value. In the future, `union` will be usable in some such cases.

**NOTE**: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as `union`s, safe use of `#[packed]` or new type layout optimizations, not to mention many other experiments.
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

💔 Test failed - auto-linux-64-opt-no-mir

Contributor

bors commented Aug 24, 2016

💔 Test failed - auto-linux-64-opt-no-mir

@eddyb eddyb referenced this pull request in rust-lang-deprecated/rust-buildbot Aug 24, 2016

Merged

Remove no-mir bots. #119

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

📌 Commit f1fde18 has been approved by nikomatsakis

Contributor

bors commented Aug 24, 2016

📌 Commit f1fde18 has been approved by nikomatsakis

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 24, 2016

Member

@bors r=nikomatsakis

Member

eddyb commented Aug 24, 2016

@bors r=nikomatsakis

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

📌 Commit 25cf800 has been approved by nikomatsakis

Contributor

bors commented Aug 24, 2016

📌 Commit 25cf800 has been approved by nikomatsakis

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 24, 2016

Member

@bors force

Member

eddyb commented Aug 24, 2016

@bors force

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

⌛️ Testing commit 25cf800 with merge 2331bf6...

Contributor

bors commented Aug 24, 2016

⌛️ Testing commit 25cf800 with merge 2331bf6...

bors added a commit that referenced this pull request Aug 24, 2016

Auto merge of #35764 - eddyb:byegone, r=nikomatsakis
Remove the old AST-based backend from rustc_trans.

Starting with Rust 1.13, `--disable-orbit` , `-Z orbit=off` and `#[rustc_no_mir]` have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), `#[unsafe_no_drop_flag]` and associated unstable APIs are gone.
Implementing `Drop` doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use `Option::None` and/or `mem::forget` if you are unsure about your ability to prevent/control the drop of a value. In the future, `union` will be usable in some such cases.

**NOTE**: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as `union`s, safe use of `#[packed]` or new type layout optimizations, not to mention many other experiments.
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

💔 Test failed - auto-mac-cross-ios-opt

Contributor

bors commented Aug 24, 2016

💔 Test failed - auto-mac-cross-ios-opt

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Aug 24, 2016

Member

@bors retry

Member

eddyb commented Aug 24, 2016

@bors retry

@Marwes Marwes referenced this pull request in gluon-lang/gluon Aug 24, 2016

Merged

perf: Use SmallVec in the Type::App variant #129

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Aug 24, 2016

Contributor

⌛️ Testing commit 25cf800 with merge e9bc1ba...

Contributor

bors commented Aug 24, 2016

⌛️ Testing commit 25cf800 with merge e9bc1ba...

bors added a commit that referenced this pull request Aug 24, 2016

Auto merge of #35764 - eddyb:byegone, r=nikomatsakis
Remove the old AST-based backend from rustc_trans.

Starting with Rust 1.13, `--disable-orbit` , `-Z orbit=off` and `#[rustc_no_mir]` have been removed.
Only the new MIR backend is left in the compiler, and only early const_eval uses ASTs from other crates.

Filling drop (previously "zeroing drop"), `#[unsafe_no_drop_flag]` and associated unstable APIs are gone.
Implementing `Drop` doesn't add a flag anymore to the type, all of the dynamic drop is function local.
This is a [breaking-change], please use `Option::None` and/or `mem::forget` if you are unsure about your ability to prevent/control the drop of a value. In the future, `union` will be usable in some such cases.

**NOTE**: DO NOT MERGE before we get the new beta as the stage0, there's some cruft to remove.

All of this will massively simplify any efforts to implement (and as such it blocks) features such as `union`s, safe use of `#[packed]` or new type layout optimizations, not to mention many other experiments.

@bors bors merged commit 25cf800 into rust-lang:master Aug 25, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@eddyb eddyb deleted the eddyb:byegone branch Aug 25, 2016

jseyfried added a commit to jseyfried/rust that referenced this pull request Aug 28, 2016

Rollup merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc rust-lang#32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- rust-lang#35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per rust-lang#32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

bors added a commit that referenced this pull request Sep 2, 2016

Auto merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc #32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- #35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per #32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

r? @eddyb

bors added a commit that referenced this pull request Sep 2, 2016

Auto merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc #32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- #35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per #32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

r? @eddyb

bors added a commit that referenced this pull request Sep 2, 2016

Auto merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc #32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- #35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per #32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

r? @eddyb

bors added a commit that referenced this pull request Sep 2, 2016

Auto merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc #32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- #35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per #32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

r? @eddyb

bors added a commit that referenced this pull request Sep 3, 2016

Auto merge of #36016 - petrochenkov:union, r=nikomatsakis
Implement untagged unions (RFC 1444)

cc #32836

Notes:
- The RFC doesn't talk about `#[packed]` unions, this implementation supports them, packing changes union's alignment to 1 and removes trailing padding.
- The RFC doesn't talk about dynamically sized unions, this implementation doesn't support them and rejects them during wf-checking (similarly, dynamically sized enums are not supported as well).
- The lint for drop fields in unions can't work precisely before monomorphization, so it works pessimistically - non-`Copy` generic fields are reported, types not implementing `Drop` directly, but having non-trivial drop code are reported.

    ```
    struct S(String); // Doesn't implement `Drop`
    union U<T> {
        a: S, // Reported
        b: T, // Reported
    }
    ```

- #35764 was indeed helpful and landed timely, I didn't have to implement internal drop flags for unions.
- Unions are not permitted in constant patterns, because matching on union fields is unsafe, I didn't want unsafety checker to dig into all constants to uncover this possible unsafety.
- The RFC doesn't talk about `#[derive]`, generally trait impls cannot be derived for unions, but some of them can. I implemented only `#[derive(Copy)]` so far. In theory shallow `#[derive(Clone)]` can be derived as well if all union fields are `Copy`, I left it for later though, it requires changing how `Clone` impls are generated.
- Moving union fields is implemented as per #32836 (comment).
- Testing strategy: union specific behavior is tested, sometimes very basically (e.g. debuginfo), behavior common for all ADTs (e.g. something like coherence
checks) is not generally tested.

r? @eddyb

@jethrogb jethrogb referenced this pull request in jethrogb/sgx-utils Sep 15, 2016

Closed

unsafe_no_drop_flag has been removed #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment