eliminate the Lrc
of a slice and just return the slice
Also, introduce `Clauses` and `Goals` type alises for readability.
This commit is contained in:
parent
294cae22ee
commit
7fa3c8f445
4 changed files with 32 additions and 34 deletions
|
@ -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>>;
|
||||
|
|
|
@ -38,7 +38,7 @@ use ty::subst::{Kind, Substs};
|
|||
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 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, '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 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
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))
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@ use traits::query::{CanonicalProjectionGoal, CanonicalTyGoal, NoSolution};
|
|||
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};
|
||||
|
@ -445,11 +445,11 @@ define_maps! { <'tcx>
|
|||
|
||||
[] 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)
|
||||
|
|
|
@ -12,11 +12,11 @@ use rustc::hir::def_id::DefId;
|
|||
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 @@ impl<'tcx> IntoFromEnvGoal for 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 @@ crate fn program_clauses_for_env<'a, '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 @@ crate fn program_clauses_for_env<'a, 'tcx>(
|
|||
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>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue