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

src/librustc_trans/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn get_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
289289
// try and trans it, in that case. Issue #23435.
290290
if mth.is_provided {
291291
let predicates = mth.method.predicates.predicates.subst(tcx, &mth.substs);
292-
if !normalize_and_test_predicates(tcx, predicates.into_vec()) {
292+
if !normalize_and_test_predicates(tcx, predicates) {
293293
debug!("get_vtable_methods: predicates do not hold");
294294
return None;
295295
}

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use hir::print as pprust;
5656
use middle::resolve_lifetime as rl;
5757
use rustc::lint;
5858
use rustc::ty::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs, ParamSpace};
59-
use rustc::ty::subst::VecPerParamSpace;
6059
use rustc::traits;
6160
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
6261
use rustc::ty::wf::object_region_bounds;
@@ -1778,7 +1777,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
17781777
let predicates = bounds.predicates(tcx, ty);
17791778
let predicates = tcx.lift_to_global(&predicates).unwrap();
17801779
tcx.predicates.borrow_mut().insert(def_id, ty::GenericPredicates {
1781-
predicates: VecPerParamSpace::new(vec![], vec![], predicates)
1780+
predicates: predicates
17821781
});
17831782

17841783
ty

src/librustc_typeck/check/compare_method.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc::infer::{self, InferOk, TypeOrigin};
1313
use rustc::ty;
1414
use rustc::traits::{self, Reveal};
1515
use rustc::ty::error::ExpectedFound;
16-
use rustc::ty::subst::{self, Subst, Substs, VecPerParamSpace};
16+
use rustc::ty::subst::{self, Subst, Substs};
1717
use rustc::hir::map::Node;
1818
use rustc::hir::{ImplItemKind, TraitItem_};
1919

@@ -213,6 +213,15 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
213213
return;
214214
}
215215

216+
// Depend on trait/impl predicates always being before method's own predicates,
217+
// to be able to split method predicates into "inherited" and method-specific.
218+
let trait_predicates = tcx.lookup_predicates(trait_m.container_id()).predicates;
219+
let impl_predicates = tcx.lookup_predicates(impl_m.container_id()).predicates;
220+
let trait_method_start = trait_predicates.len();
221+
let impl_method_start = impl_predicates.len();
222+
assert_eq!(&trait_predicates[..], &trait_m.predicates.predicates[..trait_method_start]);
223+
assert_eq!(&impl_predicates[..], &impl_m.predicates.predicates[..impl_method_start]);
224+
216225
tcx.infer_ctxt(None, None, Reveal::NotSpecializable).enter(|mut infcx| {
217226
let mut fulfillment_cx = traits::FulfillmentContext::new();
218227

@@ -224,40 +233,32 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
224233
// environment. We can't just use `impl_env.caller_bounds`,
225234
// however, because we want to replace all late-bound regions with
226235
// region variables.
227-
let impl_bounds =
228-
impl_m.predicates.instantiate(tcx, impl_to_skol_substs);
236+
let impl_bounds = impl_m.predicates.instantiate(tcx, impl_to_skol_substs);
229237

230238
debug!("compare_impl_method: impl_bounds={:?}", impl_bounds);
231239

232-
// Obtain the predicate split predicate sets for each.
233-
let trait_pred = trait_bounds.predicates.split();
234-
let impl_pred = impl_bounds.predicates.split();
235-
236240
// This is the only tricky bit of the new way we check implementation methods
237241
// We need to build a set of predicates where only the FnSpace bounds
238242
// are from the trait and we assume all other bounds from the implementation
239243
// to be previously satisfied.
240244
//
241245
// We then register the obligations from the impl_m and check to see
242246
// if all constraints hold.
243-
let hybrid_preds = VecPerParamSpace::new(
244-
impl_pred.types,
245-
impl_pred.selfs,
246-
trait_pred.fns
247-
);
247+
let hybrid_preds = impl_bounds.predicates[..impl_method_start].iter()
248+
.chain(trait_bounds.predicates[trait_method_start..].iter());
248249

249250
// Construct trait parameter environment and then shift it into the skolemized viewpoint.
250251
// The key step here is to update the caller_bounds's predicates to be
251252
// the new hybrid bounds we computed.
252253
let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_body_id);
253-
let trait_param_env = impl_param_env.with_caller_bounds(hybrid_preds.into_vec());
254+
let trait_param_env = impl_param_env.with_caller_bounds(hybrid_preds.cloned().collect());
254255
let trait_param_env = traits::normalize_param_env_or_error(tcx,
255256
trait_param_env,
256257
normalize_cause.clone());
257258
// FIXME(@jroesch) this seems ugly, but is a temporary change
258259
infcx.parameter_environment = trait_param_env;
259260

260-
debug!("compare_impl_method: trait_bounds={:?}",
261+
debug!("compare_impl_method: caller_bounds={:?}",
261262
infcx.parameter_environment.caller_bounds);
262263

263264
let mut selcx = traits::SelectionContext::new(&infcx);
@@ -266,7 +267,7 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
266267
infcx.replace_late_bound_regions_with_fresh_var(
267268
impl_m_span,
268269
infer::HigherRankedType,
269-
&ty::Binder(impl_pred.fns));
270+
&ty::Binder(impl_bounds.predicates[impl_method_start..].to_vec()));
270271
for predicate in impl_pred_fns {
271272
let traits::Normalized { value: predicate, .. } =
272273
traits::normalize(&mut selcx, normalize_cause.clone(), &predicate);

src/librustc_typeck/check/dropck.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,15 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
179179
let generic_assumptions = tcx.lookup_predicates(self_type_did);
180180

181181
let assumptions_in_impl_context = generic_assumptions.instantiate(tcx, &self_to_impl_substs);
182-
assert!(assumptions_in_impl_context.predicates.is_empty_in(subst::SelfSpace));
183-
assert!(assumptions_in_impl_context.predicates.is_empty_in(subst::FnSpace));
184-
let assumptions_in_impl_context =
185-
assumptions_in_impl_context.predicates.get_slice(subst::TypeSpace);
182+
let assumptions_in_impl_context = assumptions_in_impl_context.predicates;
186183

187184
// An earlier version of this code attempted to do this checking
188185
// via the traits::fulfill machinery. However, it ran into trouble
189186
// since the fulfill machinery merely turns outlives-predicates
190187
// 'a:'b and T:'b into region inference constraints. It is simpler
191188
// just to look for all the predicates directly.
192189

193-
assert!(dtor_predicates.predicates.is_empty_in(subst::SelfSpace));
194-
assert!(dtor_predicates.predicates.is_empty_in(subst::FnSpace));
195-
let predicates = dtor_predicates.predicates.get_slice(subst::TypeSpace);
196-
for predicate in predicates {
190+
for predicate in &dtor_predicates.predicates {
197191
// (We do not need to worry about deep analysis of type
198192
// expressions etc because the Drop impls are already forced
199193
// to take on a structure that is roughly an alpha-renaming of

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799799

800800
let trait_predicates = self.tcx.lookup_predicates(def_id);
801801
let bounds = trait_predicates.instantiate(self.tcx, substs);
802-
let predicates = bounds.predicates.into_vec();
802+
let predicates = bounds.predicates;
803803
debug!("assemble_projection_candidates: predicates={:?}",
804804
predicates);
805805
for poly_bound in

0 commit comments

Comments
 (0)