-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespace the asm!
macro
#84019
Comments
Strongly support I find the kind of issue discussed in "3. Error reporting in the event of unguarded asm: having arch::asm" to be determinative. I'm less worried about error reporting, though, than about having something accidentally cleanly assemble with different semantics because of the wrong architecture. I have an example lying around somewhere in the issue tracker that will assemble for both |
Another approach is to have arch-specific implementations in separate modules where the whole module is cfg'd, so you can use regular imports inside. |
When you write |
Yes, this would technically live in |
I'd like to see it in |
I don't think this is actually a requirement; |
Oh another think I think it probably does make sense to have them in |
Note that there is also an extensive Zulip thread where discussion is taking place: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/namespacing.20.60asm!.60 |
As a somewhat tangential benefit to namespacing |
One thing worth keeping in mind is that this decision may influence future macro namespacing. Consider these unstable macros:
It would be a bit of a reach to suggest that these macros are universal enough that they need to live in the prelude; they really ought to be namespaced. But should they be namespaced under |
Now that an QuestionShould the The most important fundamental difference between these two is that the first does not strictly require the user to have any Whatever is decided for Option 1: one public item,
|
We discussed this in today's @rust-lang/libs-api meeting. Our consensus was to put We felt that per-arch paths for it would not provide substantive protection for the issues that are more likely to arise in practice; it addresses the mixing of top-level architectures, but does not address architecture variants that aren't reflected in @bstrie plans to send in a PR that moves (Thank you to @bstrie for the detailed summary of the alternatives and tradeoffs.) |
Fixes: daily-co#2 For reference: Namespace the asm! macro: rust-lang/rust#84019 Stablization of the asm! macro: https://github.com/rust-lang/reference/blob/cf3a28145e06a3294/src/inline-assembly.md https://phip1611.de/blog/include-assembler-source-files-in-rust-project-and-build-with-cargo
The macros are now namespaced: rust-lang/rust#84019
The macros are now namespaced: rust-lang/rust#84019 In addition, llvm_asm was removed.
The macros are now namespaced: rust-lang/rust#84019 In addition, llvm_asm was removed.
The macros are now namespaced: rust-lang/rust#84019 In addition, llvm_asm was removed.
Fixes: #2 For reference: Namespace the asm! macro: rust-lang/rust#84019 Stablization of the asm! macro: https://github.com/rust-lang/reference/blob/cf3a28145e06a3294/src/inline-assembly.md https://phip1611.de/blog/include-assembler-source-files-in-rust-project-and-build-with-cargo
This commit removes the feature attribute asm and add a namespace for the usage of the asm macro. Refs: rust-lang/rust#84019 Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit removes the feature attribute asm and add a namespace for the usage of the asm macro. Currently the following build error is generated when using rustc 1.66.0-nightly (c0983a9aa 2022-10-12): $ cargo b Compiling drogue-boot v0.1.2 (/iot/drogue/drogue-boot) error: cannot find macro `asm` in this scope --> src/lib.rs:100:9 | 100 | asm! { | ^^^ | = note: consider importing this macro: core::arch::asm warning: the feature `asm` has been stable since 1.59.0 and no longer requires an attribute to enable --> src/lib.rs:4:12 | 4 | #![feature(asm)] | ^^^ | = note: `#[warn(stable_features)]` on by default warning: `drogue-boot` (lib) generated 1 warning error: could not compile `drogue-boot` due to previous error; 1 warning emitted Refs: rust-lang/rust#84019 Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
Click here for the final summary report.
Original issue preserved below:
As of today, most macros in Rust, despite being declared by the stdlib, are not properly namespaced in the sense that every other type, function, and trait in the stdlib is namespaced. Instead, historically, macros "live" in the crate root due to the technical limitations of Rust 1.0, which did not support namespacing for macros. This is distinct from items such as
Option
orVec
which are merely available as though they live in the crate root (via the prelude), but are actually defined atstd::option::Option
andstd::vec::Vec
. This has two primary downsides:In Rust 1.51,
ptr::addr_of
became the first stable macro to not be defined in the crate root. The machinery exists to namespace macros, and there seems to be at least loose consensus that this is worth using for new macros in the stdlib.One of the last remaining open questions for the stabilization of the
asm
macro is where it should live. Given the above, and the history of prior discussion on this topic, there are two options for consideration:core::arch::asm
core::arch::foo64::asm
, wherefoo64
is every architecture supported by theasm
macro.(For conciseness I will only be referring to
asm
in this document, but this decision also applies to any and all related macros, such asglobal_asm
.)First, the non-advantages of either option:
arch::foo64::asm
makes it immediately and syntactically obvious that a given platform is unsupported by dint of a nonexistent symbol, usingarch::asm
on an unsupported platform is still a compiler error.arch::asm
is straightforwardly obvious to export from the prelude,arch::foo64::asm
and friends could still possibly be exported from the prelude via#cfg
.asm
macro to have slightly different semantics on different architectures, e.g. architecture-specific register classes or clobbering behavior. Whilearch::foo64::asm
is more explicit about this potential difference, it is not necessary for enabling such behavior.arch::foo64::asm
is more straightforward to deprecate/stabilize on a per-target basis,#cfg
can be used to the same effect even forarch::asm
.The relevant differences between the the two options:
asm
is not added to the prelude,arch::asm
would still be trivial touse
in architecture-dependent code. Conversely, without a prelude addition,arch::foo64::asm
would have to fall back on a few patterns when writing architecture-dependent code, some of which are more verbose than others. Below, Pattern add an IL type checker #4 is the one that comes closest to the ergonomics ofarch::asm
, but it may be non-obvious, and it involves using a glob-import, which some may find distasteful (or even be linting against):arch::asm
would have to document all architecture-dependent behavior, which could make it unwieldy.arch::foo64::asm
would isolate architecture-dependent documentation, however, every module would be forced to duplicate all non-architecture-dependentasm
documentation, which seems unfortunate in its own way.asm
: havingarch::asm
, or else havingarch::foo64::asm
but havingasm
in the prelude, increases the chances that someone will write anasm!
invocation that is not guarded by any#cfg
directive or any other mention of the original author's platform. Such an unguarded invocation would probably give unhelpful errors if the code is ever compiled for a platform that supportsasm
in general but was not considered by this specificasm
invocation. Even worse, the code could compile but have unintended behavior. Conversely,arch::foo64::asm
essentially guarantees that an author's code will have to mention their intended platform somewhere, either in ause
or in an expression, and users on different platforms will receive obvious "cannot find valuefoo64::asm
in this scope" errors when attempting to compile it. However, this benefit requires thatasm
never be added to the prelude (and never adding any other way of circumventing the need to mention a platform, e.g. having botharch::asm
andarch::foo64::asm
).asm
supports architectures that do not have a corresponding module understd::arch
. Thearch::foo64::asm
approach would require a module for all supported architectures going forward. This includes adding modules for targets that may not ever be supported by rustc itself (e.g. SPIR-V), but are supported by theasm!
macro for the benefit of alternative backends. However, in either scenario alternative backends would still need to provide a patch to support new targets inasm!
, and adding a new module for any unstably-supported target doesn't seem like a particularly onerous part of that process. However, given enough time (and enough alternative backends, e.g. a GCC one) this could lead to quite a few submodules underarch::
, although to some degree that is the point of thearch
module.asm!
invocation to properly support multiple targets. This is the flipside of point 3 stated above: wherearch::asm
is maximally permissive,arch::foo64::asm
is maximally strict. Witharch::foo64::asm
, writing platform-agnostic assembly would require a pattern like the following:TL;DR: the benefits of either approach are fairly small.
arch::asm
is easier to use, but only ifasm
is not added to the prelude.arch::foo64::asm
could lead to better error messages in some cases, but likewise only ifasm
is not added to the prelude. If the decision is made to addasm
to the prelude, then there is essentially no advantage to either option.The text was updated successfully, but these errors were encountered: