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

Can derive Eq #919

Merged
merged 12 commits into from
Aug 22, 2017
Merged

Can derive Eq #919

merged 12 commits into from
Aug 22, 2017

Conversation

photoszzt
Copy link
Contributor

Fix: #880 r? @fitzgen

@bors-servo
Copy link

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

@photoszzt
Copy link
Contributor Author

Just find out the documentation of Union of what trait can be derived:
https://github.com/petrochenkov/rfcs/blob/8f1a960844b6ae37ec19fd89d39355fa98b1bb2b/text/1444-union.md#unions-and-derive

Looks like this approach doesn't work for Eq on Union. I think it needs a separate analysis.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Looks pretty good!

Haven't gone through the tests yet, but found a handful of nitpicks below, so I'll leave the rest for once these things are addressed and once this is rebased to resolve the conflict.

Thanks!

trace!("constrain: {:?}", id);

if self.has_float.contains(&id) {
trace!(" already know it do not have array");
Copy link
Member

Choose a reason for hiding this comment

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

s/array/float/

let inner_ty = self.ctx.resolve_type(t).canonical_type(self.ctx);
match *inner_ty.kind() {
TypeKind::Float(..) |
TypeKind::Complex(..) => {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of directly inspecting the type, shouldn't this look at the incremental results?

if self.has_float.contains(&inner_ty) {
    return self.insert(id);
}

ConstrainResult::Same

An array of a struct that contains a float should not derive(Eq), right?

/// Compute whether the type has float.
fn compute_has_float(&mut self) {
assert!(self.has_float.is_none());
self.has_float = Some(analyze::<HasFloat>(self));
Copy link
Member

Choose a reason for hiding this comment

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

This should be conditionally computed depending on whichever options enable deriving something that depends on this information. Right now that is only self.options.derive_eq, right?

/// Look up whether the item with `id` has array or not.
pub fn lookup_item_id_has_float(&self, id: &ItemId) -> bool {
assert!(self.in_codegen_phase(),
"We only compute has array when we enter codegen");
Copy link
Member

Choose a reason for hiding this comment

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

s/array/float/

src/lib.rs Outdated
@@ -731,6 +735,12 @@ impl Builder {
self
}

/// Set whether `Eq` should be derived by default.
pub fn derive_eq(mut self, doit: bool) -> Self {
self.options.derive_eq = doit;
Copy link
Member

Choose a reason for hiding this comment

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

We can't compute derive(Eq) unless we're also doing derive(PartialEq), so if doit is true, then this method should also set that option to true, and the documentation should describe this behavior.

And inside derive_partial_eq(), if its parameter is false, then it should also set otions.derive_eq to false, and its doc comment should describe that behavior too.

src/options.rs Outdated
@@ -79,6 +79,9 @@ where
Arg::with_name("with-derive-partialeq")
.long("with-derive-partialeq")
.help("Derive partialeq on any type."),
Arg::with_name("with-derive-eq")
.long("with-derive-eq")
.help("Derive eq on any type."),
Copy link
Member

Choose a reason for hiding this comment

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

We should mention here that this also implies --with-derive-partialeq.

@bors-servo
Copy link

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

@fitzgen
Copy link
Member

fitzgen commented Aug 22, 2017

@photoszzt what's the status here? We talked a little on IRC and I don't remember the conclusions we came to... is this ready for final review and merging or is there outstanding work to be done?

@photoszzt
Copy link
Contributor Author

@fitzgen It's ready for review. The Eq on Union needs manual implementation of PartialEq which doesn't solve by this patch.

@fitzgen
Copy link
Member

fitzgen commented Aug 22, 2017

The Eq on Union needs manual implementation of PartialEq which doesn't solve by this patch.

And which presumably requires contextual/domain knowledge about the usage of the union. Ok.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@fitzgen
Copy link
Member

fitzgen commented Aug 22, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit ff9d000 has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit ff9d000 with merge 978b531...

bors-servo pushed a commit that referenced this pull request Aug 22, 2017
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing 978b531 to master...

@bors-servo bors-servo merged commit ff9d000 into rust-lang:master Aug 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants