Why do we need procedural macro separation on a *crate* level?

Why do we need procedural macro separation on a crate level?

I have some questions about the overall structure of proc-macro and proc-macro2.

Prelude

I want to be clear about two things:

  1. This topic seems to dive deep into the compiler, so I'm sure there's more that I don't know about.
  2. I believe I understand why there the difference exists (at least currently circa 2024). The source I read before I write this an early (if not the first) RFC about procedural macro crates back in 2016:

Also, I have also seen other posts about this issue on previous discussions, especially this one, which links to the same RFC and other good discussions and information about this topic.

Here is an excerpt from the RFC that defines this difference in crates:

...
We introduce a special configuration option: #[cfg(proc_macro)]. Items with this configuration are not macros themselves but are compiled only for macro uses.

If a crate is a proc-macro crate, then the proc_macro cfg variable is true for the whole crate. Initially it will be false for all other crates. This has the effect of partitioning crates into macro- defining and non-macro defining crates. In the future, I hope we can relax these restrictions so that macro and non-macro code can live in the same crate.
...

From this, using #[cfg(proc-macro)] is ultimately what allows a function to "become" a procedural macro (along with its procedural macro type attribute).

However, this feels like patch-work solution, which is hinted in an even earlier RFC. The goal was to make declarative macros and procedural macro both be "first-class citizen[s] in the Rust module system".

Back to the question

This leads me back to the original question:
Why do we need procedural macro separation on a crate level?
What is stopping proc-macro2 from being a first-class citizen?

That is not a appropriate tone for the answer. You come off as highly antagonistic and condescending.

7 Likes

First Things First

I would like to apologize that I came off that way, it wasn't my intention (which is not an excuse). Rereading my post again, I can understand how someone could take in this way, and I am sorry. I do have respect for others here, and I will do better about tone in the future. This is my bad.

I do appreciate the feedback on this. Tone in writing is a weak-point of mine that I am working to improve.

Continuing On

Would it be best to just make a new post, rather than edit this one?
I would like to re-ask this question but with a better tone to the reader.

The spirit of my question is more or less of the following:
What is the status of making procedural macros a first-class citizen? If there is no real status, why?
^ Would this be a better question?

Thank you for the feedback, and once again I apologize for my highly antagonistic and condescending tone.

I did find your post particularly problematic, maybe a bit confusingly worded (I'm not entirely clear on exactly what you were trying to ask about) but not really an issue as such (followup questions can be asked).

My problem was with the answer you got which... had issues lets say (and is how apparently hidden: "This post was flagged by the community and is temporarily hidden.").

I'm not a moderator, and I'm just going to defer this mess to one of them. @steffahn @quinedot (not sure who else here is a moderator)

OH! I think I understand now. I'm a new user to this forum (and using forums in general), so correct me if I'm wrong: A user responded to MY post, got flagged by the community, and that is what you were replying to. If so, I understand now.

Yeah, I agree, this post is a bit of a mess :sweat_smile:

Exactly.

This topic contains no good answers yet and lots of meta-discussion. Thanks for @Vorpal for clearing up the misunderstanding successfully so far. I will move / copy the original post to a new clean topic, so we can have another go of getting on-topic replies without too much distraction :slight_smile:

@the-mcmaster, you can see in the top-right corner of posts that are replies to other replies, who they are replying to. Admitted, that can something easy to overlook if you're new to Discourse forums.

3 Likes

A post was split to a new topic: Why do we need procedural macro separation on a crate level?