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

nightly featuers: target-specific library features are painful #120930

Open
RalfJung opened this issue Feb 11, 2024 · 1 comment
Open

nightly featuers: target-specific library features are painful #120930

RalfJung opened this issue Feb 11, 2024 · 1 comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

In rust-lang/stdarch#1486, stdarch split up its one uber-feature into a lot of small ones. This led to some rather painful updates. portable-simd now needs code like this to compile:

#![cfg_attr(
    all(
        any(target_arch = "aarch64", target_arch = "arm",),
        any(
            all(target_feature = "v6", not(target_feature = "mclass")),
            all(target_feature = "mclass", target_feature = "dsp"),
        )
    ),
    feature(stdarch_arm_dsp)
)]
#![cfg_attr(
    all(target_arch = "arm", target_feature = "v7"),
    feature(stdarch_arm_neon_intrinsics)
)]
#![cfg_attr(
    any(target_arch = "powerpc", target_arch = "powerpc64"),
    feature(stdarch_powerpc)
)]

I think the main issue is that library features "exist" only if at least one item with that feature exists, so one has to very carefully put cfg_atrr around the feature to avoid "unknown feature" errors. std doesn't have many target-specific features so this is not usually a problem, but for stdarch it is. Additionally, feature attributes must be in lib.rs, so this can't be put inside the modules that actually import these functions -- those modules usually are cfgd, but instead of reusing those cfg we have to repeat them.

Not sure what one could do about this. rustc could ignore unknown features, but that doesn't seem great. Maybe stdarch should have a way to "declare" feature to exist even if no item in the current configuration actually carries that feature? Then portable-simd could just do #![feature(stdarch_arm_dsp, stdarch_arm_neon_intrinsics, stdarch_powerpc)] which would be a lot better.

As a crude hack stdarch could have some "dummy item" for each feature that always exists on all targets, therefore bringing the library feature into existence and letting others enable it in a cfg-independent way.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@Mark-Simulacrum
Copy link
Member

Cc @Amanieu

The dummy items in crate root (probably doc(hidden)) feels like a very reasonable approach.

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants