about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-09-02 11:04:29 +0000
committerDeadbeef <ent3rm4n@gmail.com>2021-09-09 05:21:32 +0000
commit82117289f2ac8623348725ae20e68b28331508a1 (patch)
tree7b5054c2c7a576676f2adb3c5e8ed6e1a03e9aac
parent1ca83c6451783aaa77aa69643b70b22ef9e9a01a (diff)
downloadrust-82117289f2ac8623348725ae20e68b28331508a1.tar.gz
rust-82117289f2ac8623348725ae20e68b28331508a1.zip
Remove the queries
-rw-r--r--compiler/rustc_middle/src/query/mod.rs12
-rw-r--r--compiler/rustc_middle/src/ty/util.rs29
-rw-r--r--compiler/rustc_ty_utils/src/needs_drop.rs88
3 files changed, 13 insertions, 116 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 4f13ca892dd..dd5753e95d0 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -1077,10 +1077,6 @@ rustc_queries! {
     query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
         desc { "computing whether `{}` needs drop", env.value }
     }
-    /// Query backing `Tys::needs_non_const_drop`.
-    query needs_non_const_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
-        desc { "computing whether `{}` needs non-const drop", env.value }
-    }
     /// Query backing `TyS::has_significant_drop_raw`.
     query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
         desc { "computing whether `{}` has a significant drop", env.value }
@@ -1105,14 +1101,6 @@ rustc_queries! {
         cache_on_disk_if { true }
     }
 
-    /// A list of types where the ADT requires drop if and only if any of
-    /// those types require non-const drop. If the ADT is known to always need
-    /// non-const drop then `Err(AlwaysRequiresDrop)` is returned.
-    query adt_drop_tys_non_const(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
-        desc { |tcx| "computing when `{}` needs non-const drop", tcx.def_path_str(def_id) }
-        cache_on_disk_if { true }
-    }
-
     /// A list of types where the ADT requires drop if and only if any of those types
     /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
     /// is considered to not be significant. A drop is significant if it is implemented
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs
index 1d86715772d..808c93abc8e 100644
--- a/compiler/rustc_middle/src/ty/util.rs
+++ b/compiler/rustc_middle/src/ty/util.rs
@@ -792,35 +792,6 @@ impl<'tcx> ty::TyS<'tcx> {
             }
         }
     }
-    /// If `ty.needs_non_const_drop(...)` returns true, then `ty` is definitely
-    /// non-copy and *might* have a non-const destructor attached; if it returns
-    /// `false`, then `ty` definitely has a const destructor or no destructor at all.
-    ///
-    /// (Note that this implies that if `ty` has a non-const destructor attached,
-    /// then `needs_non_const_drop` will definitely return `true` for `ty`.)
-    pub fn needs_non_const_drop(
-        &'tcx self,
-        tcx: TyCtxt<'tcx>,
-        param_env: ty::ParamEnv<'tcx>,
-    ) -> bool {
-        // Avoid querying in simple cases.
-        match needs_drop_components(self, &tcx.data_layout) {
-            Err(AlwaysRequiresDrop) => true,
-            Ok(components) => {
-                let query_ty = match *components {
-                    [] => return false,
-                    // if we've got a single component, call the query with that
-                    // to increase the chance that we hit the query cache.
-                    [component_ty] => component_ty,
-                    _ => self,
-                };
-                // This doesn't depend on regions, so try to minimize distinct
-                // query keys used.
-                let erased = tcx.normalize_erasing_regions(param_env, query_ty);
-                tcx.needs_non_const_drop_raw(param_env.and(erased))
-            }
-        }
-    }
 
     /// Checks if `ty` has has a significant drop.
     ///
diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs
index d93379aa386..32d271d94c8 100644
--- a/compiler/rustc_ty_utils/src/needs_drop.rs
+++ b/compiler/rustc_ty_utils/src/needs_drop.rs
@@ -1,40 +1,24 @@
 //! Check whether a type has (potentially) non-trivial drop glue.
 
 use rustc_data_structures::fx::FxHashSet;
-use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
-use rustc_infer::infer::TyCtxtInferExt;
 use rustc_middle::ty::subst::Subst;
 use rustc_middle::ty::util::{needs_drop_components, AlwaysRequiresDrop};
 use rustc_middle::ty::{self, Ty, TyCtxt};
 use rustc_session::Limit;
 use rustc_span::{sym, DUMMY_SP};
-use rustc_trait_selection::traits::{Obligation, ObligationCause, SelectionContext};
 
 type NeedsDropResult<T> = Result<T, AlwaysRequiresDrop>;
 
-fn needs_drop_raw<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
-    needs_non_const_drop: bool,
-) -> bool {
+fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
+    let adt_components =
+        move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter());
+
     // If we don't know a type doesn't need drop, for example if it's a type
     // parameter without a `Copy` bound, then we conservatively return that it
     // needs drop.
-    let res = if needs_non_const_drop {
-        let adt_components = move |adt_def: &ty::AdtDef| {
-            tcx.adt_drop_tys_non_const(adt_def.did).map(|tys| tys.iter())
-        };
-        NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components, needs_non_const_drop)
-            .next()
-            .is_some()
-    } else {
-        let adt_components =
-            move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter());
-        NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components, needs_non_const_drop)
-            .next()
-            .is_some()
-    };
+    let res =
+        NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components).next().is_some();
 
     debug!("needs_drop_raw({:?}) = {:?}", query, res);
     res
@@ -46,10 +30,9 @@ fn has_significant_drop_raw<'tcx>(
 ) -> bool {
     let significant_drop_fields =
         move |adt_def: &ty::AdtDef| tcx.adt_significant_drop_tys(adt_def.did).map(|tys| tys.iter());
-    let res =
-        NeedsDropTypes::new(tcx, query.param_env, query.value, significant_drop_fields, false)
-            .next()
-            .is_some();
+    let res = NeedsDropTypes::new(tcx, query.param_env, query.value, significant_drop_fields)
+        .next()
+        .is_some();
     debug!("has_significant_drop_raw({:?}) = {:?}", query, res);
     res
 }
@@ -66,7 +49,6 @@ struct NeedsDropTypes<'tcx, F> {
     unchecked_tys: Vec<(Ty<'tcx>, usize)>,
     recursion_limit: Limit,
     adt_components: F,
-    needs_non_const_drop: bool,
 }
 
 impl<'tcx, F> NeedsDropTypes<'tcx, F> {
@@ -75,7 +57,6 @@ impl<'tcx, F> NeedsDropTypes<'tcx, F> {
         param_env: ty::ParamEnv<'tcx>,
         ty: Ty<'tcx>,
         adt_components: F,
-        needs_non_const_drop: bool,
     ) -> Self {
         let mut seen_tys = FxHashSet::default();
         seen_tys.insert(ty);
@@ -87,7 +68,6 @@ impl<'tcx, F> NeedsDropTypes<'tcx, F> {
             unchecked_tys: vec![(ty, 0)],
             recursion_limit: tcx.recursion_limit(),
             adt_components,
-            needs_non_const_drop,
         }
     }
 }
@@ -170,35 +150,6 @@ where
                             queue_type(self, subst_ty);
                         }
                     }
-                    ty::Param(_)
-                        if self.needs_non_const_drop && self.tcx.features().const_trait_impl =>
-                    {
-                        // Check if the param is bounded to have a `~const Drop` impl.
-                        let drop_trait = self.tcx.require_lang_item(hir::LangItem::Drop, None);
-                        let trait_ref = ty::TraitRef {
-                            def_id: drop_trait,
-                            substs: self.tcx.mk_substs_trait(component, &[]),
-                        };
-
-                        let obligation = Obligation::new(
-                            ObligationCause::dummy(),
-                            self.param_env,
-                            ty::Binder::dummy(ty::TraitPredicate {
-                                trait_ref,
-                                constness: ty::BoundConstness::ConstIfConst,
-                            }),
-                        );
-
-                        let implsrc = tcx.infer_ctxt().enter(|infcx| {
-                            let mut selcx =
-                                SelectionContext::with_constness(&infcx, hir::Constness::Const);
-                            selcx.select(&obligation)
-                        });
-
-                        if let Ok(Some(_)) = implsrc {
-                            return None;
-                        }
-                    }
                     ty::Array(..) | ty::Opaque(..) | ty::Projection(..) | ty::Param(_) => {
                         if ty == component {
                             // Return the type to the caller: they may be able
@@ -228,7 +179,6 @@ fn adt_drop_tys_helper(
     tcx: TyCtxt<'_>,
     def_id: DefId,
     adt_has_dtor: impl Fn(&ty::AdtDef) -> bool,
-    needs_non_const_drop: bool,
 ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
     let adt_components = move |adt_def: &ty::AdtDef| {
         if adt_def.is_manually_drop() {
@@ -247,7 +197,7 @@ fn adt_drop_tys_helper(
     let adt_ty = tcx.type_of(def_id);
     let param_env = tcx.param_env(def_id);
     let res: Result<Vec<_>, _> =
-        NeedsDropTypes::new(tcx, param_env, adt_ty, adt_components, needs_non_const_drop).collect();
+        NeedsDropTypes::new(tcx, param_env, adt_ty, adt_components).collect();
 
     debug!("adt_drop_tys(`{}`) = `{:?}`", tcx.def_path_str(def_id), res);
     res.map(|components| tcx.intern_type_list(&components))
@@ -255,17 +205,7 @@ fn adt_drop_tys_helper(
 
 fn adt_drop_tys(tcx: TyCtxt<'_>, def_id: DefId) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
     let adt_has_dtor = |adt_def: &ty::AdtDef| adt_def.destructor(tcx).is_some();
-    adt_drop_tys_helper(tcx, def_id, adt_has_dtor, false)
-}
-
-fn adt_drop_tys_non_const(
-    tcx: TyCtxt<'_>,
-    def_id: DefId,
-) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
-    let adt_has_dtor = |adt_def: &ty::AdtDef| {
-        adt_def.destructor(tcx).map(|d| d.constness) == Some(hir::Constness::NotConst)
-    };
-    adt_drop_tys_helper(tcx, def_id, adt_has_dtor, true)
+    adt_drop_tys_helper(tcx, def_id, adt_has_dtor)
 }
 
 fn adt_significant_drop_tys(
@@ -278,16 +218,14 @@ fn adt_significant_drop_tys(
             .map(|dtor| !tcx.has_attr(dtor.did, sym::rustc_insignificant_dtor))
             .unwrap_or(false)
     };
-    adt_drop_tys_helper(tcx, def_id, adt_has_dtor, false)
+    adt_drop_tys_helper(tcx, def_id, adt_has_dtor)
 }
 
 pub(crate) fn provide(providers: &mut ty::query::Providers) {
     *providers = ty::query::Providers {
-        needs_drop_raw: |tcx, query| needs_drop_raw(tcx, query, false),
-        needs_non_const_drop_raw: |tcx, query| needs_drop_raw(tcx, query, true),
+        needs_drop_raw,
         has_significant_drop_raw,
         adt_drop_tys,
-        adt_drop_tys_non_const,
         adt_significant_drop_tys,
         ..*providers
     };