Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
traviscross commentedon Aug 28, 2024
@folkertdev, @Amanieu, @tgross35: Any thoughts for this?
cc @rust-lang/lang
tgross35 commentedon 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 commentedon Aug 28, 2024
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 commentedon Aug 28, 2024
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 commentedon Aug 28, 2024
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 commentedon Aug 28, 2024
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 commentedon Aug 28, 2024
@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: