Skip to content

split asm! parsing and validation #140490

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

folkertdev
Copy link
Contributor

This PR splits asm! parsing and validation into two separate steps.

The parser constructs a Vec<RawAsmArg>, with each element corresponding to an argument to one of the asm! macros.
The validation then checks things like ordering of arguments or that options are not provided twice.

The motivation is #140279, which wants to add #[cfg(...)] support to these arguments. This support can now be added in a straightforward way by adding an attributes: ast::AttrVec field to RawAsmArg.

An extra reason for this split is that rustfmt probably wants to format the assembly at some point (currently that appears to be stubbed out, and the formatting is unstable rust-lang/style-team#152).

r? @ghost (just want to look at CI for now)

cc @ytmimi we discussed asm formatting a little while ago in rust-lang/rustfmt#6526. Am I correct in assuming that AsmArgs does not give enough information for formatting, but that RawAsmArgs would (it e.g. does not join information from multiple lines). This must have been an issue before?

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 29, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] toml test:false 0.195
error[E0412]: cannot find type `RawAsmArgs` in this scope
  --> src/tools/rustfmt/src/parse/macros/asm.rs:10:17
   |
10 | ) -> Option<Vec<RawAsmArgs>> {
   |                 ^^^^^^^^^^
   |
  ::: /checkout/compiler/rustc_builtin_macros/src/asm.rs:23:1
   |
23 | pub struct RawAsmArg {
   | -------------------- similarly named struct `RawAsmArg` defined here
   |
help: a struct with a similar name exists
   |
10 - ) -> Option<Vec<RawAsmArgs>> {
10 + ) -> Option<Vec<RawAsmArg>> {
   |
help: you might be missing a type parameter
   |
7  | pub(crate) fn parse_asm<RawAsmArgs>(
   |                        ++++++++++++

error: unused import: `RawAsmArg`
 --> src/tools/rustfmt/src/parse/macros/asm.rs:2:33
  |
2 | use rustc_builtin_macros::asm::{RawAsmArg, parse_raw_asm_args};
  |                                 ^^^^^^^^^
  |
  = note: `-D unused-imports` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_imports)]`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
3 participants