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

Handle targets with more than one family #44

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

sunshowers
Copy link
Contributor

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

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 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.

(I missed this while updating targets to 1.58 earlier, and discovered the issue while testing it out.)

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.
Comment on lines +96 to +118
#[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()
}
}
Copy link
Member

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.

Copy link
Contributor Author

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.

@Jake-Shadle Jake-Shadle self-requested a review February 4, 2022 10:31
Copy link
Member

@Jake-Shadle Jake-Shadle left a 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.

@Jake-Shadle Jake-Shadle merged commit 430f476 into EmbarkStudios:main Feb 4, 2022
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.

2 participants