Skip to content

Commit e314636

Browse files
committed
rustc: use Vec instead of VecPerParamSpace for ty::GenericPredicates.
1 parent 1bf5fa3 commit e314636

File tree

19 files changed

+109
-148
lines changed

19 files changed

+109
-148
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
184184
// Search for a predicate like `Self : Sized` amongst the trait bounds.
185185
let free_substs = self.construct_free_substs(generics,
186186
self.region_maps.node_extent(ast::DUMMY_NODE_ID));
187-
let predicates = predicates.instantiate(self, &free_substs).predicates.into_vec();
187+
let predicates = predicates.instantiate(self, &free_substs).predicates;
188188
elaborate_predicates(self, predicates)
189189
.any(|predicate| {
190190
match predicate {

src/librustc/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
811811
// If so, extract what we know from the trait and try to come up with a good answer.
812812
let trait_predicates = selcx.tcx().lookup_predicates(def_id);
813813
let bounds = trait_predicates.instantiate(selcx.tcx(), substs);
814-
let bounds = elaborate_predicates(selcx.tcx(), bounds.predicates.into_vec());
814+
let bounds = elaborate_predicates(selcx.tcx(), bounds.predicates);
815815
assemble_candidates_from_predicates(selcx,
816816
obligation,
817817
obligation_trait_ref,

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12141214
bounds);
12151215

12161216
let matching_bound =
1217-
util::elaborate_predicates(self.tcx(), bounds.predicates.into_vec())
1217+
util::elaborate_predicates(self.tcx(), bounds.predicates)
12181218
.filter_to_traits()
12191219
.find(
12201220
|bound| self.probe(

src/librustc/ty/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'a, 'gcx, 'tcx> ImplHeader<'tcx> {
178178
impl_def_id: impl_def_id,
179179
self_ty: tcx.lookup_item_type(impl_def_id).ty,
180180
trait_ref: tcx.impl_trait_ref(impl_def_id),
181-
predicates: tcx.lookup_predicates(impl_def_id).predicates.into_vec(),
181+
predicates: tcx.lookup_predicates(impl_def_id).predicates
182182
}.subst(tcx, &impl_substs);
183183

184184
let traits::Normalized { value: mut header, obligations } =
@@ -775,13 +775,13 @@ impl<'tcx> Generics<'tcx> {
775775
/// Bounds on generics.
776776
#[derive(Clone)]
777777
pub struct GenericPredicates<'tcx> {
778-
pub predicates: VecPerParamSpace<Predicate<'tcx>>,
778+
pub predicates: Vec<Predicate<'tcx>>,
779779
}
780780

781781
impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
782782
pub fn empty() -> GenericPredicates<'tcx> {
783783
GenericPredicates {
784-
predicates: VecPerParamSpace::empty(),
784+
predicates: vec![]
785785
}
786786
}
787787

@@ -797,9 +797,9 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
797797
-> InstantiatedPredicates<'tcx>
798798
{
799799
InstantiatedPredicates {
800-
predicates: self.predicates.map(|pred| {
800+
predicates: self.predicates.iter().map(|pred| {
801801
pred.subst_supertrait(tcx, poly_trait_ref)
802-
})
802+
}).collect()
803803
}
804804
}
805805
}
@@ -1193,12 +1193,12 @@ impl<'tcx> Predicate<'tcx> {
11931193
/// [usize:Bar<isize>]]`.
11941194
#[derive(Clone)]
11951195
pub struct InstantiatedPredicates<'tcx> {
1196-
pub predicates: VecPerParamSpace<Predicate<'tcx>>,
1196+
pub predicates: Vec<Predicate<'tcx>>,
11971197
}
11981198

11991199
impl<'tcx> InstantiatedPredicates<'tcx> {
12001200
pub fn empty() -> InstantiatedPredicates<'tcx> {
1201-
InstantiatedPredicates { predicates: VecPerParamSpace::empty() }
1201+
InstantiatedPredicates { predicates: vec![] }
12021202
}
12031203

12041204
pub fn is_empty(&self) -> bool {
@@ -2909,7 +2909,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29092909
let tcx = self.global_tcx();
29102910
let bounds = generic_predicates.instantiate(tcx, &free_substs);
29112911
let bounds = tcx.liberate_late_bound_regions(free_id_outlive, &ty::Binder(bounds));
2912-
let predicates = bounds.predicates.into_vec();
2912+
let predicates = bounds.predicates;
29132913

29142914
// Finally, we have to normalize the bounds in the environment, in
29152915
// case they contain any associated type projections. This process

src/librustc/ty/subst.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,6 @@ pub struct VecPerParamSpace<T> {
217217
content: Vec<T>,
218218
}
219219

220-
/// The `split` function converts one `VecPerParamSpace` into this
221-
/// `SeparateVecsPerParamSpace` structure.
222-
pub struct SeparateVecsPerParamSpace<T> {
223-
pub types: Vec<T>,
224-
pub selfs: Vec<T>,
225-
pub fns: Vec<T>,
226-
}
227-
228220
impl<T: fmt::Debug> fmt::Debug for VecPerParamSpace<T> {
229221
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
230222
write!(f, "[{:?};{:?};{:?}]",
@@ -428,18 +420,6 @@ impl<T> VecPerParamSpace<T> {
428420
self.self_limit)
429421
}
430422

431-
pub fn split(self) -> SeparateVecsPerParamSpace<T> {
432-
let VecPerParamSpace { type_limit, self_limit, content } = self;
433-
434-
let mut content_iter = content.into_iter();
435-
436-
SeparateVecsPerParamSpace {
437-
types: content_iter.by_ref().take(type_limit).collect(),
438-
selfs: content_iter.by_ref().take(self_limit - type_limit).collect(),
439-
fns: content_iter.collect()
440-
}
441-
}
442-
443423
pub fn with_slice(mut self, space: ParamSpace, slice: &[T])
444424
-> VecPerParamSpace<T>
445425
where T: Clone

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
917917
let mut first = true;
918918
let mut is_sized = false;
919919
write!(f, "impl")?;
920-
for predicate in bounds.predicates.into_vec() {
920+
for predicate in bounds.predicates {
921921
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
922922
// Don't print +Sized, but rather +?Sized if absent.
923923
if Some(trait_ref.def_id()) == tcx.lang_items.sized_trait() {

src/librustc_metadata/common.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ pub const tag_type_param_def: usize = 0x94;
207207
pub const tag_item_generics: usize = 0x95;
208208
pub const tag_method_ty_generics: usize = 0x96;
209209

210-
pub const tag_type_predicate: usize = 0x97;
211-
pub const tag_self_predicate: usize = 0x98;
212-
pub const tag_fn_predicate: usize = 0x99;
210+
pub const tag_predicate: usize = 0x97;
211+
// GAP 0x98, 0x99
213212

214213
pub const tag_unsafety: usize = 0x9a;
215214

src/librustc_metadata/decoder.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,21 +1622,11 @@ fn doc_predicates<'a, 'tcx>(base_doc: rbml::Doc,
16221622
{
16231623
let doc = reader::get_doc(base_doc, tag);
16241624

1625-
let mut predicates = subst::VecPerParamSpace::empty();
1626-
for predicate_doc in reader::tagged_docs(doc, tag_type_predicate) {
1627-
predicates.push(subst::TypeSpace,
1628-
doc_predicate(cdata, predicate_doc, tcx));
1629-
}
1630-
for predicate_doc in reader::tagged_docs(doc, tag_self_predicate) {
1631-
predicates.push(subst::SelfSpace,
1632-
doc_predicate(cdata, predicate_doc, tcx));
1633-
}
1634-
for predicate_doc in reader::tagged_docs(doc, tag_fn_predicate) {
1635-
predicates.push(subst::FnSpace,
1636-
doc_predicate(cdata, predicate_doc, tcx));
1625+
ty::GenericPredicates {
1626+
predicates: reader::tagged_docs(doc, tag_predicate).map(|predicate_doc| {
1627+
doc_predicate(cdata, predicate_doc, tcx)
1628+
}).collect()
16371629
}
1638-
1639-
ty::GenericPredicates { predicates: predicates }
16401630
}
16411631

16421632
pub fn is_defaulted_trait(cdata: Cmd, trait_id: DefIndex) -> bool {

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc::hir::def;
2626
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
2727
use middle::dependency_format::Linkage;
2828
use rustc::dep_graph::{DepGraph, DepNode, DepTask};
29-
use rustc::ty::subst;
3029
use rustc::traits::specialization_graph;
3130
use rustc::ty::{self, Ty, TyCtxt};
3231
use rustc::ty::util::IntTypeExt;
@@ -541,14 +540,8 @@ fn encode_predicates_in_current_doc<'a,'tcx>(rbml_w: &mut Encoder,
541540
index: &mut CrateIndex<'a, 'tcx>,
542541
predicates: &ty::GenericPredicates<'tcx>)
543542
{
544-
for (space, _, predicate) in predicates.predicates.iter_enumerated() {
545-
let tag = match space {
546-
subst::TypeSpace => tag_type_predicate,
547-
subst::SelfSpace => tag_self_predicate,
548-
subst::FnSpace => tag_fn_predicate
549-
};
550-
551-
rbml_w.wr_tagged_u32(tag,
543+
for predicate in &predicates.predicates {
544+
rbml_w.wr_tagged_u32(tag_predicate,
552545
index.add_xref(XRef::Predicate(predicate.clone())));
553546
}
554547
}

src/librustc_trans/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12571257
assert!(mth.is_provided);
12581258

12591259
let predicates = mth.method.predicates.predicates.subst(tcx, &mth.substs);
1260-
if !normalize_and_test_predicates(tcx, predicates.into_vec()) {
1260+
if !normalize_and_test_predicates(tcx, predicates) {
12611261
continue;
12621262
}
12631263

0 commit comments

Comments
 (0)