|
| 1 | +- Feature Name: `llvm_asm` |
| 2 | +- Start Date: 2019-12-31 |
| 3 | +- RFC PR: [rust-lang/rfcs#2843](https://github.com/rust-lang/rfcs/pull/2843) |
| 4 | +- Rust Issue: [rust-lang/rust#70173](https://github.com/rust-lang/rust/issues/70173) |
| 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 | +Unlike `asm!`, `llvm_asm!` is not intended to ever become stable. |
| 13 | + |
| 14 | +# Motivation |
| 15 | +[motivation]: #motivation |
| 16 | + |
| 17 | +This change frees up the `asm!` macro so that it can be used for the new |
| 18 | +`asm!` macro designed by the inline asm project group while giving existing |
| 19 | +users of `asm!` an easy way to keep their code working. |
| 20 | + |
| 21 | +It may also be useful to have an inline asm implementation available |
| 22 | +(on nightly) for architectures that the new `asm!` macro does not support yet. |
| 23 | + |
| 24 | +# Guide-level explanation |
| 25 | +[guide-level-explanation]: #guide-level-explanation |
| 26 | + |
| 27 | +The Rust team is currently in the process of redesigning the `asm!` macro. |
| 28 | +You should replace all uses of `asm!` with `llvm_asm!` in your code to avoid breakage when the new `asm!` macro is implemented. |
| 29 | + |
| 30 | +# Reference-level explanation |
| 31 | +[reference-level-explanation]: #reference-level-explanation |
| 32 | + |
| 33 | +All references to `asm!` inside the compiler will be changed to refer to `llvm_asm!` instead. |
| 34 | +`asm!` will become a simple (deprecated) `macro_rules!` which redirects to `llvm_asm!`. |
| 35 | +The deprecation warning will advise users that the semantics of `asm!` will change in the future and invite them to use `llvm_asm!` instead. The `llvm_asm!` macro will be guarded by the `llvm_asm` feature gate. |
| 36 | + |
| 37 | +# Drawbacks |
| 38 | +[drawbacks]: #drawbacks |
| 39 | + |
| 40 | +This change may require people to change their code twice: first to `llvm_asm!`, and then to the new |
| 41 | +`asm!` macro once it is implemented. |
| 42 | + |
| 43 | +# Rationale and alternatives |
| 44 | +[rationale-and-alternatives]: #rationale-and-alternatives |
| 45 | + |
| 46 | +We could skip the deprecation period and perform the renaming at the same time the new `asm!` macro |
| 47 | +is implemented. However this is guaranteed to break a lot of code using nightly Rust at once without |
| 48 | +any transition period. |
| 49 | + |
| 50 | +# Prior art |
| 51 | +[prior-art]: #prior-art |
| 52 | + |
| 53 | +The D programming language also support 2 forms of inline assembly. The [first one][d-asm] provides an embedded DSL |
| 54 | +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. |
| 55 | + |
| 56 | +[d-asm]: https://dlang.org/spec/iasm.html |
| 57 | +[d-llvm-asm]: https://wiki.dlang.org/LDC_inline_assembly_expressions |
| 58 | + |
| 59 | +# Unresolved questions |
| 60 | +[unresolved-questions]: #unresolved-questions |
| 61 | + |
| 62 | +None |
| 63 | + |
| 64 | +# Future possibilities |
| 65 | +[future-possibilities]: #future-possibilities |
| 66 | + |
| 67 | +When the [new `asm!` macro][inline-asm-rfc] is implemented it will replace the current one. This |
| 68 | +will break anyone who has not yet transitioned their code to `llvm_asm!`. No |
| 69 | +silent miscompilations are expected since the operand separator will be changed |
| 70 | +from `:` to `,`, which will guarantee that any existing `asm!` invocations will |
| 71 | +fail with a syntax error with the new `asm!` macro. |
| 72 | + |
| 73 | +[inline-asm-rfc]: https://github.com/rust-lang/rfcs/pull/2873 |
0 commit comments