Skip to content

Commit 7fa3c8f

Browse files
committed
eliminate the Lrc of a slice and just return the slice
Also, introduce `Clauses` and `Goals` type alises for readability.
1 parent 294cae2 commit 7fa3c8f

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

src/librustc/traits/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,16 @@ pub enum QuantifierKind {
282282

283283
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
284284
pub enum Goal<'tcx> {
285-
Implies(&'tcx Slice<Clause<'tcx>>, &'tcx Goal<'tcx>),
285+
Implies(Clauses<'tcx>, &'tcx Goal<'tcx>),
286286
And(&'tcx Goal<'tcx>, &'tcx Goal<'tcx>),
287287
Not(&'tcx Goal<'tcx>),
288288
DomainGoal(DomainGoal<'tcx>),
289289
Quantified(QuantifierKind, ty::Binder<&'tcx Goal<'tcx>>),
290290
CannotProve,
291291
}
292292

293+
pub type Goals<'tcx> = &'tcx Slice<Goal<'tcx>>;
294+
293295
impl<'tcx> Goal<'tcx> {
294296
pub fn from_poly_domain_goal<'a>(
295297
domain_goal: PolyDomainGoal<'tcx>,
@@ -319,6 +321,9 @@ pub enum Clause<'tcx> {
319321
ForAll(ty::Binder<ProgramClause<'tcx>>),
320322
}
321323

324+
/// Multiple clauses.
325+
pub type Clauses<'tcx> = &'tcx Slice<Clause<'tcx>>;
326+
322327
/// A "program clause" has the form `D :- G1, ..., Gn`. It is saying
323328
/// that the domain goal `D` is true if `G1...Gn` are provable. This
324329
/// is equivalent to the implication `G1..Gn => D`; we usually write
@@ -331,7 +336,7 @@ pub struct ProgramClause<'tcx> {
331336
pub goal: DomainGoal<'tcx>,
332337

333338
/// ...if we can prove these hypotheses (there may be no hypotheses at all):
334-
pub hypotheses: &'tcx Slice<Goal<'tcx>>,
339+
pub hypotheses: Goals<'tcx>,
335340
}
336341

337342
pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>;

src/librustc/ty/context.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use ty::subst::{Kind, Substs};
3838
use ty::ReprOptions;
3939
use ty::Instance;
4040
use traits;
41-
use traits::{Clause, Goal};
41+
use traits::{Clause, Clauses, Goal, Goals};
4242
use ty::{self, Ty, TypeAndMut};
4343
use ty::{TyS, TypeVariants, Slice};
4444
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region, Const};
@@ -2517,15 +2517,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25172517
}
25182518
}
25192519

2520-
pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> &'tcx Slice<Clause<'tcx>> {
2520+
pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> Clauses<'tcx> {
25212521
if ts.len() == 0 {
25222522
Slice::empty()
25232523
} else {
25242524
self._intern_clauses(ts)
25252525
}
25262526
}
25272527

2528-
pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> &'tcx Slice<Goal<'tcx>> {
2528+
pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> Goals<'tcx> {
25292529
if ts.len() == 0 {
25302530
Slice::empty()
25312531
} else {
@@ -2579,13 +2579,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25792579
self.mk_substs(iter::once(s).chain(t.into_iter().cloned()).map(Kind::from))
25802580
}
25812581

2582-
pub fn mk_clauses<I: InternAs<[Clause<'tcx>],
2583-
&'tcx Slice<Clause<'tcx>>>>(self, iter: I) -> I::Output {
2582+
pub fn mk_clauses<I: InternAs<[Clause<'tcx>], Clauses<'tcx>>>(self, iter: I) -> I::Output {
25842583
iter.intern_with(|xs| self.intern_clauses(xs))
25852584
}
25862585

2587-
pub fn mk_goals<I: InternAs<[Goal<'tcx>],
2588-
&'tcx Slice<Goal<'tcx>>>>(self, iter: I) -> I::Output {
2586+
pub fn mk_goals<I: InternAs<[Goal<'tcx>], Goals<'tcx>>>(self, iter: I) -> I::Output {
25892587
iter.intern_with(|xs| self.intern_goals(xs))
25902588
}
25912589

src/librustc/ty/maps/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use traits::query::{CanonicalProjectionGoal, CanonicalTyGoal, NoSolution};
3737
use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
3838
use traits::query::normalize::NormalizationResult;
3939
use traits::specialization_graph;
40-
use traits::Clause;
41-
use ty::{self, CrateInherentImpls, ParamEnvAnd, Slice, Ty, TyCtxt};
40+
use traits::Clauses;
41+
use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
4242
use ty::steal::Steal;
4343
use ty::subst::Substs;
4444
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
@@ -445,11 +445,11 @@ define_maps! { <'tcx>
445445

446446
[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
447447

448-
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<&'tcx Slice<Clause<'tcx>>>,
448+
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
449449

450450
[] fn program_clauses_for_env: ProgramClausesForEnv(
451451
ty::ParamEnv<'tcx>
452-
) -> Lrc<&'tcx Slice<Clause<'tcx>>>,
452+
) -> Clauses<'tcx>,
453453

454454
[] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<Vec<DefId>>,
455455
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)

src/librustc_traits/lowering.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use rustc::hir::def_id::DefId;
1212
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
1313
use rustc::hir::map::definitions::DefPathData;
1414
use rustc::hir::{self, ImplPolarity};
15-
use rustc::traits::{Clause, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClauseAtom};
15+
use rustc::traits::{Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause,
16+
WhereClauseAtom};
1617
use rustc::ty::subst::Substs;
1718
use rustc::ty::{self, Slice, TyCtxt};
1819
use rustc_data_structures::fx::FxHashSet;
19-
use rustc_data_structures::sync::Lrc;
2020
use std::mem;
2121
use syntax::ast;
2222

@@ -122,19 +122,19 @@ impl<'tcx> IntoFromEnvGoal for DomainGoal<'tcx> {
122122
crate fn program_clauses_for<'a, 'tcx>(
123123
tcx: TyCtxt<'a, 'tcx, 'tcx>,
124124
def_id: DefId,
125-
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
125+
) -> Clauses<'tcx> {
126126
match tcx.def_key(def_id).disambiguated_data.data {
127127
DefPathData::Trait(_) => program_clauses_for_trait(tcx, def_id),
128128
DefPathData::Impl => program_clauses_for_impl(tcx, def_id),
129129
DefPathData::AssocTypeInImpl(..) => program_clauses_for_associated_type_value(tcx, def_id),
130-
_ => Lrc::new(Slice::empty()),
130+
_ => Slice::empty(),
131131
}
132132
}
133133

134134
crate fn program_clauses_for_env<'a, 'tcx>(
135135
tcx: TyCtxt<'a, 'tcx, 'tcx>,
136136
param_env: ty::ParamEnv<'tcx>,
137-
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
137+
) -> Clauses<'tcx> {
138138
debug!("program_clauses_for_env(param_env={:?})", param_env);
139139

140140
let mut last_round = FxHashSet();
@@ -164,12 +164,10 @@ crate fn program_clauses_for_env<'a, 'tcx>(
164164

165165
debug!("program_clauses_for_env: closure = {:#?}", closure);
166166

167-
return Lrc::new(
168-
tcx.mk_clauses(
169-
closure
170-
.into_iter()
171-
.flat_map(|def_id| tcx.program_clauses_for(def_id).iter().cloned()),
172-
),
167+
return tcx.mk_clauses(
168+
closure
169+
.into_iter()
170+
.flat_map(|def_id| tcx.program_clauses_for(def_id).iter().cloned()),
173171
);
174172

175173
/// Given that `predicate` is in the environment, returns the
@@ -196,7 +194,7 @@ crate fn program_clauses_for_env<'a, 'tcx>(
196194
fn program_clauses_for_trait<'a, 'tcx>(
197195
tcx: TyCtxt<'a, 'tcx, 'tcx>,
198196
def_id: DefId,
199-
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
197+
) -> Clauses<'tcx> {
200198
// `trait Trait<P1..Pn> where WC { .. } // P0 == Self`
201199

202200
// Rule Implemented-From-Env (see rustc guide)
@@ -243,7 +241,7 @@ fn program_clauses_for_trait<'a, 'tcx>(
243241
.into_iter()
244242
.map(|wc| implied_bound_from_trait(tcx, trait_pred, wc));
245243

246-
Lrc::new(tcx.mk_clauses(clauses.chain(implied_bound_clauses)))
244+
tcx.mk_clauses(clauses.chain(implied_bound_clauses))
247245
}
248246

249247
/// 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>(
262260
}))
263261
}
264262

265-
fn program_clauses_for_impl<'a, 'tcx>(
266-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
267-
def_id: DefId,
268-
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
263+
fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
269264
if let ImplPolarity::Negative = tcx.impl_polarity(def_id) {
270-
return Lrc::new(tcx.mk_clauses(iter::empty::<Clause>()));
265+
return Slice::empty();
271266
}
272267

273268
// Rule Implemented-From-Impl (see rustc guide)
@@ -295,13 +290,13 @@ fn program_clauses_for_impl<'a, 'tcx>(
295290
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
296291
),
297292
};
298-
Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
293+
tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause))))
299294
}
300295

301296
pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
302297
tcx: TyCtxt<'a, 'tcx, 'tcx>,
303298
item_id: DefId,
304-
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
299+
) -> Clauses<'tcx> {
305300
// Rule Normalize-From-Impl (see rustc guide)
306301
//
307302
// ```impl<P0..Pn> Trait<A1..An> for A0
@@ -349,7 +344,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
349344
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
350345
),
351346
};
352-
Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
347+
tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause))))
353348
}
354349

355350
pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

0 commit comments

Comments
 (0)