Skip to content

Implement asm! interpolate#156719

Open
daxpedda wants to merge 1 commit into
rust-lang:mainfrom
daxpedda:asm-interpolate
Open

Implement asm! interpolate#156719
daxpedda wants to merge 1 commit into
rust-lang:mainfrom
daxpedda:asm-interpolate

Conversation

@daxpedda
Copy link
Copy Markdown
Contributor

@daxpedda daxpedda commented May 18, 2026

This adds a new operator to inline ASM: interpolate, which allows you to pass const strings verbatim into the assembly.

As this would be a new language feature, it will require going through an RFC or similar.

Resolves #132083.

r? @Amanieu.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 18, 2026
Comment on lines +182 to +184
mir::ConstValue::Slice { alloc_id, meta } => {
(alloc_id, alloc_range(Size::ZERO, Size::from_bytes(meta)))
}
Copy link
Copy Markdown
Contributor Author

@daxpedda daxpedda May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to actually trigger this.
If this really can't happen we should remove it.

View changes since the review

Comment on lines +205 to +216
let Ok(interpret::Scalar::Ptr(ptr, _)) = ptr else {
span_bug!(
sp,
"expected Ptr in ScalarPair for promoted asm interpolate, but got {ptr:#?}",
)
};
let Ok(interpret::Scalar::Int(size)) = size else {
span_bug!(
sp,
"expected Int in ScalarPair for promoted asm interpolate, but got {size:#?}",
)
};
Copy link
Copy Markdown
Contributor Author

@daxpedda daxpedda May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is overkill. Happy to just unwrap() + unreachable!() if it actually makes sense. I assume at least the interpret::Scalar variant could be behind an unreachable!() because we check the initial abi::Scalar above.

View changes since the review

@daxpedda daxpedda marked this pull request as ready for review May 18, 2026 17:25
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

The GCC codegen subtree was changed

cc @antoyo, @GuillaumeGomez

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

The Clippy subtree was changed

cc @rust-lang/clippy

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @vakaras

The Cranelift subtree was changed

cc @bjorn3

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 18, 2026
Comment thread compiler/rustc_feature/src/unstable.rs Outdated
/// Target features on arm.
(unstable, arm_target_feature, "1.27.0", Some(150246)),
/// Enables experimental inline assembly support for the `interpolate` operator.
(unstable, asm_interpolate, "CURRENT_RUSTC_VERSION", None),
Copy link
Copy Markdown
Contributor Author

@daxpedda daxpedda May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving this here so we don't forget replacing the tracking issue with the actual one when we are ready.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for const string interpolation into inline assembly

4 participants