From 76249e1a0555a60774d475732bf3512d99af1b02 Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Sun, 6 Jul 2025 20:58:14 +0100 Subject: [PATCH 1/3] Restrict sysroot crate imports to those defined in this repo. It's common to import dependencies from the sysroot via `extern crate` rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, the `extern crate` fails to resolve. To address this, re-export all such dependencies from the appropriate `rustc_*` crates, and use this alias from crates which would otherwise need to use `extern crate`. --- src/bin/log/setup.rs | 5 +- src/bin/log/tracing_chrome.rs | 65 +++++++++--------- src/bin/miri.rs | 7 +- src/borrow_tracker/stacked_borrows/stack.rs | 2 +- src/concurrency/data_race.rs | 1 + src/concurrency/thread.rs | 2 +- src/intrinsics/simd.rs | 74 ++++++++++----------- src/lib.rs | 7 +- src/machine.rs | 1 + src/provenance_gc.rs | 2 +- src/shims/native_lib/mod.rs | 1 + 11 files changed, 80 insertions(+), 87 deletions(-) diff --git a/src/bin/log/setup.rs b/src/bin/log/setup.rs index a9392d010f..63af8706ce 100644 --- a/src/bin/log/setup.rs +++ b/src/bin/log/setup.rs @@ -2,6 +2,7 @@ use std::env::{self, VarError}; use std::str::FromStr; use std::sync::{Mutex, OnceLock}; +use rustc_log::tracing; use rustc_middle::ty::TyCtxt; use rustc_session::{CtfeBacktrace, EarlyDiagCtxt}; @@ -72,8 +73,8 @@ fn init_logger_once(early_dcx: &EarlyDiagCtxt) { early_dcx, rustc_logger_config(), || { - tracing_subscriber::layer::SubscriberExt::with( - tracing_subscriber::Registry::default(), + rustc_log::tracing_subscriber::layer::SubscriberExt::with( + rustc_log::tracing_subscriber::Registry::default(), chrome_layer, ) }, diff --git a/src/bin/log/tracing_chrome.rs b/src/bin/log/tracing_chrome.rs index 310887a13a..f4bff76c20 100644 --- a/src/bin/log/tracing_chrome.rs +++ b/src/bin/log/tracing_chrome.rs @@ -24,12 +24,9 @@ #![allow(warnings)] #![cfg(feature = "tracing")] -// This is here and not in src/lib.rs since it is a direct dependency of tracing_chrome.rs and -// should not be included if the "tracing" feature is disabled. -extern crate tracing_core; - -use tracing_core::{field::Field, span, Event, Subscriber}; -use tracing_subscriber::{ +use rustc_log::tracing_core::{field::Field, span, Event, Subscriber}; +use rustc_log::tracing_subscriber::{ + self, layer::Context, registry::{LookupSpan, SpanRef}, Layer, @@ -526,16 +523,16 @@ where } }, TraceStyle::Async => Some( - span.scope() - .from_root() - .take(1) - .next() - .unwrap_or(span) - .id() - .into_u64() + span.scope() + .from_root() + .take(1) + .next() + .unwrap_or(span) + .id() + .into_u64() .cast_signed() // the comment above explains the cast ), - } + } } fn enter_span(&self, span: SpanRef, ts: f64, tid: usize, out: &Sender) { @@ -570,11 +567,11 @@ where Some(thread_data) => (thread_data, false), None => { let tid = self.max_tid.fetch_add(1, Ordering::SeqCst); - let out = self.out.lock().unwrap().clone(); + let out = self.out.lock().unwrap().clone(); let start = TracingChromeInstant::setup_for_thread_and_start(tid); *thread_data = Some(ThreadData { tid, out, start }); (thread_data.as_mut().unwrap(), true) - } + } }; start.with_elapsed_micros_subtracting_tracing(|ts| { @@ -586,7 +583,7 @@ where let _ignored = out.send(Message::NewThread(*tid, name)); } f(ts, *tid, out); - }); + }); }); } } @@ -608,15 +605,15 @@ where fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { if self.include_args { self.with_elapsed_micros_subtracting_tracing(|_, _, _| { - let span = ctx.span(id).unwrap(); - let mut exts = span.extensions_mut(); + let span = ctx.span(id).unwrap(); + let mut exts = span.extensions_mut(); - let args = exts.get_mut::(); + let args = exts.get_mut::(); - if let Some(args) = args { - let args = Arc::make_mut(&mut args.args); - values.record(&mut JsonVisitor { object: args }); - } + if let Some(args) = args { + let args = Arc::make_mut(&mut args.args); + values.record(&mut JsonVisitor { object: args }); + } }); } } @@ -639,16 +636,16 @@ where fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { self.with_elapsed_micros_subtracting_tracing(|ts, tid, out| { - if self.include_args { - let mut args = Object::new(); - attrs.record(&mut JsonVisitor { object: &mut args }); - ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper { - args: Arc::new(args), - }); - } - if let TraceStyle::Threaded = self.trace_style { - return; - } + if self.include_args { + let mut args = Object::new(); + attrs.record(&mut JsonVisitor { object: &mut args }); + ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper { + args: Arc::new(args), + }); + } + if let TraceStyle::Threaded = self.trace_style { + return; + } self.enter_span(ctx.span(id).expect("Span not found."), ts, tid, out); }); diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 3c759521c6..40ad571fe1 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -8,11 +8,6 @@ rustc::untranslatable_diagnostic )] -// Some "regular" crates we want to share with rustc -extern crate tracing; -#[cfg(feature = "tracing")] -extern crate tracing_subscriber; - // The rustc crates we need extern crate rustc_abi; extern crate rustc_data_structures; @@ -48,6 +43,7 @@ use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{self as hir, Node}; use rustc_hir_analysis::check::check_function_signature; use rustc_interface::interface::Config; +use rustc_log::tracing::debug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::{ ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, @@ -60,7 +56,6 @@ use rustc_session::EarlyDiagCtxt; use rustc_session::config::{CrateType, ErrorOutputType, OptLevel}; use rustc_session::search_paths::PathKind; use rustc_span::def_id::DefId; -use tracing::debug; use crate::log::setup::{deinit_loggers, init_early_loggers, init_late_loggers}; diff --git a/src/borrow_tracker/stacked_borrows/stack.rs b/src/borrow_tracker/stacked_borrows/stack.rs index dc3370f125..fcd6216fc3 100644 --- a/src/borrow_tracker/stacked_borrows/stack.rs +++ b/src/borrow_tracker/stacked_borrows/stack.rs @@ -2,7 +2,7 @@ use std::ops::Range; use rustc_data_structures::fx::FxHashSet; -use tracing::trace; +use rustc_log::tracing::trace; use crate::borrow_tracker::stacked_borrows::{Item, Permission}; use crate::borrow_tracker::{AccessKind, BorTag}; diff --git a/src/concurrency/data_race.rs b/src/concurrency/data_race.rs index 1f30f9d728..bc1bb93a74 100644 --- a/src/concurrency/data_race.rs +++ b/src/concurrency/data_race.rs @@ -48,6 +48,7 @@ use rustc_abi::{Align, HasDataLayout, Size}; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::{Idx, IndexVec}; +use rustc_log::tracing; use rustc_middle::mir; use rustc_middle::ty::Ty; use rustc_span::Span; diff --git a/src/concurrency/thread.rs b/src/concurrency/thread.rs index 13492c9929..dd2b0edcb8 100644 --- a/src/concurrency/thread.rs +++ b/src/concurrency/thread.rs @@ -5,10 +5,10 @@ use std::sync::atomic::Ordering::Relaxed; use std::task::Poll; use std::time::{Duration, SystemTime}; -use either::Either; use rand::seq::IteratorRandom; use rustc_abi::ExternAbi; use rustc_const_eval::CTRL_C_RECEIVED; +use rustc_data_structures::either::Either; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_index::{Idx, IndexVec}; diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 1e7366b5a8..bf7834422a 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -38,47 +38,47 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { for i in 0..dest_len { let op = this.read_immediate(&this.project_index(&op, i)?)?; let dest = this.project_index(&dest, i)?; - let ty::Float(float_ty) = op.layout.ty.kind() else { - span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name) - }; - // Using host floats except for sqrt (but it's fine, these operations do not - // have guaranteed precision). + let ty::Float(float_ty) = op.layout.ty.kind() else { + span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name) + }; + // Using host floats except for sqrt (but it's fine, these operations do not + // have guaranteed precision). let val = match float_ty { - FloatTy::F16 => unimplemented!("f16_f128"), - FloatTy::F32 => { - let f = op.to_scalar().to_f32()?; + FloatTy::F16 => unimplemented!("f16_f128"), + FloatTy::F32 => { + let f = op.to_scalar().to_f32()?; let res = match intrinsic_name { - "fsqrt" => math::sqrt(f), - "fsin" => f.to_host().sin().to_soft(), - "fcos" => f.to_host().cos().to_soft(), - "fexp" => f.to_host().exp().to_soft(), - "fexp2" => f.to_host().exp2().to_soft(), - "flog" => f.to_host().ln().to_soft(), - "flog2" => f.to_host().log2().to_soft(), - "flog10" => f.to_host().log10().to_soft(), - _ => bug!(), - }; - let res = this.adjust_nan(res, &[f]); - Scalar::from(res) - } - FloatTy::F64 => { - let f = op.to_scalar().to_f64()?; + "fsqrt" => math::sqrt(f), + "fsin" => f.to_host().sin().to_soft(), + "fcos" => f.to_host().cos().to_soft(), + "fexp" => f.to_host().exp().to_soft(), + "fexp2" => f.to_host().exp2().to_soft(), + "flog" => f.to_host().ln().to_soft(), + "flog2" => f.to_host().log2().to_soft(), + "flog10" => f.to_host().log10().to_soft(), + _ => bug!(), + }; + let res = this.adjust_nan(res, &[f]); + Scalar::from(res) + } + FloatTy::F64 => { + let f = op.to_scalar().to_f64()?; let res = match intrinsic_name { - "fsqrt" => math::sqrt(f), - "fsin" => f.to_host().sin().to_soft(), - "fcos" => f.to_host().cos().to_soft(), - "fexp" => f.to_host().exp().to_soft(), - "fexp2" => f.to_host().exp2().to_soft(), - "flog" => f.to_host().ln().to_soft(), - "flog2" => f.to_host().log2().to_soft(), - "flog10" => f.to_host().log10().to_soft(), - _ => bug!(), + "fsqrt" => math::sqrt(f), + "fsin" => f.to_host().sin().to_soft(), + "fcos" => f.to_host().cos().to_soft(), + "fexp" => f.to_host().exp().to_soft(), + "fexp2" => f.to_host().exp2().to_soft(), + "flog" => f.to_host().ln().to_soft(), + "flog2" => f.to_host().log2().to_soft(), + "flog10" => f.to_host().log10().to_soft(), + _ => bug!(), + }; + let res = this.adjust_nan(res, &[f]); + Scalar::from(res) + } + FloatTy::F128 => unimplemented!("f16_f128"), }; - let res = this.adjust_nan(res, &[f]); - Scalar::from(res) - } - FloatTy::F128 => unimplemented!("f16_f128"), - }; this.write_scalar(val, &dest)?; } diff --git a/src/lib.rs b/src/lib.rs index 07af4dcaad..8b85e9e3dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,10 +49,6 @@ // Needed for rustdoc from bootstrap (with `-Znormalize-docs`). #![recursion_limit = "256"] -// Some "regular" crates we want to share with rustc -extern crate either; -extern crate tracing; - // The rustc crates we need extern crate rustc_abi; extern crate rustc_apfloat; @@ -63,6 +59,7 @@ extern crate rustc_errors; extern crate rustc_hash; extern crate rustc_hir; extern crate rustc_index; +extern crate rustc_log; extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; @@ -96,8 +93,8 @@ pub use rustc_const_eval::interpret::*; // Resolve ambiguity. #[doc(no_inline)] pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _}; +use rustc_log::tracing::{self, info, trace}; use rustc_middle::{bug, span_bug}; -use tracing::{info, trace}; #[cfg(all(unix, feature = "native-lib"))] pub mod native_lib { diff --git a/src/machine.rs b/src/machine.rs index 49c2351665..b9785b85eb 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -16,6 +16,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; #[allow(unused)] use rustc_data_structures::static_assert_size; use rustc_hir::attrs::InlineAttr; +use rustc_log::tracing; use rustc_middle::middle::codegen_fn_attrs::TargetFeatureKind; use rustc_middle::mir; use rustc_middle::query::TyCtxtAt; diff --git a/src/provenance_gc.rs b/src/provenance_gc.rs index 6adf144864..66b0adb3c4 100644 --- a/src/provenance_gc.rs +++ b/src/provenance_gc.rs @@ -1,4 +1,4 @@ -use either::Either; +use rustc_data_structures::either::Either; use rustc_data_structures::fx::FxHashSet; use crate::*; diff --git a/src/shims/native_lib/mod.rs b/src/shims/native_lib/mod.rs index 47102c30bc..d111d8d32d 100644 --- a/src/shims/native_lib/mod.rs +++ b/src/shims/native_lib/mod.rs @@ -6,6 +6,7 @@ use std::sync::atomic::AtomicBool; use libffi::low::CodePtr; use libffi::middle::Type as FfiType; use rustc_abi::{HasDataLayout, Size}; +use rustc_data_structures::either; use rustc_middle::ty::layout::HasTypingEnv; use rustc_middle::ty::{self, IntTy, Ty, UintTy}; use rustc_span::Symbol; From a04e2b04a343c7280b31da5299b8c6f4be738fcc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 Oct 2025 21:01:18 +0200 Subject: [PATCH 2/3] Prepare for merging from rust-lang/rust This updates the rust-version file to 28d0a4a205f9e511ad2f51ee79a4aa19a704a455. --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index f4bdbbff8e..1160b1b972 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -235a4c083eb2a2bfe8779d211c3232f39396de00 +28d0a4a205f9e511ad2f51ee79a4aa19a704a455 From afceaa048a19349db4b6ad0a7e22f67050eea401 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 Oct 2025 21:58:02 +0200 Subject: [PATCH 3/3] fix genmc build --- src/concurrency/genmc/global_allocations.rs | 2 +- src/concurrency/genmc/run.rs | 1 + src/concurrency/genmc/scheduling.rs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/concurrency/genmc/global_allocations.rs b/src/concurrency/genmc/global_allocations.rs index 272f8d2484..7f34c60dcd 100644 --- a/src/concurrency/genmc/global_allocations.rs +++ b/src/concurrency/genmc/global_allocations.rs @@ -6,7 +6,7 @@ use rand::SeedableRng; use rand::rngs::StdRng; use rustc_const_eval::interpret::{AllocId, AllocInfo, InterpResult, interp_ok}; use rustc_data_structures::fx::FxHashMap; -use tracing::debug; +use rustc_log::tracing::debug; use crate::alloc_addresses::AddressGenerator; diff --git a/src/concurrency/genmc/run.rs b/src/concurrency/genmc/run.rs index 6721a38c68..6eb51e1b50 100644 --- a/src/concurrency/genmc/run.rs +++ b/src/concurrency/genmc/run.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use std::time::Instant; use genmc_sys::EstimationResult; +use rustc_log::tracing; use rustc_middle::ty::TyCtxt; use super::GlobalState; diff --git a/src/concurrency/genmc/scheduling.rs b/src/concurrency/genmc/scheduling.rs index 6ccbaf4f24..0703e0595b 100644 --- a/src/concurrency/genmc/scheduling.rs +++ b/src/concurrency/genmc/scheduling.rs @@ -1,4 +1,5 @@ use genmc_sys::{ActionKind, ExecutionState}; +use rustc_data_structures::either::Either; use rustc_middle::mir::TerminatorKind; use rustc_middle::ty::{self, Ty}; @@ -38,7 +39,7 @@ fn get_next_instruction_kind<'tcx>( let Some(frame) = thread_manager.active_thread_stack().last() else { return interp_ok(NonAtomic); }; - let either::Either::Left(loc) = frame.current_loc() else { + let Either::Left(loc) = frame.current_loc() else { // We are unwinding, so the next step is definitely not atomic. return interp_ok(NonAtomic); };