-
Notifications
You must be signed in to change notification settings - Fork 16
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
Handle targets with more than one family #44
Conversation
Rust 1.58 introduces a couple of targets with multiple target families. To handle this, introduce a new `Families` newtype wrapper which can contain any number of families. Handle both the const case and the non-const one. Unfortunately this is an unavoidable breaking change to the `TargetInfo` data model.
#[inline] | ||
pub fn new(val: impl IntoIterator<Item = Family>) -> Self { | ||
let mut families: Vec<_> = val.into_iter().collect(); | ||
families.sort_unstable(); | ||
Self(Cow::Owned(families)) | ||
} | ||
|
||
/// Constructs a new instance of this field from a static slice of `&'static str`. | ||
/// | ||
/// `val` must be in sorted order: this constructor cannot check for that due to | ||
/// limitations in current versions of Rust. | ||
#[inline] | ||
pub const fn new_const(val: &'static [Family]) -> Self { | ||
// TODO: Check that val is sorted. | ||
Self(Cow::Borrowed(val)) | ||
} | ||
|
||
/// Returns true if this list of families contains a given family. | ||
pub fn contains(&self, val: &Family) -> bool { | ||
// This relies on the sorted-ness of its contents. | ||
self.0.binary_search(val).is_ok() | ||
} | ||
} |
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.
Given that the maximum for a reasonable target is 2, at least at this time, it feels like sorting/binary searching is unnecessary and should just be linear.
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! Note that while the binary searching is probably unnecessary, the sorting is not: incorrectly sorted lists will cause the Eq
, Hash
and Ord
implementations to behave incorrectly.
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 the PR! I'll just fix up some things and make a release.
Checklist
Description of Changes
Rust 1.58 introduces a couple of targets with multiple target families.
To handle this, introduce a new
Families
newtype wrapper which cancontain any number of families. Handle both the const case and the
non-const one.
Unfortunately this is an unavoidable breaking change to the
TargetInfo
data model.
(I missed this while updating targets to 1.58 earlier, and discovered the issue while testing it out.)