Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 22, 2024
1 parent 8ba11b7 commit 947ada5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ rustc_queries! {
/// *IMPORTANT*: *DO NOT* run this query before promoted MIR body is constructed,
/// because this query partially depends on that query.
/// Otherwise, there is a risk of query cycles.
query list_significant_drop_tys(ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> &'tcx ty::List<Ty<'tcx>> {
query list_significant_drop_tys(ty: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> &'tcx ty::List<Ty<'tcx>> {
desc { |tcx| "computing when `{}` has a significant destructor", ty.value }
cache_on_disk_if { false }
}
Expand Down
31 changes: 13 additions & 18 deletions compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,30 +216,25 @@ fn true_significant_drop_ty<'tcx>(

/// Returns the list of types with a "potentially sigificant" that may be dropped
/// by dropping a value of type `ty`.
#[instrument(level = "debug", skip(tcx, param_env))]
#[instrument(level = "debug", skip(tcx, typing_env))]
fn extract_component_raw<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
ty: Ty<'tcx>,
ty_seen: &mut UnordSet<Ty<'tcx>>,
) -> SmallVec<[Ty<'tcx>; 4]> {
// Droppiness does not depend on regions, so let us erase them.
let ty = tcx
.try_normalize_erasing_regions(
ty::TypingEnv { param_env, typing_mode: ty::TypingMode::PostAnalysis },
ty,
)
.unwrap_or(ty);

let tys = tcx.list_significant_drop_tys(param_env.and(ty));
let ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);

let tys = tcx.list_significant_drop_tys(typing_env.as_query_input(ty));
debug!(?ty, "components");
let mut out_tys = smallvec![];
for ty in tys {
if let Some(tys) = true_significant_drop_ty(tcx, ty) {
// Some types can be further opened up because the drop is simply delegated
for ty in tys {
if ty_seen.insert(ty) {
out_tys.extend(extract_component_raw(tcx, param_env, ty, ty_seen));
out_tys.extend(extract_component_raw(tcx, typing_env, ty, ty_seen));
}
}
} else {
Expand All @@ -251,13 +246,13 @@ fn extract_component_raw<'tcx>(
out_tys
}

#[instrument(level = "debug", skip(tcx, param_env))]
#[instrument(level = "debug", skip(tcx, typing_env))]
fn extract_component_with_significant_dtor<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
ty: Ty<'tcx>,
) -> SmallVec<[Ty<'tcx>; 4]> {
let mut tys = extract_component_raw(tcx, param_env, ty, &mut Default::default());
let mut tys = extract_component_raw(tcx, typing_env, ty, &mut Default::default());
let mut deduplicate = FxHashSet::default();
tys.retain(|oty| deduplicate.insert(*oty));
tys.into_iter().collect()
Expand Down Expand Up @@ -359,15 +354,15 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
// We group them per-block because they tend to scheduled in the same drop ladder block.
let mut bid_per_block = IndexMap::default();
let mut bid_places = UnordSet::new();
let param_env = tcx.param_env(def_id).with_reveal_all_normalized(tcx);
let typing_env = ty::TypingEnv::post_analysis(tcx, def_id);
let mut ty_dropped_components = UnordMap::default();
for (block, data) in body.basic_blocks.iter_enumerated() {
for (statement_index, stmt) in data.statements.iter().enumerate() {
if let StatementKind::BackwardIncompatibleDropHint { place, reason: _ } = &stmt.kind {
let ty = place.ty(body, tcx).ty;
if ty_dropped_components
.entry(ty)
.or_insert_with(|| extract_component_with_significant_dtor(tcx, param_env, ty))
.or_insert_with(|| extract_component_with_significant_dtor(tcx, typing_env, ty))
.is_empty()
{
continue;
Expand Down Expand Up @@ -479,7 +474,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
if ty_dropped_components
.entry(observer_ty)
.or_insert_with(|| {
extract_component_with_significant_dtor(tcx, param_env, observer_ty)
extract_component_with_significant_dtor(tcx, typing_env, observer_ty)
})
.is_empty()
{
Expand Down Expand Up @@ -575,7 +570,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
let name = name.as_str();

let mut seen_dyn = false;
let destructors = extract_component_with_significant_dtor(tcx, param_env, observer_ty)
let destructors = extract_component_with_significant_dtor(tcx, typing_env, observer_ty)
.into_iter()
.filter_map(|ty| {
if let Some(span) = ty_dtor_span(tcx, ty) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Normalizes MIR in `TypingMode::PostAnalysis`` mode, most notably revealing
//! Normalizes MIR in `TypingMode::PostAnalysis` mode, most notably revealing
//! its opaques. We also only normalize specializable associated items once in
//! `PostAnalysis` mode.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ fn adt_significant_drop_tys(
#[instrument(level = "debug", skip(tcx), ret)]
fn list_significant_drop_tys<'tcx>(
tcx: TyCtxt<'tcx>,
ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
) -> &'tcx ty::List<Ty<'tcx>> {
tcx.mk_type_list(
&drop_tys_helper(
tcx,
ty.value,
ty::TypingEnv { typing_mode: ty::TypingMode::PostAnalysis, param_env: ty.param_env },
key.value,
key.typing_env,
adt_consider_insignificant_dtor(tcx),
true,
true,
Expand Down

0 comments on commit 947ada5

Please sign in to comment.