add dedicated type for ABI target feature constraints

This commit is contained in:
Ralf Jung 2025-01-05 10:34:33 +01:00
parent 43ede97ebf
commit 2e64b5352b
5 changed files with 45 additions and 31 deletions

View file

@ -669,9 +669,9 @@ pub(crate) fn global_llvm_features(
// Ensure that all ABI-required features are enabled, and the ABI-forbidden ones
// are disabled.
let (abi_enable, abi_disable) = sess.target.abi_required_features();
let abi_enable_set = FxHashSet::from_iter(abi_enable.iter().copied());
let abi_disable_set = FxHashSet::from_iter(abi_disable.iter().copied());
let abi_feature_constraints = sess.target.abi_required_features();
let abi_incompatible_set =
FxHashSet::from_iter(abi_feature_constraints.incompatible.iter().copied());
// Compute implied features
let mut all_rust_features = vec![];
@ -745,7 +745,7 @@ pub(crate) fn global_llvm_features(
// Ensure that the features we enable/disable are compatible with the ABI.
if enable {
if abi_disable_set.contains(feature) {
if abi_incompatible_set.contains(feature) {
sess.dcx().emit_warn(ForbiddenCTargetFeature {
feature,
enabled: "enabled",
@ -755,8 +755,7 @@ pub(crate) fn global_llvm_features(
} else {
// FIXME: we have to request implied features here since
// negative features do not handle implied features above.
#[allow(rustc::potential_query_instability)] // order does not matter
for &required in abi_enable_set.iter() {
for &required in abi_feature_constraints.required.iter() {
let implied =
sess.target.implied_target_features(std::iter::once(required));
if implied.contains(feature) {
@ -783,7 +782,11 @@ pub(crate) fn global_llvm_features(
// still override it... that's unsound, but more compatible with past behavior.
all_rust_features.splice(
0..0,
abi_enable.iter().map(|&f| (true, f)).chain(abi_disable.iter().map(|&f| (false, f))),
abi_feature_constraints
.required
.iter()
.map(|&f| (true, f))
.chain(abi_feature_constraints.incompatible.iter().map(|&f| (false, f))),
);
// Translate this into LLVM features.