Skip to content

Commit 5ff4b03

Browse files
committed
Auto merge of rust-lang#138994 - TaKO8Ki:rollup-jjezkmx, r=TaKO8Ki
Rollup of 9 pull requests Successful merges: - rust-lang#130883 (Add environment variable query) - rust-lang#138672 (Avoiding calling queries when collecting active queries) - rust-lang#138702 (Allow spawning threads after TLS destruction) - rust-lang#138935 (Update wg-prio triagebot config) - rust-lang#138946 (Un-bury chapters from the chapter list in rustc book) - rust-lang#138964 (Implement lint against using Interner and InferCtxtLike in random compiler crates) - rust-lang#138977 (Don't deaggregate InvocationParent just to reaggregate it again) - rust-lang#138980 (Collect items referenced from var_debug_info) - rust-lang#138985 (Use the correct binder scope for elided lifetimes in assoc consts) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a2e6356 + ff60436 commit 5ff4b03

File tree

44 files changed

+718
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+718
-310
lines changed

compiler/rustc_borrowck/src/nll.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! The entry point of the NLL borrow checker.
22
3+
use std::io;
34
use std::path::PathBuf;
45
use std::rc::Rc;
56
use std::str::FromStr;
6-
use std::{env, io};
77

88
use polonius_engine::{Algorithm, Output};
99
use rustc_index::IndexSlice;
@@ -162,9 +162,8 @@ pub(crate) fn compute_regions<'a, 'tcx>(
162162
}
163163

164164
if polonius_output {
165-
let algorithm =
166-
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
167-
let algorithm = Algorithm::from_str(&algorithm).unwrap();
165+
let algorithm = infcx.tcx.env_var("POLONIUS_ALGORITHM").unwrap_or("Hybrid");
166+
let algorithm = Algorithm::from_str(algorithm).unwrap();
168167
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
169168
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");
170169
Some(Box::new(Output::compute(polonius_facts, algorithm, false)))

compiler/rustc_data_structures/src/stable_hasher.rs

+2
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ where
564564
}
565565
}
566566

567+
impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);
568+
567569
impl_stable_traits_for_trivial_type!(::std::path::Path);
568570
impl_stable_traits_for_trivial_type!(::std::path::PathBuf);
569571

compiler/rustc_interface/src/passes.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::any::Any;
2-
use std::ffi::OsString;
2+
use std::ffi::{OsStr, OsString};
33
use std::io::{self, BufWriter, Write};
44
use std::path::{Path, PathBuf};
55
use std::sync::{Arc, LazyLock, OnceLock};
@@ -361,6 +361,31 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
361361
)
362362
}
363363

364+
fn env_var_os<'tcx>(tcx: TyCtxt<'tcx>, key: &'tcx OsStr) -> Option<&'tcx OsStr> {
365+
let value = env::var_os(key);
366+
367+
let value_tcx = value.as_ref().map(|value| {
368+
let encoded_bytes = tcx.arena.alloc_slice(value.as_encoded_bytes());
369+
debug_assert_eq!(value.as_encoded_bytes(), encoded_bytes);
370+
// SAFETY: The bytes came from `as_encoded_bytes`, and we assume that
371+
// `alloc_slice` is implemented correctly, and passes the same bytes
372+
// back (debug asserted above).
373+
unsafe { OsStr::from_encoded_bytes_unchecked(encoded_bytes) }
374+
});
375+
376+
// Also add the variable to Cargo's dependency tracking
377+
//
378+
// NOTE: This only works for passes run before `write_dep_info`. See that
379+
// for extension points for configuring environment variables to be
380+
// properly change-tracked.
381+
tcx.sess.psess.env_depinfo.borrow_mut().insert((
382+
Symbol::intern(&key.to_string_lossy()),
383+
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(&value)),
384+
));
385+
386+
value_tcx
387+
}
388+
364389
// Returns all the paths that correspond to generated files.
365390
fn generated_output_paths(
366391
tcx: TyCtxt<'_>,
@@ -725,6 +750,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
725750
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
726751
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
727752
providers.early_lint_checks = early_lint_checks;
753+
providers.env_var_os = env_var_os;
728754
limits::provide(providers);
729755
proc_macro_decls::provide(providers);
730756
rustc_const_eval::provide(providers);

compiler/rustc_interface/src/util.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_session::{EarlyDiagCtxt, Session, filesearch};
1818
use rustc_span::edit_distance::find_best_match_for_name;
1919
use rustc_span::edition::Edition;
2020
use rustc_span::source_map::SourceMapInputs;
21-
use rustc_span::{Symbol, sym};
21+
use rustc_span::{SessionGlobals, Symbol, sym};
2222
use rustc_target::spec::Target;
2323
use tracing::info;
2424

@@ -188,26 +188,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
188188
// On deadlock, creates a new thread and forwards information in thread
189189
// locals to it. The new thread runs the deadlock handler.
190190

191-
// Get a `GlobalCtxt` reference from `CurrentGcx` as we cannot rely on having a
192-
// `TyCtxt` TLS reference here.
193-
let query_map = current_gcx2.access(|gcx| {
194-
tls::enter_context(&tls::ImplicitCtxt::new(gcx), || {
195-
tls::with(|tcx| {
196-
match QueryCtxt::new(tcx).collect_active_jobs() {
197-
Ok(query_map) => query_map,
198-
Err(_) => {
199-
// There was an unexpected error collecting all active jobs, which we need
200-
// to find cycles to break.
201-
// We want to avoid panicking in the deadlock handler, so we abort instead.
202-
eprintln!("internal compiler error: failed to get query map in deadlock handler, aborting process");
203-
process::abort();
204-
}
205-
}
206-
})
207-
})
208-
});
209-
let query_map = FromDyn::from(query_map);
191+
let current_gcx2 = current_gcx2.clone();
210192
let registry = rayon_core::Registry::current();
193+
let session_globals = rustc_span::with_session_globals(|session_globals| {
194+
session_globals as *const SessionGlobals as usize
195+
});
211196
thread::Builder::new()
212197
.name("rustc query cycle handler".to_string())
213198
.spawn(move || {
@@ -217,7 +202,24 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
217202
// otherwise the compiler could just hang,
218203
process::abort();
219204
});
220-
break_query_cycles(query_map.into_inner(), &registry);
205+
206+
// Get a `GlobalCtxt` reference from `CurrentGcx` as we cannot rely on having a
207+
// `TyCtxt` TLS reference here.
208+
current_gcx2.access(|gcx| {
209+
tls::enter_context(&tls::ImplicitCtxt::new(gcx), || {
210+
tls::with(|tcx| {
211+
// Accessing session globals is sound as they outlive `GlobalCtxt`.
212+
// They are needed to hash query keys containing spans or symbols.
213+
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
214+
// Ensure there was no errors collecting all active jobs.
215+
// We need the complete map to ensure we find a cycle to break.
216+
QueryCtxt::new(tcx).collect_active_jobs().ok().expect("failed to collect active queries in deadlock handler")
217+
});
218+
break_query_cycles(query_map, &registry);
219+
})
220+
})
221+
});
222+
221223
on_panic.disable();
222224
})
223225
.unwrap();

compiler/rustc_lint/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ lint_tykind_kind = usage of `ty::TyKind::<kind>`
799799
lint_type_ir_inherent_usage = do not use `rustc_type_ir::inherent` unless you're inside of the trait solver
800800
.note = the method or struct you're looking for is likely defined somewhere else downstream in the compiler
801801
802+
lint_type_ir_trait_usage = do not use `rustc_type_ir::Interner` or `rustc_type_ir::InferCtxtLike` unless you're inside of the trait solver
803+
.note = the method or struct you're looking for is likely defined somewhere else downstream in the compiler
804+
802805
lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
803806
.label = argument has type `{$arg_ty}`
804807
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value

0 commit comments

Comments
 (0)