Skip to content

Commit 43a9251

Browse files
authored
Merge pull request #7 from Amanieu/llvm-asm
Add llvm_asm! and deprecate asm!
2 parents 610a09d + 13065f5 commit 43a9251

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

rfcs/0000-llvm-asm.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
- Feature Name: `llvm_asm`
2+
- Start Date: 2019-12-31
3+
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000)
4+
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
5+
6+
# Summary
7+
[summary]: #summary
8+
9+
Deprecate the existing `asm!` macro and provide an identical one called
10+
`llvm_asm!`. The feature gate is also renamed from `asm` to `llvm_asm`.
11+
12+
# Motivation
13+
[motivation]: #motivation
14+
15+
This change frees up the `asm!` macro so that it can be used for the new
16+
`asm!` macro designed by the inline asm project group while giving existing
17+
users of `asm!` an easy way to keep their code working.
18+
19+
It may also be useful to have an inline asm implementation available
20+
(on nightly) for architectures that the new `asm!` macro does not support yet.
21+
22+
# Guide-level explanation
23+
[guide-level-explanation]: #guide-level-explanation
24+
25+
The Rust team is currently in the process of redesigning the `asm!` macro.
26+
You should replace all uses of `asm!` with `llvm_asm!` in your code to avoid breakage when the new `asm!` macro is implemented.
27+
28+
# Reference-level explanation
29+
[reference-level-explanation]: #reference-level-explanation
30+
31+
All references to `asm!` inside the compiler will be changed to refer to `llvm_asm!` instead.
32+
`asm!` will become a simple (deprecated) `macro_rules!` which redirects to `llvm_asm!`.
33+
The deprecation warning will advise users that the semantics of `asm!` will change in the future and invite them to use `llvm_asm!` instead.
34+
35+
# Drawbacks
36+
[drawbacks]: #drawbacks
37+
38+
This change may require people to change their code twice: first to `llvm_asm!`, and then to the new
39+
`asm!` macro once it is implemented.
40+
41+
# Rationale and alternatives
42+
[rationale-and-alternatives]: #rationale-and-alternatives
43+
44+
We could skip the deprecation period and perform the renaming at the same time the new `asm!` macro
45+
is implemented. However this is guaranteed to break a lot of code using nightly Rust at once without
46+
any transition period.
47+
48+
# Prior art
49+
[prior-art]: #prior-art
50+
51+
The D programming language also support 2 forms of inline assembly. The [first one][d-asm] provides an embedded DSL
52+
for inline assembly, which allows direct access to variables in scope and does not require the use of clobbers, but is only available on x86 and x86_64. The [second one][d-llvm-asm] is a raw interface to LLVM's internal inline assembly syntax, which is available on all architectures but only on the LDC backend.
53+
54+
[d-asm]: https://dlang.org/spec/iasm.html
55+
[d-llvm-asm]: https://wiki.dlang.org/LDC_inline_assembly_expressions
56+
57+
# Unresolved questions
58+
[unresolved-questions]: #unresolved-questions
59+
60+
- Should the deprecated `asm!` macro be under the `asm` or `llvm_asm` feature gate?
61+
62+
# Future possibilities
63+
[future-possibilities]: #future-possibilities
64+
65+
When the new `asm!` macro is implemented it will replace the current one. This
66+
will break anyone who has not yet transitioned their code to `llvm_asm!`. No
67+
silent miscompilations are expected since the operand separator will be changed
68+
from `:` to `,`, which will guarantee that any existing `asm!` invocations will
69+
fail with a syntax error with the new `asm!` macro.

0 commit comments

Comments
 (0)