-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Inject compiler_builtins during crate resolution #113634
Conversation
This is an alternative to rust-lang#113557 which removes `compiler_builtins` from the prelude and injects it during crate resolution instead. Fixes rust-lang#113533
Unfortunately this hits an issue:
|
The job Click to see the possible cause of the failure (guessed by this bot)
|
|
||
info!("loading compiler_builtins"); | ||
|
||
let Some(cnum) = self.resolve_crate(sym::compiler_builtins, DUMMY_SP, CrateDepKind::Implicit) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let Some(cnum) = self.resolve_crate(sym::compiler_builtins, DUMMY_SP, CrateDepKind::Implicit) else { | |
let Some(cnum) = self.resolve_crate(sym::compiler_builtins, DUMMY_SP, CrateDepKind::Explicit) else { |
extern crate
item from code will result in a call like this (see fn process_extern_crate
).
So this change should make the behavior closer to whatever we've been doing previously, maybe it will fix the issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't help.
Won't That order could be tweaked if necessary by placing |
// the one with the prelude. | ||
let name = names[0]; | ||
let ident = | ||
if edition >= Edition2018 { Ident::new(name, span) } else { Ident::new(name, call_site) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if edition >= Edition2018 { Ident::new(name, span) } else { Ident::new(name, call_site) }; | |
Ident::new(name, if edition >= Edition2018 { span } else { call_site }); |
Here is the log generated by rustc when failing to find compiler_builtins. You can find the relevant part by searching for "can't find crate for". It works fine when building crates like libc, rustc-demangle, std, alloc, which all have This line stands out:
|
Ok, let's fall back to #113557 then. Crate loading is known to have issues like this, and I planned to investigate them some time, but cannot do it in the near future. |
`compiler_builtins` is currently injected as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: rust-lang#113634
…<try> Inject `compiler_builtins` during postprocessing rather than via AST `compiler_builtins` is currently injected into the AST as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: rust-lang#113634 try-job: dist-x86_64-linux try-job: x86_64-gnu-distcheck try-job: x86_64-msvc-1 try-job: x86_64-rust-for-linux try-job: test-various
`compiler_builtins` is currently injected as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: rust-lang#113634
…<try> Inject `compiler_builtins` during postprocessing rather than via AST `compiler_builtins` is currently injected into the AST as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: rust-lang#113634 try-job: dist-x86_64-linux try-job: x86_64-gnu-distcheck try-job: x86_64-msvc-1 try-job: x86_64-rust-for-linux try-job: test-various
`compiler_builtins` is currently injected as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: rust-lang#113634
…<try> Inject `compiler_builtins` during postprocessing rather than via AST `compiler_builtins` is currently injected into the AST as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. This PR is a smaller subset of changes, split from rust-lang#135501. rust-lang#135501 builds on this to resolve a couple remaining privacy issues and actually do the update that has been troublesome. [1]: rust-lang#113634 try-job: aarch64-gnu try-job: dist-x86_64-linux try-job: i686-mingw try-job: x86_64-gnu-distcheck try-job: x86_64-msvc-1 try-job: x86_64-rust-for-linux try-job: test-various
This is an alternative to #113557 which removes
compiler_builtins
from the prelude and injects it during crate resolution instead.Fixes #113533
r? @petrochenkov