diff --git a/compiler/rustc_borrowck/src/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs index 8813ef5249262..df20eb0e49c62 100644 --- a/compiler/rustc_borrowck/src/def_use.rs +++ b/compiler/rustc_borrowck/src/def_use.rs @@ -59,8 +59,7 @@ pub(crate) fn categorize(context: PlaceContext) -> Option { PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) | PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) | PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) | - PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) | - PlaceContext::MutatingUse(MutatingUseContext::Retag) => Some(DefUse::Use), + PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) => Some(DefUse::Use), /////////////////////////////////////////////////////////////////////////// // DROP USES diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 45a9e04986c74..5bf6b44c41ebc 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -211,8 +211,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> Visitor<'tcx> for LocalAnalyzer } PlaceContext::NonUse(_) - | PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) - | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {} + | PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) => {} PlaceContext::NonMutatingUse( NonMutatingUseContext::Copy diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 6f4919cbe507f..722c97d64c03f 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -606,6 +606,11 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_type_info(ty, dest)?; } + sym::type_id_is_signed => { + let ty = ecx.read_type_id(&args[0])?; + ecx.write_scalar(Scalar::from_bool(ty.is_signed()), dest)?; + } + sym::size_of_type_id => { let ty = ecx.read_type_id(&args[0])?; let layout = ecx.layout_of(ty)?; diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 3fea9d44946f6..11d21744bd7ae 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -221,6 +221,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::type_id_field_representing_type | sym::type_id_fields | sym::type_id_generics + | sym::type_id_is_signed | sym::type_id_variants | sym::type_id_vtable | sym::type_name @@ -332,6 +333,7 @@ pub(crate) fn check_intrinsic_type( (0, 0, vec![type_id_ty(), tcx.types.usize, tcx.types.usize], type_id_ty()) } sym::type_id_fields => (0, 0, vec![type_id_ty(), tcx.types.usize], tcx.types.usize), + sym::type_id_is_signed => (0, 0, vec![type_id_ty()], tcx.types.bool), sym::type_id_variants => (0, 0, vec![type_id_ty()], tcx.types.usize), sym::type_id_vtable => { let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, span); diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 429ab7d928fc5..0ae59e99c2b5a 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1354,8 +1354,6 @@ pub enum MutatingUseContext { /// f(&mut x.y); /// ``` Projection, - /// Retagging, a "Stacked Borrows" shadow state operation - Retag, } #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 5c77827a67165..2787365c17be1 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -180,8 +180,7 @@ impl DefUse { PlaceContext::MutatingUse( MutatingUseContext::RawBorrow | MutatingUseContext::Borrow - | MutatingUseContext::Drop - | MutatingUseContext::Retag, + | MutatingUseContext::Drop, ) | PlaceContext::NonMutatingUse( NonMutatingUseContext::RawBorrow diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs index bcd43bc40d8bc..5bba125aefc58 100644 --- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs +++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs @@ -74,8 +74,7 @@ impl<'tcx> Visitor<'tcx> for DeduceParamAttrs { MutatingUseContext::Store | MutatingUseContext::SetDiscriminant | MutatingUseContext::AsmOutput - | MutatingUseContext::Projection - | MutatingUseContext::Retag) => { + | MutatingUseContext::Projection) => { self.usage[i] |= UsageSummary::MUTATE; } | PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) => { diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 1a2d47f4cc258..a2f2f8fa063c2 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -975,7 +975,6 @@ impl<'tcx> Visitor<'tcx> for CanConstProp { // whether they'd be fine right now. MutatingUse(MutatingUseContext::Yield) | MutatingUse(MutatingUseContext::Drop) - | MutatingUse(MutatingUseContext::Retag) // These can't ever be propagated under any scheme, as we can't reason about indirect // mutation. | NonMutatingUse(NonMutatingUseContext::SharedBorrow) diff --git a/compiler/rustc_mir_transform/src/liveness.rs b/compiler/rustc_mir_transform/src/liveness.rs index c895819a9f8cc..4da8ca0760257 100644 --- a/compiler/rustc_mir_transform/src/liveness.rs +++ b/compiler/rustc_mir_transform/src/liveness.rs @@ -1548,8 +1548,7 @@ impl DefUse { PlaceContext::MutatingUse( MutatingUseContext::RawBorrow | MutatingUseContext::Borrow - | MutatingUseContext::Drop - | MutatingUseContext::Retag, + | MutatingUseContext::Drop, ) | PlaceContext::NonMutatingUse( NonMutatingUseContext::RawBorrow diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs index 093b930ce9c70..cf10b3a30f318 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs @@ -162,7 +162,20 @@ where let prev_universe = delegate.universe(); let universes_created_in_query = response.max_universe.index(); for _ in 0..universes_created_in_query { - delegate.create_next_universe(); + let new_universe = delegate.create_next_universe(); + if delegate.cx().assumptions_on_binders() { + // FIXME(-Zassumptions-on-binders): Remove this temporary workaround once + // opaque types no longer escape query responses with query-created placeholders. + // Region constraints involving query-created placeholders were handled inside + // the query. However, the placeholders can still escape in other response + // fields, such as opaque type constraints. To avoid triggering + // assertions, we explicitly insert empty assumptions for the + // recreated universes here. + delegate.insert_placeholder_assumptions( + new_universe, + Some(rustc_type_ir::region_constraint::Assumptions::empty()), + ); + } } compute_query_response_instantiation_values_in_universe( diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/fast_path.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/fast_path.rs index 299eeda404878..307aa2bfd6893 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/fast_path.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/fast_path.rs @@ -7,7 +7,7 @@ use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{ - Certainty, ComputeGoalFastPathOutcome, Goal, GoalStalledOn, GoalStalledOnOpaques, + Certainty, ComputeGoalFastPathOutcome, Goal, GoalStalledOn, GoalStalledOnOpaques, MaybeInfo, SucceededInErased, }; use rustc_type_ir::{InferCtxtLike, Interner}; @@ -18,7 +18,7 @@ use crate::solve::{GoalEvaluation, HasChanged}; #[derive(Debug, Clone, Copy)] pub(super) enum RerunStalled { - WontMakeProgress(Certainty), + WontMakeProgress(MaybeInfo), MayMakeProgress, } @@ -43,7 +43,7 @@ where } // If the goal isn't stalled, we should definitely run it. - let Some(&GoalStalledOn { ref opaques, ref stalled_vars, ref sub_roots, stalled_certainty }) = + let Some(&GoalStalledOn { ref opaques, ref stalled_vars, ref sub_roots, stalled_maybe_info }) = stalled_on else { return MayMakeProgress; @@ -105,7 +105,7 @@ where // Otherwise, we can be sure that this stalled goal cannot make any progress // and we can exit early. - WontMakeProgress(stalled_certainty) + WontMakeProgress(stalled_maybe_info) } /// `compute_goal_fast_path` is complicated enough that outling helps, so it gets optimized diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index ba06f8a2a0193..2feaa6206de83 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -181,8 +181,7 @@ pub trait SolverDelegateEvalExt: SolverDelegate { /// Checks whether a stalled goal would remain stalled if re-evaluated, without consuming /// `stalled_on`. - fn goal_remains_stalled(&self, stalled_on: &GoalStalledOn) - -> Option; + fn goal_remains_stalled(&self, stalled_on: &GoalStalledOn) -> bool; /// Checks whether evaluating `goal` may hold while treating not-yet-defined /// opaque types as being kind of rigid. @@ -231,12 +230,12 @@ where stalled_on: Option>, ) -> Result, NoSolution> { // Run fast paths *before* building an `EvalCtxt`, saving a little bit of time. - if let RerunStalled::WontMakeProgress(stalled_certainty) = + if let RerunStalled::WontMakeProgress(stalled_maybe_info) = rerunning_stalled_goal_may_make_progress(self, stalled_on.as_ref()) { return Ok(GoalEvaluation { goal, - certainty: stalled_certainty, + certainty: Certainty::Maybe(stalled_maybe_info), has_changed: HasChanged::No, stalled_on, }); @@ -265,13 +264,10 @@ where } } - fn goal_remains_stalled( - &self, - stalled_on: &GoalStalledOn, - ) -> Option { + fn goal_remains_stalled(&self, stalled_on: &GoalStalledOn) -> bool { match rerunning_stalled_goal_may_make_progress(self, Some(stalled_on)) { - RerunStalled::WontMakeProgress(certainty) => Some(certainty), - RerunStalled::MayMakeProgress => None, + RerunStalled::WontMakeProgress(_) => true, + RerunStalled::MayMakeProgress => false, } } @@ -608,12 +604,12 @@ where goal: Goal, stalled_on: Option>, ) -> Result, NoSolutionOrRerunNonErased> { - if let RerunStalled::WontMakeProgress(stalled_certainty) = + if let RerunStalled::WontMakeProgress(stalled_maybe_info) = rerunning_stalled_goal_may_make_progress(self.delegate, stalled_on.as_ref()) { return Ok(GoalEvaluation { goal, - certainty: stalled_certainty, + certainty: Certainty::Maybe(stalled_maybe_info), has_changed: HasChanged::No, stalled_on, }); @@ -814,7 +810,7 @@ where let stalled_on = match certainty { Certainty::Yes => None, - Certainty::Maybe { .. } => match has_changed { + Certainty::Maybe(maybe_info) => match has_changed { // FIXME: We could recompute a *new* set of stalled variables by walking // through the orig values, resolving, and computing the root vars of anything // that is not resolved. Only when *these* have changed is it meaningful @@ -822,7 +818,7 @@ where HasChanged::Yes => None, HasChanged::No => Some(self.build_stalled_on( canonical_goal, - certainty, + maybe_info, orig_values, succeeded_in_erased, )), @@ -838,7 +834,7 @@ where fn build_stalled_on( &self, canonical_goal: CanonicalInput, - certainty: Certainty, + maybe_info: MaybeInfo, stalled_vars: ThinVec, previously_succeeded_in_erased: SucceededInErased, ) -> GoalStalledOn { @@ -872,7 +868,7 @@ where GoalStalledOn { stalled_vars, sub_roots, - stalled_certainty: certainty, + stalled_maybe_info: maybe_info, opaques: GoalStalledOnOpaques::Yes { num_opaques_in_storage: canonical_goal .canonical diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 07d6eb03ae8da..85f0ce7e6af00 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2179,6 +2179,7 @@ symbols! { type_id_field_representing_type, type_id_fields, type_id_generics, + type_id_is_signed, type_id_variants, type_id_vtable, type_info, diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index 908b3452fc743..fa8d6e3656273 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -14,7 +14,7 @@ use rustc_infer::traits::solve::{ ComputeGoalFastPathOutcome, FetchEligibleAssocItemResponse, Goal, SucceededInErased, }; use rustc_middle::traits::query::NoSolution; -use rustc_middle::traits::solve::Certainty; +use rustc_middle::traits::solve::{Certainty, MaybeInfo}; use rustc_middle::ty::{ self, MayBeErased, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, @@ -61,7 +61,7 @@ fn goal_stalled_on_args<'tcx>( stalled_on: GoalStalledOn { stalled_vars, sub_roots: ThinVec::new(), - stalled_certainty: Certainty::AMBIGUOUS, + stalled_maybe_info: MaybeInfo::AMBIGUOUS, opaques: GoalStalledOnOpaques::No, }, } @@ -77,7 +77,7 @@ fn goal_stalled_on_args_or_nonempty_opaques<'tcx>( stalled_on: GoalStalledOn { stalled_vars, sub_roots: ThinVec::new(), - stalled_certainty: Certainty::AMBIGUOUS, + stalled_maybe_info: MaybeInfo::AMBIGUOUS, opaques: GoalStalledOnOpaques::Yes { num_opaques_in_storage: 0, // This function should only be called when not in erased mode, diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index b3b8337a81f6a..549dcc24cfa9a 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -9,8 +9,7 @@ use rustc_infer::traits::{ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode}; use rustc_next_trait_solver::solve::fast_path::compute_goal_fast_path; use rustc_next_trait_solver::solve::{ - GoalEvaluation, GoalStalledOn, HasChanged, MaybeInfo, SolverDelegateEvalExt as _, - StalledOnCoroutines, + GoalEvaluation, GoalStalledOn, HasChanged, SolverDelegateEvalExt as _, StalledOnCoroutines, }; use thin_vec::ThinVec; use tracing::instrument; @@ -208,8 +207,7 @@ where // Common case: still stalled; keep the obligation. This path is extremely hot in // some cases; there can be thousands of pending obligations. if let Some(stalled_on) = opt_stalled_on - && let Some(certainty) = delegate.goal_remains_stalled(stalled_on) - && matches!(certainty, Certainty::Maybe(_)) + && delegate.goal_remains_stalled(stalled_on) { return true; } @@ -378,13 +376,11 @@ where self.obligations .drain_pending(|_, stalled_on| { - stalled_on.as_ref().is_some_and(|s| match s.stalled_certainty { - Certainty::Maybe(MaybeInfo { - cause: _, - opaque_types_jank: _, - stalled_on_coroutines: StalledOnCoroutines::Yes, - }) => true, - Certainty::Maybe(_) | Certainty::Yes => false, + stalled_on.as_ref().is_some_and(|s| { + match s.stalled_maybe_info.stalled_on_coroutines { + StalledOnCoroutines::Yes => true, + StalledOnCoroutines::No => false, + } }) }) .into_iter() diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index 3f5ad1ed9a8f5..aa250c04388e3 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -993,9 +993,9 @@ pub struct GoalStalledOn { pub stalled_vars: ThinVec, // `ThinVec` is important for performance. See #160005. pub sub_roots: ThinVec, - /// The certainty that will be returned on subsequent evaluations if this + /// The `MaybeInfo` that will be returned on subsequent evaluations if this /// goal remains stalled. - pub stalled_certainty: Certainty, + pub stalled_maybe_info: MaybeInfo, pub opaques: GoalStalledOnOpaques, } diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index fad2cb08a8a64..4e67199bba8c9 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -3128,6 +3128,14 @@ pub const fn type_id_eq(a: crate::any::TypeId, b: crate::any::TypeId) -> bool { unsafe { crate::mem::transmute::<_, u128>(a) == crate::mem::transmute::<_, u128>(b) } } +/// Returns whether the type represented by this `TypeId` is a signed integer. +/// +/// The more user-friendly version of this intrinsic is [`core::any::TypeId::is_signed`]. +#[rustc_intrinsic] +#[unstable(feature = "core_intrinsics", issue = "none")] +#[rustc_comptime] +pub fn type_id_is_signed(_id: crate::any::TypeId) -> bool; + /// Gets the size of the type represented by this `TypeId`. /// /// The more user-friendly version of this intrinsic is [`core::any::TypeId::size`]. diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index 66f85dab7b6c9..dd97a3c7197fd 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -379,6 +379,27 @@ pub enum Abi { } impl TypeId { + /// Returns `true` if the type represented by this `TypeId` is an signed integer. + /// + /// For everything else this returns false. + /// + /// # Examples + /// + /// ``` + /// #![feature(type_info)] + /// use std::any::TypeId; + /// + /// assert_eq!(const { TypeId::of::().is_signed() }, true); + /// assert_eq!(const { TypeId::of::().is_signed() }, false); + /// assert_eq!(const { TypeId::of::().is_signed() }, false); + /// ``` + #[unstable(feature = "type_info", issue = "146922")] + #[rustc_const_unstable(feature = "type_info", issue = "146922")] + #[rustc_comptime] + pub fn is_signed(self) -> bool { + intrinsics::type_id_is_signed(self) + } + /// Returns the size of the type represented by this `TypeId`. `None` if it is unsized. /// /// # Examples diff --git a/src/bootstrap/src/cli_main.rs b/src/bootstrap/src/cli_main.rs index 879cf7159fb6b..59f3c1a1e5e1c 100644 --- a/src/bootstrap/src/cli_main.rs +++ b/src/bootstrap/src/cli_main.rs @@ -13,10 +13,14 @@ use std::sync::Once; use std::time::Instant; use std::{env, process}; -use crate::{ - Build, CONFIG_CHANGE_HISTORY, ChangeId, Config, Flags, StepStack, Subcommand, debug, - find_recent_config_change_ids, human_readable_changes, t, +use crate::core::builder::StepStack; +use crate::core::config::flags::Flags; +use crate::core::config::{ChangeId, Config, Subcommand}; +use crate::utils::change_tracker::{ + CONFIG_CHANGE_HISTORY, find_recent_config_change_ids, human_readable_changes, }; +use crate::utils::helpers::t; +use crate::{Build, debug}; fn is_tracing_enabled() -> bool { cfg!(feature = "tracing") diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 0b2a74a0426ac..82b7a11d0183c 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -16,9 +16,10 @@ use crate::core::builder::{ self, Alias, Builder, Cargo, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description, }; -use crate::core::config::TargetSelection; +use crate::core::config::{Subcommand, TargetSelection}; use crate::utils::build_stamp::{self, BuildStamp}; -use crate::{CodegenBackendKind, Compiler, Mode, Subcommand, t}; +use crate::utils::helpers::t; +use crate::{CodegenBackendKind, Compiler, Mode}; /// Allows individual check-step instances to keep track of whether they /// represent `cargo check` or `cargo fix`, independently of [`Builder::kind`]. diff --git a/src/bootstrap/src/core/build_steps/clean.rs b/src/bootstrap/src/core/build_steps/clean.rs index 8219ffd5ec586..57a5ccdeadfac 100644 --- a/src/bootstrap/src/core/build_steps/clean.rs +++ b/src/bootstrap/src/core/build_steps/clean.rs @@ -9,10 +9,13 @@ use std::fs; use std::io::{self, ErrorKind}; use std::path::Path; -use crate::core::builder::{Builder, CommandLineStep, RunConfig, ShouldRun, crate_description}; +use crate::core::builder::{ + Builder, CommandLineStep, Kind, RunConfig, ShouldRun, crate_description, +}; +use crate::core::config::Subcommand; use crate::utils::build_stamp::BuildStamp; use crate::utils::helpers::t; -use crate::{Build, Compiler, Kind, Mode, Subcommand}; +use crate::{Build, Compiler, Mode}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CleanAll {} diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 8df931a24fd25..f3f54b380dd0c 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -14,17 +14,17 @@ //! (as usual) a massive undertaking/refactoring. use super::tool::{SourceType, prepare_tool_cargo}; -use crate::builder::{Builder, ShouldRun}; use crate::core::build_steps::check::{CompilerForCheck, prepare_compiler_for_check}; use crate::core::build_steps::compile::{ ArtifactKeepMode, run_cargo, rustc_cargo, std_cargo, std_crates_for_make_run, }; use crate::core::builder; use crate::core::builder::{ - Alias, CommandLineStep, Kind, RunConfig, StepMetadata, crate_description, + Alias, Builder, CommandLineStep, Kind, RunConfig, ShouldRun, StepMetadata, crate_description, }; +use crate::core::config::{Subcommand, TargetSelection}; use crate::utils::build_stamp::{self, BuildStamp}; -use crate::{Compiler, Mode, Subcommand, TargetSelection, exit}; +use crate::{Compiler, Mode, exit}; /// Disable the most spammy clippy lints const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[ diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index f7ef0a93c1446..8894a7d257de1 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -20,7 +20,7 @@ use crate::core::builder::{ crate_description, }; use crate::core::config::{Config, TargetSelection}; -use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date}; +use crate::utils::helpers::{submodule_path_of, symlink_dir, t, up_to_date}; use crate::{FileType, Mode}; macro_rules! book { diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs index ed0e57b884aa8..d3540bd21b0e4 100644 --- a/src/bootstrap/src/core/build_steps/gcc.rs +++ b/src/bootstrap/src/core/build_steps/gcc.rs @@ -16,7 +16,7 @@ use std::sync::OnceLock; use build_helper::git::PathFreshness; use crate::core::builder::{Builder, Cargo, CommandLineStep, Kind, RunConfig, ShouldRun}; -use crate::core::config::TargetSelection; +use crate::core::config::{Config, TargetSelection}; use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash}; use crate::utils::exec::command; use crate::utils::helpers::{self, t}; @@ -366,12 +366,12 @@ pub fn add_cg_gcc_cargo_flags(cargo: &mut Cargo, gcc: &GccOutput) { } /// The absolute path to the downloaded GCC artifacts. -fn ci_gcc_root(config: &crate::Config, target: TargetSelection) -> PathBuf { +fn ci_gcc_root(config: &Config, target: TargetSelection) -> PathBuf { config.out.join(target).join("ci-gcc") } /// Detect whether GCC sources have been modified locally or not. -fn detect_gcc_freshness(config: &crate::Config, is_git: bool) -> build_helper::git::PathFreshness { +fn detect_gcc_freshness(config: &Config, is_git: bool) -> build_helper::git::PathFreshness { assert!(cfg!(not(test)), "unit tests shouldn't care about GCC freshness"); if is_git { diff --git a/src/bootstrap/src/core/build_steps/install.rs b/src/bootstrap/src/core/build_steps/install.rs index 7950caa18ce71..766c2cc0297d6 100644 --- a/src/bootstrap/src/core/build_steps/install.rs +++ b/src/bootstrap/src/core/build_steps/install.rs @@ -6,14 +6,14 @@ use std::path::{Component, Path, PathBuf}; use std::{env, fs}; +use crate::Compiler; use crate::core::build_steps::dist; use crate::core::build_steps::tool::RustcPrivateCompilers; -use crate::core::builder::{Builder, CommandLineStep, RunConfig, ShouldRun}; +use crate::core::builder::{Builder, CommandLineStep, Kind, RunConfig, ShouldRun}; use crate::core::config::{Config, TargetSelection}; use crate::utils::exec::command; use crate::utils::helpers::t; use crate::utils::tarball::GeneratedTarball; -use crate::{Compiler, Kind}; #[cfg(target_os = "illumos")] const SHELL: &str = "bash"; diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index a402092e7d0e2..67615353b1d9f 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -17,14 +17,16 @@ use std::{env, fs}; use build_helper::git::PathFreshness; use crate::core::build_steps::llvm; -use crate::core::builder::{Builder, CommandLineStep, RunConfig, ShouldRun, Step, StepMetadata}; +use crate::core::builder::{ + Builder, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata, +}; use crate::core::config::{Config, LlvmPgoGenerationMode, TargetSelection}; use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash}; use crate::utils::exec::command; use crate::utils::helpers::{ self, exe, get_clang_cl_resource_dir, libdir, t, unhashed_basename, up_to_date, }; -use crate::{CLang, GitRepo, Kind, exit, trace}; +use crate::{CLang, GitRepo, exit, trace}; /// Result of building or downloading LLVM artifacts. #[derive(Clone)] diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index c062144aa5c41..c7825ed1a0345 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -16,7 +16,8 @@ use crate::core::builder::{Builder, CommandLineStep, Kind, RunConfig, ShouldRun, use crate::core::config::TargetSelection; use crate::core::config::flags::{get_completion, top_level_help}; use crate::utils::exec::command; -use crate::{Mode, exit, t}; +use crate::utils::helpers::t; +use crate::{Mode, exit}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct BuildManifest; diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs index 1ebed576d3806..1ddcb43a68588 100644 --- a/src/bootstrap/src/core/build_steps/setup.rs +++ b/src/bootstrap/src/core/build_steps/setup.rs @@ -20,10 +20,10 @@ use sha2::Digest; use crate::core::build_steps::format; use crate::core::builder::{Builder, CommandLineStep, RunConfig, ShouldRun}; +use crate::core::config::Config; use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY; use crate::utils::exec::command; -use crate::utils::helpers::{self, hex_encode}; -use crate::{Config, t}; +use crate::utils::helpers::{self, hex_encode, t}; #[cfg(test)] mod tests; diff --git a/src/bootstrap/src/core/build_steps/test/failed_tests.rs b/src/bootstrap/src/core/build_steps/test/failed_tests.rs index abcfbe31bb2c3..a41b485b34cb2 100644 --- a/src/bootstrap/src/core/build_steps/test/failed_tests.rs +++ b/src/bootstrap/src/core/build_steps/test/failed_tests.rs @@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader, ErrorKind}; use std::path::{Path, PathBuf}; use crate::core::builder::{Builder, Step}; -use crate::t; +use crate::utils::helpers::t; #[derive(Clone)] pub struct RecordFailedTests { diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index bc029cdfed54d..101309cc2451d 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -16,15 +16,14 @@ use std::{env, fs}; use crate::core::build_steps::compile::is_lto_stage; use crate::core::build_steps::toolstate::ToolState; use crate::core::build_steps::{compile, llvm}; -use crate::core::builder; use crate::core::builder::{ - Builder, Cargo as CargoCommand, CommandLineStep, RunConfig, ShouldRun, Step, StepMetadata, - apply_pgo, cargo_profile_var, + self, Builder, Cargo as CargoCommand, CommandLineStep, Kind, RunConfig, ShouldRun, Step, + StepMetadata, apply_pgo, cargo_profile_var, }; use crate::core::config::{Allocator, DebuginfoLevel, RustcLto, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; use crate::utils::helpers::{add_dylib_path, exe, t}; -use crate::{Compiler, FileType, Kind, Mode}; +use crate::{Compiler, FileType, Mode}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum SourceType { diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 3a1e4299b5475..cd4e40a58ffc3 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -7,12 +7,12 @@ use crate::core::build_steps::test; use crate::core::build_steps::tool::SourceType; use crate::core::config::flags::Color; use crate::core::config::toml::pgo::PgoConfig; -use crate::core::config::{CompressDebuginfo, SplitDebuginfo}; +use crate::core::config::{CompressDebuginfo, Config, DryRun, SplitDebuginfo, TargetSelection}; use crate::utils::build_stamp; -use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_flags}; +use crate::utils::exec::{BootstrapCommand, command}; +use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_flags, t}; use crate::{ - BootstrapCommand, CLang, Compiler, Config, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode, - RemapScheme, TargetSelection, command, prepare_behaviour_dump_dir, t, + CLang, Compiler, EXTRA_CHECK_CFGS, GitRepo, Mode, RemapScheme, prepare_behaviour_dump_dir, }; /// Represents flag values in `String` form with a `\x1f` delimiter to pass to the compiler later. diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index fa10de3c92fac..fc69eada5eb02 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -13,12 +13,13 @@ //! and the `bootstrap.toml` file—merging them, applying defaults, and performing //! cross-component validation. The main `parse_inner` function and its supporting //! helpers reside here, transforming raw `Toml` data into the structured `Config` type. + use std::cell::Cell; use std::collections::{BTreeSet, HashMap, HashSet}; use std::io::IsTerminal; use std::path::{Path, PathBuf, absolute}; use std::str::FromStr; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, OnceLock}; use std::{cmp, env, fs}; use build_helper::ci::CiEnv; @@ -51,15 +52,13 @@ use crate::core::config::toml::target::{ use crate::core::config::{ Allocator, CompilerBuiltins, CompressDebuginfo, DebuggerPath, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool, - threads_from_config, + TargetSelection, threads_from_config, }; use crate::core::download::{DownloadContext, download_beta_toolchain, is_download_ci_available}; -use crate::utils::channel; +use crate::utils::channel::{self, GitInfo}; use crate::utils::exec::{ExecutionContext, command}; -use crate::utils::helpers::{exe, fail, get_host_target}; -use crate::{ - CodegenBackendKind, GitInfo, OnceLock, TargetSelection, check_ci_llvm, exit, helpers, t, -}; +use crate::utils::helpers::{self, exe, fail, get_host_target, t}; +use crate::{CodegenBackendKind, check_ci_llvm, exit}; /// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic. /// This means they can be modified and changes to these paths should never trigger a compiler build diff --git a/src/bootstrap/src/core/config/mod.rs b/src/bootstrap/src/core/config/mod.rs index 6a3ab55f71aad..db901434a47e8 100644 --- a/src/bootstrap/src/core/config/mod.rs +++ b/src/bootstrap/src/core/config/mod.rs @@ -28,7 +28,9 @@ mod tests; pub mod toml; use std::collections::HashSet; +use std::fmt::Display; use std::path::PathBuf; +use std::str::FromStr; pub use config::*; use serde::de::Unexpected; @@ -40,8 +42,7 @@ pub use toml::change_id::ChangeId; pub use toml::rust::BootstrapOverrideLld; pub use toml::target::Target; -use crate::str::FromStr; -use crate::{Display, exit}; +use crate::exit; // We are using a decl macro instead of a derive proc macro here to reduce the compile time of bootstrap. #[macro_export] @@ -63,8 +64,8 @@ macro_rules! define_config { impl Merge for $name { fn merge( &mut self, - _parent_config_path: Option, - _included_extensions: &mut HashSet, + _parent_config_path: Option, + _included_extensions: &mut std::collections::HashSet, other: Self, replace: ReplaceOpt ) { @@ -87,7 +88,7 @@ macro_rules! define_config { panic!("overriding existing option") } else { eprintln!("overriding existing option: `{}`", stringify!($field)); - exit!(2); + $crate::exit!(2); } } else { self.$field = other.$field; diff --git a/src/bootstrap/src/core/config/target_selection.rs b/src/bootstrap/src/core/config/target_selection.rs index 62abd3038768b..4835755dd00b6 100644 --- a/src/bootstrap/src/core/config/target_selection.rs +++ b/src/bootstrap/src/core/config/target_selection.rs @@ -1,8 +1,8 @@ -use std::fmt; +use std::path::Path; +use std::{env, fmt}; use crate::core::config::SplitDebuginfo; use crate::utils::cache::{INTERNER, Interned}; -use crate::{Path, env}; #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] // N.B.: This type is used everywhere, and the entire codebase relies on it being Copy. diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index d179d0713fcda..ad0859727c8fc 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -12,10 +12,11 @@ use super::flags::Flags; use super::toml::change_id::ChangeIdWrapper; use super::toml::rust::parse_codegen_backends; use super::{Config, DebuggerPath, RUSTC_IF_UNCHANGED_ALLOWED_PATHS}; -use crate::ChangeId; use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order}; use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS; -use crate::core::config::{BootstrapOverrideLld, CompilerBuiltins, Target, TargetSelection}; +use crate::core::config::{ + BootstrapOverrideLld, ChangeId, CompilerBuiltins, Target, TargetSelection, +}; use crate::utils::tests::TestCtx; use crate::utils::tests::git::git_test; diff --git a/src/bootstrap/src/core/config/toml/build.rs b/src/bootstrap/src/core/config/toml/build.rs index 265dde78e08eb..3c8c4d450adf0 100644 --- a/src/bootstrap/src/core/config/toml/build.rs +++ b/src/bootstrap/src/core/config/toml/build.rs @@ -6,13 +6,14 @@ //! various feature flags. These options apply across different stages and components //! unless specifically overridden by other configuration sections or command-line flags. -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; +use std::path::PathBuf; use serde::{Deserialize, Deserializer}; use crate::core::config::toml::ReplaceOpt; use crate::core::config::{Allocator, CompilerBuiltins, DebuggerPath, Merge, StringOrBool}; -use crate::{HashSet, PathBuf, define_config, exit}; +use crate::define_config; define_config! { /// TOML representation of various global build decisions. diff --git a/src/bootstrap/src/core/config/toml/dist.rs b/src/bootstrap/src/core/config/toml/dist.rs index 934d64d889919..7983cc6f6b8a1 100644 --- a/src/bootstrap/src/core/config/toml/dist.rs +++ b/src/bootstrap/src/core/config/toml/dist.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Deserializer}; use crate::core::config::Merge; use crate::core::config::toml::ReplaceOpt; -use crate::{HashSet, PathBuf, define_config, exit}; +use crate::define_config; define_config! { #[derive(Default)] diff --git a/src/bootstrap/src/core/config/toml/gcc.rs b/src/bootstrap/src/core/config/toml/gcc.rs index 94d15a9baaff9..7f194e5521967 100644 --- a/src/bootstrap/src/core/config/toml/gcc.rs +++ b/src/bootstrap/src/core/config/toml/gcc.rs @@ -4,11 +4,13 @@ //! The `[gcc]` table contains options specifically related to building or //! acquiring the GCC compiler for use within the Rust build process. +use std::path::PathBuf; + use serde::{Deserialize, Deserializer}; use crate::core::config::Merge; use crate::core::config::toml::ReplaceOpt; -use crate::{HashSet, PathBuf, define_config, exit}; +use crate::define_config; define_config! { /// TOML representation of how the GCC build is configured. diff --git a/src/bootstrap/src/core/config/toml/install.rs b/src/bootstrap/src/core/config/toml/install.rs index 60fa958bd82f8..a3cd7ab3ae393 100644 --- a/src/bootstrap/src/core/config/toml/install.rs +++ b/src/bootstrap/src/core/config/toml/install.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Deserializer}; use crate::core::config::Merge; use crate::core::config::toml::ReplaceOpt; -use crate::{HashSet, PathBuf, define_config, exit}; +use crate::define_config; define_config! { /// TOML representation of various global install decisions. diff --git a/src/bootstrap/src/core/config/toml/llvm.rs b/src/bootstrap/src/core/config/toml/llvm.rs index 2538c591df79e..ba24b17abfc6a 100644 --- a/src/bootstrap/src/core/config/toml/llvm.rs +++ b/src/bootstrap/src/core/config/toml/llvm.rs @@ -1,11 +1,13 @@ //! This module defines the `Llvm` struct, which represents the `[llvm]` table //! in the `bootstrap.toml` configuration file. +use std::collections::HashMap; + use serde::{Deserialize, Deserializer}; use crate::core::config::StringOrBool; use crate::core::config::toml::{Merge, ReplaceOpt, TomlConfig}; -use crate::{HashMap, HashSet, PathBuf, define_config, exit}; +use crate::define_config; define_config! { /// TOML representation of how the LLVM build is configured. diff --git a/src/bootstrap/src/core/config/toml/mod.rs b/src/bootstrap/src/core/config/toml/mod.rs index 74c21617746bf..8629f143e9106 100644 --- a/src/bootstrap/src/core/config/toml/mod.rs +++ b/src/bootstrap/src/core/config/toml/mod.rs @@ -19,6 +19,10 @@ pub mod pgo; pub mod rust; pub mod target; +use std::collections::{HashMap, HashSet}; +use std::fs; +use std::path::{Path, PathBuf}; + use build::Build; use change_id::{ChangeId, ChangeIdWrapper}; use dist::Dist; @@ -29,8 +33,10 @@ use rust::Rust; use target::TomlTarget; use crate::core::config::toml::pgo::Pgo; -use crate::core::config::{Merge, ReplaceOpt}; -use crate::{Config, HashMap, HashSet, Path, PathBuf, exit, fs, t}; +use crate::core::config::{Config, Merge, ReplaceOpt}; +use crate::exit; +use crate::utils::change_tracker::{find_recent_config_change_ids, human_readable_changes}; +use crate::utils::helpers::t; /// Structure of the `bootstrap.toml` file that configuration is read from. /// @@ -183,11 +189,11 @@ impl Config { toml::from_str::(&contents) .and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table)) { - let changes = crate::find_recent_config_change_ids(id); + let changes = find_recent_config_change_ids(id); if !changes.is_empty() { println!( "WARNING: There have been changes to x.py since you last updated:\n{}", - crate::human_readable_changes(changes) + human_readable_changes(changes) ); } } diff --git a/src/bootstrap/src/core/config/toml/pgo.rs b/src/bootstrap/src/core/config/toml/pgo.rs index fd41cd473f5e3..fe250d71d055a 100644 --- a/src/bootstrap/src/core/config/toml/pgo.rs +++ b/src/bootstrap/src/core/config/toml/pgo.rs @@ -4,11 +4,13 @@ //! The `[pgo]` table contains options related PGO (Profile-Guided Optimization) of various //! components built by bootstrap. +use std::path::PathBuf; + use serde::{Deserialize, Deserializer}; use crate::core::config::Merge; use crate::core::config::toml::ReplaceOpt; -use crate::{HashSet, PathBuf, define_config, exit}; +use crate::define_config; #[derive(Clone, Default, Debug, serde_derive::Deserialize)] #[serde(deny_unknown_fields)] diff --git a/src/bootstrap/src/core/config/toml/rust.rs b/src/bootstrap/src/core/config/toml/rust.rs index d0954e3ad70a5..4a4de50a5deaa 100644 --- a/src/bootstrap/src/core/config/toml/rust.rs +++ b/src/bootstrap/src/core/config/toml/rust.rs @@ -1,12 +1,17 @@ //! This module defines the `Rust` struct, which represents the `[rust]` table //! in the `bootstrap.toml` configuration file. +use std::collections::BTreeSet; +use std::path::PathBuf; + use build_helper::ci::CiEnv; use serde::{Deserialize, Deserializer}; use crate::core::config::toml::TomlConfig; -use crate::core::config::{CompressDebuginfo, DebuginfoLevel, Merge, ReplaceOpt, StringOrBool}; -use crate::{BTreeSet, CodegenBackendKind, HashSet, PathBuf, TargetSelection, define_config, exit}; +use crate::core::config::{ + CompressDebuginfo, DebuginfoLevel, Merge, ReplaceOpt, StringOrBool, TargetSelection, +}; +use crate::{CodegenBackendKind, define_config, exit}; define_config! { /// TOML representation of how the Rust build is configured. diff --git a/src/bootstrap/src/core/config/toml/target.rs b/src/bootstrap/src/core/config/toml/target.rs index 8e354060eceff..7acf906d7d996 100644 --- a/src/bootstrap/src/core/config/toml/target.rs +++ b/src/bootstrap/src/core/config/toml/target.rs @@ -10,6 +10,7 @@ //! build target, which is is stored in the main `Config` structure. use std::collections::HashMap; +use std::path::PathBuf; use serde::de::Error; use serde::{Deserialize, Deserializer}; @@ -18,7 +19,7 @@ use crate::core::config::{ Allocator, CompilerBuiltins, CompressDebuginfo, LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool, }; -use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit}; +use crate::{CodegenBackendKind, define_config}; define_config! { /// TOML representation of how each build target is configured. diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 596bd5bc2fa99..665a976fe8cea 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -13,11 +13,11 @@ use xz2::bufread::XzDecoder; use crate::core::build_steps::llvm::detect_llvm_freshness; use crate::core::config::toml::llvm::check_incompatible_options_for_ci_llvm; -use crate::core::config::{BUILDER_CONFIG_FILENAME, TargetSelection}; +use crate::core::config::{BUILDER_CONFIG_FILENAME, Config, TargetSelection}; +use crate::exit; use crate::utils::build_stamp::BuildStamp; use crate::utils::exec::{ExecutionContext, command}; -use crate::utils::helpers::{exe, hex_encode, move_file}; -use crate::{Config, exit, t}; +use crate::utils::helpers::{exe, hex_encode, move_file, t}; static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock = OnceLock::new(); diff --git a/src/bootstrap/src/core/metadata.rs b/src/bootstrap/src/core/metadata.rs index c79fbbeb55cc1..14f33ef9bdc5d 100644 --- a/src/bootstrap/src/core/metadata.rs +++ b/src/bootstrap/src/core/metadata.rs @@ -11,7 +11,8 @@ use std::path::PathBuf; use serde_derive::Deserialize; use crate::utils::exec::command; -use crate::{Build, Crate, t}; +use crate::utils::helpers::t; +use crate::{Build, Crate}; /// For more information, see the output of /// diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index dc59ec6d7a0bb..c043dc3944f18 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -14,11 +14,12 @@ use std::ffi::{OsStr, OsString}; use std::path::PathBuf; use std::{env, fs}; -use crate::builder::Builder; +use crate::Build; use crate::core::build_steps::tool; -use crate::core::config::{CompilerBuiltins, DebuggerPath, Target}; +use crate::core::builder::Builder; +use crate::core::config::{CompilerBuiltins, DebuggerPath, Subcommand, Target}; use crate::utils::exec::command; -use crate::{Build, Subcommand, t}; +use crate::utils::helpers::t; pub struct Finder { cache: HashMap>, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index f9b29a155eab1..c084c12ae4ab8 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -33,21 +33,14 @@ use tracing::{instrument, span}; use crate::core::build_steps::format::InternalRustfmt; use crate::core::build_steps::vendor::VENDOR_DIR; -#[cfg(feature = "tracing")] -use crate::core::builder::STEP_SPAN_TARGET; -use crate::core::builder::{self, Kind, StepStack}; -use crate::core::config::flags::{Flags, Subcommand}; -use crate::core::config::{ - BootstrapOverrideLld, ChangeId, Config, DryRun, LlvmLibunwind, TargetSelection, flags, -}; +use crate::core::builder::{self, Kind}; +use crate::core::config::flags::{self, Subcommand}; +use crate::core::config::{BootstrapOverrideLld, Config, DryRun, LlvmLibunwind, TargetSelection}; use crate::utils::build_stamp::BuildStamp; -use crate::utils::change_tracker::{ - CONFIG_CHANGE_HISTORY, find_recent_config_change_ids, human_readable_changes, -}; use crate::utils::channel::GitInfo; use crate::utils::exec::{BootstrapCommand, ExecutionContext, command}; use crate::utils::helpers::{ - self, PanicTracker, dir_is_empty, exe, libdir, set_file_times, split_debuginfo, symlink_dir, + self, dir_is_empty, exe, libdir, set_file_times, split_debuginfo, symlink_dir, t, }; pub mod cli_main; diff --git a/src/bootstrap/src/utils/build_stamp.rs b/src/bootstrap/src/utils/build_stamp.rs index 5cd68f6d4fe7f..de7f4c7343c5e 100644 --- a/src/bootstrap/src/utils/build_stamp.rs +++ b/src/bootstrap/src/utils/build_stamp.rs @@ -9,8 +9,8 @@ use sha2::digest::Digest; use crate::core::builder::Builder; use crate::core::config::TargetSelection; -use crate::utils::helpers::{hex_encode, mtime}; -use crate::{CodegenBackendKind, Compiler, Mode, helpers, t}; +use crate::utils::helpers::{self, hex_encode, mtime, t}; +use crate::{CodegenBackendKind, Compiler, Mode}; #[cfg(test)] mod tests; diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 86fe5cf946071..5a3fac5afeadf 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -25,7 +25,7 @@ use std::collections::HashSet; use std::iter; use std::path::{Path, PathBuf}; -use crate::core::config::{CompressDebuginfo, TargetSelection}; +use crate::core::config::{CompressDebuginfo, Subcommand, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; use crate::{Build, CLang, GitRepo}; @@ -70,10 +70,10 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build { pub fn fill_compilers(build: &mut Build) { let mut targets: HashSet<_> = match build.config.cmd { // We don't need to check cross targets for these commands. - crate::Subcommand::Clean { .. } - | crate::Subcommand::Check { .. } - | crate::Subcommand::Format { .. } - | crate::Subcommand::Setup { .. } => { + Subcommand::Clean { .. } + | Subcommand::Check { .. } + | Subcommand::Format { .. } + | Subcommand::Setup { .. } => { build.hosts.iter().cloned().chain(iter::once(build.host_target)).collect() } diff --git a/src/bootstrap/src/utils/change_tracker/tests.rs b/src/bootstrap/src/utils/change_tracker/tests.rs index 730b65b4879c9..6c33efb78979a 100644 --- a/src/bootstrap/src/utils/change_tracker/tests.rs +++ b/src/bootstrap/src/utils/change_tracker/tests.rs @@ -1,4 +1,4 @@ -use crate::{CONFIG_CHANGE_HISTORY, find_recent_config_change_ids}; +use super::{CONFIG_CHANGE_HISTORY, find_recent_config_change_ids}; #[test] fn test_find_recent_config_change_ids() { diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index d3a7c4ec6e1a1..0f8f7550045c0 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -15,7 +15,7 @@ use std::fs::File; use std::hash::Hash; use std::io::{BufWriter, Write}; use std::panic::Location; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{ Child, ChildStderr, ChildStdout, Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio, }; @@ -25,7 +25,8 @@ use std::time::{Duration, Instant}; use build_helper::drop_bomb::DropBomb; use crate::core::config::DryRun; -use crate::{PathBuf, exit, t}; +use crate::exit; +use crate::utils::helpers::t; /// What should be done when the command fails. #[derive(Debug, Copy, Clone)] diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 8cddd822c806e..4ad5ffe38d42b 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -14,10 +14,10 @@ use build_helper::ci::CiEnv; use object::read::archive::ArchiveFile; pub(crate) use shim_utils::{dylib_path, dylib_path_var}; -use crate::core::builder::Builder; -use crate::core::config::{Config, TargetSelection}; +pub(crate) use self::macros::t; +use crate::core::builder::{Builder, StepStack}; +use crate::core::config::{BootstrapOverrideLld, Config, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; -use crate::{BootstrapOverrideLld, StepStack}; #[cfg(test)] mod tests; @@ -39,34 +39,36 @@ impl Drop for PanicTracker<'_> { } } -/// A helper macro to `unwrap` a result except also print out details like: -/// -/// * The file/line of the panic -/// * The expression that failed -/// * The error itself -/// -/// This is currently used judiciously throughout the build system rather than -/// using a `Result` with `try!`, but this may change one day... -#[macro_export] -macro_rules! t { - ($e:expr) => {{ - let _panic_guard = $crate::PanicTracker(std::panic::Location::caller()); - match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - } - }}; - // it can show extra info in the second parameter - ($e:expr, $extra:expr) => {{ - let _panic_guard = $crate::PanicTracker(std::panic::Location::caller()); - match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {} ({:?})", stringify!($e), e, $extra), - } - }}; +mod macros { + /// A helper macro to `unwrap` a result except also print out details like: + /// + /// * The file/line of the panic + /// * The expression that failed + /// * The error itself + /// + /// This is currently used judiciously throughout the build system rather than + /// using a `Result` with `try!`, but this may change one day... + macro_rules! t { + ($e:expr) => {{ + let _panic_guard = $crate::utils::helpers::PanicTracker(std::panic::Location::caller()); + match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + } + }}; + // it can show extra info in the second parameter + ($e:expr, $extra:expr) => {{ + let _panic_guard = $crate::utils::helpers::PanicTracker(std::panic::Location::caller()); + match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {} ({:?})", stringify!($e), e, $extra), + } + }}; + } + + pub(crate) use t; } -pub use t; pub fn exe(name: &str, target: TargetSelection) -> String { shim_utils::exe(name, &target.triple) } diff --git a/src/bootstrap/src/utils/tests/mod.rs b/src/bootstrap/src/utils/tests/mod.rs index ee180fbf224a8..5690e4aeb44d1 100644 --- a/src/bootstrap/src/utils/tests/mod.rs +++ b/src/bootstrap/src/utils/tests/mod.rs @@ -4,7 +4,8 @@ use std::path::{Path, PathBuf}; use tempfile::TempDir; -use crate::{Config, Flags}; +use crate::core::config::Config; +use crate::core::config::flags::Flags; pub mod git; mod shim_utils_tests; diff --git a/src/bootstrap/src/utils/tracing.rs b/src/bootstrap/src/utils/tracing.rs index 541aa088b9c30..9ab1ca23ee5a8 100644 --- a/src/bootstrap/src/utils/tracing.rs +++ b/src/bootstrap/src/utils/tracing.rs @@ -117,7 +117,7 @@ mod inner { use tracing_subscriber::{EnvFilter, Layer}; use super::{COMMAND_SPAN_TARGET, IO_SPAN_TARGET}; - use crate::STEP_SPAN_TARGET; + use crate::core::builder::STEP_SPAN_TARGET; pub fn setup_tracing(env_name: &str) -> TracingGuard { let filter = EnvFilter::from_env(env_name); diff --git a/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.rs b/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.rs new file mode 100644 index 0000000000000..29c4d8a6a02a3 --- /dev/null +++ b/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.rs @@ -0,0 +1,24 @@ +//@ compile-flags: -Znext-solver=globally -Zassumptions-on-binders + +#![feature(type_alias_impl_trait)] + +// Regression test for #159889. Normalizing `FooAssoc<'a>` returns an opaque type constraint +// containing a query-created placeholder. Applying that response recreates its universe in the +// caller, where it must have an assumptions entry before eager placeholder handling visits it. + +trait Trait { + type Assoc<'a>: ?Sized; +} + +type Foo = impl for<'a> Trait = FooAssoc<'a>>; +type FooAssoc<'a> = impl ?Sized; + +impl Trait for () { + type Assoc<'a> = FooAssoc<'a>; +} + +#[define_opaque(Foo)] +fn foo() -> Foo {} +//~^ ERROR item does not constrain `Foo::{opaque#0}` + +fn main() {} diff --git a/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.stderr b/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.stderr new file mode 100644 index 0000000000000..87b225e58c06b --- /dev/null +++ b/tests/ui/assumptions_on_binders/canonical-response-placeholder-assumptions-issue-159889.stderr @@ -0,0 +1,15 @@ +error: item does not constrain `Foo::{opaque#0}` + --> $DIR/canonical-response-placeholder-assumptions-issue-159889.rs:21:4 + | +LL | fn foo() -> Foo {} + | ^^^ + | + = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]` +note: this opaque type is supposed to be constrained + --> $DIR/canonical-response-placeholder-assumptions-issue-159889.rs:13:12 + | +LL | type Foo = impl for<'a> Trait = FooAssoc<'a>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/scalable-vectors/project-into-field-okay.rs b/tests/ui/scalable-vectors/project-into-field-okay.rs new file mode 100644 index 0000000000000..4d9b3f1b52206 --- /dev/null +++ b/tests/ui/scalable-vectors/project-into-field-okay.rs @@ -0,0 +1,95 @@ +//@ build-pass +//@ compile-flags: -Copt-level=3 --test -Cdebuginfo=2 +//@ only-aarch64 +#![allow(internal_features, unused, improper_ctypes_definitions, nonstandard_style)] +#![feature( + abi_unadjusted, + link_llvm_intrinsics, + rustc_attrs, + min_adt_const_params +)] + +// This snippet is reduced from stdarch and previously failed prior to preventing projection into +// fields during MIR validation in rust#160642. + +use std::{marker::ConstParamTy, mem::transmute}; + +#[derive(Copy, Clone)] +#[rustc_scalable_vector(4)] +pub struct svfloat32_t(f32); + +#[repr(i32)] +#[allow(non_camel_case_types)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, ConstParamTy)] +#[non_exhaustive] +pub enum svpattern { + SV_ALL = 31, +} + +#[inline] +#[target_feature(enable = "sve")] +pub fn svlen_f32(_op: svfloat32_t) -> u64 { + svcntw() +} + +#[test] +#[allow(non_snake_case)] +fn assert_svlen_f32_cntw() { + #[target_feature(enable = "sve")] + #[unsafe(no_mangle)] + #[inline(never)] + pub unsafe extern "C" fn stdarch_test_shim_svlen_f32_cntw(_op: svfloat32_t) -> u64 { + svlen_f32(_op) + } + std::hint::black_box(stdarch_test_shim_svlen_f32_cntw as usize); + //~^ WARN: direct cast of function item into an integer +} + +#[inline] +#[target_feature(enable = "sve")] +pub fn svcntw() -> u64 { + svcntw_pat::<{ svpattern::SV_ALL }>() +} + +#[test] +#[allow(non_snake_case)] +fn assert_svcntw_cntw() { + #[target_feature(enable = "sve")] + #[unsafe(no_mangle)] + #[inline(never)] + pub unsafe extern "C" fn stdarch_test_shim_svcntw_cntw() -> u64 { + svcntw() + } + std::hint::black_box(stdarch_test_shim_svcntw_cntw as usize); + //~^ WARN: direct cast of function item into an integer +} + +#[inline] +#[target_feature(enable = "sve")] +pub fn svcntw_pat() -> u64 { + unsafe extern "unadjusted" { + #[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.sve.cntw")] + fn _svcntw_pat(pattern: svpattern) -> i64; + } + unsafe { transmute(_svcntw_pat(PATTERN)) } + //~^ WARN: unnecessary transmute +} + +#[test] +#[allow(non_snake_case)] +fn assert_svcntw_pat_cntw() { + #[target_feature(enable = "sve")] + #[unsafe(no_mangle)] + #[inline(never)] + pub unsafe extern "C" fn stdarch_test_shim_svcntw_pat_cntw() -> u64 { + svcntw_pat::<{ svpattern::SV_ALL }>() + } + std::hint::black_box(stdarch_test_shim_svcntw_pat_cntw as usize); + //~^ WARN: direct cast of function item into an integer +} + +fn main() { + unsafe { + let _ = svlen_f32(unimplemented!()); + } +} diff --git a/tests/ui/scalable-vectors/project-into-field-okay.stderr b/tests/ui/scalable-vectors/project-into-field-okay.stderr new file mode 100644 index 0000000000000..9787511cc214a --- /dev/null +++ b/tests/ui/scalable-vectors/project-into-field-okay.stderr @@ -0,0 +1,49 @@ +warning: direct cast of function item into an integer + --> $DIR/project-into-field-okay.rs:44:59 + | +LL | std::hint::black_box(stdarch_test_shim_svlen_f32_cntw as usize); + | ^^^^^^^^ + | + = note: `#[warn(function_casts_as_integer)]` on by default +help: first cast to a pointer `as *const ()` + | +LL | std::hint::black_box(stdarch_test_shim_svlen_f32_cntw as *const () as usize); + | ++++++++++++ + +warning: direct cast of function item into an integer + --> $DIR/project-into-field-okay.rs:63:56 + | +LL | std::hint::black_box(stdarch_test_shim_svcntw_cntw as usize); + | ^^^^^^^^ + | +help: first cast to a pointer `as *const ()` + | +LL | std::hint::black_box(stdarch_test_shim_svcntw_cntw as *const () as usize); + | ++++++++++++ + +warning: unnecessary transmute + --> $DIR/project-into-field-okay.rs:74:14 + | +LL | unsafe { transmute(_svcntw_pat(PATTERN)) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unnecessary_transmutes)]` on by default +help: replace this with + | +LL - unsafe { transmute(_svcntw_pat(PATTERN)) } +LL + unsafe { i64::cast_unsigned(_svcntw_pat(PATTERN)) } + | + +warning: direct cast of function item into an integer + --> $DIR/project-into-field-okay.rs:87:60 + | +LL | std::hint::black_box(stdarch_test_shim_svcntw_pat_cntw as usize); + | ^^^^^^^^ + | +help: first cast to a pointer `as *const ()` + | +LL | std::hint::black_box(stdarch_test_shim_svcntw_pat_cntw as *const () as usize); + | ++++++++++++ + +warning: 4 warnings emitted +