Skip to content

Commit 8211728

Browse files
committed
Remove the queries
1 parent 1ca83c6 commit 8211728

File tree

3 files changed

+13
-116
lines changed

3 files changed

+13
-116
lines changed

compiler/rustc_middle/src/query/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,6 @@ rustc_queries! {
10771077
query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
10781078
desc { "computing whether `{}` needs drop", env.value }
10791079
}
1080-
/// Query backing `Tys::needs_non_const_drop`.
1081-
query needs_non_const_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1082-
desc { "computing whether `{}` needs non-const drop", env.value }
1083-
}
10841080
/// Query backing `TyS::has_significant_drop_raw`.
10851081
query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
10861082
desc { "computing whether `{}` has a significant drop", env.value }
@@ -1105,14 +1101,6 @@ rustc_queries! {
11051101
cache_on_disk_if { true }
11061102
}
11071103

1108-
/// A list of types where the ADT requires drop if and only if any of
1109-
/// those types require non-const drop. If the ADT is known to always need
1110-
/// non-const drop then `Err(AlwaysRequiresDrop)` is returned.
1111-
query adt_drop_tys_non_const(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1112-
desc { |tcx| "computing when `{}` needs non-const drop", tcx.def_path_str(def_id) }
1113-
cache_on_disk_if { true }
1114-
}
1115-
11161104
/// A list of types where the ADT requires drop if and only if any of those types
11171105
/// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
11181106
/// is considered to not be significant. A drop is significant if it is implemented

compiler/rustc_middle/src/ty/util.rs

-29
Original file line numberDiff line numberDiff line change
@@ -792,35 +792,6 @@ impl<'tcx> ty::TyS<'tcx> {
792792
}
793793
}
794794
}
795-
/// If `ty.needs_non_const_drop(...)` returns true, then `ty` is definitely
796-
/// non-copy and *might* have a non-const destructor attached; if it returns
797-
/// `false`, then `ty` definitely has a const destructor or no destructor at all.
798-
///
799-
/// (Note that this implies that if `ty` has a non-const destructor attached,
800-
/// then `needs_non_const_drop` will definitely return `true` for `ty`.)
801-
pub fn needs_non_const_drop(
802-
&'tcx self,
803-
tcx: TyCtxt<'tcx>,
804-
param_env: ty::ParamEnv<'tcx>,
805-
) -> bool {
806-
// Avoid querying in simple cases.
807-
match needs_drop_components(self, &tcx.data_layout) {
808-
Err(AlwaysRequiresDrop) => true,
809-
Ok(components) => {
810-
let query_ty = match *components {
811-
[] => return false,
812-
// if we've got a single component, call the query with that
813-
// to increase the chance that we hit the query cache.
814-
[component_ty] => component_ty,
815-
_ => self,
816-
};
817-
// This doesn't depend on regions, so try to minimize distinct
818-
// query keys used.
819-
let erased = tcx.normalize_erasing_regions(param_env, query_ty);
820-
tcx.needs_non_const_drop_raw(param_env.and(erased))
821-
}
822-
}
823-
}
824795

825796
/// Checks if `ty` has has a significant drop.
826797
///

compiler/rustc_ty_utils/src/needs_drop.rs

+13-75
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
//! Check whether a type has (potentially) non-trivial drop glue.
22
33
use rustc_data_structures::fx::FxHashSet;
4-
use rustc_hir as hir;
54
use rustc_hir::def_id::DefId;
6-
use rustc_infer::infer::TyCtxtInferExt;
75
use rustc_middle::ty::subst::Subst;
86
use rustc_middle::ty::util::{needs_drop_components, AlwaysRequiresDrop};
97
use rustc_middle::ty::{self, Ty, TyCtxt};
108
use rustc_session::Limit;
119
use rustc_span::{sym, DUMMY_SP};
12-
use rustc_trait_selection::traits::{Obligation, ObligationCause, SelectionContext};
1310

1411
type NeedsDropResult<T> = Result<T, AlwaysRequiresDrop>;
1512

16-
fn needs_drop_raw<'tcx>(
17-
tcx: TyCtxt<'tcx>,
18-
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
19-
needs_non_const_drop: bool,
20-
) -> bool {
13+
fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
14+
let adt_components =
15+
move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter());
16+
2117
// If we don't know a type doesn't need drop, for example if it's a type
2218
// parameter without a `Copy` bound, then we conservatively return that it
2319
// needs drop.
24-
let res = if needs_non_const_drop {
25-
let adt_components = move |adt_def: &ty::AdtDef| {
26-
tcx.adt_drop_tys_non_const(adt_def.did).map(|tys| tys.iter())
27-
};
28-
NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components, needs_non_const_drop)
29-
.next()
30-
.is_some()
31-
} else {
32-
let adt_components =
33-
move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter());
34-
NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components, needs_non_const_drop)
35-
.next()
36-
.is_some()
37-
};
20+
let res =
21+
NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components).next().is_some();
3822

3923
debug!("needs_drop_raw({:?}) = {:?}", query, res);
4024
res
@@ -46,10 +30,9 @@ fn has_significant_drop_raw<'tcx>(
4630
) -> bool {
4731
let significant_drop_fields =
4832
move |adt_def: &ty::AdtDef| tcx.adt_significant_drop_tys(adt_def.did).map(|tys| tys.iter());
49-
let res =
50-
NeedsDropTypes::new(tcx, query.param_env, query.value, significant_drop_fields, false)
51-
.next()
52-
.is_some();
33+
let res = NeedsDropTypes::new(tcx, query.param_env, query.value, significant_drop_fields)
34+
.next()
35+
.is_some();
5336
debug!("has_significant_drop_raw({:?}) = {:?}", query, res);
5437
res
5538
}
@@ -66,7 +49,6 @@ struct NeedsDropTypes<'tcx, F> {
6649
unchecked_tys: Vec<(Ty<'tcx>, usize)>,
6750
recursion_limit: Limit,
6851
adt_components: F,
69-
needs_non_const_drop: bool,
7052
}
7153

7254
impl<'tcx, F> NeedsDropTypes<'tcx, F> {
@@ -75,7 +57,6 @@ impl<'tcx, F> NeedsDropTypes<'tcx, F> {
7557
param_env: ty::ParamEnv<'tcx>,
7658
ty: Ty<'tcx>,
7759
adt_components: F,
78-
needs_non_const_drop: bool,
7960
) -> Self {
8061
let mut seen_tys = FxHashSet::default();
8162
seen_tys.insert(ty);
@@ -87,7 +68,6 @@ impl<'tcx, F> NeedsDropTypes<'tcx, F> {
8768
unchecked_tys: vec![(ty, 0)],
8869
recursion_limit: tcx.recursion_limit(),
8970
adt_components,
90-
needs_non_const_drop,
9171
}
9272
}
9373
}
@@ -170,35 +150,6 @@ where
170150
queue_type(self, subst_ty);
171151
}
172152
}
173-
ty::Param(_)
174-
if self.needs_non_const_drop && self.tcx.features().const_trait_impl =>
175-
{
176-
// Check if the param is bounded to have a `~const Drop` impl.
177-
let drop_trait = self.tcx.require_lang_item(hir::LangItem::Drop, None);
178-
let trait_ref = ty::TraitRef {
179-
def_id: drop_trait,
180-
substs: self.tcx.mk_substs_trait(component, &[]),
181-
};
182-
183-
let obligation = Obligation::new(
184-
ObligationCause::dummy(),
185-
self.param_env,
186-
ty::Binder::dummy(ty::TraitPredicate {
187-
trait_ref,
188-
constness: ty::BoundConstness::ConstIfConst,
189-
}),
190-
);
191-
192-
let implsrc = tcx.infer_ctxt().enter(|infcx| {
193-
let mut selcx =
194-
SelectionContext::with_constness(&infcx, hir::Constness::Const);
195-
selcx.select(&obligation)
196-
});
197-
198-
if let Ok(Some(_)) = implsrc {
199-
return None;
200-
}
201-
}
202153
ty::Array(..) | ty::Opaque(..) | ty::Projection(..) | ty::Param(_) => {
203154
if ty == component {
204155
// Return the type to the caller: they may be able
@@ -228,7 +179,6 @@ fn adt_drop_tys_helper(
228179
tcx: TyCtxt<'_>,
229180
def_id: DefId,
230181
adt_has_dtor: impl Fn(&ty::AdtDef) -> bool,
231-
needs_non_const_drop: bool,
232182
) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
233183
let adt_components = move |adt_def: &ty::AdtDef| {
234184
if adt_def.is_manually_drop() {
@@ -247,25 +197,15 @@ fn adt_drop_tys_helper(
247197
let adt_ty = tcx.type_of(def_id);
248198
let param_env = tcx.param_env(def_id);
249199
let res: Result<Vec<_>, _> =
250-
NeedsDropTypes::new(tcx, param_env, adt_ty, adt_components, needs_non_const_drop).collect();
200+
NeedsDropTypes::new(tcx, param_env, adt_ty, adt_components).collect();
251201

252202
debug!("adt_drop_tys(`{}`) = `{:?}`", tcx.def_path_str(def_id), res);
253203
res.map(|components| tcx.intern_type_list(&components))
254204
}
255205

256206
fn adt_drop_tys(tcx: TyCtxt<'_>, def_id: DefId) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
257207
let adt_has_dtor = |adt_def: &ty::AdtDef| adt_def.destructor(tcx).is_some();
258-
adt_drop_tys_helper(tcx, def_id, adt_has_dtor, false)
259-
}
260-
261-
fn adt_drop_tys_non_const(
262-
tcx: TyCtxt<'_>,
263-
def_id: DefId,
264-
) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
265-
let adt_has_dtor = |adt_def: &ty::AdtDef| {
266-
adt_def.destructor(tcx).map(|d| d.constness) == Some(hir::Constness::NotConst)
267-
};
268-
adt_drop_tys_helper(tcx, def_id, adt_has_dtor, true)
208+
adt_drop_tys_helper(tcx, def_id, adt_has_dtor)
269209
}
270210

271211
fn adt_significant_drop_tys(
@@ -278,16 +218,14 @@ fn adt_significant_drop_tys(
278218
.map(|dtor| !tcx.has_attr(dtor.did, sym::rustc_insignificant_dtor))
279219
.unwrap_or(false)
280220
};
281-
adt_drop_tys_helper(tcx, def_id, adt_has_dtor, false)
221+
adt_drop_tys_helper(tcx, def_id, adt_has_dtor)
282222
}
283223

284224
pub(crate) fn provide(providers: &mut ty::query::Providers) {
285225
*providers = ty::query::Providers {
286-
needs_drop_raw: |tcx, query| needs_drop_raw(tcx, query, false),
287-
needs_non_const_drop_raw: |tcx, query| needs_drop_raw(tcx, query, true),
226+
needs_drop_raw,
288227
has_significant_drop_raw,
289228
adt_drop_tys,
290-
adt_drop_tys_non_const,
291229
adt_significant_drop_tys,
292230
..*providers
293231
};

0 commit comments

Comments
 (0)