Skip to content

Commit e0ca6b1

Browse files
committed
Auto merge of #25975 - arielb1:remove-param-space, r=nikomatsakis
r? @nikomatsakis
2 parents 20cf4cf + 4b116fe commit e0ca6b1

File tree

10 files changed

+62
-154
lines changed

10 files changed

+62
-154
lines changed

src/librustc/middle/subst.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,6 @@ impl<T> VecPerParamSpace<T> {
448448
self.self_limit)
449449
}
450450

451-
pub fn map_move<U, F>(self, mut pred: F) -> VecPerParamSpace<U> where
452-
F: FnMut(T) -> U,
453-
{
454-
let SeparateVecsPerParamSpace {
455-
types: t,
456-
selfs: s,
457-
fns: f
458-
} = self.split();
459-
460-
VecPerParamSpace::new(t.into_iter().map(|p| pred(p)).collect(),
461-
s.into_iter().map(|p| pred(p)).collect(),
462-
f.into_iter().map(|p| pred(p)).collect())
463-
}
464-
465451
pub fn split(self) -> SeparateVecsPerParamSpace<T> {
466452
let VecPerParamSpace { type_limit, self_limit, content } = self;
467453

src/librustc/middle/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
329329
false
330330
}
331331
Ok(Some(s)) => {
332-
s.map_move_nested(|p| new_obligations.push(p));
332+
new_obligations.append(&mut s.nested_obligations());
333333
true
334334
}
335335
Err(selection_err) => {

src/librustc/middle/traits/mod.rs

Lines changed: 29 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::subst;
2020
use middle::ty::{self, HasProjectionTypes, Ty};
2121
use middle::ty_fold::TypeFoldable;
2222
use middle::infer::{self, fixup_err_to_string, InferCtxt};
23-
use std::slice::Iter;
2423
use std::rc::Rc;
2524
use syntax::ast;
2625
use syntax::codemap::{Span, DUMMY_SP};
@@ -146,9 +145,9 @@ pub struct DerivedObligationCause<'tcx> {
146145
parent_code: Rc<ObligationCauseCode<'tcx>>
147146
}
148147

149-
pub type Obligations<'tcx, O> = subst::VecPerParamSpace<Obligation<'tcx, O>>;
150-
pub type PredicateObligations<'tcx> = subst::VecPerParamSpace<PredicateObligation<'tcx>>;
151-
pub type TraitObligations<'tcx> = subst::VecPerParamSpace<TraitObligation<'tcx>>;
148+
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
149+
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
150+
pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
152151

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

@@ -266,7 +265,7 @@ pub enum Vtable<'tcx, N> {
266265
pub struct VtableImplData<'tcx, N> {
267266
pub impl_def_id: ast::DefId,
268267
pub substs: subst::Substs<'tcx>,
269-
pub nested: subst::VecPerParamSpace<N>
268+
pub nested: Vec<N>
270269
}
271270

272271
#[derive(Debug,Clone)]
@@ -277,7 +276,7 @@ pub struct VtableDefaultImplData<N> {
277276

278277
#[derive(Debug,Clone)]
279278
pub struct VtableBuiltinData<N> {
280-
pub nested: subst::VecPerParamSpace<N>
279+
pub nested: Vec<N>
281280
}
282281

283282
/// A vtable for some object-safe trait `Foo` automatically derived
@@ -525,114 +524,35 @@ impl<'tcx> ObligationCause<'tcx> {
525524
}
526525

527526
impl<'tcx, N> Vtable<'tcx, N> {
528-
pub fn iter_nested(&self) -> Iter<N> {
529-
match *self {
530-
VtableImpl(ref i) => i.iter_nested(),
531-
VtableParam(ref n) => n.iter(),
532-
VtableBuiltin(ref i) => i.iter_nested(),
533-
VtableObject(_) |
534-
VtableDefaultImpl(..) | VtableFnPointer(..) |
535-
VtableClosure(..) => (&[]).iter(),
536-
}
537-
}
538-
539-
pub fn map_nested<M, F>(&self, op: F) -> Vtable<'tcx, M> where
540-
F: FnMut(&N) -> M,
541-
{
542-
match *self {
543-
VtableImpl(ref i) => VtableImpl(i.map_nested(op)),
544-
VtableDefaultImpl(ref t) => VtableDefaultImpl(t.map_nested(op)),
545-
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()),
546-
VtableClosure(d, ref s) => VtableClosure(d, s.clone()),
547-
VtableParam(ref n) => VtableParam(n.iter().map(op).collect()),
548-
VtableObject(ref p) => VtableObject(p.clone()),
549-
VtableBuiltin(ref b) => VtableBuiltin(b.map_nested(op)),
527+
pub fn nested_obligations(self) -> Vec<N> {
528+
match self {
529+
VtableImpl(i) => i.nested,
530+
VtableParam(n) => n,
531+
VtableBuiltin(i) => i.nested,
532+
VtableDefaultImpl(d) => d.nested,
533+
VtableObject(_) | VtableFnPointer(..) |
534+
VtableClosure(..) => vec![]
550535
}
551536
}
552537

553-
pub fn map_move_nested<M, F>(self, op: F) -> Vtable<'tcx, M> where
554-
F: FnMut(N) -> M,
555-
{
538+
pub fn map<M, F>(self, f: F) -> Vtable<'tcx, M> where F: FnMut(N) -> M {
556539
match self {
557-
VtableImpl(i) => VtableImpl(i.map_move_nested(op)),
558-
VtableFnPointer(sig) => VtableFnPointer(sig),
540+
VtableImpl(i) => VtableImpl(VtableImplData {
541+
impl_def_id: i.impl_def_id,
542+
substs: i.substs,
543+
nested: i.nested.into_iter().map(f).collect()
544+
}),
545+
VtableParam(n) => VtableParam(n.into_iter().map(f).collect()),
546+
VtableBuiltin(i) => VtableBuiltin(VtableBuiltinData {
547+
nested: i.nested.into_iter().map(f).collect()
548+
}),
549+
VtableObject(o) => VtableObject(o),
550+
VtableDefaultImpl(d) => VtableDefaultImpl(VtableDefaultImplData {
551+
trait_def_id: d.trait_def_id,
552+
nested: d.nested.into_iter().map(f).collect()
553+
}),
554+
VtableFnPointer(f) => VtableFnPointer(f),
559555
VtableClosure(d, s) => VtableClosure(d, s),
560-
VtableDefaultImpl(t) => VtableDefaultImpl(t.map_move_nested(op)),
561-
VtableParam(n) => VtableParam(n.into_iter().map(op).collect()),
562-
VtableObject(p) => VtableObject(p),
563-
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)),
564-
}
565-
}
566-
}
567-
568-
impl<'tcx, N> VtableImplData<'tcx, N> {
569-
pub fn iter_nested(&self) -> Iter<N> {
570-
self.nested.iter()
571-
}
572-
573-
pub fn map_nested<M, F>(&self, op: F) -> VtableImplData<'tcx, M> where
574-
F: FnMut(&N) -> M,
575-
{
576-
VtableImplData {
577-
impl_def_id: self.impl_def_id,
578-
substs: self.substs.clone(),
579-
nested: self.nested.map(op)
580-
}
581-
}
582-
583-
pub fn map_move_nested<M, F>(self, op: F) -> VtableImplData<'tcx, M> where
584-
F: FnMut(N) -> M,
585-
{
586-
let VtableImplData { impl_def_id, substs, nested } = self;
587-
VtableImplData {
588-
impl_def_id: impl_def_id,
589-
substs: substs,
590-
nested: nested.map_move(op)
591-
}
592-
}
593-
}
594-
595-
impl<N> VtableDefaultImplData<N> {
596-
pub fn iter_nested(&self) -> Iter<N> {
597-
self.nested.iter()
598-
}
599-
600-
pub fn map_nested<M, F>(&self, op: F) -> VtableDefaultImplData<M> where
601-
F: FnMut(&N) -> M,
602-
{
603-
VtableDefaultImplData {
604-
trait_def_id: self.trait_def_id,
605-
nested: self.nested.iter().map(op).collect()
606-
}
607-
}
608-
609-
pub fn map_move_nested<M, F>(self, op: F) -> VtableDefaultImplData<M> where
610-
F: FnMut(N) -> M,
611-
{
612-
let VtableDefaultImplData { trait_def_id, nested } = self;
613-
VtableDefaultImplData {
614-
trait_def_id: trait_def_id,
615-
nested: nested.into_iter().map(op).collect()
616-
}
617-
}
618-
}
619-
620-
impl<N> VtableBuiltinData<N> {
621-
pub fn iter_nested(&self) -> Iter<N> {
622-
self.nested.iter()
623-
}
624-
625-
pub fn map_nested<M, F>(&self, op: F) -> VtableBuiltinData<M> where F: FnMut(&N) -> M {
626-
VtableBuiltinData {
627-
nested: self.nested.map(op)
628-
}
629-
}
630-
631-
pub fn map_move_nested<M, F>(self, op: F) -> VtableBuiltinData<M> where
632-
F: FnMut(N) -> M,
633-
{
634-
VtableBuiltinData {
635-
nested: self.nested.map_move(op)
636556
}
637557
}
638558
}

src/librustc/middle/traits/project.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tc
203203
{
204204
let mut normalizer = AssociatedTypeNormalizer::new(selcx, cause, depth);
205205
let result = normalizer.fold(value);
206+
206207
Normalized {
207208
value: result,
208209
obligations: normalizer.obligations,
@@ -864,7 +865,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
864865
if let ty::TypeTraitItem(ref assoc_ty) = impl_or_trait_items_map[&impl_item.def_id()] {
865866
if assoc_ty.name == obligation.predicate.item_name {
866867
return (assoc_ty.ty.unwrap().subst(selcx.tcx(), &impl_vtable.substs),
867-
impl_vtable.nested.into_vec());
868+
impl_vtable.nested);
868869
}
869870
}
870871
}
@@ -876,7 +877,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
876877
if assoc_ty.name == obligation.predicate.item_name {
877878
if let Some(ty) = assoc_ty.ty {
878879
return (ty.subst(selcx.tcx(), trait_ref.substs),
879-
impl_vtable.nested.into_vec());
880+
impl_vtable.nested);
880881
} else {
881882
// This means that the impl is missing a
882883
// definition for the associated type. This error

src/librustc/middle/traits/select.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use super::object_safety;
3636
use super::util;
3737

3838
use middle::fast_reject;
39-
use middle::subst::{Subst, Substs, TypeSpace, VecPerParamSpace};
39+
use middle::subst::{Subst, Substs, TypeSpace};
4040
use middle::ty::{self, AsPredicate, RegionEscape, ToPolyTraitRef, Ty};
4141
use middle::infer;
4242
use middle::infer::{InferCtxt, TypeFreshener};
@@ -1134,7 +1134,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11341134
// type/region parameters
11351135
let self_ty = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
11361136
let (closure_def_id, substs) = match self_ty.sty {
1137-
ty::ty_closure(id, ref substs) => (id, substs.clone()),
1137+
ty::ty_closure(id, substs) => (id, substs),
11381138
ty::ty_infer(ty::TyVar(_)) => {
11391139
debug!("assemble_unboxed_closure_candidates: ambiguous self-type");
11401140
candidates.ambiguous = true;
@@ -1152,7 +1152,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11521152
Some(closure_kind) => {
11531153
debug!("assemble_unboxed_candidates: closure_kind = {:?}", closure_kind);
11541154
if closure_kind.extends(kind) {
1155-
candidates.vec.push(ClosureCandidate(closure_def_id, substs.clone()));
1155+
candidates.vec.push(ClosureCandidate(closure_def_id,
1156+
substs.clone()));
11561157
}
11571158
}
11581159
None => {
@@ -1479,7 +1480,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14791480
selection: Selection<'tcx>)
14801481
-> EvaluationResult<'tcx>
14811482
{
1482-
self.evaluate_predicates_recursively(stack, selection.iter_nested())
1483+
self.evaluate_predicates_recursively(stack,
1484+
selection.nested_obligations().iter())
14831485
}
14841486

14851487
/// Returns true if `candidate_i` should be dropped in favor of
@@ -1987,7 +1989,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19871989

19881990
PhantomFnCandidate |
19891991
ErrorCandidate => {
1990-
Ok(VtableBuiltin(VtableBuiltinData { nested: VecPerParamSpace::empty() }))
1992+
Ok(VtableBuiltin(VtableBuiltinData { nested: vec![] }))
19911993
}
19921994

19931995
ParamCandidate(param) => {
@@ -2120,8 +2122,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21202122

21212123
let obligations = self.collect_predicates_for_types(obligation, trait_def, nested);
21222124

2123-
let obligations = VecPerParamSpace::new(obligations, Vec::new(), Vec::new());
2124-
21252125
debug!("vtable_builtin_data: obligations={}",
21262126
obligations.repr(self.tcx()));
21272127

@@ -2207,7 +2207,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22072207
trait_def_id,
22082208
nested);
22092209

2210-
let trait_obligations: Result<VecPerParamSpace<_>,()> = self.infcx.commit_if_ok(|snapshot| {
2210+
let trait_obligations: Result<Vec<_>,()> = self.infcx.commit_if_ok(|snapshot| {
22112211
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
22122212
let (trait_ref, skol_map) =
22132213
self.infcx().skolemize_late_bound_regions(&poly_trait_ref, snapshot);
@@ -2219,7 +2219,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22192219
snapshot))
22202220
});
22212221

2222-
obligations.extend(trait_obligations.unwrap().into_iter()); // no Errors in that code above
2222+
// no Errors in that code above
2223+
obligations.append(&mut trait_obligations.unwrap());
22232224

22242225
debug!("vtable_default_impl_data: obligations={}", obligations.repr(self.tcx()));
22252226

@@ -2253,7 +2254,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22532254

22542255
fn vtable_impl(&mut self,
22552256
impl_def_id: ast::DefId,
2256-
substs: Normalized<'tcx, Substs<'tcx>>,
2257+
mut substs: Normalized<'tcx, Substs<'tcx>>,
22572258
cause: ObligationCause<'tcx>,
22582259
recursion_depth: usize,
22592260
skol_map: infer::SkolemizationMap,
@@ -2278,7 +2279,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22782279
impl_def_id.repr(self.tcx()),
22792280
impl_obligations.repr(self.tcx()));
22802281

2281-
impl_obligations.extend(TypeSpace, substs.obligations.into_iter());
2282+
impl_obligations.append(&mut substs.obligations);
22822283

22832284
VtableImplData { impl_def_id: impl_def_id,
22842285
substs: substs.value,
@@ -2568,9 +2569,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25682569
_ => unreachable!()
25692570
};
25702571

2571-
Ok(VtableBuiltinData {
2572-
nested: VecPerParamSpace::new(nested, vec![], vec![])
2573-
})
2572+
Ok(VtableBuiltinData { nested: nested })
25742573
}
25752574

25762575
///////////////////////////////////////////////////////////////////////////
@@ -2851,20 +2850,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28512850
substs: &Substs<'tcx>, // for impl or trait
28522851
skol_map: infer::SkolemizationMap,
28532852
snapshot: &infer::CombinedSnapshot)
2854-
-> VecPerParamSpace<PredicateObligation<'tcx>>
2853+
-> Vec<PredicateObligation<'tcx>>
28552854
{
28562855
debug!("impl_or_trait_obligations(def_id={})", def_id.repr(self.tcx()));
28572856

28582857
let predicates = ty::lookup_predicates(self.tcx(), def_id);
28592858
let predicates = predicates.instantiate(self.tcx(), substs);
28602859
let predicates = normalize_with_depth(self, cause.clone(), recursion_depth, &predicates);
2861-
let predicates = self.infcx().plug_leaks(skol_map, snapshot, &predicates);
2860+
let mut predicates = self.infcx().plug_leaks(skol_map, snapshot, &predicates);
28622861
let mut obligations =
28632862
util::predicates_for_generics(self.tcx(),
28642863
cause,
28652864
recursion_depth,
28662865
&predicates.value);
2867-
obligations.extend(TypeSpace, predicates.obligations.into_iter());
2866+
obligations.append(&mut predicates.obligations);
28682867
obligations
28692868
}
28702869

src/librustc/middle/traits/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use middle::subst::{Substs, VecPerParamSpace};
11+
use middle::subst::Substs;
1212
use middle::infer::InferCtxt;
1313
use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef};
1414
use std::fmt;
@@ -319,16 +319,16 @@ pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
319319
cause: ObligationCause<'tcx>,
320320
recursion_depth: usize,
321321
generic_bounds: &ty::InstantiatedPredicates<'tcx>)
322-
-> VecPerParamSpace<PredicateObligation<'tcx>>
322+
-> Vec<PredicateObligation<'tcx>>
323323
{
324324
debug!("predicates_for_generics(generic_bounds={})",
325325
generic_bounds.repr(tcx));
326326

327-
generic_bounds.predicates.map(|predicate| {
327+
generic_bounds.predicates.iter().map(|predicate| {
328328
Obligation { cause: cause.clone(),
329329
recursion_depth: recursion_depth,
330330
predicate: predicate.clone() }
331-
})
331+
}).collect()
332332
}
333333

334334
pub fn trait_ref_for_builtin_bound<'tcx>(

src/librustc_trans/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10511051
// all nested obligations. This is because they can inform the
10521052
// inference of the impl's type parameters.
10531053
let mut fulfill_cx = traits::FulfillmentContext::new();
1054-
let vtable = selection.map_move_nested(|predicate| {
1054+
let vtable = selection.map(|predicate| {
10551055
fulfill_cx.register_predicate_obligation(&infcx, predicate);
10561056
});
10571057
let vtable = drain_fulfillment_cx_or_panic(span, &infcx, &mut fulfill_cx, &vtable);

0 commit comments

Comments
 (0)