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

Migrate symbols to use declarative macro. #95726

Conversation

fee1-dead
Copy link
Member

Pros:

  • faster build times
  • completion for IDE users
  • easier to understand

Cons:

  • check for duplicates and alphabetical order is moved to tidy

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 6, 2022
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2022
@bjorn3
Copy link
Member

bjorn3 commented Apr 6, 2022

Another con: With a proc macro it would have been possible to precompute hashes of all symbols to make building the symbol interner faster.

@petrochenkov
Copy link
Contributor

petrochenkov commented Apr 6, 2022

IIRC, it was migrated from a declarative to procedural macro only 1-2 years ago.

@fee1-dead
Copy link
Member Author

With a proc macro it would have been possible to precompute hashes of all symbols to make building the symbol interner faster.

Yes, but how would that work with FxHashMap? With some improvements to CTFE I think this can be done in const contexts in the near future.

IIRC, it was migrated from a declarative to procedural macro only 1-2 years ago.

Actually 3 years ago. It was #59655. You commented that if we could use macro_rules then we should use macro_rules.

We could also test the performance:

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 7, 2022
@bors
Copy link
Contributor

bors commented Apr 7, 2022

⌛ Trying commit 1a53e93 with merge a08229a10eb3728f98c4b330da365247e3d8a90b...

@bors
Copy link
Contributor

bors commented Apr 7, 2022

☀️ Try build successful - checks-actions
Build commit: a08229a10eb3728f98c4b330da365247e3d8a90b (a08229a10eb3728f98c4b330da365247e3d8a90b)

@rust-timer
Copy link
Collaborator

Queued a08229a10eb3728f98c4b330da365247e3d8a90b with parent 2310da4, future comparison URL.

@bjorn3
Copy link
Member

bjorn3 commented Apr 7, 2022

FxHashMap has the raw_entry api which allows providing the hash directly AFAIK.

@bjorn3
Copy link
Member

bjorn3 commented Apr 7, 2022

With some improvements to CTFE I think this can be done in const contexts in the near future.

Even if it could it may still be slower.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a08229a10eb3728f98c4b330da365247e3d8a90b): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: changes not relevant. 1 results were found to be statistically significant but the changes were too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 7, 2022
@Mark-Simulacrum
Copy link
Member

I am not entirely convinced by this change -- the diagnostics cycle seems likely to be worse (a proc-macro gives you immediate feedback), and the macro itself is not as digestible to me. Proc macros are a little clunky, but macro-rules at least as it stands today forces into annoying and not easily comprehensible hacks like ____anchor here. (FWIW, it seems like using https://doc.rust-lang.org/nightly/std/mem/fn.variant_count.html should be a better fit there).

I think in terms of benefits, the strongest one is probably the completion for IDE users, but it was my recollection that rust-analyzer (and presumably eventually other IDEs) already support completion with proc-macros in some cases. Maybe there's something we can adjust to make that feasible? For example, with some adjustments, it might be possible to make most of this derive-macro capable, emitting some constants on the side to talk to the other macros -- that would probably greatly improve the IDE story?

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2022
@fee1-dead
Copy link
Member Author

I am going to close this in favor of rust-lang/rust-analyzer#11956 which would allow customizing how rust-analyzer runs build scripts and expands procedural macros. A followup PR after that to rustc should make IDE support a lot better for procedural macros.

@fee1-dead fee1-dead closed this Apr 13, 2022
@fee1-dead fee1-dead deleted the migrate-symbols-to-declarative-macro branch April 13, 2022 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants