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

cleanups and fixes for #[derive] #32139

Closed
wants to merge 9 commits into from
Closed

Conversation

durka
Copy link
Contributor

@durka durka commented Mar 8, 2016

This contains a bunch of little cleanups and fixes to #[derive]. There are more extensive comments on each individual commit.

  • hygiene cleanups
  • use discriminant_value instead of variant index in #[derive(Hash)]
  • don't move out of borrowed content in #[derive(PartialOrd, PartialEq)]
  • use intrinsics::unreachable() instead of unreachable!()

I don't believe there are any breaking changes in here, but I do want some more eyes on that.

Fixes #2810 (!), I believe (we still assume that "std" or "core" is the standard library but so does the rest of rustc...).
Fixes #21714 (cc @apasel422).
Fixes (postponed) #24047 (cc @withoutboats @bluss).
Fixes #31714 (cc @alexcrichton @bluss).
Fixes #31886 (cc @oli-obk).

@durka
Copy link
Contributor Author

durka commented Mar 9, 2016

High five? No high five? ✋ 😿

r? @alexcrichton

@bors
Copy link
Contributor

bors commented Mar 9, 2016

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

@durka
Copy link
Contributor Author

durka commented Mar 9, 2016

The failing test is here and I don't really know how to interpret it. I guess the &s I added to the output of #[derive(PartialEq)] affected the monomorphizations that trans had to generate?

@bluss
Copy link
Member

bluss commented Mar 9, 2016

I think that issue (#24047) should not be worked around in derive but it may be fixed directly instead.

@durka
Copy link
Contributor Author

durka commented Mar 9, 2016

I can back out that commit and leave it for later.

On Tue, Mar 8, 2016 at 10:59 PM, bluss notifications@github.com wrote:

I think that issue (#24047
#24047) should not be worked
around in derive but it may be fixed directly instead.


Reply to this email directly or view it on GitHub
#32139 (comment).

let eq = cx.expr_binary(span,
BinOpKind::Ne,
cx.expr_addr_of(span, self_f),
cx.expr_addr_of(span, other_f.clone()));
Copy link
Member

Choose a reason for hiding this comment

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

In the past we've had subtle bugs where fields didn't actually implement some trait you were deriving but it worked anyway, so I'm curious why the extra & is needed here? In theory that should all happen automatically, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because of this: http://is.gd/Dgj5u2

Copy link
Member

Choose a reason for hiding this comment

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

Hm I'm somewhat confused, each of those lines works independently? Perhaps this is a case where UFCS should be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah maybe we should use UFCS in the derive expansion, but there's a deeper issue (which is why @bluss suggested not working around it here)... line 17 should be exactly the same as line 19, right?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps yeah? I'm not too familiar with auto-ref and how that works

@alexcrichton
Copy link
Member

Fixes #24047

Wait this is an issue that can be fixed? PartialEq isn't object safe?

@alexcrichton
Copy link
Member

Oh then I keep reading and realize it's PartialEq for Trait...

@bluss
Copy link
Member

bluss commented Mar 9, 2016

Yes it can be fixed. The code snippet I showed in that issue is a bug that's independent of derive itself.

@alexcrichton alexcrichton self-assigned this Mar 10, 2016
@durka
Copy link
Contributor Author

durka commented Mar 10, 2016

OK I addressed the comments and removed the two commits related to #24047 (don't worry I still have them in another branch!). Let's see if it builds!

@@ -8,32 +8,33 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rand, collections, rustc_private)]
#![no_std]
// no-prefer-dynamic
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the record I have no idea what this does, but without it it asks for the lang items (even though this is supposed to be a lib).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah building a dylib requires lang items to be resolved, but as an rlib (what no-prefer-dynamic asks for) means that they can stay dangling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It already says #![crate_type = "rlib"] though.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but that's ignored as --crate-type dylib is passed on the command line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I'll take that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually #![crate_type = "rlib"] and // no-prefer-dynamic are required for it not to try and resolve the lang items.

@durka durka force-pushed the derive-fix branch 2 times, most recently from 3831056 to 47900e6 Compare March 10, 2016 06:55
/// Construct a name for the inner type parameter that can't collide with any type parameters of
/// the item. This is achieved by starting with a base and then concatenating the names of all
/// other type parameters.
fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this may want to continue to have a FIXME for doing something "more correct" here, this seems like it's still kinda a hack to get the job done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a hack yes (but a better one than before IMO). I'll add a FIXME.

@alexcrichton
Copy link
Member

Thanks @durka! Just a comment to be added I think but other than that looks good to me.

@durka
Copy link
Contributor Author

durka commented Mar 10, 2016

Added the FIXME comment.

@durka
Copy link
Contributor Author

durka commented Mar 10, 2016

cc @talchas

The #31886 test was going to fail on 32-bit platforms because I changed it from assuming i32 to assuming isize but that's no different. Now it assumes i64. Hopefully this has little to no impact on codegen? (I don't expect so because discriminant_value returns u64 already.)

@alexcrichton
Copy link
Member

@bors: r+ 8cccdd0

Thanks!

bors added a commit that referenced this pull request Mar 13, 2016
cleanups and fixes for #[derive]

This contains a bunch of little cleanups and fixes to `#[derive]`. There are more extensive comments on each individual commit.

- hygiene cleanups
- use `discriminant_value` instead of variant index in `#[derive(Hash)]`
- ~~don't move out of borrowed content in `#[derive(PartialOrd, PartialEq)]`~~
- use `intrinsics::unreachable()` instead of `unreachable!()`

I don't believe there are any breaking changes in here, but I do want some more eyes on that.

Fixes #2810 (!), I believe (we still assume that "std" or "core" is the standard library but so does the rest of rustc...).
Fixes #21714 (cc @apasel422).
~~Fixes~~ (postponed) #24047 (cc @withoutboats @bluss).
Fixes #31714 (cc @alexcrichton @bluss).
Fixes #31886 (cc @oli-obk).
@bors
Copy link
Contributor

bors commented Mar 13, 2016

💔 Test failed - auto-mac-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Sun, Mar 13, 2016 at 12:24 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-mac-32-opt
http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/8396


Reply to this email directly or view it on GitHub
#32139 (comment).

@bors
Copy link
Contributor

bors commented Mar 13, 2016

⌛ Testing commit a037073 with merge fb9b646...

@alexcrichton
Copy link
Member

@bors: retry force

@bors
Copy link
Contributor

bors commented Mar 13, 2016

⌛ Testing commit a037073 with merge afacbfd...

@bors
Copy link
Contributor

bors commented Mar 13, 2016

💔 Test failed - auto-mac-32-opt

@durka
Copy link
Contributor Author

durka commented Mar 14, 2016

Okay what the heck is going on.

@eddyb
Copy link
Member

eddyb commented Mar 14, 2016

@bors retry

@bors
Copy link
Contributor

bors commented Mar 14, 2016

⌛ Testing commit a037073 with merge 97339bc...

@bors
Copy link
Contributor

bors commented Mar 14, 2016

💔 Test failed - auto-mac-32-opt

@durka
Copy link
Contributor Author

durka commented Mar 14, 2016

This is starting to seem legitimate just by repetition! I'm thinking I
should close this and resubmit the fixes individually to see which one
isn't harmless.
On Mar 14, 2016 08:44, "bors" notifications@github.com wrote:

[image: 💔] Test failed - auto-mac-32-opt
http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/8406


Reply to this email directly or view it on GitHub
#32139 (comment).

@alexcrichton
Copy link
Member

Something seems to be getting oddly mixed up as it's referencing stage1 dylibs? Probably couldn't hurt to break apart though I guess?

@durka durka closed this Mar 14, 2016
bors added a commit that referenced this pull request Mar 15, 2016
derive: use intrinsics::unreachable over unreachable!()

derive: use intrinsics::unreachable over unreachable!()

Fixes #31574.

Spawned from #32139.

r? @alexcrichton
bors added a commit that referenced this pull request Mar 15, 2016
derive: clean up hygiene

derive: clean up hygiene

Fixes #2810.

Spawned from #32139.

r? @alexcrichton
bors added a commit that referenced this pull request Mar 22, 2016
derive: assume enum repr defaults to isize

derive: assume enum repr defaults to isize

Fixes #31886.

Spawned from #32139.

r? @alexcrichton
bors added a commit that referenced this pull request Mar 27, 2016
derive: use discriminant_value in #[derive(Hash)]

derive: use discriminant_value in #[derive(Hash)]

Fixes #21714.

Spawned from #32139.

r? @alexcrichton
bors added a commit that referenced this pull request Mar 27, 2016
derive: use discriminant_value in #[derive(Hash)]

derive: use discriminant_value in #[derive(Hash)]

Fixes #21714.

Spawned from #32139.

r? @alexcrichton
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 27, 2016
derive: use discriminant_value in #[derive(Hash)]

derive: use discriminant_value in #[derive(Hash)]

Fixes rust-lang#21714.

Spawned from rust-lang#32139.

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants