Skip to content

Commit 4cfcdb1

Browse files
committed
---
yaml --- r: 150993 b: refs/heads/try2 c: c9bf843 h: refs/heads/master i: 150991: 216aee4 v: v3
1 parent 05f333e commit 4cfcdb1

File tree

12 files changed

+210
-227
lines changed

12 files changed

+210
-227
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 158d7a19b3f39bcdf3c8d7094fda8f0dd6e121b5
8+
refs/heads/try2: c9bf84333d4f76417f935e24b7a70340b8f1b1be
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ fn encode_impl_vtables(ebml_w: &mut Encoder,
146146
ecx: &EncodeContext,
147147
vtables: &typeck::impl_res) {
148148
ebml_w.start_tag(tag_item_impl_vtables);
149-
astencode::encode_vtable_res(ecx, ebml_w, vtables.trait_vtables);
150-
astencode::encode_vtable_param_res(ecx, ebml_w, vtables.self_vtables);
149+
astencode::encode_vtable_res(ecx, ebml_w, &vtables.trait_vtables);
150+
astencode::encode_vtable_param_res(ecx, ebml_w, &vtables.self_vtables);
151151
ebml_w.end_tag();
152152
}
153153

branches/try2/src/librustc/middle/astencode.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl tr for MethodOrigin {
658658
fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
659659
ebml_w: &mut Encoder,
660660
autoderef: u32,
661-
dr: typeck::vtable_res) {
661+
dr: &typeck::vtable_res) {
662662
ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| {
663663
ebml_w.emit_struct_field("autoderef", 0u, |ebml_w| {
664664
autoderef.encode(ebml_w)
@@ -671,19 +671,19 @@ fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
671671

672672
pub fn encode_vtable_res(ecx: &e::EncodeContext,
673673
ebml_w: &mut Encoder,
674-
dr: typeck::vtable_res) {
674+
dr: &typeck::vtable_res) {
675675
// can't autogenerate this code because automatic code of
676676
// ty::t doesn't work, and there is no way (atm) to have
677677
// hand-written encoding routines combine with auto-generated
678678
// ones. perhaps we should fix this.
679679
ebml_w.emit_from_vec(dr.as_slice(), |ebml_w, param_tables| {
680-
Ok(encode_vtable_param_res(ecx, ebml_w, *param_tables))
680+
Ok(encode_vtable_param_res(ecx, ebml_w, param_tables))
681681
}).unwrap()
682682
}
683683

684684
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
685685
ebml_w: &mut Encoder,
686-
param_tables: typeck::vtable_param_res) {
686+
param_tables: &typeck::vtable_param_res) {
687687
ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| {
688688
Ok(encode_vtable_origin(ecx, ebml_w, vtable_origin))
689689
}).unwrap()
@@ -695,7 +695,7 @@ pub fn encode_vtable_origin(ecx: &e::EncodeContext,
695695
vtable_origin: &typeck::vtable_origin) {
696696
ebml_w.emit_enum("vtable_origin", |ebml_w| {
697697
match *vtable_origin {
698-
typeck::vtable_static(def_id, ref tys, vtable_res) => {
698+
typeck::vtable_static(def_id, ref tys, ref vtable_res) => {
699699
ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| {
700700
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
701701
Ok(ebml_w.emit_def_id(def_id))
@@ -756,21 +756,15 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
756756
fn read_vtable_res(&mut self,
757757
tcx: &ty::ctxt, cdata: @cstore::crate_metadata)
758758
-> typeck::vtable_res {
759-
@self.read_to_vec(|this|
760-
Ok(this.read_vtable_param_res(tcx, cdata)))
761-
.unwrap()
762-
.move_iter()
763-
.collect()
759+
self.read_to_vec(|this| Ok(this.read_vtable_param_res(tcx, cdata)))
760+
.unwrap().move_iter().collect()
764761
}
765762

766763
fn read_vtable_param_res(&mut self,
767764
tcx: &ty::ctxt, cdata: @cstore::crate_metadata)
768765
-> typeck::vtable_param_res {
769-
@self.read_to_vec(|this|
770-
Ok(this.read_vtable_origin(tcx, cdata)))
771-
.unwrap()
772-
.move_iter()
773-
.collect()
766+
self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata)))
767+
.unwrap().move_iter().collect()
774768
}
775769

776770
fn read_vtable_origin(&mut self,
@@ -1063,7 +1057,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10631057
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
10641058
ebml_w.id(id);
10651059
ebml_w.tag(c::tag_table_val, |ebml_w| {
1066-
encode_vtable_res_with_key(ecx, ebml_w, method_call.autoderef, *dr);
1060+
encode_vtable_res_with_key(ecx, ebml_w, method_call.autoderef, dr);
10671061
})
10681062
})
10691063
}
@@ -1087,7 +1081,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10871081
ebml_w.id(id);
10881082
ebml_w.tag(c::tag_table_val, |ebml_w| {
10891083
encode_vtable_res_with_key(ecx, ebml_w,
1090-
method_call.autoderef, *dr);
1084+
method_call.autoderef, dr);
10911085
})
10921086
})
10931087
}

branches/try2/src/librustc/middle/trans/callee.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ pub fn trans_fn_ref(bcx: &Block, def_id: ast::DefId, node: ExprOrMethodCall) ->
176176
def_id.repr(bcx.tcx()), node, type_params.repr(bcx.tcx()),
177177
vtables.repr(bcx.tcx()));
178178
trans_fn_ref_with_vtables(bcx, def_id, node,
179-
type_params.as_slice(),
179+
type_params,
180180
vtables)
181181
}
182182

183183
fn trans_fn_ref_with_vtables_to_callee<'a>(bcx: &'a Block<'a>,
184184
def_id: ast::DefId,
185185
ref_id: ast::NodeId,
186-
type_params: &[ty::t],
186+
type_params: Vec<ty::t>,
187187
vtables: Option<typeck::vtable_res>)
188188
-> Callee<'a> {
189189
Callee {bcx: bcx,
@@ -206,29 +206,32 @@ fn resolve_default_method_vtables(bcx: &Block,
206206
let param_substs = Some(@param_substs {
207207
tys: substs.tps.clone(),
208208
self_ty: substs.self_ty,
209-
vtables: impl_vtables,
209+
vtables: impl_vtables.clone(),
210210
self_vtables: None
211211
});
212212

213-
let trait_vtables_fixed = resolve_vtables_under_param_substs(
214-
bcx.tcx(), param_substs, impl_res.trait_vtables);
213+
let mut param_vtables = resolve_vtables_under_param_substs(
214+
bcx.tcx(), param_substs, impl_res.trait_vtables.as_slice());
215215

216216
// Now we pull any vtables for parameters on the actual method.
217217
let num_method_vtables = method.generics.type_param_defs().len();
218-
let method_vtables = match impl_vtables {
219-
Some(vtables) => {
218+
match impl_vtables {
219+
Some(ref vtables) => {
220220
let num_impl_type_parameters =
221221
vtables.len() - num_method_vtables;
222-
Vec::from_slice(vtables.tailn(num_impl_type_parameters))
222+
param_vtables.push_all(vtables.tailn(num_impl_type_parameters))
223223
},
224-
None => Vec::from_elem(num_method_vtables, @Vec::new())
225-
};
226-
227-
let method_vtables = method_vtables.as_slice();
228-
let param_vtables = @((*trait_vtables_fixed).clone().append(method_vtables));
224+
None => {
225+
param_vtables.extend(range(0, num_method_vtables).map(
226+
|_| -> typeck::vtable_param_res {
227+
Vec::new()
228+
}
229+
))
230+
}
231+
}
229232

230233
let self_vtables = resolve_param_vtables_under_param_substs(
231-
bcx.tcx(), param_substs, impl_res.self_vtables);
234+
bcx.tcx(), param_substs, impl_res.self_vtables.as_slice());
232235

233236
(param_vtables, self_vtables)
234237
}
@@ -238,7 +241,7 @@ pub fn trans_fn_ref_with_vtables(
238241
bcx: &Block, //
239242
def_id: ast::DefId, // def id of fn
240243
node: ExprOrMethodCall, // node id of use of fn; may be zero if N/A
241-
type_params: &[ty::t], // values for fn's ty params
244+
type_params: Vec<ty::t>, // values for fn's ty params
242245
vtables: Option<typeck::vtable_res>) // vtables for the call
243246
-> ValueRef {
244247
/*!
@@ -273,9 +276,11 @@ pub fn trans_fn_ref_with_vtables(
273276
// Polytype of the function item (may have type params)
274277
let fn_tpt = ty::lookup_item_type(tcx, def_id);
275278

276-
let substs = ty::substs { regions: ty::ErasedRegions,
277-
self_ty: None,
278-
tps: /*bad*/ Vec::from_slice(type_params) };
279+
let substs = ty::substs {
280+
regions: ty::ErasedRegions,
281+
self_ty: None,
282+
tps: type_params
283+
};
279284

280285
// Load the info for the appropriate trait if necessary.
281286
match ty::trait_of_method(tcx, def_id) {
@@ -318,19 +323,20 @@ pub fn trans_fn_ref_with_vtables(
318323
// And compose them
319324
let new_substs = first_subst.subst(tcx, &substs);
320325

326+
debug!("trans_fn_with_vtables - default method: \
327+
substs = {}, trait_subst = {}, \
328+
first_subst = {}, new_subst = {}, \
329+
vtables = {}",
330+
substs.repr(tcx), trait_ref.substs.repr(tcx),
331+
first_subst.repr(tcx), new_substs.repr(tcx),
332+
vtables.repr(tcx));
321333

322334
let (param_vtables, self_vtables) =
323335
resolve_default_method_vtables(bcx, impl_id,
324336
method, &substs, vtables);
325337

326338
debug!("trans_fn_with_vtables - default method: \
327-
substs = {}, trait_subst = {}, \
328-
first_subst = {}, new_subst = {}, \
329-
vtables = {}, \
330339
self_vtable = {}, param_vtables = {}",
331-
substs.repr(tcx), trait_ref.substs.repr(tcx),
332-
first_subst.repr(tcx), new_substs.repr(tcx),
333-
vtables.repr(tcx),
334340
self_vtables.repr(tcx), param_vtables.repr(tcx));
335341

336342
(true, source_id,
@@ -352,7 +358,7 @@ pub fn trans_fn_ref_with_vtables(
352358
// intrinsic, or is a default method. In particular, if we see an
353359
// intrinsic that is inlined from a different crate, we want to reemit the
354360
// intrinsic instead of trying to call it in the other crate.
355-
let must_monomorphise = if type_params.len() > 0 || is_default {
361+
let must_monomorphise = if substs.tps.len() > 0 || is_default {
356362
true
357363
} else if def_id.krate == ast::LOCAL_CRATE {
358364
let map_node = session::expect(
@@ -504,7 +510,7 @@ pub fn trans_lang_call<'a>(
504510
trans_fn_ref_with_vtables_to_callee(bcx,
505511
did,
506512
0,
507-
[],
513+
vec!(),
508514
None)
509515
},
510516
ArgVals(args),

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -797,41 +797,42 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec<ty::t> {
797797

798798
pub fn node_vtables(bcx: &Block, id: typeck::MethodCall)
799799
-> Option<typeck::vtable_res> {
800-
let vtable_map = bcx.tcx().vtable_map.borrow();
801-
let raw_vtables = vtable_map.find(&id);
802-
raw_vtables.map(|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
800+
bcx.tcx().vtable_map.borrow().find(&id).map(|vts| {
801+
resolve_vtables_in_fn_ctxt(bcx.fcx, vts.as_slice())
802+
})
803803
}
804804

805805
// Apply the typaram substitutions in the FunctionContext to some
806806
// vtables. This should eliminate any vtable_params.
807-
pub fn resolve_vtables_in_fn_ctxt(fcx: &FunctionContext, vts: typeck::vtable_res)
808-
-> typeck::vtable_res {
807+
pub fn resolve_vtables_in_fn_ctxt(fcx: &FunctionContext,
808+
vts: &[typeck::vtable_param_res])
809+
-> typeck::vtable_res {
809810
resolve_vtables_under_param_substs(fcx.ccx.tcx(),
810811
fcx.param_substs,
811812
vts)
812813
}
813814

814815
pub fn resolve_vtables_under_param_substs(tcx: &ty::ctxt,
815816
param_substs: Option<@param_substs>,
816-
vts: typeck::vtable_res)
817-
-> typeck::vtable_res {
818-
@vts.iter().map(|ds|
817+
vts: &[typeck::vtable_param_res])
818+
-> typeck::vtable_res {
819+
vts.iter().map(|ds| {
819820
resolve_param_vtables_under_param_substs(tcx,
820821
param_substs,
821-
*ds))
822-
.collect()
822+
ds.as_slice())
823+
}).collect()
823824
}
824825

825826
pub fn resolve_param_vtables_under_param_substs(
826827
tcx: &ty::ctxt,
827828
param_substs: Option<@param_substs>,
828-
ds: typeck::vtable_param_res)
829+
ds: &[typeck::vtable_origin])
829830
-> typeck::vtable_param_res {
830-
@ds.iter().map(
831-
|d| resolve_vtable_under_param_substs(tcx,
832-
param_substs,
833-
d))
834-
.collect()
831+
ds.iter().map(|d| {
832+
resolve_vtable_under_param_substs(tcx,
833+
param_substs,
834+
d)
835+
}).collect()
835836
}
836837

837838

@@ -841,7 +842,7 @@ pub fn resolve_vtable_under_param_substs(tcx: &ty::ctxt,
841842
vt: &typeck::vtable_origin)
842843
-> typeck::vtable_origin {
843844
match *vt {
844-
typeck::vtable_static(trait_id, ref tys, sub) => {
845+
typeck::vtable_static(trait_id, ref tys, ref sub) => {
845846
let tys = match param_substs {
846847
Some(substs) => {
847848
tys.iter().map(|t| {
@@ -855,7 +856,7 @@ pub fn resolve_vtable_under_param_substs(tcx: &ty::ctxt,
855856
};
856857
typeck::vtable_static(
857858
trait_id, tys,
858-
resolve_vtables_under_param_substs(tcx, param_substs, sub))
859+
resolve_vtables_under_param_substs(tcx, param_substs, sub.as_slice()))
859860
}
860861
typeck::vtable_param(n_param, n_bound) => {
861862
match param_substs {
@@ -881,11 +882,11 @@ pub fn find_vtable(tcx: &ty::ctxt,
881882
n_param, n_bound, ps.repr(tcx));
882883

883884
let param_bounds = match n_param {
884-
typeck::param_self => ps.self_vtables.expect("self vtables missing"),
885+
typeck::param_self => ps.self_vtables.as_ref().expect("self vtables missing"),
885886
typeck::param_numbered(n) => {
886-
let tables = ps.vtables
887+
let tables = ps.vtables.as_ref()
887888
.expect("vtables missing where they are needed");
888-
*tables.get(n)
889+
tables.get(n)
889890
}
890891
};
891892
param_bounds.get(n_bound).clone()

0 commit comments

Comments
 (0)