Document asm_cfg inline assembly attributes#653
Document asm_cfg inline assembly attributes#653PLeVasseur wants to merge 13 commits intorust-lang:mainfrom
Conversation
|
Hey @tshepang, @kirtchev-adacore -- could this be reviewed? |
c7f1f37 to
da682f3
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
src/inline-assembly.rst
Outdated
| :std:`core::arch::global_asm`, and | ||
| :std:`core::arch::naked_asm`. | ||
|
|
||
| :dp:`fls_nLBhw2w6uznH` |
There was a problem hiding this comment.
Pete,
How about adding a paragraph before this one which defines "inline assembly argument"? Something along the lines of
An :t:`inline assembly argument` is either an :t:`assembly instruction`, a :t:`register argument`, an :t:`ABI clobber`, or an :t:`assembly option`.
(with a :dt:inline assembly argument in the Glossary)
There was a problem hiding this comment.
Added a local definition before the legality rule and a matching glossary entry for :t:inline assembly argument``.
The new definition is:
An :t:inline assembly argument is either an :t:assembly instruction, a :t:register argument, an :t:ABI clobber, or an :t:assembly option.
This is now present in src/inline-assembly.rst and src/glossary.rst, and the changelog records the new glossary term.
src/inline-assembly.rst
Outdated
| :std:`core::arch::naked_asm`. | ||
|
|
||
| :dp:`fls_nLBhw2w6uznH` | ||
| Only :t:`attribute` :c:`cfg` and :t:`attribute` :c:`cfg_attr` shall decorate :t:`[assembly instruction]s`, :t:`[register argument]s`, :t:`[ABI clobber]s`, and :t:`[assembly option]s` in :s:`AsmArguments` and :s:`GlobalAsmArguments`; all other :t:`[attribute]s` shall be rejected. |
There was a problem hiding this comment.
| Only :t:`attribute` :c:`cfg` and :t:`attribute` :c:`cfg_attr` shall decorate :t:`[assembly instruction]s`, :t:`[register argument]s`, :t:`[ABI clobber]s`, and :t:`[assembly option]s` in :s:`AsmArguments` and :s:`GlobalAsmArguments`; all other :t:`[attribute]s` shall be rejected. | |
| Only :t:`attribute` :c:`cfg` and :t:`attribute` :c:`cfg_attr` shall decorate :t:`[inline assembly arguments]s in :s:`AsmArguments` and :s:`GlobalAsmArguments`. |
Note that "all other attributes shall be rejected" does not make sense as a rule because it implies that the programmer shall be rejecting the attributes, not the confirming tool. Normative "shall" and "must" are for the programmer to obey, facts are what a conforming tool guarantees.
There was a problem hiding this comment.
Reworked this into a pure legality rule using the newly defined inline assembly argument term:
Only :t:attribute :c:cfg and :t:attribute :c:cfg_attr shall decorate :t:[inline assembly arguments]sin:s:AsmArguments`` and :s:GlobalAsmArguments``.
I also removed the all other attributes shall be rejected clause so the paragraph no longer mixes a programmer-facing rule with tool behavior.
src/inline-assembly.rst
Outdated
| Only :t:`attribute` :c:`cfg` and :t:`attribute` :c:`cfg_attr` shall decorate :t:`[assembly instruction]s`, :t:`[register argument]s`, :t:`[ABI clobber]s`, and :t:`[assembly option]s` in :s:`AsmArguments` and :s:`GlobalAsmArguments`; all other :t:`[attribute]s` shall be rejected. | ||
|
|
||
| :dp:`fls_xzDPz2zfRfoI` | ||
| If a :t:`assembly instruction`, :t:`register argument`, :t:`ABI clobber`, or :t:`assembly option` in :s:`AsmArguments` or :s:`GlobalAsmArguments` is subject to :t:`attribute` :c:`cfg` or :t:`attribute` :c:`cfg_attr` where the related :t:`configuration predicate` evaluates to ``false``, then that construct is not considered part of the related :s:`AsmArguments` or :s:`GlobalAsmArguments`, consistent with :t:`conditional compilation`. |
There was a problem hiding this comment.
| If a :t:`assembly instruction`, :t:`register argument`, :t:`ABI clobber`, or :t:`assembly option` in :s:`AsmArguments` or :s:`GlobalAsmArguments` is subject to :t:`attribute` :c:`cfg` or :t:`attribute` :c:`cfg_attr` where the related :t:`configuration predicate` evaluates to ``false``, then that construct is not considered part of the related :s:`AsmArguments` or :s:`GlobalAsmArguments`, consistent with :t:`conditional compilation`. | |
| If an :t:`inline assembly argument` in :s:`AsmArguments` or :s:`GlobalAsmArguments` is subject to :t:`attribute` :c:`cfg` or :t:`attribute` :c:`cfg_attr` where the related :t:`configuration predicate` evaluates to ``false``, then the :t:`inline assembly argument` is not considered part of the related :s:`AsmArguments` or :s:`GlobalAsmArguments`, consistent with :t:`conditional compilation`. |
I wonder whether this paragraph is even needed because it is subsumed by
18.6:3 A construct subject to attribute cfg where the related configuration predicate evaluates to false is not considered part of a Rust program.
There was a problem hiding this comment.
I ended up removing the standalone paragraph.
The generic conditional-compilation rule in 18.6 already covers the cfg-false case, so keeping a separate paragraph here seemed redundant. I kept the asm-specific template-first rule and tightened it so the cfg-disabled operand case is still covered locally where that unique behavior matters.
Summary
asm_cfgattribute support on inline assembly templates/operands and update the inline-assembly grammarReference alignment
cfgconditions on inline assembly templates and operands reference#2063AsmAttrFormatString/AsmAttrOperand; FLS introducesAssemblyTemplate/AssemblyAttribute*wrappers to match, splitting operands intoRegisterArgument,AbiClobber, andAssemblyOptioncfg/cfg_attrsupport and the template-first rule match the Reference; FLS makes cfg-false argument behavior explicit to align with conditional compilation semanticsTesting