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 aa5697dfc9ced..dc09459e58be2 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -327,9 +327,40 @@ pub fn eval_to_const_value_raw_provider<'tcx>( tcx: TyCtxt<'tcx>, key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, ) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> { - if let Some((value, _ty)) = tcx.trivial_const(key.value.instance.def_id()) { + let ty::PseudoCanonicalInput { typing_env, value } = key; + + if let Some((value, _ty)) = tcx.trivial_const(value.instance.def_id()) { return Ok(value); } + + match typing_env.typing_mode() { + ty::TypingMode::PostAnalysis => {} + // 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. + ty::TypingMode::Codegen => { + let with_postanalysis = + ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis); + 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(_)) => {} + } + } + // Const eval always happens in PostAnalysis or Codegen mode. See the comment in + // `InterpCx::new` for more details. + ty::TypingMode::Coherence + | ty::TypingMode::Analysis { .. } + | ty::TypingMode::Borrowck { .. } + | ty::TypingMode::PostBorrowckAnalysis { .. } => { + if cfg!(debug_assertions) { + bug!( + "Const eval should always happens in PostAnalysis or Codegen mode. See the comment in `InterpCx::new` for more details." + ) + } + } + } + tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key)) } @@ -369,33 +400,49 @@ 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())); - if cfg!(debug_assertions) { - match key.typing_env.typing_mode() { - ty::TypingMode::PostAnalysis => {} - ty::TypingMode::Coherence - | ty::TypingMode::Analysis { .. } - | ty::TypingMode::Borrowck { .. } - | ty::TypingMode::PostBorrowckAnalysis { .. } => { + match key.typing_env.typing_mode() { + ty::TypingMode::PostAnalysis => {} + // 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. + ty::TypingMode::Codegen => { + let with_postanalysis = + ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis); + 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(_)) => {} + } + } + ty::TypingMode::Coherence + | ty::TypingMode::Analysis { .. } + | ty::TypingMode::Borrowck { .. } + | ty::TypingMode::PostBorrowckAnalysis { .. } => { + if cfg!(debug_assertions) { bug!( - "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details." + "Const eval should always happens in PostAnalysis or Codegen mode. See the comment in `InterpCx::new` for more details." ) } } + } + 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); } - 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 9e23f56d372b2..b087885530bff 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -238,13 +238,13 @@ pub(crate) fn eval_to_valtree<'tcx>( ) -> EvalToValTreeResult<'tcx> { if cfg!(debug_assertions) { match typing_env.typing_mode() { - ty::TypingMode::PostAnalysis => {} + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => {} ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } => { bug!( - "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details." + "Const eval should always happens in PostAnalysis or Codegen mode. See the comment in `InterpCx::new` for more details." ) } } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 466dcff359829..69fe8989122a5 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -244,12 +244,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // already been revealed, so we'd be able to at least partially observe the hidden types anyways. if cfg!(debug_assertions) { match typing_env.typing_mode() { - TypingMode::PostAnalysis => {} + TypingMode::PostAnalysis | TypingMode::Codegen => {} TypingMode::Coherence | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => { - bug!("Const eval should always happens in PostAnalysis mode."); + bug!("Const eval should always happens in PostAnalysis or Codegen mode."); } } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 50dc150a76668..a0cf3fdd0ad28 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -660,7 +660,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::TypingMode::Coherence | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } - | ty::TypingMode::PostAnalysis => { + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen => { bug!() } }; diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 7d2a00c435cb7..3c3e78b58afc1 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -144,7 +144,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_hir_typeck/src/opaque_types.rs b/compiler/rustc_hir_typeck/src/opaque_types.rs index b7936ea47944c..3229ad161783b 100644 --- a/compiler/rustc_hir_typeck/src/opaque_types.rs +++ b/compiler/rustc_hir_typeck/src/opaque_types.rs @@ -105,7 +105,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> { ty::TypingMode::Coherence | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } - | ty::TypingMode::PostAnalysis => { + | ty::TypingMode::PostAnalysis + | ty::TypingMode::Codegen => { bug!() } }; diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 05043f8617a92..c9b89dad4d817 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1078,7 +1078,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, } } @@ -1408,7 +1409,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::new(param_env, typing_mode) } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index ad6dd5c3cad52..9cf0a691ee3cf 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -281,7 +281,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 cb41974af41b0..a88239e8d1f61 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1180,10 +1180,10 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { && (!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()) - .as_query_input(tcx.type_of(def_id).instantiate_identity().skip_norm_wip()), - ); + tcx.ensure_ok() + .layout_of(ty::TypingEnv::codegen(tcx, def_id.to_def_id()).as_query_input( + tcx.type_of(def_id).instantiate_identity().skip_norm_wip(), + )); } }); }); diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index f4bd64e4ca211..dc014ea229ed8 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -378,18 +378,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/queries.rs b/compiler/rustc_middle/src/queries.rs index f0c367beefd65..5cf40bb37b81a 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -1652,7 +1652,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 { "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 93da73e1e4505..caa3054e82b8e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1005,6 +1005,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)] @@ -1050,7 +1061,7 @@ impl<'tcx> TypingEnv<'tcx> { /// use `TypingMode::PostAnalysis`, they may still have where-clauses /// in scope. pub fn fully_monomorphized() -> TypingEnv<'tcx> { - Self::new(ParamEnv::empty(), TypingMode::PostAnalysis) + Self::new(ParamEnv::empty(), TypingMode::Codegen) } /// Create a typing environment for use during analysis outside of a body. @@ -1067,12 +1078,15 @@ impl<'tcx> TypingEnv<'tcx> { } pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey) -> TypingEnv<'tcx> { - let def_id = def_id.into_query_key(); - tcx.typing_env_normalized_for_post_analysis(def_id) + TypingEnv::new(tcx.param_env_normalized_for_post_analysis(def_id), TypingMode::PostAnalysis) + } + + pub fn codegen(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey) -> TypingEnv<'tcx> { + TypingEnv::new(tcx.param_env_normalized_for_post_analysis(def_id), TypingMode::Codegen) } - /// 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; match typing_mode.0 { @@ -1080,17 +1094,28 @@ impl<'tcx> TypingEnv<'tcx> { | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => {} - TypingMode::PostAnalysis => return self, + TypingMode::PostAnalysis | TypingMode::Codegen => 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())) - }; - TypingEnv { typing_mode: TypingModeEqWrapper(TypingMode::PostAnalysis), param_env } + let param_env = param_env.with_normalized(tcx); + TypingEnv::new(param_env, TypingMode::PostAnalysis) + } + + /// 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; + match typing_mode.0 { + TypingMode::Coherence + | TypingMode::Analysis { .. } + | TypingMode::Borrowck { .. } + | TypingMode::PostBorrowckAnalysis { .. } + | TypingMode::PostAnalysis => {} + TypingMode::Codegen => return self, + } + + let param_env = param_env.with_normalized(tcx); + TypingEnv::new(param_env, TypingMode::Codegen) } /// Combine this typing environment with the given `value` to be used by 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 0c6e1b83c9535..60d656aeb86b4 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 @@ -100,10 +100,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 042b937a76a0c..fef6c82f6fe4d 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -548,7 +548,7 @@ where let tcx = self.tcx(); match self.elaborator.typing_env().typing_mode() { - ty::TypingMode::PostAnalysis => {} + ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => {} ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index a7376fa7e65aa..0ee15f6ae62b4 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -386,7 +386,6 @@ struct VnState<'body, 'a, '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. @@ -425,7 +424,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, '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), @@ -577,11 +575,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, '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 fbe3a827d6394..8968f1a9fd7a4 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -122,8 +122,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( @@ -197,10 +195,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() @@ -776,11 +755,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. - let Some(cyclic_callees) = inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()) - else { + let Some(cyclic_callees) = inliner.tcx().mir_callgraph_cyclic(caller_def_id) else { return Err("call graph cycle detection bailed due to recursion limit"); }; if cyclic_callees.contains(&callee_def_id) { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 882fdda544a50..9351cecab46e3 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -92,12 +92,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 mut finder = TOFinder { tcx, diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 45c8bae295d96..6c0450cf9b1ee 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 c133586f6d78f..7c2391358d5c6 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().skip_norm_wip().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 3cfa9781ec4ae..e203edc35ca5d 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().skip_norm_wip().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 5a73c99616815..7ba9459e6aab1 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -471,7 +471,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => !candidates.iter().any(|c| { + | TypingMode::PostAnalysis + | TypingMode::Codegen => !candidates.iter().any(|c| { matches!( c.source, CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) @@ -964,7 +965,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => {} + | TypingMode::PostAnalysis + | TypingMode::Codegen => {} } let mut i = 0; @@ -1027,7 +1029,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 aa49997253dc2..78c81b1cd488b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -147,7 +147,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 6f05df707ad84..bc39a93242a4c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -360,7 +360,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 d93b7843b2251..7bbfc20569db7 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 @@ -303,7 +303,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, @@ -341,7 +342,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 6e21366955d82..4a88d886c9b39 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 @@ -96,7 +96,8 @@ where } TypingMode::Coherence | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => unreachable!(), + | TypingMode::PostAnalysis + | TypingMode::Codegen => unreachable!(), } } @@ -130,7 +131,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).skip_norm_wip(); 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 0490b285aedf0..f3a15cb1f5783 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 b97d895bec15f..12dc137c82b8e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -81,7 +81,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => return Err(NoSolution), + | TypingMode::PostAnalysis + | TypingMode::Codegen => return Err(NoSolution), }, // Impl matches polarity @@ -1398,7 +1399,8 @@ where TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => {} + | TypingMode::PostAnalysis + | TypingMode::Codegen => {} } if candidates @@ -1575,6 +1577,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 c61702a10f6e0..5ebce16d5dafd 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -293,7 +293,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 8848b4c40f510..d6c1557f26a7c 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -282,7 +282,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 0b1d4a8453d05..ba788beaf23bd 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -178,7 +178,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 2946d8d1d487d..8c83cb4c0840b 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -144,7 +144,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) @@ -416,7 +416,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 5423e394119c4..5ad8e6c7d003c 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 bd9fee90d8903..e5823e038aa61 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 9eca0f31a4402..8e71a6f7e3d95 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1482,7 +1482,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()"); @@ -1541,7 +1542,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, } } @@ -2908,6 +2909,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 c6e8ae49e4c9d..d7e9af87cbd64 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -160,7 +160,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 2ee27ed0914f7..d21712f008386 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -66,6 +66,23 @@ fn layout_of<'tcx>( return tcx.layout_of(typing_env.as_query_input(ty)); } + match typing_env.typing_mode() { + ty::TypingMode::Codegen => { + let with_postanalysis = + ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis); + let res = tcx.layout_of(with_postanalysis.as_query_input(ty)); + match res { + Err(LayoutError::TooGeneric(_)) => {} + _ => return res, + }; + } + ty::TypingMode::Coherence + | ty::TypingMode::Analysis { .. } + | ty::TypingMode::Borrowck { .. } + | ty::TypingMode::PostBorrowckAnalysis { .. } + | ty::TypingMode::PostAnalysis => {} + } + let cx = LayoutCx::new(tcx, typing_env); let layout = layout_of_uncached(&cx, ty)?; @@ -519,6 +536,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)?; @@ -686,7 +714,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::new( + tcx.param_env_normalized_for_post_analysis(def.did()), + cx.typing_env.typing_mode(), + ); !tcx.type_of(last_field.did) .instantiate_identity() .skip_norm_wip() diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 258b9db60960d..c12a82d074c91 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -292,8 +292,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. @@ -404,7 +404,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 1b6bdf8c34dd8..dc5a0c05c6940 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -99,15 +99,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, } /// We want to highly discourage using equality checks on typing modes. @@ -145,12 +147,14 @@ impl PartialEq for TypingModeEqWrapper { TypingMode::PostBorrowckAnalysis { defined_opaque_types: r }, ) => l == r, (TypingMode::PostAnalysis, TypingMode::PostAnalysis) => true, + (TypingMode::Codegen, TypingMode::Codegen) => true, ( TypingMode::Coherence | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis, + | TypingMode::PostAnalysis + | TypingMode::Codegen, _, ) => false, } @@ -171,7 +175,8 @@ impl TypingMode { TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => false, + | TypingMode::PostAnalysis + | TypingMode::Codegen => false, } } @@ -410,9 +415,8 @@ where TypingMode::Coherence | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } - | TypingMode::PostBorrowckAnalysis { .. } => { - infcx.cx().features().feature_bound_holds_in_crate(symbol) - } - TypingMode::PostAnalysis => true, + | TypingMode::PostBorrowckAnalysis { .. } + | TypingMode::PostAnalysis => infcx.cx().features().feature_bound_holds_in_crate(symbol), + TypingMode::Codegen => true, } } diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index 3489e1f55bc3f..fdb0ef38b5366 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -143,7 +143,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/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-trait.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr index 8197cfcba5025..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/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 89f9c1e36920d..5e1179d3993af 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 crate `const_eval_query_stack` +#2 [eval_to_const_value_raw] simplifying constant for the type system `X` +#3 [analysis] running analysis passes on crate `const_eval_query_stack` end of query stack diff --git a/tests/ui/consts/const-size_of-cycle.stderr b/tests/ui/consts/const-size_of-cycle.stderr index 01aa5e726b451..eb4115ce0ce11 100644 --- a/tests/ui/consts/const-size_of-cycle.stderr +++ b/tests/ui/consts/const-size_of-cycle.stderr @@ -4,6 +4,11 @@ error[E0391]: cycle detected when evaluating type-level constant LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... + --> $DIR/const-size_of-cycle.rs:2:17 + | +LL | bytes: [u8; std::mem::size_of::()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... --> $SRC_DIR/core/src/mem/mod.rs:LL:COL note: ...which requires simplifying constant for the type system `core::mem::SizedTypeProperties::SIZE`... diff --git a/tests/ui/consts/issue-44415.stderr b/tests/ui/consts/issue-44415.stderr index 0e3f2e6199f76..e53b6df974120 100644 --- a/tests/ui/consts/issue-44415.stderr +++ b/tests/ui/consts/issue-44415.stderr @@ -7,6 +7,11 @@ LL | bytes: [u8; unsafe { intrinsics::size_of::() }], note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... --> $DIR/issue-44415.rs:6:17 | +LL | bytes: [u8; unsafe { intrinsics::size_of::() }], + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... + --> $DIR/issue-44415.rs:6:17 + | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which requires computing layout of `Foo`... 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/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 b51beb514ba80..f06d88500a885 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 @@ -17,3 +19,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/recursion_limit/zero-overflow.rs b/tests/ui/recursion/recursion_limit/zero-overflow.rs index 3887972a51623..718b8550c26c6 100644 --- a/tests/ui/recursion/recursion_limit/zero-overflow.rs +++ b/tests/ui/recursion/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/recursion_limit/zero-overflow.stderr b/tests/ui/recursion/recursion_limit/zero-overflow.stderr index fc03cc5b604b7..ca100c7c81a0c 100644 --- a/tests/ui/recursion/recursion_limit/zero-overflow.stderr +++ b/tests/ui/recursion/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`.