Simplify implied_target_features
.
Currently its argument is an iterator, but in practice it's always a singleton.
This commit is contained in:
parent
1df93fd6a7
commit
2df8e657f2
4 changed files with 10 additions and 12 deletions
|
@ -48,7 +48,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
|
||||||
for feature in sess.opts.cg.target_feature.split(',') {
|
for feature in sess.opts.cg.target_feature.split(',') {
|
||||||
if let Some(feature) = feature.strip_prefix('+') {
|
if let Some(feature) = feature.strip_prefix('+') {
|
||||||
all_rust_features.extend(
|
all_rust_features.extend(
|
||||||
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
|
UnordSet::from(sess.target.implied_target_features(feature))
|
||||||
.to_sorted_stable_ord()
|
.to_sorted_stable_ord()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&&s| (true, s)),
|
.map(|&&s| (true, s)),
|
||||||
|
|
|
@ -360,7 +360,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
|
||||||
#[allow(rustc::potential_query_instability)]
|
#[allow(rustc::potential_query_instability)]
|
||||||
features.extend(
|
features.extend(
|
||||||
sess.target
|
sess.target
|
||||||
.implied_target_features(std::iter::once(feature.as_str()))
|
.implied_target_features(feature.as_str())
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| Symbol::intern(s)),
|
.map(|s| Symbol::intern(s)),
|
||||||
);
|
);
|
||||||
|
@ -373,7 +373,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
|
||||||
features.retain(|f| {
|
features.retain(|f| {
|
||||||
if sess
|
if sess
|
||||||
.target
|
.target
|
||||||
.implied_target_features(std::iter::once(f.as_str()))
|
.implied_target_features(f.as_str())
|
||||||
.contains(&feature.as_str())
|
.contains(&feature.as_str())
|
||||||
{
|
{
|
||||||
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
|
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
|
||||||
|
@ -681,7 +681,7 @@ pub(crate) fn global_llvm_features(
|
||||||
for feature in sess.opts.cg.target_feature.split(',') {
|
for feature in sess.opts.cg.target_feature.split(',') {
|
||||||
if let Some(feature) = feature.strip_prefix('+') {
|
if let Some(feature) = feature.strip_prefix('+') {
|
||||||
all_rust_features.extend(
|
all_rust_features.extend(
|
||||||
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
|
UnordSet::from(sess.target.implied_target_features(feature))
|
||||||
.to_sorted_stable_ord()
|
.to_sorted_stable_ord()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&&s| (true, s)),
|
.map(|&&s| (true, s)),
|
||||||
|
|
|
@ -190,7 +190,7 @@ pub(crate) fn provide(providers: &mut Providers) {
|
||||||
},
|
},
|
||||||
implied_target_features: |tcx, feature: Symbol| {
|
implied_target_features: |tcx, feature: Symbol| {
|
||||||
let feature = feature.as_str();
|
let feature = feature.as_str();
|
||||||
UnordSet::from(tcx.sess.target.implied_target_features(std::iter::once(feature)))
|
UnordSet::from(tcx.sess.target.implied_target_features(feature))
|
||||||
.into_sorted_stable_ord()
|
.into_sorted_stable_ord()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| Symbol::intern(s))
|
.map(|s| Symbol::intern(s))
|
||||||
|
|
|
@ -768,17 +768,15 @@ impl Target {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn implied_target_features<'a>(
|
// Note: the returned set includes `base_feature`.
|
||||||
&self,
|
pub fn implied_target_features<'a>(&self, base_feature: &'a str) -> FxHashSet<&'a str> {
|
||||||
base_features: impl Iterator<Item = &'a str>,
|
|
||||||
) -> FxHashSet<&'a str> {
|
|
||||||
let implied_features =
|
let implied_features =
|
||||||
self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
|
self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
// implied target features have their own implied target features, so we traverse the
|
// Implied target features have their own implied target features, so we traverse the
|
||||||
// map until there are no more features to add
|
// map until there are no more features to add.
|
||||||
let mut features = FxHashSet::default();
|
let mut features = FxHashSet::default();
|
||||||
let mut new_features = base_features.collect::<Vec<&str>>();
|
let mut new_features = vec![base_feature];
|
||||||
while let Some(new_feature) = new_features.pop() {
|
while let Some(new_feature) = new_features.pop() {
|
||||||
if features.insert(new_feature) {
|
if features.insert(new_feature) {
|
||||||
if let Some(implied_features) = implied_features.get(&new_feature) {
|
if let Some(implied_features) = implied_features.get(&new_feature) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue