Skip to content

Commit

Permalink
Auto merge of rust-lang#122236 - matthiaskrgr:rollup-cg2zzhq, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#121567 (Avoid some interning in bootstrap)
 - rust-lang#121813 (Misc improvements to non local defs lint implementation)
 - rust-lang#121860 (Add a tidy check that checks whether the fluent slugs only appear once)
 - rust-lang#121907 (skip sanity check for non-host targets in `check` builds)
 - rust-lang#122160 (Eagerly translate `HelpUseLatestEdition` in parser diagnostics)
 - rust-lang#122178 (ci: add a runner for vanilla LLVM 18)
 - rust-lang#122186 (Remove a workaround for a bug)
 - rust-lang#122187 (Move metadata header and version checks together)
 - rust-lang#122215 (Some tweaks to the parallel query cycle handler)
 - rust-lang#122223 (Fix typo in `VisitorResult`)
 - rust-lang#122232 (library/core: fix a comment, and a cfg(miri) warning)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 9, 2024
2 parents b054da8 + 28fca59 commit cfc2310
Show file tree
Hide file tree
Showing 44 changed files with 513 additions and 308 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ jobs:
- name: x86_64-gnu-distcheck
os: ubuntu-20.04-8core-32gb
env: {}
- name: x86_64-gnu-llvm-18
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-llvm-17
env:
RUST_BACKTRACE: 1
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4133,7 +4133,6 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"smallvec",
"tracing",
"unicode-security",
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_ir/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl VisitorResult for () {
type Residual = !;

#[cfg(not(feature = "nightly"))]
type Residual = core::ops::Infallible;
type Residual = core::convert::Infallible;

fn output() -> Self {}
fn from_residual(_: Self::Residual) -> Self {}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ const_eval_intern_kind = {$kind ->
*[other] {""}
}
const_eval_invalid_align =
align has to be a power of 2
const_eval_invalid_align_details =
invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ fn list_metadata(early_dcx: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dy
metadata_loader,
&mut v,
&sess.opts.unstable_opts.ls,
sess.cfg_version,
)
.unwrap();
safe_println!("{}", String::from_utf8(v).unwrap());
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ infer_more_targeted = {$has_param_name ->
infer_msl_introduces_static = introduces a `'static` lifetime requirement
infer_msl_unmet_req = because this has an unmet lifetime requirement
infer_need_type_info_in_coroutine =
type inside {$coroutine_kind ->
[async_block] `async` block
[async_closure] `async` closure
[async_fn] `async fn` body
*[coroutine] coroutine
} must be known in this context
infer_nothing = {""}
Expand Down
19 changes: 16 additions & 3 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
threads: usize,
f: F,
) -> R {
use rustc_data_structures::{jobserver, sync::FromDyn};
use rustc_data_structures::{defer, jobserver, sync::FromDyn};
use rustc_middle::ty::tls;
use rustc_query_impl::QueryCtxt;
use rustc_query_system::query::{deadlock, QueryContext};
use rustc_query_system::query::{break_query_cycles, QueryContext};
use std::process;

let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());

Expand All @@ -128,7 +129,19 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
let query_map =
FromDyn::from(tls::with(|tcx| QueryCtxt::new(tcx).collect_active_jobs()));
let registry = rayon_core::Registry::current();
thread::spawn(move || deadlock(query_map.into_inner(), &registry));
thread::Builder::new()
.name("rustc query cycle handler".to_string())
.spawn(move || {
let on_panic = defer(|| {
eprintln!("query cycle handler thread panicked, aborting process");
// We need to abort here as we failed to resolve the deadlock,
// otherwise the compiler could just hang,
process::abort();
});
break_query_cycles(query_map.into_inner(), &registry);
on_panic.disable();
})
.unwrap();
});
if let Some(size) = get_stack_size() {
builder = builder.stack_size(size);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
unicode-security = "0.1.0"
# tidy-alphabetical-end
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ lint_suspicious_double_ref_clone =
lint_suspicious_double_ref_deref =
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
lint_trivial_untranslatable_diag = diagnostic with static strings only
lint_ty_qualified = usage of qualified `ty::{$ty}`
.suggestion = try importing it and using it unqualified
Expand Down
34 changes: 21 additions & 13 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, Path, QPath, TyKind};
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::{sym, symbol::kw, ExpnKind, MacroKind};

use smallvec::{smallvec, SmallVec};

use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag};
use crate::{LateContext, LateLintPass, LintContext};

Expand Down Expand Up @@ -85,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
if let Some(def_id) = oexpn.macro_def_id
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
&& def_id.krate != LOCAL_CRATE
&& std::env::var_os("CARGO").is_some()
&& rustc_session::utils::was_invoked_from_cargo()
{
Some(NonLocalDefinitionsCargoUpdateNote {
macro_kind: macro_kind.descr(),
Expand Down Expand Up @@ -114,25 +112,25 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
// is using local items and so we don't lint on it.

// We also ignore anon-const in item by including the anon-const
// parent as well; and since it's quite uncommon, we use smallvec
// to avoid unnecessary heap allocations.
let local_parents: SmallVec<[DefId; 1]> = if parent_def_kind == DefKind::Const
// parent as well.
let parent_parent = if parent_def_kind == DefKind::Const
&& parent_opt_item_name == Some(kw::Underscore)
{
smallvec![parent, cx.tcx.parent(parent)]
Some(cx.tcx.parent(parent))
} else {
smallvec![parent]
None
};

let self_ty_has_local_parent = match impl_.self_ty.kind {
TyKind::Path(QPath::Resolved(_, ty_path)) => {
path_has_local_parent(ty_path, cx, &*local_parents)
path_has_local_parent(ty_path, cx, parent, parent_parent)
}
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
path_has_local_parent(
principle_poly_trait_ref.trait_ref.path,
cx,
&*local_parents,
parent,
parent_parent,
)
}
TyKind::TraitObject([], _, _)
Expand All @@ -154,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {

let of_trait_has_local_parent = impl_
.of_trait
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
.map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent))
.unwrap_or(false);

// If none of them have a local parent (LOGICAL NOR) this means that
Expand Down Expand Up @@ -218,6 +216,16 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
/// std::convert::PartialEq<Foo<Bar>>
/// ^^^^^^^^^^^^^^^^^^^^^^^
/// ```
fn path_has_local_parent(path: &Path<'_>, cx: &LateContext<'_>, local_parents: &[DefId]) -> bool {
path.res.opt_def_id().is_some_and(|did| local_parents.contains(&cx.tcx.parent(did)))
fn path_has_local_parent(
path: &Path<'_>,
cx: &LateContext<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
) -> bool {
path.res.opt_def_id().is_some_and(|did| {
did.is_local() && {
let res_parent = cx.tcx.parent(did);
res_parent == impl_parent || Some(res_parent) == impl_parent_parent
}
})
}
127 changes: 60 additions & 67 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ use std::{cmp, fmt};
pub(crate) struct CrateLocator<'a> {
// Immutable per-session configuration.
only_needs_metadata: bool,
sysroot: &'a Path,
metadata_loader: &'a dyn MetadataLoader,
cfg_version: &'static str,

Expand Down Expand Up @@ -319,7 +318,6 @@ impl<'a> CrateLocator<'a> {

CrateLocator {
only_needs_metadata,
sysroot: &sess.sysroot,
metadata_loader,
cfg_version: sess.cfg_version,
crate_name,
Expand Down Expand Up @@ -569,31 +567,47 @@ impl<'a> CrateLocator<'a> {
debug!("skipping empty file");
continue;
}
let (hash, metadata) =
match get_metadata_section(self.target, flavor, &lib, self.metadata_loader) {
Ok(blob) => {
if let Some(h) = self.crate_matches(&blob, &lib) {
(h, blob)
} else {
info!("metadata mismatch");
continue;
}
}
Err(MetadataError::LoadFailure(err)) => {
info!("no metadata found: {}", err);
// The file was present and created by the same compiler version, but we
// couldn't load it for some reason. Give a hard error instead of silently
// ignoring it, but only if we would have given an error anyway.
self.crate_rejections
.via_invalid
.push(CrateMismatch { path: lib, got: err });
continue;
}
Err(err @ MetadataError::NotPresent(_)) => {
info!("no metadata found: {}", err);
let (hash, metadata) = match get_metadata_section(
self.target,
flavor,
&lib,
self.metadata_loader,
self.cfg_version,
) {
Ok(blob) => {
if let Some(h) = self.crate_matches(&blob, &lib) {
(h, blob)
} else {
info!("metadata mismatch");
continue;
}
};
}
Err(MetadataError::VersionMismatch { expected_version, found_version }) => {
// The file was present and created by the same compiler version, but we
// couldn't load it for some reason. Give a hard error instead of silently
// ignoring it, but only if we would have given an error anyway.
info!(
"Rejecting via version: expected {} got {}",
expected_version, found_version
);
self.crate_rejections
.via_version
.push(CrateMismatch { path: lib, got: found_version });
continue;
}
Err(MetadataError::LoadFailure(err)) => {
info!("no metadata found: {}", err);
// The file was present and created by the same compiler version, but we
// couldn't load it for some reason. Give a hard error instead of silently
// ignoring it, but only if we would have given an error anyway.
self.crate_rejections.via_invalid.push(CrateMismatch { path: lib, got: err });
continue;
}
Err(err @ MetadataError::NotPresent(_)) => {
info!("no metadata found: {}", err);
continue;
}
};
// If we see multiple hashes, emit an error about duplicate candidates.
if slot.as_ref().is_some_and(|s| s.0 != hash) {
if let Some(candidates) = err_data {
Expand All @@ -610,32 +624,6 @@ impl<'a> CrateLocator<'a> {
continue;
}

// Ok so at this point we've determined that `(lib, kind)` above is
// a candidate crate to load, and that `slot` is either none (this
// is the first crate of its kind) or if some the previous path has
// the exact same hash (e.g., it's the exact same crate).
//
// In principle these two candidate crates are exactly the same so
// we can choose either of them to link. As a stupidly gross hack,
// however, we favor crate in the sysroot.
//
// You can find more info in rust-lang/rust#39518 and various linked
// issues, but the general gist is that during testing libstd the
// compilers has two candidates to choose from: one in the sysroot
// and one in the deps folder. These two crates are the exact same
// crate but if the compiler chooses the one in the deps folder
// it'll cause spurious errors on Windows.
//
// As a result, we favor the sysroot crate here. Note that the
// candidates are all canonicalized, so we canonicalize the sysroot
// as well.
if let Some((prev, _)) = &ret {
let sysroot = self.sysroot;
let sysroot = try_canonicalize(sysroot).unwrap_or_else(|_| sysroot.to_path_buf());
if prev.starts_with(&sysroot) {
continue;
}
}
*slot = Some((hash, metadata, lib.clone()));
ret = Some((lib, kind));
}
Expand All @@ -648,16 +636,6 @@ impl<'a> CrateLocator<'a> {
}

fn crate_matches(&mut self, metadata: &MetadataBlob, libpath: &Path) -> Option<Svh> {
let rustc_version = rustc_version(self.cfg_version);
let found_version = metadata.get_rustc_version();
if found_version != rustc_version {
info!("Rejecting via version: expected {} got {}", rustc_version, found_version);
self.crate_rejections
.via_version
.push(CrateMismatch { path: libpath.to_path_buf(), got: found_version });
return None;
}

let header = metadata.get_header();
if header.is_proc_macro_crate != self.is_proc_macro {
info!(
Expand Down Expand Up @@ -770,6 +748,7 @@ fn get_metadata_section<'p>(
flavor: CrateFlavor,
filename: &'p Path,
loader: &dyn MetadataLoader,
cfg_version: &'static str,
) -> Result<MetadataBlob, MetadataError<'p>> {
if !filename.exists() {
return Err(MetadataError::NotPresent(filename));
Expand Down Expand Up @@ -847,13 +826,18 @@ fn get_metadata_section<'p>(
}
};
let blob = MetadataBlob(raw_bytes);
if blob.is_compatible() {
Ok(blob)
} else {
Err(MetadataError::LoadFailure(format!(
match blob.check_compatibility(cfg_version) {
Ok(()) => Ok(blob),
Err(None) => Err(MetadataError::LoadFailure(format!(
"invalid metadata version found: {}",
filename.display()
)))
))),
Err(Some(found_version)) => {
return Err(MetadataError::VersionMismatch {
expected_version: rustc_version(cfg_version),
found_version,
});
}
}
}

Expand All @@ -864,9 +848,10 @@ pub fn list_file_metadata(
metadata_loader: &dyn MetadataLoader,
out: &mut dyn Write,
ls_kinds: &[String],
cfg_version: &'static str,
) -> IoResult<()> {
let flavor = get_flavor_from_path(path);
match get_metadata_section(target, flavor, path, metadata_loader) {
match get_metadata_section(target, flavor, path, metadata_loader, cfg_version) {
Ok(metadata) => metadata.list_crate_metadata(out, ls_kinds),
Err(msg) => write!(out, "{msg}\n"),
}
Expand Down Expand Up @@ -932,6 +917,8 @@ enum MetadataError<'a> {
NotPresent(&'a Path),
/// The file was present and invalid.
LoadFailure(String),
/// The file was present, but compiled with a different rustc version.
VersionMismatch { expected_version: String, found_version: String },
}

impl fmt::Display for MetadataError<'_> {
Expand All @@ -941,6 +928,12 @@ impl fmt::Display for MetadataError<'_> {
f.write_str(&format!("no such file: '{}'", filename.display()))
}
MetadataError::LoadFailure(msg) => f.write_str(msg),
MetadataError::VersionMismatch { expected_version, found_version } => {
f.write_str(&format!(
"rustc version mismatch. expected {}, found {}",
expected_version, found_version,
))
}
}
}
}
Expand Down
Loading

0 comments on commit cfc2310

Please sign in to comment.