diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 4da2663319c34..df6cfd5007ecb 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -1,3 +1,4 @@ +use std::assert_matches::debug_assert_matches; use std::sync::atomic::Ordering::Relaxed; use either::{Left, Right}; @@ -292,6 +293,30 @@ pub fn eval_to_const_value_raw_provider<'tcx>( tcx: TyCtxt<'tcx>, key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, ) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> { + let ty::PseudoCanonicalInput { typing_env, value } = key; + + // Const eval always happens in PostAnalysis or Codegen mode. See the comment in + // `InterpCx::new` for more details. + debug_assert_matches!( + typing_env.typing_mode, + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen + ); + + // We are in codegen. It's very likely this constant has been evaluated in PostAnalysis before. + // Try to reuse this evaluation, and only re-run if we hit a `TooGeneric` error. + if let ty::TypingMode::Codegen = typing_env.typing_mode { + let with_postanalysis = ty::TypingEnv { + typing_mode: ty::TypingMode::PostAnalysis, + param_env: typing_env.param_env, + }; + let with_postanalysis = + tcx.eval_to_const_value_raw(with_postanalysis.as_query_input(value)); + match with_postanalysis { + Ok(_) | Err(ErrorHandled::Reported(..)) => return with_postanalysis, + Err(ErrorHandled::TooGeneric(_)) => {} + } + } + tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key)) } @@ -331,23 +356,44 @@ pub fn eval_to_allocation_raw_provider<'tcx>( tcx: TyCtxt<'tcx>, key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, ) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> { + let ty::PseudoCanonicalInput { typing_env, value } = key; + // This shouldn't be used for statics, since statics are conceptually places, // not values -- so what we do here could break pointer identity. - assert!(key.value.promoted.is_some() || !tcx.is_static(key.value.instance.def_id())); - // Const eval always happens in PostAnalysis mode . See the comment in + assert!(value.promoted.is_some() || !tcx.is_static(value.instance.def_id())); + + // Const eval always happens in PostAnalysis or Codegen mode. See the comment in // `InterpCx::new` for more details. - debug_assert_eq!(key.typing_env.typing_mode, ty::TypingMode::PostAnalysis); + debug_assert_matches!( + typing_env.typing_mode, + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen + ); + if cfg!(debug_assertions) { // Make sure we format the instance even if we do not print it. // This serves as a regression test against an ICE on printing. // The next two lines concatenated contain some discussion: // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/ // subject/anon_const_instance_printing/near/135980032 - let instance = with_no_trimmed_paths!(key.value.instance.to_string()); - trace!("const eval: {:?} ({})", key, instance); + let instance = with_no_trimmed_paths!(value.instance.to_string()); + trace!("const eval: {:?} ({}) inside {:?}", value, instance, typing_env); + } + + // We are in codegen. It's very likely this constant has been evaluated in PostAnalysis before. + // Try to reuse this evaluation, and only re-run if we hit a `TooGeneric` error. + if let ty::TypingMode::Codegen = typing_env.typing_mode { + let with_postanalysis = ty::TypingEnv { + typing_mode: ty::TypingMode::PostAnalysis, + param_env: typing_env.param_env, + }; + let with_postanalysis = tcx.eval_to_allocation_raw(with_postanalysis.as_query_input(value)); + match with_postanalysis { + Ok(_) | Err(ErrorHandled::Reported(..)) => return with_postanalysis, + Err(ErrorHandled::TooGeneric(_)) => {} + } } - eval_in_interpreter(tcx, key.value, key.typing_env) + eval_in_interpreter(tcx, value, typing_env) } fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 7c41258ebfe5f..31022fcad5a8d 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -1,3 +1,5 @@ +use std::assert_matches::debug_assert_matches; + use rustc_abi::{BackendRepr, FieldIdx, VariantIdx}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError}; @@ -232,9 +234,12 @@ pub(crate) fn eval_to_valtree<'tcx>( typing_env: ty::TypingEnv<'tcx>, cid: GlobalId<'tcx>, ) -> EvalToValTreeResult<'tcx> { - // Const eval always happens in PostAnalysis mode . See the comment in + // Const eval always happens in PostAnalysis or Codegen mode . See the comment in // `InterpCx::new` for more details. - debug_assert_eq!(typing_env.typing_mode, ty::TypingMode::PostAnalysis); + debug_assert_matches!( + typing_env.typing_mode, + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen + ); let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?; // FIXME Need to provide a span to `eval_to_valtree` diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 0e4a98f0941ac..6b8712c014775 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -226,11 +226,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { typing_env: ty::TypingEnv<'tcx>, machine: M, ) -> Self { - // Const eval always happens in post analysis mode in order to be able to use the hidden types of - // opaque types. This is needed for trivial things like `size_of`, but also for using associated - // types that are not specified in the opaque type. We also use MIR bodies whose opaque types have - // already been revealed, so we'd be able to at least partially observe the hidden types anyways. - debug_assert_matches!(typing_env.typing_mode, ty::TypingMode::PostAnalysis); + // Const eval always happens in post analysis or codegen mode in order to be able to use + // the hidden types of opaque types. This is needed for trivial things like `size_of`, but + // also for using associated types that are not specified in the opaque type. We also use + // MIR bodies whose opaque types have already been revealed, so we'd be able to at least + // partially observe the hidden types anyways. + debug_assert_matches!( + typing_env.typing_mode, + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen + ); InterpCx { machine, tcx: tcx.at(root_span), diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 7567f8ba34883..8979b1870b572 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -147,7 +147,7 @@ pub(crate) fn check_transmutes(tcx: TyCtxt<'_>, owner: LocalDefId) { let typeck_results = tcx.typeck(owner); let None = typeck_results.tainted_by_errors else { return }; - let typing_env = ty::TypingEnv::post_analysis(tcx, owner); + let typing_env = ty::TypingEnv::codegen(tcx, owner); for &(from, to, hir_id) in &typeck_results.transmutes_to_check { check_transmute(tcx, typing_env, from, to, hir_id); } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index f3ebfde06ab6b..c8e97603d73a0 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1056,7 +1056,8 @@ impl<'tcx> InferCtxt<'tcx> { // to support PostBorrowckAnalysis in the old solver as well. TypingMode::Coherence | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => false, + | TypingMode::PostAnalysis + | TypingMode::Codegen => false, } } @@ -1379,7 +1380,8 @@ impl<'tcx> InferCtxt<'tcx> { } mode @ (ty::TypingMode::Coherence | ty::TypingMode::PostBorrowckAnalysis { .. } - | ty::TypingMode::PostAnalysis) => mode, + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen) => mode, }; ty::TypingEnv { typing_mode, param_env } } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index 220e025c3f7d6..f15d6f0778845 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -276,7 +276,9 @@ impl<'tcx> InferCtxt<'tcx> { .map(|obligation| obligation.as_goal()), ); } - mode @ (ty::TypingMode::PostBorrowckAnalysis { .. } | ty::TypingMode::PostAnalysis) => { + mode @ (ty::TypingMode::PostBorrowckAnalysis { .. } + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen) => { bug!("insert hidden type in {mode:?}") } } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index c1bba0b01975e..64dfd83ea81b2 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1112,7 +1112,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { if !tcx.is_async_drop_in_place_coroutine(def_id.to_def_id()) { // Eagerly check the unsubstituted layout for cycles. tcx.ensure_ok().layout_of( - ty::TypingEnv::post_analysis(tcx, def_id.to_def_id()) + ty::TypingEnv::codegen(tcx, def_id.to_def_id()) .as_query_input(tcx.type_of(def_id).instantiate_identity()), ); } diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index 9762e0f21da9f..8f85af8c9d150 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -384,18 +384,20 @@ impl<'tcx> GlobalAlloc<'tcx> { .type_of(def_id) .no_bound_vars() .expect("statics should not have generic parameters"); - let layout = tcx.layout_of(typing_env.as_query_input(ty)).unwrap(); - assert!(layout.is_sized()); + let layout = tcx.layout_of(typing_env.as_query_input(ty)); + let (size, mut align) = if let Ok(layout) = layout { + assert!(layout.is_sized()); + (layout.size, layout.align.abi) + } else { + (Size::ZERO, Align::ONE) + }; // Take over-alignment from attributes into account. - let align = match tcx.codegen_fn_attrs(def_id).alignment { - Some(align_from_attribute) => { - Ord::max(align_from_attribute, layout.align.abi) - } - None => layout.align.abi, - }; + if let Some(align_from_attribute) = tcx.codegen_fn_attrs(def_id).alignment { + align = Ord::max(align_from_attribute, align); + } - (layout.size, align) + (size, align) } } GlobalAlloc::Memory(alloc) => { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 895c8c0295a04..4998cdd913f5f 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1663,7 +1663,7 @@ rustc_queries! { /// Like `param_env`, but returns the `ParamEnv` after all opaque types have been /// replaced with their hidden type. This is used in the old trait solver /// when in `PostAnalysis` mode and should not be called directly. - query typing_env_normalized_for_post_analysis(def_id: DefId) -> ty::TypingEnv<'tcx> { + query param_env_normalized_for_post_analysis(def_id: DefId) -> ty::ParamEnv<'tcx> { desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index ce4de6b95e0bb..2769172616484 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1003,6 +1003,17 @@ impl<'tcx> ParamEnv<'tcx> { pub fn and>>(self, value: T) -> ParamEnvAnd<'tcx, T> { ParamEnvAnd { param_env: self, value } } + + /// Eagerly reveal all opaque types in the `param_env`. + pub fn with_normalized(self, tcx: TyCtxt<'tcx>) -> ParamEnv<'tcx> { + // No need to reveal opaques with the new solver enabled, + // since we have lazy norm. + if tcx.next_trait_solver_globally() { + self + } else { + ParamEnv::new(tcx.reveal_opaque_types_in_bounds(self.caller_bounds)) + } + } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] @@ -1040,7 +1051,7 @@ impl<'tcx> TypingEnv<'tcx> { /// use `TypingMode::PostAnalysis`, they may still have where-clauses /// in scope. pub fn fully_monomorphized() -> TypingEnv<'tcx> { - TypingEnv { typing_mode: TypingMode::PostAnalysis, param_env: ParamEnv::empty() } + TypingEnv { typing_mode: TypingMode::Codegen, param_env: ParamEnv::empty() } } /// Create a typing environment for use during analysis outside of a body. @@ -1056,27 +1067,43 @@ impl<'tcx> TypingEnv<'tcx> { } pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryParam) -> TypingEnv<'tcx> { - tcx.typing_env_normalized_for_post_analysis(def_id) + TypingEnv { + typing_mode: TypingMode::PostAnalysis, + param_env: tcx.param_env_normalized_for_post_analysis(def_id), + } + } + + pub fn codegen(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryParam) -> TypingEnv<'tcx> { + TypingEnv { + typing_mode: TypingMode::Codegen, + param_env: tcx.param_env_normalized_for_post_analysis(def_id), + } } - /// Modify the `typing_mode` to `PostAnalysis` and eagerly reveal all - /// opaque types in the `param_env`. + /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types + /// in the `param_env`. pub fn with_post_analysis_normalized(self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> { let TypingEnv { typing_mode, param_env } = self; - if let TypingMode::PostAnalysis = typing_mode { + if let TypingMode::PostAnalysis | TypingMode::Codegen = typing_mode { return self; } - // No need to reveal opaques with the new solver enabled, - // since we have lazy norm. - let param_env = if tcx.next_trait_solver_globally() { - param_env - } else { - ParamEnv::new(tcx.reveal_opaque_types_in_bounds(param_env.caller_bounds())) - }; + let param_env = param_env.with_normalized(tcx); TypingEnv { typing_mode: TypingMode::PostAnalysis, param_env } } + /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types + /// in the `param_env`. + pub fn with_codegen_normalized(self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> { + let TypingEnv { typing_mode, param_env } = self; + if let TypingMode::Codegen = typing_mode { + return self; + } + + let param_env = param_env.with_normalized(tcx); + TypingEnv { typing_mode: TypingMode::Codegen, param_env } + } + /// Combine this typing environment with the given `value` to be used by /// not (yet) canonicalized queries. This only works if the value does not /// contain anything local to some `InferCtxt`, i.e. inference variables or diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 6316ccf1b8c5b..bc8638cdef1a5 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -105,10 +105,8 @@ impl<'tcx> ConstToPat<'tcx> { // // FIXME: `const_eval_resolve_for_typeck` should probably just modify the env itself // instead of having this logic here - let typing_env = self - .tcx - .erase_and_anonymize_regions(self.typing_env) - .with_post_analysis_normalized(self.tcx); + let typing_env = + self.tcx.erase_and_anonymize_regions(self.typing_env).with_codegen_normalized(self.tcx); let uv = self.tcx.erase_and_anonymize_regions(uv); // try to resolve e.g. associated constants to their definition on an impl, and then diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index 4f3c53d761f10..039c98c308166 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -1,3 +1,4 @@ +use std::assert_matches::debug_assert_matches; use std::{fmt, iter, mem}; use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx}; @@ -510,7 +511,10 @@ where let subpath = self.elaborator.field_subpath(variant_path, field_idx); let tcx = self.tcx(); - assert_eq!(self.elaborator.typing_env().typing_mode, ty::TypingMode::PostAnalysis); + debug_assert_matches!( + self.elaborator.typing_env().typing_mode, + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen + ); let field_ty = match tcx.try_normalize_erasing_regions( self.elaborator.typing_env(), field.ty(tcx, args), diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 3ff8dc6dbb378..1c42897eac865 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -340,7 +340,6 @@ struct VnState<'body, 'tcx> { tcx: TyCtxt<'tcx>, ecx: InterpCx<'tcx, DummyMachine>, local_decls: &'body LocalDecls<'tcx>, - is_coroutine: bool, /// Value stored in each local. locals: IndexVec>, /// Locals that are assigned that value. @@ -376,7 +375,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { tcx, ecx: InterpCx::new(tcx, DUMMY_SP, typing_env, DummyMachine), local_decls, - is_coroutine: body.coroutine.is_some(), locals: IndexVec::from_elem(None, local_decls), rev_locals: IndexVec::with_capacity(num_values), values: ValueSet::new(num_values), @@ -516,11 +514,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { use Value::*; let ty = self.ty(value); // Avoid computing layouts inside a coroutine, as that can cause cycles. - let ty = if !self.is_coroutine || ty.is_scalar() { - self.ecx.layout_of(ty).ok()? - } else { - return None; - }; + let ty = self.ecx.layout_of(ty).ok()?; let op = match *self.get(value) { _ if ty.is_zst() => ImmTy::uninit(ty).into(), diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 8593e25d6aa5e..4fa4817437a7d 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -124,8 +124,6 @@ trait Inliner<'tcx> { callee_attrs: &CodegenFnAttrs, ) -> Result<(), &'static str>; - fn check_caller_mir_body(&self, body: &Body<'tcx>) -> bool; - /// Returns inlining decision that is based on the examination of callee MIR body. /// Assumes that codegen attributes have been checked for compatibility already. fn check_callee_mir_body( @@ -199,10 +197,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> { Ok(()) } - fn check_caller_mir_body(&self, _: &Body<'tcx>) -> bool { - true - } - #[instrument(level = "debug", skip(self, callee_body))] fn check_callee_mir_body( &self, @@ -349,17 +343,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> { } } - fn check_caller_mir_body(&self, body: &Body<'tcx>) -> bool { - // Avoid inlining into coroutines, since their `optimized_mir` is used for layout computation, - // which can create a cycle, even when no attempt is made to inline the function in the other - // direction. - if body.coroutine.is_some() { - return false; - } - - true - } - #[instrument(level = "debug", skip(self, callee_body))] fn check_callee_mir_body( &self, @@ -502,10 +485,6 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b } let mut inliner = T::new(tcx, def_id, body); - if !inliner.check_caller_mir_body(body) { - return false; - } - let blocks = START_BLOCK..body.basic_blocks.next_index(); process_blocks(&mut inliner, body, blocks); inliner.changed() @@ -774,11 +753,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>( && !inliner .tcx() .is_lang_item(inliner.tcx().parent(caller_def_id), rustc_hir::LangItem::FnOnce) + // The caller may be a shim. + && let Some(caller_def_id) = caller_def_id.as_local() { // If we know for sure that the function we're calling will itself try to // call us, then we avoid inlining that function. - if inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()).contains(&callee_def_id) - { + if inliner.tcx().mir_callgraph_cyclic(caller_def_id).contains(&callee_def_id) { debug!("query cycle avoidance"); return Err("caller might be reachable from callee"); } diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 68298767e7fd8..9d7140ba2bf8a 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -49,7 +49,7 @@ use rustc_middle::ty::{self, ScalarInt, TyCtxt}; use rustc_mir_dataflow::lattice::HasBottom; use rustc_mir_dataflow::value_analysis::{Map, PlaceIndex, State, TrackElem}; use rustc_span::DUMMY_SP; -use tracing::{debug, instrument, trace}; +use tracing::{debug, instrument}; use crate::cost_checker::CostChecker; @@ -69,12 +69,6 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading { let def_id = body.source.def_id(); debug!(?def_id); - // Optimizing coroutines creates query cycles. - if tcx.is_coroutine(def_id) { - trace!("Skipped for coroutine {:?}", def_id); - return; - } - let typing_env = body.typing_env(tcx); let arena = &DroplessArena::default(); let mut finder = TOFinder { diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 93abc0f8860b9..6ab3789732279 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -44,13 +44,6 @@ impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint { return; } - // FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles - // computing their layout. - if tcx.is_coroutine(def_id.to_def_id()) { - trace!("KnownPanicsLint skipped for coroutine {:?}", def_id); - return; - } - trace!("KnownPanicsLint starting for {:?}", def_id); let mut linter = ConstPropagator::new(body, tcx); diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index 90c1b3520b96e..700dad44dafcd 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -12,11 +12,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveZsts { } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - // Avoid query cycles (coroutines require optimized MIR for layout). - if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() { - return; - } - let typing_env = body.typing_env(tcx); let local_decls = &body.local_decls; let mut replacer = Replacer { tcx, typing_env, local_decls }; diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 99f10b8d91d2c..f9b459f78982b 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -23,11 +23,6 @@ impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); - // Avoid query cycles (coroutines require optimized MIR for layout). - if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() { - return; - } - let mut excluded = excluded_locals(body); let typing_env = body.typing_env(tcx); loop { diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index d58c264841c85..7425e922c0451 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -921,7 +921,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => {} + | TypingMode::PostAnalysis + | TypingMode::Codegen => {} } let mut i = 0; @@ -984,7 +985,8 @@ where TypingMode::Coherence | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => vec![], + | TypingMode::PostAnalysis + | TypingMode::Codegen => vec![], }; if opaque_types.is_empty() { diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 65a5edf6b7250..a232d65dc0ebb 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -143,7 +143,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => return Err(NoSolution), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Err(NoSolution), }, ty::ImplPolarity::Positive => Certainty::Yes, }; diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index a58caeecc33c5..c8530e67df5dd 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -368,7 +368,7 @@ where fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool { match self.typing_mode() { // Opaques are never rigid outside of analysis mode. - TypingMode::Coherence | TypingMode::PostAnalysis => false, + TypingMode::Coherence | TypingMode::PostAnalysis | TypingMode::Codegen => false, // During analysis, opaques are rigid unless they may be defined by // the current body. TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 0674b3d42ab4d..853b4f127347c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -282,7 +282,8 @@ where ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } - | ty::TypingMode::PostAnalysis => { + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen => { ecx.structurally_instantiate_normalizes_to_term( goal, goal.predicate.alias, @@ -320,7 +321,8 @@ where ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } - | ty::TypingMode::PostAnalysis => { + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen => { ecx.structurally_instantiate_normalizes_to_term( goal, goal.predicate.alias, diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs index a5f857a1dd85b..e1054ccab0a62 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs @@ -126,7 +126,7 @@ where self.eq(goal.param_env, expected, actual)?; self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } - TypingMode::PostAnalysis => { + TypingMode::PostAnalysis | TypingMode::Codegen => { // FIXME: Add an assertion that opaque type storage is empty. let actual = cx.type_of(opaque_ty.def_id).instantiate(cx, opaque_ty.args); self.eq(goal.param_env, expected, actual)?; diff --git a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs index 109c8476ccb16..0f56609c91256 100644 --- a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs +++ b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs @@ -69,7 +69,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => Err(NoSolution), + | TypingMode::PostAnalysis + | TypingMode::Codegen => Err(NoSolution), }, } } diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index e790ecd595be7..103b6f7a21807 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -77,7 +77,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => return Err(NoSolution), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Err(NoSolution), }, // Impl matches polarity @@ -1331,7 +1332,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => {} + | TypingMode::PostAnalysis + | TypingMode::Codegen => {} } if candidates @@ -1486,6 +1488,7 @@ where } TypingMode::Coherence | TypingMode::PostAnalysis + | TypingMode::Codegen | TypingMode::Borrowck { defining_opaque_types: _ } | TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ } => {} } diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index b6bdf1067a35e..efa78701468ca 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -279,7 +279,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => false, - TypingMode::PostAnalysis => { + TypingMode::PostAnalysis | TypingMode::Codegen => { let poly_trait_ref = self.resolve_vars_if_possible(goal_trait_ref); !poly_trait_ref.still_further_specializable() } diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index bff4f6ce3fc6b..bb93054285252 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -289,7 +289,8 @@ where TypingMode::Coherence | TypingMode::Borrowck { defining_opaque_types: _ } | TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ } - | TypingMode::PostAnalysis => return Default::default(), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Default::default(), }; if stalled_coroutines.is_empty() { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 6b884b3608044..6cd282954dbd7 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -179,7 +179,8 @@ where TypingMode::Coherence | TypingMode::Borrowck { defining_opaque_types: _ } | TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ } - | TypingMode::PostAnalysis => return Default::default(), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Default::default(), }; if stalled_coroutines.is_empty() { diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 9e02ce32b21cd..86fade7472fce 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -138,7 +138,7 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable>>( | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE), - TypingMode::PostAnalysis => {} + TypingMode::PostAnalysis | TypingMode::Codegen => {} } value.has_type_flags(flags) @@ -401,7 +401,7 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => ty.super_fold_with(self), - TypingMode::PostAnalysis => { + TypingMode::PostAnalysis | TypingMode::Codegen => { let recursion_limit = self.cx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { self.selcx.infcx.err_ctxt().report_overflow_error( diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 042d6def84c33..89d74e56d12eb 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -962,7 +962,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( ); false } - TypingMode::PostAnalysis => { + TypingMode::PostAnalysis | TypingMode::Codegen => { // NOTE(eddyb) inference variables can resolve to parameters, so // assume `poly_trait_ref` isn't monomorphic, if it contains any. let poly_trait_ref = diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index c6eb0caee1a6f..28894bb4c3cd2 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -221,7 +221,7 @@ impl<'a, 'tcx> FallibleTypeFolder> for QueryNormalizer<'a, 'tcx> { | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => ty.try_super_fold_with(self)?, - TypingMode::PostAnalysis => { + TypingMode::PostAnalysis | TypingMode::Codegen => { let args = data.args.try_fold_with(self)?; let recursion_limit = self.cx().recursion_limit(); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index fb4f28412d428..86984e87610bb 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1462,7 +1462,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => return Ok(()), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Ok(()), } debug!("is_knowable()"); @@ -1521,7 +1522,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // // FIXME(#132279): This is still incorrect as we treat opaque types // and default associated items differently between these two modes. - TypingMode::PostAnalysis => true, + TypingMode::PostAnalysis | TypingMode::Codegen => true, } } @@ -2844,6 +2845,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } TypingMode::Coherence | TypingMode::PostAnalysis + | TypingMode::Codegen | TypingMode::Borrowck { defining_opaque_types: _ } | TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ } => false, } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index e28ebaabc0a1f..75a0bd4626046 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -159,7 +159,9 @@ fn resolve_associated_item<'tcx>( | ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } => false, - ty::TypingMode::PostAnalysis => !trait_ref.still_further_specializable(), + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => { + !trait_ref.still_further_specializable() + } } }; if !eligible { diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 317d101dafe05..d4e697c8e7fc8 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -65,6 +65,18 @@ fn layout_of<'tcx>( return tcx.layout_of(typing_env.as_query_input(ty)); } + if let ty::TypingMode::Codegen = typing_env.typing_mode { + let with_postanalysis = ty::TypingEnv { + typing_mode: ty::TypingMode::PostAnalysis, + param_env: typing_env.param_env, + }; + let res = tcx.layout_of(with_postanalysis.as_query_input(ty)); + match res { + Err(LayoutError::TooGeneric(_)) => {} + _ => return res, + }; + } + let cx = LayoutCx::new(tcx, typing_env); let layout = layout_of_uncached(&cx, ty)?; @@ -486,6 +498,17 @@ fn layout_of_uncached<'tcx>( } ty::Coroutine(def_id, args) => { + match cx.typing_env.typing_mode { + ty::TypingMode::Codegen => {} + ty::TypingMode::Coherence + | ty::TypingMode::Analysis { .. } + | ty::TypingMode::Borrowck { .. } + | ty::TypingMode::PostBorrowckAnalysis { .. } + | ty::TypingMode::PostAnalysis => { + return Err(error(cx, LayoutError::TooGeneric(ty))); + } + } + use rustc_middle::ty::layout::PrimitiveExt as _; let info = tcx.coroutine_layout(def_id, args)?; @@ -625,7 +648,10 @@ fn layout_of_uncached<'tcx>( let maybe_unsized = def.is_struct() && def.non_enum_variant().tail_opt().is_some_and(|last_field| { - let typing_env = ty::TypingEnv::post_analysis(tcx, def.did()); + let typing_env = ty::TypingEnv { + typing_mode: cx.typing_env.typing_mode, + param_env: tcx.param_env_normalized_for_post_analysis(def.did()), + }; !tcx.type_of(last_field.did).instantiate_identity().is_sized(tcx, typing_env) }); diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index bb25a14ef7443..0d442dad601fd 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -285,8 +285,8 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { } } -fn typing_env_normalized_for_post_analysis(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TypingEnv<'_> { - ty::TypingEnv::non_body_analysis(tcx, def_id).with_post_analysis_normalized(tcx) +fn param_env_normalized_for_post_analysis(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { + tcx.param_env(def_id).with_normalized(tcx) } /// Check if a function is async. @@ -402,7 +402,7 @@ pub(crate) fn provide(providers: &mut Providers) { asyncness, adt_sizedness_constraint, param_env, - typing_env_normalized_for_post_analysis, + param_env_normalized_for_post_analysis, defaultness, unsizing_params_for_adt, impl_self_is_guaranteed_unsized, diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs index feafcee7bad9e..810c6c8378c02 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -79,15 +79,17 @@ pub enum TypingMode { /// This is currently only used by the new solver, but should be implemented in /// the old solver as well. PostBorrowckAnalysis { defined_opaque_types: I::LocalDefIds }, - /// After analysis, mostly during codegen and MIR optimizations, we're able to + /// After analysis, mostly during MIR optimizations, we're able to /// reveal all opaque types. As the hidden type should *never* be observable /// directly by the user, this should not be used by checks which may expose /// such details to the user. /// - /// There are some exceptions to this as for example `layout_of` and const-evaluation - /// always run in `PostAnalysis` mode, even when used during analysis. This exposes - /// some information about the underlying type to users, but not the type itself. + /// However, we restrict `layout_of` and const-evaluation from exposing some information like + /// coroutine layout which requires optimized MIR. PostAnalysis, + /// During codegen and MIR optimizations, we're able to reveal all opaque types and compute all + /// layouts. + Codegen, } impl Eq for TypingMode {} @@ -322,6 +324,8 @@ where // Note: `feature_bound_holds_in_crate` does not consider a feature to be enabled // if we are in std/core even if there is a corresponding `feature` attribute on the crate. - (infcx.typing_mode() == TypingMode::PostAnalysis) - || infcx.cx().features().feature_bound_holds_in_crate(symbol) + match infcx.typing_mode() { + TypingMode::Codegen => true, + _ => infcx.cx().features().feature_bound_holds_in_crate(symbol), + } } diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index 8dd7c4df24421..38d3949603650 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -139,7 +139,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => structurally_relate_tys(relation, a, b), + | TypingMode::PostAnalysis + | TypingMode::Codegen => structurally_relate_tys(relation, a, b), } } diff --git a/src/tools/miri/tests/fail/layout_cycle.stderr b/src/tools/miri/tests/fail/layout_cycle.stderr index c233f85063cc9..1917fd683500c 100644 --- a/src/tools/miri/tests/fail/layout_cycle.stderr +++ b/src/tools/miri/tests/fail/layout_cycle.stderr @@ -2,6 +2,7 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `S>`, completing the cycle + = note: cycle used when computing layout of `S>` = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: post-monomorphization error: a cycle occurred during layout computation diff --git a/tests/coverage/await_ready.cov-map b/tests/coverage/await_ready.cov-map index a7eb051ff0938..dfb1510d95826 100644 --- a/tests/coverage/await_ready.cov-map +++ b/tests/coverage/await_ready.cov-map @@ -8,15 +8,13 @@ Number of file 0 mappings: 1 Highest counter ID seen: c0 Function name: await_ready::await_ready::{closure#0} -Raw bytes (21): 0x[01, 01, 01, 05, 09, 03, 01, 0e, 1e, 00, 1f, 01, 02, 05, 01, 0f, 02, 02, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 0e, 1e, 00, 1f, 01, 02, 05, 01, 0f, 05, 02, 01, 00, 02] Number of files: 1 - file 0 => $DIR/await_ready.rs -Number of expressions: 1 -- expression 0 operands: lhs = Counter(1), rhs = Counter(2) +Number of expressions: 0 Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 14, 30) to (start + 0, 31) - Code(Counter(0)) at (prev + 2, 5) to (start + 1, 15) -- Code(Expression(0, Sub)) at (prev + 2, 1) to (start + 0, 2) - = (c1 - c2) -Highest counter ID seen: c0 +- Code(Counter(1)) at (prev + 2, 1) to (start + 0, 2) +Highest counter ID seen: c1 diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr index bf37f537a4976..3e9e4b9ba2c29 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr @@ -30,7 +30,11 @@ note: ...which requires elaborating drops for ` $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1 + | +LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; + | ^^^^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 1 previous error diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr index 317af7975aa7e..842b5328024b0 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr @@ -30,7 +30,11 @@ note: ...which requires elaborating drops for ` $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1 + | +LL | const TRAIT_REF_BAR: u32 = ::BAR; + | ^^^^^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 1 previous error diff --git a/tests/crashes/137916.rs b/tests/ui/async-await/box-dyn-non-send.rs similarity index 65% rename from tests/crashes/137916.rs rename to tests/ui/async-await/box-dyn-non-send.rs index b25e7b200d959..648a8e459cbee 100644 --- a/tests/crashes/137916.rs +++ b/tests/ui/async-await/box-dyn-non-send.rs @@ -1,9 +1,11 @@ -//@ known-bug: #137916 +//! Regression test for ICE #137916. //@ edition: 2021 + use std::ptr::null; async fn a() -> Box { Box::new(async { + //~^ ERROR future cannot be sent between threads safely let non_send = null::<()>(); &non_send; async {}.await diff --git a/tests/ui/async-await/box-dyn-non-send.stderr b/tests/ui/async-await/box-dyn-non-send.stderr new file mode 100644 index 0000000000000..33ebf9881db83 --- /dev/null +++ b/tests/ui/async-await/box-dyn-non-send.stderr @@ -0,0 +1,24 @@ +error: future cannot be sent between threads safely + --> $DIR/box-dyn-non-send.rs:7:5 + | +LL | / Box::new(async { +LL | | +LL | | let non_send = null::<()>(); +LL | | &non_send; +LL | | async {}.await +LL | | }) + | |______^ future created by async block is not `Send` + | + = help: within `{async block@$DIR/box-dyn-non-send.rs:7:14: 7:19}`, the trait `Send` is not implemented for `*const ()` +note: future is not `Send` as this value is used across an await + --> $DIR/box-dyn-non-send.rs:11:18 + | +LL | let non_send = null::<()>(); + | -------- has type `*const ()` which is not `Send` +LL | &non_send; +LL | async {}.await + | ^^^^^ await occurs here, with `non_send` maybe used later + = note: required for the cast from `Box<{async block@$DIR/box-dyn-non-send.rs:7:14: 7:19}>` to `Box` + +error: aborting due to 1 previous error + diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.rs b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs index 7113f591630d1..550496be8c100 100644 --- a/tests/ui/async-await/future-sizes/async-awaiting-fut.rs +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs @@ -5,7 +5,7 @@ //@ edition:2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit async fn wait() {} diff --git a/tests/ui/async-await/future-sizes/large-arg.rs b/tests/ui/async-await/future-sizes/large-arg.rs index b05a2b7191512..1ec7a8d50cb38 100644 --- a/tests/ui/async-await/future-sizes/large-arg.rs +++ b/tests/ui/async-await/future-sizes/large-arg.rs @@ -5,7 +5,7 @@ //@ edition: 2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit pub async fn test() { let _ = a([0u8; 1024]).await; diff --git a/tests/ui/consts/const-eval/const-eval-query-stack.stderr b/tests/ui/consts/const-eval/const-eval-query-stack.stderr index 96206dc5078bc..131b06ace7607 100644 --- a/tests/ui/consts/const-eval/const-eval-query-stack.stderr +++ b/tests/ui/consts/const-eval/const-eval-query-stack.stderr @@ -10,5 +10,6 @@ note: please make sure that you have updated to the latest nightly query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `X` #1 [eval_to_const_value_raw] simplifying constant for the type system `X` -#2 [analysis] running analysis passes on this crate +#2 [eval_to_const_value_raw] simplifying constant for the type system `X` +#3 [analysis] running analysis passes on this crate end of query stack diff --git a/tests/ui/consts/recursive-block.stderr b/tests/ui/consts/recursive-block.stderr index 90814e2e0002a..6294632e19864 100644 --- a/tests/ui/consts/recursive-block.stderr +++ b/tests/ui/consts/recursive-block.stderr @@ -5,7 +5,7 @@ LL | const { foo::<&T>() } | ^^^^^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_block`) - = note: query depth increased by 1 when computing layout of `foo<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>` + = note: query depth increased by 1 when computing layout of `foo<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>` error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-17252.stderr b/tests/ui/issues/issue-17252.stderr index 56bc32b19ab73..404aa5d0bfb91 100644 --- a/tests/ui/issues/issue-17252.stderr +++ b/tests/ui/issues/issue-17252.stderr @@ -10,7 +10,11 @@ note: ...which requires const-evaluating + checking `FOO`... LL | const FOO: usize = FOO; | ^^^ = note: ...which again requires simplifying constant for the type system `FOO`, completing the cycle - = note: cycle used when running analysis passes on this crate +note: cycle used when simplifying constant for the type system `FOO` + --> $DIR/issue-17252.rs:1:1 + | +LL | const FOO: usize = FOO; + | ^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error[E0391]: cycle detected when simplifying constant for the type system `main::BAR` @@ -25,7 +29,11 @@ note: ...which requires const-evaluating + checking `main::BAR`... LL | const BAR: usize = BAR; | ^^^ = note: ...which again requires simplifying constant for the type system `main::BAR`, completing the cycle - = note: cycle used when running analysis passes on this crate +note: cycle used when simplifying constant for the type system `main::BAR` + --> $DIR/issue-17252.rs:6:9 + | +LL | const BAR: usize = BAR; + | ^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 2 previous errors diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr index a3cdb7edcc232..ccaeda9acaa4c 100644 --- a/tests/ui/layout/layout-cycle.stderr +++ b/tests/ui/layout/layout-cycle.stderr @@ -2,6 +2,7 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `S>`, completing the cycle + = note: cycle used when computing layout of `S>` = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: failed to get layout for S>: a cycle occurred during layout computation diff --git a/tests/ui/layout/valid_range_oob.stderr b/tests/ui/layout/valid_range_oob.stderr index 1a0c384125038..a3a3d2eede831 100644 --- a/tests/ui/layout/valid_range_oob.stderr +++ b/tests/ui/layout/valid_range_oob.stderr @@ -5,4 +5,4 @@ error: the compiler unexpectedly panicked. this is a bug. query stack during panic: #0 [layout_of] computing layout of `Foo` #1 [eval_to_allocation_raw] const-evaluating + checking `FOO` -... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack +... and 3 other queries... use `env RUST_BACKTRACE=1` to see the full query stack diff --git a/tests/ui/parallel-rustc/cycle_crash-issue-135870.stderr b/tests/ui/parallel-rustc/cycle_crash-issue-135870.stderr index 6e588d1f89466..03952dedbd373 100644 --- a/tests/ui/parallel-rustc/cycle_crash-issue-135870.stderr +++ b/tests/ui/parallel-rustc/cycle_crash-issue-135870.stderr @@ -1,18 +1,37 @@ -error[E0391]: cycle detected when simplifying constant for the type system `FOO` --> $DIR/cycle_crash-issue-135870.rs:6:1 | LL | const FOO: usize = FOO; | ^^^^^^^^^^^^^^^^ | -note: ...which requires const-evaluating + checking `FOO`... --> $DIR/cycle_crash-issue-135870.rs:6:20 | +LL | const FOO: usize = FOO; + | ^^^^^^^^^^^^^^^^ + | + | +LL | const FOO: usize = FOO; + | ^^^ + | + | +LL | const FOO: usize = FOO; + | ^^^ + | +error[E0391]: cycle detected when simplifying constant for the type system `FOO` + | +LL | const FOO: usize = FOO; + | ^^^^^^^^^^^^^^^^ + | +note: ...which requires const-evaluating + checking `FOO`... + | LL | const FOO: usize = FOO; | ^^^ = note: ...which again requires simplifying constant for the type system `FOO`, completing the cycle - = note: cycle used when running analysis passes on this crate +note: cycle used when simplifying constant for the type system `FOO` + | +LL | const FOO: usize = FOO; + | ^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0391`. \ No newline at end of file diff --git a/tests/ui/print_type_sizes/async.rs b/tests/ui/print_type_sizes/async.rs index b6ec88426345b..8e670ba5df4a4 100644 --- a/tests/ui/print_type_sizes/async.rs +++ b/tests/ui/print_type_sizes/async.rs @@ -5,7 +5,7 @@ //@ edition:2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit #![allow(dropping_copy_types)] diff --git a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout index 4ce1ce46f6e82..f4a2e90a5c4fd 100644 --- a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout +++ b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout @@ -1,3 +1,5 @@ +print-type-size type: `std::pin::Pin<&mut {coroutine@$DIR/coroutine_discr_placement.rs:13:5: 13:7}>`: 8 bytes, alignment: 8 bytes +print-type-size field `.pointer`: 8 bytes print-type-size type: `{coroutine@$DIR/coroutine_discr_placement.rs:13:5: 13:7}`: 8 bytes, alignment: 4 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes @@ -15,3 +17,9 @@ print-type-size type: `std::mem::MaybeUninit`: 4 bytes, alignment: 4 bytes print-type-size variant `MaybeUninit`: 4 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 4 bytes +print-type-size type: `std::ops::CoroutineState<(), ()>`: 1 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Yielded`: 0 bytes +print-type-size field `.0`: 0 bytes +print-type-size variant `Complete`: 0 bytes +print-type-size field `.0`: 0 bytes diff --git a/tests/ui/recursion/issue-23302-3.stderr b/tests/ui/recursion/issue-23302-3.stderr index 8a152f5896634..b3e933a21718e 100644 --- a/tests/ui/recursion/issue-23302-3.stderr +++ b/tests/ui/recursion/issue-23302-3.stderr @@ -20,7 +20,11 @@ note: ...which requires const-evaluating + checking `B`... LL | const B: i32 = A; | ^ = note: ...which again requires simplifying constant for the type system `A`, completing the cycle - = note: cycle used when running analysis passes on this crate +note: cycle used when simplifying constant for the type system `A` + --> $DIR/issue-23302-3.rs:1:1 + | +LL | const A: i32 = B; + | ^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 1 previous error diff --git a/tests/ui/recursion_limit/zero-overflow.rs b/tests/ui/recursion_limit/zero-overflow.rs index 3887972a51623..718b8550c26c6 100644 --- a/tests/ui/recursion_limit/zero-overflow.rs +++ b/tests/ui/recursion_limit/zero-overflow.rs @@ -1,4 +1,4 @@ -//~ ERROR overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome> +//~ ERROR queries overflow the depth limit! //~| HELP consider increasing the recursion limit //@ build-fail diff --git a/tests/ui/recursion_limit/zero-overflow.stderr b/tests/ui/recursion_limit/zero-overflow.stderr index fc03cc5b604b7..ca100c7c81a0c 100644 --- a/tests/ui/recursion_limit/zero-overflow.stderr +++ b/tests/ui/recursion_limit/zero-overflow.stderr @@ -1,7 +1,7 @@ -error[E0275]: overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>` +error: queries overflow the depth limit! | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero_overflow`) + = note: query depth increased by 2 when computing layout of `isize` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr b/tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr index 1a0563b469c1e..e23f397d9b98b 100644 --- a/tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr +++ b/tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr @@ -12,7 +12,7 @@ LL | struct ExplicitlyPadded(Box); error[E0391]: cycle detected when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` | = note: ...which immediately requires computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` again - = note: cycle used when evaluating trait selection obligation `(): core::mem::transmutability::TransmuteFrom` + = note: cycle used when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: aborting due to 2 previous errors