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

Add builtin# for compiler-intrinsic syntax #580

Closed
1 of 3 tasks
est31 opened this issue Jan 19, 2023 · 5 comments
Closed
1 of 3 tasks

Add builtin# for compiler-intrinsic syntax #580

est31 opened this issue Jan 19, 2023 · 5 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@est31
Copy link
Member

est31 commented Jan 19, 2023

Proposal

Some of rust's builtin macros use their direct access to the AST to do things that proc macros can't: create AST nodes that are not present in syntax. This turns those macros into language extensions more than actual macros.

The proposed solution is to add the builtin#... syntax intended for constructs that are perma-unstable, possibly having stable wrappers, where no final syntax is known.

builtin# would always be followed by a conditional keyword that corresponds to the functionality of the construct, and then contain its arguments in parentheses. So asm!(foo) becomes builtin#asm(foo).

Possible cases of builtin#:

  • the asm!/global_asm! macros
  • there is a PRs open for format_args
  • another PR is open for offset_of
  • An eventual replacement for box syntax that is more of an implementation detail than a future feature at this point. It is still used in the vec macro thus can't be removed easily. This would free up box as a keyword.
  • Any future language feature whose syntax is not decided yet but people want to experiment with it. E.g. do yeet comes to mind.

Acceptance of this MCP does not imply that all of these should be migrated. For the last few non-macro cases the migration discussion is explicitly left for the future. Mainly, the list serves to show the targeted area of builtin#.

Macros can be changed to macro_rules macros with an allow_internal_unstable (or alternatively macro macros).

Mentors or Reviewers

@petrochenkov has expressed desire for this.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@est31 est31 added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Jan 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2023

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Jan 19, 2023
@est31 est31 changed the title Add builtin# for syntax with no better syntax Add builtin# for compiler-intrinsic syntax Jan 19, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jan 19, 2023
@m-ou-se
Copy link
Member

m-ou-se commented Jan 24, 2023

A bit of a tangent but related: having lang#… for lang items could also be very nice, at least for -Zunpretty=hir. Now, it uses #[lang=…] syntax whenever it refers to lang items, which gets weird:

match #[lang = "branch"](x) {
    #[lang = "Break"] {  0: residual } =>
        #[allow(unreachable_code)]
        return #[lang = "from_residual"](residual),
    #[lang = "Continue"] {  0: val } =>
        #[allow(unreachable_code)]
        val,
};

changing that to lang#Break (etc.) in the pretty printed hir output is trivial, but it might be cool if that would actually also become (permanently unstable) syntax to refer to lang items. (Useful for in rustc tests, etc. And it'd be nice if rustfmt understands it.)

(Or maybe we should rename 'lang items' to something that makes more sense first. ^^)

@clubby789
Copy link

Another potential use case is include_bytes, which expands to a custom AST node to avoid escaping large blobs

@pnkfelix
Copy link
Member

pnkfelix commented Apr 6, 2023

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Apr 6, 2023
@apiraino
Copy link
Contributor

@rustbot label -final-comment-period +major-change-accepted

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Apr 17, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 20, 2023
bors added a commit to rust-lang/rust-analyzer that referenced this issue Sep 5, 2023
Parse builtin# syntax and add typechecking for builtin#offset_of expression

Also removes box syntax, fixes #14504

cc rust-lang/compiler-team#580 #15082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

6 participants