-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Deprecate #![crate_type] and #![crate_name] #83676
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
This has previously been discussed a bit in https://rust-lang.zulipchat.com/#narrow/stream/268952-edition-2021/topic/remove.20.23!.5Bcrate_type.5D |
These are used quite a lot for tests, and I also use them for testing rustdoc issues locally. It would be annoying to have to run with
|
This attribute is very extensively used in tests and similar one-off programs that are compiled with rustc directly. I know I type this attribute out at least once every week. I would like to see what the impact of this change would be by running crater with this lint denied. Perhaps MCP too, though I guess we can FCP this PR too. I'm worried all sorts of playground and godbolt links would break once this lint is denied too. |
As a middle ground could we keep |
Can you explain why you want to deprecate these? You've mentioned that the thread-locals feel hacky and that this is unhelpful when using cargo, but not everyone uses cargo and I don't think we should remove language features just because it cleans up the implementation. |
It is not a thread local, but a field of the |
I marked this as needs-fcp because I think the lang team should weigh in on deprecating any language features. |
Personally, I would love to see these deprecated, in favor of the command-line options. The command-line options don't require Cargo, they just require passing the values into However, these attributes are part of the language, and while we could consider deprecating them, I don't think we can reasonably remove them except as part of an edition boundary. @bjorn3 Would any of the potential simplifications you're describing be possible if we need to retain compatibility with previous editions that support these attributes indefinitely? (For instance, assume that cosmetic issues such as messages were not a problem, and we only had to produce a compatible compiled crate.) If there's still substantial improvement available even given that constraint, I think this might be worth considering. If there isn't, then I don't think this would be worth the churn it would introduce. |
No, unfortunately not. Keeping the attributes, requiring them to be equal to the default value when no commandline argument is passed instead of only requiring a match when the commandline arguments are passed would allow for these simplifications though. In addition I wonder if gcc-rs could even support these attributes at all or whether the gcc driver requires to know of it needs to link in advance before invoking the language specific frontend. (cc @philberty) Removing on an edition boundary would help other backends if they choose to not support older editions. |
As per the definition and intent of editions, you're not a valid Rust compiler unless you actually do support older editions. |
Thanks, @bjorn3 for the heads up. I think there is a method to implement #![crate_name] (by overriding passed options) but no other FE in GCC does this and would likely just cause more problems than it solves. As for #![crate_type] I am currently unaware of any method to actually implement this in gcc-rs. @tschwinge or @dkm do you have any opinions on this? |
What about deprecating and removing cfg_attr-dependent |
I personally think @est31 proposal of deprecating crate_type is a great move forward, this is a difficult thing for GCC Rust to support in a graceful way. Crate name is something that is much more easily implemented. I would like to see this change moving forward in Rust. |
(To clarify, my proposal also extends to |
The PR as originally proposed here isn't something we can merge; removing these would break existing code, and we shouldn't deprecate them if we don't plan to remove them. And it sounds like even dropping these in an edition wouldn't help, even if that were something we wanted to do. So, I'm going to close this PR. Proposals to make some other change in this area should likely be a separate PR, and would almost certainly need both an FCP and a crater run. |
Done in #83744 |
…e_name, r=Mark-Simulacrum Deprecate crate_type and crate_name nested inside #![cfg_attr] This implements the proposal in rust-lang#83676 (comment), with a future compatibility lint imposed on usage of crate_type/crate_name inside cfg's. This is a compromise between removing `#![crate_type]` and `#![crate_name]` completely and keeping them as a whole, which requires somewhat of a hack in rustc and is impossible to support by gcc-rust. By only removing `#![crate_type]` and `#![crate_name]` nested inside `#![cfg_attr]` it becomes possible to parse them before a big chunk of the compiler has started. Replaces rust-lang#83676 ```rust #![crate_type = "lib"] // remains working #![cfg_attr(foo, crate_type = "bin")] // will stop working ``` # Rationale As it currently is it is possible to try to access the stable crate id before it is actually set, which will panic. The fact that the Session contains mutable state beyond debugging things also doesn't completely sit well with me. Especially once parallel rustc becomes the default. I think there is currently also a cyclic dependency where you need to set the stable crate id to be able to load crates, but you need to load crates to expand proc macro attributes that may define #![crate_name] or #![crate_type]. Currently crate level proc macro attributes are unstable or completely unsupported (can't remember which), so this is not a problem, but it may become an issue in the future. Finally if we want to add incremental compilation to macro expansion or even parsing, we need the StableCrateId to be created together with the Session or even earlier as incremental compilation determines the incremental compilation session dir based on the StableCrateId.
…e_name, r=Mark-Simulacrum Deprecate crate_type and crate_name nested inside #![cfg_attr] This implements the proposal in rust-lang#83676 (comment), with a future compatibility lint imposed on usage of crate_type/crate_name inside cfg's. This is a compromise between removing `#![crate_type]` and `#![crate_name]` completely and keeping them as a whole, which requires somewhat of a hack in rustc and is impossible to support by gcc-rust. By only removing `#![crate_type]` and `#![crate_name]` nested inside `#![cfg_attr]` it becomes possible to parse them before a big chunk of the compiler has started. Replaces rust-lang#83676 ```rust #![crate_type = "lib"] // remains working #![cfg_attr(foo, crate_type = "bin")] // will stop working ``` # Rationale As it currently is it is possible to try to access the stable crate id before it is actually set, which will panic. The fact that the Session contains mutable state beyond debugging things also doesn't completely sit well with me. Especially once parallel rustc becomes the default. I think there is currently also a cyclic dependency where you need to set the stable crate id to be able to load crates, but you need to load crates to expand proc macro attributes that may define #![crate_name] or #![crate_type]. Currently crate level proc macro attributes are unstable or completely unsupported (can't remember which), so this is not a problem, but it may become an issue in the future. Finally if we want to add incremental compilation to macro expansion or even parsing, we need the StableCrateId to be created together with the Session or even earlier as incremental compilation determines the incremental compilation session dir based on the StableCrateId.
#![crate_type]
is implemented using aOnceCell
in theSession
to allow for setting it after the main source file has already been parsed. This is rather ugly IMO and makes it easy to attempt to access it before it has been set.#![crate_name]
is implemented by threading the determined crate name everywhere after the crate has been parsed up till the moment theTyCtxt
is created, at which point thecrate_name
stored inTyCtxt
is used. A local patch which used the same technique as#![crate_type]
resulted in "17 files changed, 72 insertions(+), 127 deletions(-)".Both
#![crate_type]
and#![crate_name]
are useless when using Cargo as they must match the values passed in at the command line. Other build systems are unlikely to use either attribute too.I propose that
#![crate_type]
and#![crate_name]
will be deprecated and at a future date removed.