Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch the value of has_ffi_unwind_calls before stealing mir_built. #108777

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/ffi_unwind_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ fn mir_const(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are ensure() calls few lines above this, are they unaffected by the same issue for some reason?

Also, what is the use-case for ensure, if it doesn't ensure that we have the query value?... I'm very confused by all of this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure creates a dependency edge. However, it does not compute the value. For instance, if has_ffi_unwind_calls were to emit diagnostics, ensure would check that the dependencies are unchanged, replay the diagnostics (loaded from disk), but wouldn't try to load the cached value.

And yes, all uses of ensure() before a steal() are probably wrong. However, I find unelegant to invoke a query just to ignore its result.

There are 2 ways to definitely fix this:

  1. change most of the ensures;
  2. check that we can decode the value from disk on ensure.

I'm leaning on 2, but haven't finished implementing it.

}

let mut body = tcx.mir_built(def).steal();

Expand Down