Skip to content
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

Move asm! and global_asm! to core::arch #1183

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/core_arch/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ mod simd;
#[doc = include_str!("core_arch_docs.md")]
#[stable(feature = "simd_arch", since = "1.27.0")]
pub mod arch {
/// Inline assembly.
///
/// Read the [unstable book] for the usage.
///
/// [unstable book]: ../unstable-book/library-features/asm.html
#[unstable(
feature = "asm",
issue = "72016",
reason = "inline assembly is not stable enough for use and is subject to change"
)]
#[rustc_builtin_macro]
pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
Copy link
Member

Choose a reason for hiding this comment

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

asm! is currently defined using macro_rules!. What are the differences of using pub macro compared to macro_rules!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To export a macro_rules macro you have to use #macro_export, which both makes the macro public and declares the macro in the crate root. Being declared in the crate root is undesirable because it means the macro is effectively "in the prelude" whether you want it to be or not. It also means that documentation lists the macro as being defined in the crate root, which is why the stdlib API docs display a giant wall of random macros (https://doc.rust-lang.org/std/index.html#macros).

In contrast, pub macro makes the macro public without defining it in the crate root. This is strictly more flexible, since we can add it to the prelude if we choose (which I will be doing with my aforementioned Rust repo PR, so as to not break nightly users). It also means we can have the documentation live somewhere sensible and avoid further cluttering the main stdlib API index.

As far as the implementation goes, all the actual macro machinery gets ignored since it's ultimately just a builtin. So the proper namespacing should be the only thing different here AFAIK.

/* compiler built-in */
}

/// Module-level inline assembly.
#[unstable(
feature = "global_asm",
issue = "35119",
reason = "`global_asm!` is not stable enough for use and is subject to change"
)]
#[rustc_builtin_macro]
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
/* compiler built-in */
}

/// Platform-specific intrinsics for the `x86` platform.
///
/// See the [module documentation](../index.html) for more details.
Expand Down