1
Fork 0

Hide implicit target features from diagnostics when possible

This commit is contained in:
Caleb Zulawski 2024-08-04 23:51:59 -04:00
parent 6b96a60611
commit 83276f5680
16 changed files with 89 additions and 43 deletions

View file

@ -6,6 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::TargetFeature;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::parse::feature_err;
@ -18,7 +19,7 @@ pub fn from_target_feature(
tcx: TyCtxt<'_>,
attr: &ast::Attribute,
supported_target_features: &UnordMap<String, Option<Symbol>>,
target_features: &mut Vec<Symbol>,
target_features: &mut Vec<TargetFeature>,
) {
let Some(list) = attr.meta_item_list() else { return };
let bad_item = |span| {
@ -99,14 +100,27 @@ pub fn from_target_feature(
}));
}
// Add both explicit and implied target features, using a set to deduplicate
let mut target_features_set = UnordSet::new();
// Add explicit features
target_features.extend(
added_target_features.iter().copied().map(|name| TargetFeature { name, implied: false }),
);
// Add implied features
let mut implied_target_features = UnordSet::new();
for feature in added_target_features.iter() {
target_features_set
implied_target_features
.extend_unord(tcx.implied_target_features(*feature).clone().into_items());
}
target_features_set.extend(added_target_features);
target_features.extend(target_features_set.into_sorted_stable_ord())
for feature in added_target_features.iter() {
implied_target_features.remove(feature);
}
target_features.extend(
implied_target_features
.into_sorted_stable_ord()
.iter()
.copied()
.map(|name| TargetFeature { name, implied: true }),
)
}
/// Computes the set of target features used in a function for the purposes of
@ -115,7 +129,7 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet<Symbol> {
let mut target_features = tcx.sess.unstable_target_features.clone();
if tcx.def_kind(did).has_codegen_attrs() {
let attrs = tcx.codegen_fn_attrs(did);
target_features.extend(&attrs.target_features);
target_features.extend(attrs.target_features.iter().map(|feature| feature.name));
match attrs.instruction_set {
None => {}
Some(InstructionSetAttr::ArmA32) => {