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 release notes of #128570: Stabilize asm_const #129569

Closed
1 of 4 tasks
rustbot opened this issue Aug 25, 2024 · 7 comments
Closed
1 of 4 tasks

Tracking issue for release notes of #128570: Stabilize asm_const #129569

rustbot opened this issue Aug 25, 2024 · 7 comments
Labels
I-release-nominated Nominated for the release team. relnotes Marks issues that should be documented in the release notes of the next release. relnotes-tracking-issue Marks issues tracking what text to put in release notes. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Milestone

Comments

@rustbot
Copy link
Collaborator

rustbot commented Aug 25, 2024

This issue tracks the release notes text for #128570.

  • Issue is nominated for the responsible team (and T-release nomination is removed).
  • Proposed text is drafted by team responsible for underlying change.
  • Issue is nominated for release team review of clarity for wider audience.
  • Release team includes text in release notes/blog posts.

Release notes text:

The section title will be de-duplicated by the release team with other release notes issues.
Prefer to use the standard titles from previous releases.
More than one section can be included if needed.

# Language
- [Stabilize `const` operands in inline assembly](https://github.com/rust-lang/rust/pull/128570)

Release blog section (if any, leave blank if no section is expected):

# Constants as assembly immediates

The `const` assembly operand now provides a way to use integers as immediates
without first storing them in a register. As an example, we implement a syscall to
[`write`](https://man7.org/linux/man-pages/man2/write.2.html) by hand: 

```rust
const WRITE_SYSCALL: c_int = 0x01; // syscall 1 is `write`
const STDOUT_HANDLE: c_int = 0x01; // `stdout` has file handle 1
const MSG: &str = "Hello, world!\n";

let written: usize;

// Signature: `ssize_t write(int fd, const void buf[], size_t count)`
unsafe {
    core::arch::asm!(
        "mov rax, {SYSCALL} // rax holds the syscall number",
        "mov rdi, {OUTPUT}  // rdi is `fd` (first argument)",
        "mov rdx, {LEN}     // rdx is `count` (third argument)",
        "syscall            // invoke the syscall",
        "mov {written}, rax // save the return value",
        SYSCALL = const WRITE_SYSCALL,
        OUTPUT = const STDOUT_HANDLE,
        LEN = const MSG.len(),
        in("rsi") MSG.as_ptr(), // rsi is `buf *` (second argument)
        written = out(reg) written,
    );
}

assert_eq!(written, MSG.len());
```

Output:

```text
Hello, world!
```

[Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0cf8e21335b38011b49156c6c65929bc).

In the above, a statement such as `LEN = const MSG.len()` populates the format
specifier `LEN` with an immediate that takes the value of `MSG.len()`. This can be seen
in the generated assembly (the value is `14`):

```asm
lea     rsi, [rip + .L__unnamed_3]
mov     rax, 1    # rax holds the syscall number
mov     rdi, 1    # rdi is `fd` (first argument)
mov     rdx, 14   # rdx is `count` (third argument)
syscall # invoke the syscall
mov     rax, rax  # save the return value
```

See [the reference](https://doc.rust-lang.org/reference/inline-assembly.html)
for more details.
@rustbot rustbot added I-release-nominated Nominated for the release team. relnotes Marks issues that should be documented in the release notes of the next release. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 25, 2024
@Mark-Simulacrum Mark-Simulacrum added I-lang-nominated Nominated for discussion during a lang team meeting. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-release-nominated Nominated for the release team. labels Aug 25, 2024
@Mark-Simulacrum Mark-Simulacrum added this to the 1.82.0 milestone Aug 25, 2024
@traviscross
Copy link
Contributor

traviscross commented Aug 28, 2024

@folkertdev, @Amanieu, @tgross35: Any thoughts for this?

cc @rust-lang/lang

@tgross35
Copy link
Contributor

tgross35 commented Aug 28, 2024

What exactly is needed here? I don't think there is a need for anything special, unless this merits a small demo in the blog post.

@Mark-Simulacrum
Copy link
Member

At minimum, I would expect that the release notes section is updated to provide a 1-sentence description of the feature in human language, not just referencing the feature gate name.

@tgross35
Copy link
Contributor

Okay - so the issue needs to be edited to replace the "Stabilize xxx" link with a description? It isn't clear from the top post what is actually expected to happen.

I'm also not sure why it shows up under "# Compatibility Notes" rather than "# Language", unless that is also expected to be adjusted.

@Mark-Simulacrum
Copy link
Member

Yes, the section title is arbitrary (I'll look at modifying that for future with something more obvious like EDIT ME), and should be adjusted by the team.

Do you have a suggestion on how to make the request clearer? I'm happy (and probably best to) take that offline / to zulip.

@tgross35
Copy link
Contributor

Okay, that makes sense. Rustbot could probably add more or less what you said here to the top post, a la "Edit this section to replace the automatically generated link with a succinct description of what changed. If the change is notable enough for inclusion in the blog post, add a section there.".

(I like this idea btw)

@traviscross
Copy link
Contributor

@tgross35: It'd be good to write up a blog post section for this. It's a notable user-facing feature. If there happens to be an RfL use case for this (as there is for asm_goto), it might be interesting to briefly mention that so as to advertise that ongoing collaboration a bit.

Here's a good example of such a section:

@Mark-Simulacrum Mark-Simulacrum added the relnotes-tracking-issue Marks issues tracking what text to put in release notes. label Sep 6, 2024
@traviscross traviscross added T-lang Relevant to the language team, which will review and decide on the PR/issue. relnotes Marks issues that should be documented in the release notes of the next release. I-release-nominated Nominated for the release team. relnotes-tracking-issue Marks issues tracking what text to put in release notes. and removed relnotes Marks issues that should be documented in the release notes of the next release. I-lang-nominated Nominated for discussion during a lang team meeting. relnotes-tracking-issue Marks issues tracking what text to put in release notes. labels Sep 24, 2024
@cuviper cuviper closed this as completed Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-release-nominated Nominated for the release team. relnotes Marks issues that should be documented in the release notes of the next release. relnotes-tracking-issue Marks issues tracking what text to put in release notes. 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

5 participants