Skip to content

Commit de8e0ae

Browse files
committed
Remove the AssocSpace
1 parent 42e645c commit de8e0ae

File tree

14 files changed

+41
-96
lines changed

14 files changed

+41
-96
lines changed

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,8 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
707707
{
708708
let types = self.read_to_vec(|this| Ok(f(this))).unwrap();
709709
let selfs = self.read_to_vec(|this| Ok(f(this))).unwrap();
710-
let assocs = self.read_to_vec(|this| Ok(f(this))).unwrap();
711710
let fns = self.read_to_vec(|this| Ok(f(this))).unwrap();
712-
VecPerParamSpace::new(types, selfs, assocs, fns)
711+
VecPerParamSpace::new(types, selfs, fns)
713712
}
714713

715714
fn read_vtable_res_with_key(&mut self,

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
864864
let region_param_defs = generics.regions.get_slice(subst::TypeSpace);
865865
let regions = self.region_vars_for_defs(span, region_param_defs);
866866

867-
let assoc_type_parameter_count = generics.types.len(subst::AssocSpace);
868-
let assoc_type_parameters = self.next_ty_vars(assoc_type_parameter_count);
869-
870-
subst::Substs::new_trait(type_parameters, regions, assoc_type_parameters, self_ty)
867+
subst::Substs::new_trait(type_parameters, regions, self_ty)
871868
}
872869

873870
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region {

src/librustc/middle/subst.rs

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,17 @@ impl<'tcx> Substs<'tcx> {
5555
r: Vec<ty::Region>)
5656
-> Substs<'tcx>
5757
{
58-
Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new(), Vec::new()),
59-
VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new()))
58+
Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new()),
59+
VecPerParamSpace::new(r, Vec::new(), Vec::new()))
6060
}
6161

6262
pub fn new_trait(t: Vec<Ty<'tcx>>,
6363
r: Vec<ty::Region>,
64-
a: Vec<Ty<'tcx>>,
6564
s: Ty<'tcx>)
6665
-> Substs<'tcx>
6766
{
68-
Substs::new(VecPerParamSpace::new(t, vec!(s), a, Vec::new()),
69-
VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new()))
67+
Substs::new(VecPerParamSpace::new(t, vec!(s), Vec::new()),
68+
VecPerParamSpace::new(r, Vec::new(), Vec::new()))
7069
}
7170

7271
pub fn erased(t: VecPerParamSpace<Ty<'tcx>>) -> Substs<'tcx>
@@ -123,13 +122,6 @@ impl<'tcx> Substs<'tcx> {
123122
s
124123
}
125124

126-
pub fn with_assoc_tys(&self, assoc_tys: Vec<Ty<'tcx>>) -> Substs<'tcx> {
127-
assert!(self.types.is_empty_in(AssocSpace));
128-
let mut s = (*self).clone();
129-
s.types.replace(AssocSpace, assoc_tys);
130-
s
131-
}
132-
133125
pub fn erase_regions(self) -> Substs<'tcx> {
134126
let Substs { types, regions: _ } = self;
135127
Substs { types: types, regions: ErasedRegions }
@@ -192,30 +184,27 @@ impl RegionSubsts {
192184
pub enum ParamSpace {
193185
TypeSpace, // Type parameters attached to a type definition, trait, or impl
194186
SelfSpace, // Self parameter on a trait
195-
AssocSpace, // Assoc types defined in a trait/impl
196187
FnSpace, // Type parameters attached to a method or fn
197188
}
198189

199190
impl ParamSpace {
200-
pub fn all() -> [ParamSpace, ..4] {
201-
[TypeSpace, SelfSpace, AssocSpace, FnSpace]
191+
pub fn all() -> [ParamSpace, ..3] {
192+
[TypeSpace, SelfSpace, FnSpace]
202193
}
203194

204195
pub fn to_uint(self) -> uint {
205196
match self {
206197
TypeSpace => 0,
207198
SelfSpace => 1,
208-
AssocSpace => 2,
209-
FnSpace => 3,
199+
FnSpace => 2,
210200
}
211201
}
212202

213203
pub fn from_uint(u: uint) -> ParamSpace {
214204
match u {
215205
0 => TypeSpace,
216206
1 => SelfSpace,
217-
2 => AssocSpace,
218-
3 => FnSpace,
207+
2 => FnSpace,
219208
_ => panic!("Invalid ParamSpace: {}", u)
220209
}
221210
}
@@ -235,11 +224,9 @@ pub struct VecPerParamSpace<T> {
235224
//
236225
// AF(self) = (self.content[..self.type_limit],
237226
// self.content[self.type_limit..self.self_limit],
238-
// self.content[self.self_limit..self.assoc_limit],
239-
// self.content[self.assoc_limit..])
227+
// self.content[self.self_limit..])
240228
type_limit: uint,
241229
self_limit: uint,
242-
assoc_limit: uint,
243230
content: Vec<T>,
244231
}
245232

@@ -248,7 +235,6 @@ pub struct VecPerParamSpace<T> {
248235
pub struct SeparateVecsPerParamSpace<T> {
249236
pub types: Vec<T>,
250237
pub selfs: Vec<T>,
251-
pub assocs: Vec<T>,
252238
pub fns: Vec<T>,
253239
}
254240

@@ -268,16 +254,14 @@ impl<T> VecPerParamSpace<T> {
268254
match space {
269255
TypeSpace => (0, self.type_limit),
270256
SelfSpace => (self.type_limit, self.self_limit),
271-
AssocSpace => (self.self_limit, self.assoc_limit),
272-
FnSpace => (self.assoc_limit, self.content.len()),
257+
FnSpace => (self.self_limit, self.content.len()),
273258
}
274259
}
275260

276261
pub fn empty() -> VecPerParamSpace<T> {
277262
VecPerParamSpace {
278263
type_limit: 0,
279264
self_limit: 0,
280-
assoc_limit: 0,
281265
content: Vec::new()
282266
}
283267
}
@@ -290,31 +274,27 @@ impl<T> VecPerParamSpace<T> {
290274
/// `s` is the self space.
291275
/// `a` is the assoc space.
292276
/// `f` is the fn space.
293-
pub fn new(t: Vec<T>, s: Vec<T>, a: Vec<T>, f: Vec<T>) -> VecPerParamSpace<T> {
277+
pub fn new(t: Vec<T>, s: Vec<T>, f: Vec<T>) -> VecPerParamSpace<T> {
294278
let type_limit = t.len();
295279
let self_limit = type_limit + s.len();
296-
let assoc_limit = self_limit + a.len();
297280

298281
let mut content = t;
299282
content.extend(s.into_iter());
300-
content.extend(a.into_iter());
301283
content.extend(f.into_iter());
302284

303285
VecPerParamSpace {
304286
type_limit: type_limit,
305287
self_limit: self_limit,
306-
assoc_limit: assoc_limit,
307288
content: content,
308289
}
309290
}
310291

311-
fn new_internal(content: Vec<T>, type_limit: uint, self_limit: uint, assoc_limit: uint)
292+
fn new_internal(content: Vec<T>, type_limit: uint, self_limit: uint)
312293
-> VecPerParamSpace<T>
313294
{
314295
VecPerParamSpace {
315296
type_limit: type_limit,
316297
self_limit: self_limit,
317-
assoc_limit: assoc_limit,
318298
content: content,
319299
}
320300
}
@@ -326,9 +306,8 @@ impl<T> VecPerParamSpace<T> {
326306
pub fn push(&mut self, space: ParamSpace, value: T) {
327307
let (_, limit) = self.limits(space);
328308
match space {
329-
TypeSpace => { self.type_limit += 1; self.self_limit += 1; self.assoc_limit += 1; }
330-
SelfSpace => { self.self_limit += 1; self.assoc_limit += 1; }
331-
AssocSpace => { self.assoc_limit += 1; }
309+
TypeSpace => { self.type_limit += 1; self.self_limit += 1; }
310+
SelfSpace => { self.self_limit += 1; }
332311
FnSpace => { }
333312
}
334313
self.content.insert(limit, value);
@@ -340,9 +319,8 @@ impl<T> VecPerParamSpace<T> {
340319
None
341320
} else {
342321
match space {
343-
TypeSpace => { self.type_limit -= 1; self.self_limit -= 1; self.assoc_limit -= 1; }
344-
SelfSpace => { self.self_limit -= 1; self.assoc_limit -= 1; }
345-
AssocSpace => { self.assoc_limit -= 1; }
322+
TypeSpace => { self.type_limit -= 1; self.self_limit -= 1; }
323+
SelfSpace => { self.self_limit -= 1; }
346324
FnSpace => {}
347325
}
348326
self.content.remove(limit - 1)
@@ -439,8 +417,7 @@ impl<T> VecPerParamSpace<T> {
439417
let result = self.iter().map(pred).collect();
440418
VecPerParamSpace::new_internal(result,
441419
self.type_limit,
442-
self.self_limit,
443-
self.assoc_limit)
420+
self.self_limit)
444421
}
445422

446423
pub fn map_enumerated<U, P>(&self, pred: P) -> VecPerParamSpace<U> where
@@ -449,8 +426,7 @@ impl<T> VecPerParamSpace<T> {
449426
let result = self.iter_enumerated().map(pred).collect();
450427
VecPerParamSpace::new_internal(result,
451428
self.type_limit,
452-
self.self_limit,
453-
self.assoc_limit)
429+
self.self_limit)
454430
}
455431

456432
pub fn map_move<U, F>(self, mut pred: F) -> VecPerParamSpace<U> where
@@ -459,25 +435,22 @@ impl<T> VecPerParamSpace<T> {
459435
let SeparateVecsPerParamSpace {
460436
types: t,
461437
selfs: s,
462-
assocs: a,
463438
fns: f
464439
} = self.split();
465440

466441
VecPerParamSpace::new(t.into_iter().map(|p| pred(p)).collect(),
467442
s.into_iter().map(|p| pred(p)).collect(),
468-
a.into_iter().map(|p| pred(p)).collect(),
469443
f.into_iter().map(|p| pred(p)).collect())
470444
}
471445

472446
pub fn split(self) -> SeparateVecsPerParamSpace<T> {
473-
let VecPerParamSpace { type_limit, self_limit, assoc_limit, content } = self;
447+
let VecPerParamSpace { type_limit, self_limit, content } = self;
474448

475449
let mut content_iter = content.into_iter();
476450

477451
SeparateVecsPerParamSpace {
478452
types: content_iter.by_ref().take(type_limit).collect(),
479453
selfs: content_iter.by_ref().take(self_limit - type_limit).collect(),
480-
assocs: content_iter.by_ref().take(assoc_limit - self_limit).collect(),
481454
fns: content_iter.collect()
482455
}
483456
}

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16741674
});
16751675
}
16761676

1677-
let obligations = VecPerParamSpace::new(obligations, Vec::new(),
1678-
Vec::new(), Vec::new());
1677+
let obligations = VecPerParamSpace::new(obligations, Vec::new(), Vec::new());
16791678

16801679
debug!("vtable_builtin_data: obligations={}",
16811680
obligations.repr(self.tcx()));
@@ -1769,7 +1768,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17691768
Substs::new_trait(
17701769
vec![arguments_tuple, output_type],
17711770
vec![],
1772-
vec![],
17731771
self_ty);
17741772
let trait_ref = ty::Binder(Rc::new(ty::TraitRef {
17751773
def_id: obligation.predicate.def_id(),
@@ -1810,7 +1808,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18101808
vec![arguments_tuple.subst(self.tcx(), substs),
18111809
closure_sig.0.output.unwrap().subst(self.tcx(), substs)],
18121810
vec![],
1813-
vec![],
18141811
obligation.self_ty());
18151812
let trait_ref = ty::Binder(Rc::new(ty::TraitRef {
18161813
def_id: obligation.predicate.def_id(),

src/librustc/middle/traits/util.rs

Lines changed: 2 additions & 13 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::{Subst, Substs, VecPerParamSpace};
11+
use middle::subst::{Substs, VecPerParamSpace};
1212
use middle::infer::InferCtxt;
1313
use middle::ty::{mod, Ty, AsPredicate, ToPolyTraitRef};
1414
use std::collections::HashSet;
@@ -229,18 +229,7 @@ pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
229229
{
230230
let tcx = infcx.tcx;
231231
let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
232-
let input_substs = infcx.fresh_substs_for_generics(span, &impl_generics);
233-
234-
// Add substs for the associated types bound in the impl.
235-
let ref items = tcx.impl_items.borrow()[impl_def_id];
236-
let mut assoc_tys = Vec::new();
237-
for item in items.iter() {
238-
if let &ty::ImplOrTraitItemId::TypeTraitItemId(id) = item {
239-
assoc_tys.push(tcx.tcache.borrow()[id].ty.subst(tcx, &input_substs));
240-
}
241-
}
242-
243-
input_substs.with_assoc_tys(assoc_tys)
232+
infcx.fresh_substs_for_generics(span, &impl_generics)
244233
}
245234

246235
impl<'tcx, N> fmt::Show for VtableImplData<'tcx, N> {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,9 @@ impl<'tcx> Repr<'tcx> for subst::Substs<'tcx> {
701701

702702
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for subst::VecPerParamSpace<T> {
703703
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
704-
format!("[{};{};{};{}]",
704+
format!("[{};{};{}]",
705705
self.get_slice(subst::TypeSpace).repr(tcx),
706706
self.get_slice(subst::SelfSpace).repr(tcx),
707-
self.get_slice(subst::AssocSpace).repr(tcx),
708707
self.get_slice(subst::FnSpace).repr(tcx))
709708
}
710709
}

src/librustc_trans/trans/meth.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ pub fn trans_static_method_callee(bcx: Block,
209209
let subst::SeparateVecsPerParamSpace {
210210
types: rcvr_type,
211211
selfs: rcvr_self,
212-
assocs: rcvr_assoc,
213212
fns: rcvr_method
214213
} = rcvr_substs.types.split();
215214

@@ -238,7 +237,6 @@ pub fn trans_static_method_callee(bcx: Block,
238237
let trait_substs =
239238
Substs::erased(VecPerParamSpace::new(rcvr_type,
240239
rcvr_self,
241-
rcvr_assoc,
242240
Vec::new()));
243241
let trait_substs = bcx.tcx().mk_substs(trait_substs);
244242
debug!("trait_substs={}", trait_substs.repr(bcx.tcx()));
@@ -276,13 +274,11 @@ pub fn trans_static_method_callee(bcx: Block,
276274
let subst::SeparateVecsPerParamSpace {
277275
types: impl_type,
278276
selfs: impl_self,
279-
assocs: impl_assoc,
280277
fns: _
281278
} = impl_substs.types.split();
282279
let callee_substs =
283280
Substs::erased(VecPerParamSpace::new(impl_type,
284281
impl_self,
285-
impl_assoc,
286282
rcvr_method));
287283

288284
let mth_id = method_with_name(ccx, impl_did, mname);
@@ -411,13 +407,12 @@ fn combine_impl_and_methods_tps<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
411407
let subst::SeparateVecsPerParamSpace {
412408
types: rcvr_type,
413409
selfs: rcvr_self,
414-
assocs: rcvr_assoc,
415410
fns: rcvr_method
416411
} = rcvr_substs.types.clone().split();
417412
assert!(rcvr_method.is_empty());
418413
subst::Substs {
419414
regions: subst::ErasedRegions,
420-
types: subst::VecPerParamSpace::new(rcvr_type, rcvr_self, rcvr_assoc, node_method)
415+
types: subst::VecPerParamSpace::new(rcvr_type, rcvr_self, node_method)
421416
}
422417
}
423418

src/librustc_typeck/check/method/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,11 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
155155
}
156156
};
157157

158-
let number_assoc_types = trait_def.generics.types.len(subst::AssocSpace);
159-
let assoc_types = fcx.inh.infcx.next_ty_vars(number_assoc_types);
160-
161158
assert_eq!(trait_def.generics.types.len(subst::FnSpace), 0);
162159
assert!(trait_def.generics.regions.is_empty());
163160

164161
// Construct a trait-reference `self_ty : Trait<input_tys>`
165-
let substs = subst::Substs::new_trait(input_types, Vec::new(), assoc_types, self_ty);
162+
let substs = subst::Substs::new_trait(input_types, Vec::new(), self_ty);
166163
let trait_ref = Rc::new(ty::TraitRef::new(trait_def_id, fcx.tcx().mk_substs(substs)));
167164

168165
// Construct an obligation

src/librustc_typeck/check/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5430,7 +5430,6 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
54305430
span_err!(fcx.tcx().sess, data.bindings[0].span, E0182,
54315431
"unexpected binding of associated item in expression path \
54325432
(only allowed in type paths)");
5433-
substs.types.truncate(subst::ParamSpace::AssocSpace, 0);
54345433
}
54355434

54365435
{

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
898898
// ...and also create the `Self` parameter.
899899
let self_ty = ty::mk_self_type(ccx.tcx);
900900

901-
subst::Substs::new_trait(types, regions, Vec::new(), self_ty)
901+
subst::Substs::new_trait(types, regions, self_ty)
902902
}
903903
}
904904

Binary file not shown.

0 commit comments

Comments
 (0)