Skip to content

Commit 71042b4

Browse files
committed
Auto merge of rust-lang#132880 - RalfJung:implied-features, r=workingjubilee
target_features: explain what exacty 'implied' means here
2 parents 3a258d1 + 2c7f3ba commit 71042b4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,23 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
344344
})
345345
{
346346
if enabled {
347+
// Also add all transitively implied features.
347348
features.extend(sess.target.implied_target_features(std::iter::once(feature)));
348349
} else {
350+
// Remove transitively reverse-implied features.
351+
349352
// We don't care about the order in `features` since the only thing we use it for is the
350353
// `features.contains` below.
351354
#[allow(rustc::potential_query_instability)]
352355
features.retain(|f| {
353-
// Keep a feature if it does not imply `feature`. Or, equivalently,
354-
// remove the reverse-dependencies of `feature`.
355-
!sess.target.implied_target_features(std::iter::once(*f)).contains(&feature)
356+
if sess.target.implied_target_features(std::iter::once(*f)).contains(&feature) {
357+
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
358+
// remove `f`. (This is the standard logical contraposition principle.)
359+
false
360+
} else {
361+
// We can keep `f`.
362+
true
363+
}
356364
});
357365
}
358366
}

compiler/rustc_target/src/target_features.rs

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ impl Stability {
9292
//
9393
// Stabilizing a target feature requires t-lang approval.
9494

95+
// If feature A "implies" feature B, then:
96+
// - when A gets enabled (via `-Ctarget-feature` or `#[target_feature]`), we also enable B
97+
// - when B gets disabled (via `-Ctarget-feature`), we also disable A
98+
//
99+
// Both of these are also applied transitively.
95100
type ImpliedFeatures = &'static [&'static str];
96101

97102
const ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[

0 commit comments

Comments
 (0)