From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_mir_build/src/build/mod.rs | 85 ++++++++++++++----------------- 1 file changed, 38 insertions(+), 47 deletions(-) (limited to 'compiler/rustc_mir_build/src/build/mod.rs') diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index bc50bcbc3..4e3e98b56 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -11,7 +11,7 @@ use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{GeneratorKind, Node}; -use rustc_index::vec::{Idx, IndexSlice, IndexVec}; +use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::middle::region; @@ -32,43 +32,34 @@ use super::lints; pub(crate) fn mir_built( tcx: TyCtxt<'_>, - def: ty::WithOptConstParam, + def: LocalDefId, ) -> &rustc_data_structures::steal::Steal> { - if let Some(def) = def.try_upgrade(tcx) { - return tcx.mir_built(def); - } - - let mut body = mir_build(tcx, def); - if def.const_param_did.is_some() { - assert!(matches!(body.source.instance, ty::InstanceDef::Item(_))); - body.source = MirSource::from_instance(ty::InstanceDef::Item(def.to_global())); - } - - tcx.alloc_steal_mir(body) + tcx.alloc_steal_mir(mir_build(tcx, def)) } /// Construct the MIR for a given `DefId`. -fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { +fn mir_build(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> { // Ensure unsafeck and abstract const building is ran before we steal the THIR. - match def { - ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => { - tcx.ensure_with_value().thir_check_unsafety_for_const_arg((did, const_param_did)); - tcx.ensure_with_value().thir_abstract_const_of_const_arg((did, const_param_did)); - } - ty::WithOptConstParam { did, const_param_did: None } => { - tcx.ensure_with_value().thir_check_unsafety(did); - tcx.ensure_with_value().thir_abstract_const(did); - tcx.ensure_with_value().check_match(did); - } + tcx.ensure_with_value().thir_check_unsafety(def); + tcx.ensure_with_value().thir_abstract_const(def); + if let Err(e) = tcx.check_match(def) { + return construct_error(tcx, def, e); } let body = match tcx.thir_body(def) { - Err(error_reported) => construct_error(tcx, def.did, error_reported), + Err(error_reported) => construct_error(tcx, def, error_reported), Ok((thir, expr)) => { // We ran all queries that depended on THIR at the beginning // of `mir_build`, so now we can steal it let thir = thir.steal(); + tcx.ensure().check_match(def); + // this must run before MIR dump, because + // "not all control paths return a value" is reported here. + // + // maybe move the check to a MIR pass? + tcx.ensure().check_liveness(def); + match thir.body_type { thir::BodyTy::Fn(fn_sig) => construct_fn(tcx, def, &thir, expr, fn_sig), thir::BodyTy::Const(ty) => construct_const(tcx, def, &thir, expr, ty), @@ -161,8 +152,7 @@ struct Builder<'a, 'tcx> { thir: &'a Thir<'tcx>, cfg: CFG<'tcx>, - def: ty::WithOptConstParam, - def_id: DefId, + def_id: LocalDefId, hir_id: hir::HirId, parent_module: DefId, check_overflow: bool, @@ -428,26 +418,26 @@ macro_rules! unpack { fn construct_fn<'tcx>( tcx: TyCtxt<'tcx>, - fn_def: ty::WithOptConstParam, + fn_def: LocalDefId, thir: &Thir<'tcx>, expr: ExprId, fn_sig: ty::FnSig<'tcx>, ) -> Body<'tcx> { - let span = tcx.def_span(fn_def.did); - let fn_id = tcx.hir().local_def_id_to_hir_id(fn_def.did); - let generator_kind = tcx.generator_kind(fn_def.did); + let span = tcx.def_span(fn_def); + let fn_id = tcx.hir().local_def_id_to_hir_id(fn_def); + let generator_kind = tcx.generator_kind(fn_def); // The representation of thir for `-Zunpretty=thir-tree` relies on // the entry expression being the last element of `thir.exprs`. assert_eq!(expr.as_usize(), thir.exprs.len() - 1); // Figure out what primary body this item has. - let body_id = tcx.hir().body_owned_by(fn_def.did); + let body_id = tcx.hir().body_owned_by(fn_def); let span_with_body = tcx.hir().span_with_body(fn_id); let return_ty_span = tcx .hir() .fn_decl_by_hir_id(fn_id) - .unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def.did)) + .unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def)) .output .span(); @@ -457,7 +447,7 @@ fn construct_fn<'tcx>( }; let mut abi = fn_sig.abi; - if let DefKind::Closure = tcx.def_kind(fn_def.did) { + if let DefKind::Closure = tcx.def_kind(fn_def) { // HACK(eddyb) Avoid having RustCall on closures, // as it adds unnecessary (and wrong) auto-tupling. abi = Abi::Rust; @@ -483,7 +473,7 @@ fn construct_fn<'tcx>( { return custom::build_custom_mir( tcx, - fn_def.did.to_def_id(), + fn_def.to_def_id(), fn_id, thir, expr, @@ -547,12 +537,12 @@ fn construct_fn<'tcx>( fn construct_const<'a, 'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, + def: LocalDefId, thir: &'a Thir<'tcx>, expr: ExprId, const_ty: Ty<'tcx>, ) -> Body<'tcx> { - let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); + let hir_id = tcx.hir().local_def_id_to_hir_id(def); // Figure out what primary body this item has. let (span, const_ty_span) = match tcx.hir().get(hir_id) { @@ -568,10 +558,10 @@ fn construct_const<'a, 'tcx>( .. }) => (*span, ty.span), Node::AnonConst(_) => { - let span = tcx.def_span(def.did); + let span = tcx.def_span(def); (span, span) } - _ => span_bug!(tcx.def_span(def.did), "can't build MIR for {:?}", def.did), + _ => span_bug!(tcx.def_span(def), "can't build MIR for {:?}", def), }; let infcx = tcx.infer_ctxt().build(); @@ -669,7 +659,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn new( thir: &'a Thir<'tcx>, infcx: InferCtxt<'tcx>, - def: ty::WithOptConstParam, + def: LocalDefId, hir_id: hir::HirId, span: Span, arg_count: usize, @@ -688,20 +678,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { check_overflow |= tcx.sess.overflow_checks(); // Constants always need overflow checks. check_overflow |= matches!( - tcx.hir().body_owner_kind(def.did), + tcx.hir().body_owner_kind(def), hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) ); let lint_level = LintLevel::Explicit(hir_id); - let param_env = tcx.param_env(def.did); + let param_env = tcx.param_env(def); let mut builder = Builder { thir, tcx, infcx, - region_scope_tree: tcx.region_scope_tree(def.did), + region_scope_tree: tcx.region_scope_tree(def), param_env, - def, - def_id: def.did.to_def_id(), + def_id: def, hir_id, parent_module: tcx.parent_module(hir_id).to_def_id(), check_overflow, @@ -741,7 +730,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } Body::new( - MirSource::item(self.def_id), + MirSource::item(self.def_id.to_def_id()), self.cfg.basic_blocks, self.source_scopes, self.local_decls, @@ -779,7 +768,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let tcx = self.tcx; self.upvars = tcx - .closure_captures(self.def.did) + .closure_captures(self.def_id) .iter() .zip(capture_tys) .enumerate() @@ -809,6 +798,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }; self.var_debug_info.push(VarDebugInfo { name, + references: 0, source_info: SourceInfo::outermost(captured_place.var_ident.span), value: VarDebugInfoContents::Place(use_place), argument_index: None, @@ -839,6 +829,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.var_debug_info.push(VarDebugInfo { name, source_info, + references: 0, value: VarDebugInfoContents::Place(arg_local.into()), argument_index: Some(argument_index as u16 + 1), }); -- cgit v1.2.3