]> git.lizzy.rs Git - rust.git/commitdiff
eliminate the `Lrc` of a slice and just return the slice
authorNiko Matsakis <niko@alum.mit.edu>
Mon, 23 Apr 2018 17:12:00 +0000 (13:12 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 23 Apr 2018 17:28:14 +0000 (13:28 -0400)
Also, introduce `Clauses` and `Goals` type alises for readability.

src/librustc/traits/mod.rs
src/librustc/ty/context.rs
src/librustc/ty/maps/mod.rs
src/librustc_traits/lowering.rs

index b05c4539f6a49c06e686c1b258849aa5f35e2c14..5bfea1631894b172f6516bfe88ed51b6365b0d63 100644 (file)
@@ -282,7 +282,7 @@ pub enum QuantifierKind {
 
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 pub enum Goal<'tcx> {
-    Implies(&'tcx Slice<Clause<'tcx>>, &'tcx Goal<'tcx>),
+    Implies(Clauses<'tcx>, &'tcx Goal<'tcx>),
     And(&'tcx Goal<'tcx>, &'tcx Goal<'tcx>),
     Not(&'tcx Goal<'tcx>),
     DomainGoal(DomainGoal<'tcx>),
@@ -290,6 +290,8 @@ pub enum Goal<'tcx> {
     CannotProve,
 }
 
+pub type Goals<'tcx> = &'tcx Slice<Goal<'tcx>>;
+
 impl<'tcx> Goal<'tcx> {
     pub fn from_poly_domain_goal<'a>(
         domain_goal: PolyDomainGoal<'tcx>,
@@ -319,6 +321,9 @@ pub enum Clause<'tcx> {
     ForAll(ty::Binder<ProgramClause<'tcx>>),
 }
 
+/// Multiple clauses.
+pub type Clauses<'tcx> = &'tcx Slice<Clause<'tcx>>;
+
 /// A "program clause" has the form `D :- G1, ..., Gn`. It is saying
 /// that the domain goal `D` is true if `G1...Gn` are provable. This
 /// is equivalent to the implication `G1..Gn => D`; we usually write
@@ -331,7 +336,7 @@ pub struct ProgramClause<'tcx> {
     pub goal: DomainGoal<'tcx>,
 
     /// ...if we can prove these hypotheses (there may be no hypotheses at all):
-    pub hypotheses: &'tcx Slice<Goal<'tcx>>,
+    pub hypotheses: Goals<'tcx>,
 }
 
 pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>;
index f3a2aa519465c9933e5269b10c287c571fc09dc9..56669243f273a071cffefb80062dde2157a2f459 100644 (file)
@@ -38,7 +38,7 @@
 use ty::ReprOptions;
 use ty::Instance;
 use traits;
-use traits::{Clause, Goal};
+use traits::{Clause, Clauses, Goal, Goals};
 use ty::{self, Ty, TypeAndMut};
 use ty::{TyS, TypeVariants, Slice};
 use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region, Const};
@@ -2517,7 +2517,7 @@ pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVar
         }
     }
 
-    pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> &'tcx Slice<Clause<'tcx>> {
+    pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> Clauses<'tcx> {
         if ts.len() == 0 {
             Slice::empty()
         } else {
@@ -2525,7 +2525,7 @@ pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> &'tcx Slice<Clause<'tcx>> {
         }
     }
 
-    pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> &'tcx Slice<Goal<'tcx>> {
+    pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> Goals<'tcx> {
         if ts.len() == 0 {
             Slice::empty()
         } else {
@@ -2579,13 +2579,11 @@ pub fn mk_substs_trait(self,
         self.mk_substs(iter::once(s).chain(t.into_iter().cloned()).map(Kind::from))
     }
 
-    pub fn mk_clauses<I: InternAs<[Clause<'tcx>],
-        &'tcx Slice<Clause<'tcx>>>>(self, iter: I) -> I::Output {
+    pub fn mk_clauses<I: InternAs<[Clause<'tcx>], Clauses<'tcx>>>(self, iter: I) -> I::Output {
         iter.intern_with(|xs| self.intern_clauses(xs))
     }
 
-    pub fn mk_goals<I: InternAs<[Goal<'tcx>],
-        &'tcx Slice<Goal<'tcx>>>>(self, iter: I) -> I::Output {
+    pub fn mk_goals<I: InternAs<[Goal<'tcx>], Goals<'tcx>>>(self, iter: I) -> I::Output {
         iter.intern_with(|xs| self.intern_goals(xs))
     }
 
index 368e9dc0fadca780d3b93628a5642ff060ecb1ab..92d23d4338f9d904a31332bd782dd01a2b773330 100644 (file)
@@ -37,8 +37,8 @@
 use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
 use traits::query::normalize::NormalizationResult;
 use traits::specialization_graph;
-use traits::Clause;
-use ty::{self, CrateInherentImpls, ParamEnvAnd, Slice, Ty, TyCtxt};
+use traits::Clauses;
+use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
 use ty::steal::Steal;
 use ty::subst::Substs;
 use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
 
     [] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
 
-    [] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<&'tcx Slice<Clause<'tcx>>>,
+    [] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
 
     [] fn program_clauses_for_env: ProgramClausesForEnv(
         ty::ParamEnv<'tcx>
-    ) -> Lrc<&'tcx Slice<Clause<'tcx>>>,
+    ) -> Clauses<'tcx>,
 
     [] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<Vec<DefId>>,
     [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
index 25a3621fd00b6f031f4b5fc502a50be1d983f362..8acc77be60d4f9426d2eacd685e6b75b45993fc4 100644 (file)
 use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
 use rustc::hir::map::definitions::DefPathData;
 use rustc::hir::{self, ImplPolarity};
-use rustc::traits::{Clause, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClauseAtom};
+use rustc::traits::{Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause,
+                    WhereClauseAtom};
 use rustc::ty::subst::Substs;
 use rustc::ty::{self, Slice, TyCtxt};
 use rustc_data_structures::fx::FxHashSet;
-use rustc_data_structures::sync::Lrc;
 use std::mem;
 use syntax::ast;
 
@@ -122,19 +122,19 @@ fn into_from_env_goal(self) -> DomainGoal<'tcx> {
 crate fn program_clauses_for<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     def_id: DefId,
-) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
+) -> Clauses<'tcx> {
     match tcx.def_key(def_id).disambiguated_data.data {
         DefPathData::Trait(_) => program_clauses_for_trait(tcx, def_id),
         DefPathData::Impl => program_clauses_for_impl(tcx, def_id),
         DefPathData::AssocTypeInImpl(..) => program_clauses_for_associated_type_value(tcx, def_id),
-        _ => Lrc::new(Slice::empty()),
+        _ => Slice::empty(),
     }
 }
 
 crate fn program_clauses_for_env<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     param_env: ty::ParamEnv<'tcx>,
-) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
+) -> Clauses<'tcx> {
     debug!("program_clauses_for_env(param_env={:?})", param_env);
 
     let mut last_round = FxHashSet();
@@ -164,12 +164,10 @@ fn into_from_env_goal(self) -> DomainGoal<'tcx> {
 
     debug!("program_clauses_for_env: closure = {:#?}", closure);
 
-    return Lrc::new(
-        tcx.mk_clauses(
-            closure
-                .into_iter()
-                .flat_map(|def_id| tcx.program_clauses_for(def_id).iter().cloned()),
-        ),
+    return tcx.mk_clauses(
+        closure
+            .into_iter()
+            .flat_map(|def_id| tcx.program_clauses_for(def_id).iter().cloned()),
     );
 
     /// Given that `predicate` is in the environment, returns the
@@ -196,7 +194,7 @@ fn predicate_def_id<'tcx>(predicate: ty::Predicate<'tcx>) -> Option<DefId> {
 fn program_clauses_for_trait<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     def_id: DefId,
-) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
+) -> Clauses<'tcx> {
     // `trait Trait<P1..Pn> where WC { .. } // P0 == Self`
 
     // Rule Implemented-From-Env (see rustc guide)
@@ -243,7 +241,7 @@ fn program_clauses_for_trait<'a, 'tcx>(
         .into_iter()
         .map(|wc| implied_bound_from_trait(tcx, trait_pred, wc));
 
-    Lrc::new(tcx.mk_clauses(clauses.chain(implied_bound_clauses)))
+    tcx.mk_clauses(clauses.chain(implied_bound_clauses))
 }
 
 /// For a given `where_clause`, returns a clause `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`.
@@ -262,12 +260,9 @@ fn implied_bound_from_trait<'a, 'tcx>(
     }))
 }
 
-fn program_clauses_for_impl<'a, 'tcx>(
-    tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    def_id: DefId,
-) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
+fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
     if let ImplPolarity::Negative = tcx.impl_polarity(def_id) {
-        return Lrc::new(tcx.mk_clauses(iter::empty::<Clause>()));
+        return Slice::empty();
     }
 
     // Rule Implemented-From-Impl (see rustc guide)
@@ -295,13 +290,13 @@ fn program_clauses_for_impl<'a, 'tcx>(
                 .map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
         ),
     };
-    Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
+    tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause))))
 }
 
 pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     item_id: DefId,
-) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
+) -> Clauses<'tcx> {
     // Rule Normalize-From-Impl (see rustc guide)
     //
     // ```impl<P0..Pn> Trait<A1..An> for A0
@@ -349,7 +344,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
                 .map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
         ),
     };
-    Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
+    tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause))))
 }
 
 pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {