From 434226256d3dad92065354897ba13196797b020c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 5 Mar 2023 14:58:31 +0000 Subject: [PATCH] Fetch the value of has_ffi_unwind_calls before stealing mir_built. --- compiler/rustc_mir_transform/src/ffi_unwind_calls.rs | 5 ++--- compiler/rustc_mir_transform/src/lib.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index e6546911a2d0d..ffa1743b4efe5 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -47,14 +47,12 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool { return false; } - let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow(); - let body_ty = tcx.type_of(def_id).skip_binder(); let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::Closure(..) => Abi::RustCall, ty::Generator(..) => Abi::Rust, - _ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty), + _ => span_bug!(tcx.def_span(def_id), "unexpected body ty: {:?}", body_ty), }; let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi); @@ -65,6 +63,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool { let mut tainted = false; + let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow(); for block in body.basic_blocks.iter() { if block.is_cleanup { continue; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index cdd28ae0c0197..128c5e2a05739 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -284,8 +284,12 @@ fn mir_const(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> &Steal< } } - // has_ffi_unwind_calls query uses the raw mir, so make sure it is run. - tcx.ensure().has_ffi_unwind_calls(def.did); + // has_ffi_unwind_calls query uses `mir_built(WithOptConstParam::unknown(def.did))`, + // so make sure it is run. + if def.const_param_did.is_none() { + // Actually fetch the value, to avoid having to compute the query later. + let _ = tcx.has_ffi_unwind_calls(def.did); + } let mut body = tcx.mir_built(def).steal();