Skip to content

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

Closed
@rustbot

Description

@rustbot
Collaborator

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.

Activity

added
relnotesMarks issues that should be documented in the release notes of the next release.
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 25, 2024
added
I-lang-nominatedNominated for discussion during a lang team meeting.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 25, 2024
added this to the 1.82.0 milestone on Aug 25, 2024
traviscross

traviscross commented on Aug 28, 2024

@traviscross
Contributor

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

cc @rust-lang/lang

tgross35

tgross35 commented on Aug 28, 2024

@tgross35
Contributor

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

Mark-Simulacrum commented on Aug 28, 2024

@Mark-Simulacrum
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

tgross35 commented on Aug 28, 2024

@tgross35
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

Mark-Simulacrum commented on Aug 28, 2024

@Mark-Simulacrum
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

tgross35 commented on Aug 28, 2024

@tgross35
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

traviscross commented on Aug 28, 2024

@traviscross
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:

added
T-langRelevant to the language team
relnotesMarks issues that should be documented in the release notes of the next release.
relnotes-tracking-issueMarks issues tracking what text to put in release notes.
and removed
relnotesMarks issues that should be documented in the release notes of the next release.
I-lang-nominatedNominated for discussion during a lang team meeting.
relnotes-tracking-issueMarks issues tracking what text to put in release notes.
on Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-release-nominatedNominated for the release team.T-langRelevant to the language teamrelnotesMarks issues that should be documented in the release notes of the next release.relnotes-tracking-issueMarks issues tracking what text to put in release notes.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cuviper@traviscross@Mark-Simulacrum@tgross35@rustbot

        Issue actions

          Tracking issue for release notes of #128570: Stabilize `asm_const` · Issue #129569 · rust-lang/rust