use TypingEnv
when no infcx
is available
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
This commit is contained in:
parent
bf6adec108
commit
9cba14b95b
240 changed files with 1739 additions and 1340 deletions
|
@ -1,7 +1,7 @@
|
|||
use rustc_abi::FieldIdx;
|
||||
use rustc_index::bit_set::ChunkedBitSet;
|
||||
use rustc_middle::mir::{Body, TerminatorKind};
|
||||
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, VariantDef};
|
||||
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, VariantDef};
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
|
||||
use rustc_mir_dataflow::{Analysis, MaybeReachable, move_path_children_matching};
|
||||
|
@ -18,8 +18,8 @@ pub(super) struct RemoveUninitDrops;
|
|||
|
||||
impl<'tcx> crate::MirPass<'tcx> for RemoveUninitDrops {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let param_env = tcx.param_env(body.source.def_id());
|
||||
let move_data = MoveData::gather_moves(body, tcx, |ty| ty.needs_drop(tcx, param_env));
|
||||
let typing_env = body.typing_env(tcx);
|
||||
let move_data = MoveData::gather_moves(body, tcx, |ty| ty.needs_drop(tcx, typing_env));
|
||||
|
||||
let mut maybe_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
|
||||
.iterate_to_fixpoint(tcx, body, Some("remove_uninit_drops"))
|
||||
|
@ -40,7 +40,7 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUninitDrops {
|
|||
|
||||
let should_keep = is_needs_drop_and_init(
|
||||
tcx,
|
||||
param_env,
|
||||
typing_env,
|
||||
maybe_inits,
|
||||
&move_data,
|
||||
place.ty(body, tcx).ty,
|
||||
|
@ -66,24 +66,24 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUninitDrops {
|
|||
|
||||
fn is_needs_drop_and_init<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
typing_env: ty::TypingEnv<'tcx>,
|
||||
maybe_inits: &ChunkedBitSet<MovePathIndex>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
mpi: MovePathIndex,
|
||||
) -> bool {
|
||||
// No need to look deeper if the root is definitely uninit or if it has no `Drop` impl.
|
||||
if !maybe_inits.contains(mpi) || !ty.needs_drop(tcx, param_env) {
|
||||
if !maybe_inits.contains(mpi) || !ty.needs_drop(tcx, typing_env) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let field_needs_drop_and_init = |(f, f_ty, mpi)| {
|
||||
let child = move_path_children_matching(move_data, mpi, |x| x.is_field_to(f));
|
||||
let Some(mpi) = child else {
|
||||
return Ty::needs_drop(f_ty, tcx, param_env);
|
||||
return Ty::needs_drop(f_ty, tcx, typing_env);
|
||||
};
|
||||
|
||||
is_needs_drop_and_init(tcx, param_env, maybe_inits, move_data, f_ty, mpi)
|
||||
is_needs_drop_and_init(tcx, typing_env, maybe_inits, move_data, f_ty, mpi)
|
||||
};
|
||||
|
||||
// This pass is only needed for const-checking, so it doesn't handle as many cases as
|
||||
|
@ -110,7 +110,7 @@ fn is_needs_drop_and_init<'tcx>(
|
|||
let downcast =
|
||||
move_path_children_matching(move_data, mpi, |x| x.is_downcast_to(vid));
|
||||
let Some(dc_mpi) = downcast else {
|
||||
return variant_needs_drop(tcx, param_env, args, variant);
|
||||
return variant_needs_drop(tcx, typing_env, args, variant);
|
||||
};
|
||||
|
||||
dc_mpi
|
||||
|
@ -139,12 +139,12 @@ fn is_needs_drop_and_init<'tcx>(
|
|||
|
||||
fn variant_needs_drop<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
typing_env: ty::TypingEnv<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
variant: &VariantDef,
|
||||
) -> bool {
|
||||
variant.fields.iter().any(|field| {
|
||||
let f_ty = field.ty(tcx, args);
|
||||
f_ty.needs_drop(tcx, param_env)
|
||||
f_ty.needs_drop(tcx, typing_env)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue