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

Relax ordering rules for asm! operands #1323

Merged
merged 1 commit into from
Mar 26, 2023
Merged

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Jan 27, 2023

This updates the reference to match the changes in rust-lang/rust#105798

This updates the reference to match the changes in rust-lang/rust#105798
@joshtriplett
Copy link
Member

@bors r+

asm := "asm!(" format_string *("," format_string) *("," [ident "="] operand) *("," clobber_abi) *("," options) [","] ")"
global_asm := "global_asm!(" format_string *("," format_string) *("," [ident "="] operand) *("," options) [","] ")"
operand := reg_operand / clobber_abi / options
asm := "asm!(" format_string *("," format_string) *("," operand) [","] ")"
Copy link
Contributor

Choose a reason for hiding this comment

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

This grammar doesn't seem to capture the order requirements for how it is parsed. Am I missing something for how this is defined? That is, why is it not something closer to:

asm := "asm!(" format_string *("," format_string) *("," operand) *("," ident "=" operand) *("," options) [","] ")"

Copy link
Member Author

Choose a reason for hiding this comment

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

The new rules allow options and operands to be freely mixed, so there are no order requirements anymore (except that the template strings must come first).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what I'm getting after is to capture the rule that positional operands must come before named operands. This grammar seems to allow:

let x: i64;
asm!("add {}, {foo}, {}", out(reg) x, foo=in(reg) 2, in(reg) 1);

But that generates an error "positional arguments cannot follow named arguments or explicit register arguments".

Copy link
Member Author

@Amanieu Amanieu Mar 19, 2023

Choose a reason for hiding this comment

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

Right, but then again options and clobber_abi can appear in any position between named & positional arguments. It's a bit difficult to express all the details in the grammar.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand how it parses correctly, the following doesn't seem too unwieldy:

asm := "asm!(" format_string *("," format_string) operands ")"
operands := *("," reg_operand / clobber_abi / options) *("," ident "=" reg_operand) *("," clobber_abi / options)

Does that seem like it would be OK to have?

Copy link
Member Author

Choose a reason for hiding this comment

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

I gave this a try but I think it just makes the grammar harder to read overall. I prefer leaving it as it currently is and describing the operand ordering constraints in the text.

Copy link
Member Author

Choose a reason for hiding this comment

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

The example you gave isn't actually correct since it doesn't cover explicit register operands which don't have names and can be mixed with named operands.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. Thanks for taking a look!

@nikomatsakis
Copy link
Contributor

Discussed in lang-team meeting: matching the implementation seems good, we don't need further review, but it'd be good @Amanieu to figure out whether @ehuss is correct.

@nikomatsakis
Copy link
Contributor

@rustbot labels -I-lang-nominated

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

@ehuss ehuss merged commit 3c47807 into rust-lang:master Mar 26, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 28, 2023
Update books

## rust-lang/nomicon

1 commits in 1f3e4cd4fd88b5b5d45feb86a11b6d2f93e5a974..b5f7500fc40775096c2bbd204eae096612cf9047
2023-03-27 13:47:36 UTC to 2023-03-27 13:47:36 UTC

- Fix typo in 3.8 Subtyping and Variance (rust-lang/nomicon#395)

## rust-lang/reference

4 commits in 24c87f6663aed55b05d2cc286878f28f21918825..3c47807a3131b3c7cacb508f52632078d253cd0a
2023-03-26 18:42:43 UTC to 2023-03-14 18:28:23 UTC

- Relax ordering rules for `asm!` operands (rust-lang/reference#1323)
- Improve labeled blocks documentation (rust-lang/reference#1342)
- Inline assembly: Fix repeated and unordered items in guaranteed directives (rust-lang/reference#1341)
- Clarify that free constants are always evaluated at compile time (rust-lang/reference#1328)

## rust-lang/rust-by-example

7 commits in af0998b7473839ca75563ba3d3e7fd0160bef235..cfbfd648ce33926c3490f24de9a5b56cce404b88
2023-03-21 12:05:17 UTC to 2023-03-21 11:58:20 UTC

- Fix two typos in the asm chapter (rust-lang/rust-by-example#1692)
- Change `runtime` error to `compile time` error (rust-lang/rust-by-example#1690)
- Fix tests running on non-x86 platforms. (rust-lang/rust-by-example#1687)
- Remove trailing semicolon from macro expression (rust-lang/rust-by-example#1683)
- Explained why it should not work in Chapter 4.1 (rust-lang/rust-by-example#1682)
- Fix comment to mention the correct type of error (rust-lang/rust-by-example#1680)
- Improve the content for `read_lines` (rust-lang/rust-by-example#1679)

## rust-lang/rustc-dev-guide

9 commits in b1b6d693cd1461e53de4132c1b183ace31cd36e5..d08baa166b463537229eeb737c4ccadabd83cf78
2023-03-26 17:55:53 UTC to 2023-03-14 03:50:20 UTC

- Add locale_resources (rust-lang/rustc-dev-guide#1651)
- Don't require $GITHUB_TOKEN to build locally (rust-lang/rustc-dev-guide#1652)
- bootsrapping stages overview list (rust-lang/rustc-dev-guide#1555)
- Update labels overview (rust-lang/rustc-dev-guide#1639)
- first mention of type, and add a link (rust-lang/rustc-dev-guide#1643)
- Add SIP solution for macOS users (rust-lang/rustc-dev-guide#1636)
- Add chapter on fuzzing (rust-lang/rustc-dev-guide#1646)
- Fix "Crate disambiguator" in libs-and-metadata.md (rust-lang/rustc-dev-guide#1648)
- Update rustdoc-internals.md (rust-lang/rustc-dev-guide#1644)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants