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

Tracking Issue for naked_functions_target_feature #138568

Open
4 tasks
folkertdev opened this issue Mar 16, 2025 · 1 comment
Open
4 tasks

Tracking Issue for naked_functions_target_feature #138568

folkertdev opened this issue Mar 16, 2025 · 1 comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-naked_functions_target_feature `#![feature(naked_functions_target_feature)]` F-naked_functions `#![feature(naked_functions)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@folkertdev
Copy link
Contributor

folkertdev commented Mar 16, 2025

The feature gate for the issue is #![feature(naked_functions_target_feature)].

The #[target_feature(enable = "...")] attribute on standard functions can have two effects:

  1. change the ABI (e.g. how vector types are passed)
  2. change what instructions are accepted in the body (e.g. whether vector instructions are allowed)

At the time of writing, target_feature is ignored when generating code for naked functions even with this feature enabled! Hence, you almost certainly don't need to enable this feature.

If you need to change what instructions are accepted, you can use assembler directives in the naked assembly. See #137720 for examples on how to do that on the most common platforms.

For naked functions, a target_feature does not change the generated code of that function: naked functions must already assume that their registers are in particular registers, and can document assumptions about e.g. the use of vector registers as safety conditions on the naked function itself. Hence, the target feature is useful only as documentation, and currently not strictly needed. Note that there are plans to it a hard requirement that functions using vector types in their signature enable the relevant target features.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

Unresolved Questions

  • should we try to automatically handle target features at all?
  • if so, how do we deal with platforms where LLVM has no tools for toggling target features from inline assembly (e.g. wasm simd128)
  • and how do we deal with the complex interplay of target features with the (different versions of) the target platform (e.g. armv8 has very complex target features)

Implementation history

@folkertdev folkertdev added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Mar 16, 2025
@folkertdev
Copy link
Contributor Author

@rustbot label +A-naked +F-naked_functions

@rustbot rustbot added A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS F-naked_functions `#![feature(naked_functions)]` labels Mar 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2025
…eature-gate, r=Amanieu

add `naked_functions_target_feature` unstable feature

tracking issue: rust-lang#138568

tagging rust-lang#134213 rust-lang#90957

This PR puts `#[target_feature(/* ... */)]` on `#[naked]` functions behind its own feature gate, so that naked functions can be stabilized. It turns out that supporting `target_feature` on naked functions is tricky on some targets, so we're splitting it out to not block stabilization of naked functions themselves. See the tracking issue for more information and workarounds.

Note that at the time of writing, the `target_features` attribute is ignored when generating code for naked functions.

r? `@Amanieu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2025
…eature-gate, r=Amanieu

add `naked_functions_target_feature` unstable feature

tracking issue: rust-lang#138568

tagging rust-lang#134213 rust-lang#90957

This PR puts `#[target_feature(/* ... */)]` on `#[naked]` functions behind its own feature gate, so that naked functions can be stabilized. It turns out that supporting `target_feature` on naked functions is tricky on some targets, so we're splitting it out to not block stabilization of naked functions themselves. See the tracking issue for more information and workarounds.

Note that at the time of writing, the `target_features` attribute is ignored when generating code for naked functions.

r? ``@Amanieu``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 21, 2025
Rollup merge of rust-lang#138570 - folkertdev:naked-function-target-feature-gate, r=Amanieu

add `naked_functions_target_feature` unstable feature

tracking issue: rust-lang#138568

tagging rust-lang#134213 rust-lang#90957

This PR puts `#[target_feature(/* ... */)]` on `#[naked]` functions behind its own feature gate, so that naked functions can be stabilized. It turns out that supporting `target_feature` on naked functions is tricky on some targets, so we're splitting it out to not block stabilization of naked functions themselves. See the tracking issue for more information and workarounds.

Note that at the time of writing, the `target_features` attribute is ignored when generating code for naked functions.

r? ``@Amanieu``
@jieyouxu jieyouxu added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-attributes Area: Attributes (`#[…]`, `#![…]`) A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. labels Mar 22, 2025
@traviscross traviscross added the F-naked_functions_target_feature `#![feature(naked_functions_target_feature)]` label Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-naked_functions_target_feature `#![feature(naked_functions_target_feature)]` F-naked_functions `#![feature(naked_functions)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants