-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Tweaks to equality comparisons for slices/arrays/vectors #22320
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Utility macros for implementing PartialEq on slice-like types | ||
|
||
#![doc(hidden)] | ||
|
||
#[macro_export] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this macro wants to be marked with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The macros are defined in libcore and used in libcollection. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, good point! Carry on then! |
||
macro_rules! __impl_slice_eq1 { | ||
($Lhs: ty, $Rhs: ty) => { | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, 'b, A, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> { | ||
#[inline] | ||
fn eq(&self, other: &$Rhs) -> bool { &self[..] == &other[..] } | ||
#[inline] | ||
fn ne(&self, other: &$Rhs) -> bool { &self[..] != &other[..] } | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! __impl_slice_eq2 { | ||
($Lhs: ty, $Rhs: ty) => { | ||
__impl_slice_eq2! { $Lhs, $Rhs, Sized } | ||
}; | ||
($Lhs: ty, $Rhs: ty, $Bound: ident) => { | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> { | ||
#[inline] | ||
fn eq(&self, other: &$Rhs) -> bool { &self[..] == &other[..] } | ||
#[inline] | ||
fn ne(&self, other: &$Rhs) -> bool { &self[..] != &other[..] } | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, 'b, A: $Bound, B> PartialEq<$Lhs> for $Rhs where B: PartialEq<A> { | ||
#[inline] | ||
fn eq(&self, other: &$Lhs) -> bool { &self[..] == &other[..] } | ||
#[inline] | ||
fn ne(&self, other: &$Lhs) -> bool { &self[..] != &other[..] } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried about the impact this has on the metadata, this seems like a huge number of implementations being thrown in, not all of which are really that necessary. Can you make sure we're not blowing up the metadata by a few megabytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just by comparing the sizes of produced rlibs before and after or is there a smarter way to compare rlibs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcrichton
Sadly, the bloat is significant.
libcore: 36MB -> 39MB
libcollections: 11MB -> 18MB (15MB without
CowVec
impls)Besides, if I purge libcore/array.rs completely, then libcore.rlib loses another 6MB and becomes 30MB.
That's one more reason, why we need something like this sooner.
I think the reasonable subsequent actions would be:
Then the bloat should be tolerable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yeah this is quite unfortunate how big a blowup this is (11MB => 18MB is huge!). I suspect there is a huge trove of optimizations that we could exploit for metadata layout, but unfortunately it will take time to examine.
I think that your proposed sequence of actions should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(thanks for analyzing by the way!)
Also, for the future, I analyze metadata by running
ar x libfoo.rlib
and then looking atrust.metadata.bin
to see how big it is.