Skip to content

Commit e1b0c86

Browse files
committed
---
yaml --- r: 111222 b: refs/heads/snap-stage3 c: 5fa7be6 h: refs/heads/master v: v3
1 parent 70959d7 commit e1b0c86

File tree

4 files changed

+62
-66
lines changed

4 files changed

+62
-66
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 296e60be6b027a52de58251848037a92f23a0878
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c709c1efc6c399b404bc73ef9a8de10c81a67e35
4+
refs/heads/snap-stage3: 5fa7be659c00eb0cc2fc7cce1ad1ab65b2219637
55
refs/heads/try: 38201d7c6bf0c32b0e5bdc8ecd63976ebc1b3a4c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ pub fn is_null(val: ValueRef) -> bool {
690690
#[deriving(Eq, TotalEq, Hash)]
691691
pub struct MonoParamId {
692692
pub subst: ty::t,
693+
// Do we really need the vtables to be hashed? Isn't the type enough?
693694
pub vtables: Vec<mono_id>
694695
}
695696

branches/snap-stage3/src/librustc/middle/trans/meth.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -427,29 +427,6 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
427427
};
428428
}
429429

430-
pub fn vtable_id(ccx: &CrateContext,
431-
origin: &typeck::vtable_origin)
432-
-> mono_id {
433-
match origin {
434-
&typeck::vtable_static(impl_id, ref substs, ref sub_vtables) => {
435-
let psubsts = param_substs {
436-
tys: (*substs).clone(),
437-
vtables: Some(sub_vtables.clone()),
438-
self_ty: None,
439-
self_vtables: None
440-
};
441-
442-
monomorphize::make_mono_id(
443-
ccx,
444-
impl_id,
445-
&psubsts)
446-
}
447-
448-
// can't this be checked at the callee?
449-
_ => fail!("vtable_id")
450-
}
451-
}
452-
453430
/// Creates a returns a dynamic vtable for the given type and vtable origin.
454431
/// This is used only for objects.
455432
fn get_vtable(bcx: &Block,
@@ -460,7 +437,7 @@ fn get_vtable(bcx: &Block,
460437
let _icx = push_ctxt("meth::get_vtable");
461438

462439
// Check the cache.
463-
let hash_id = (self_ty, vtable_id(ccx, origins.get(0)));
440+
let hash_id = (self_ty, monomorphize::make_vtable_id(ccx, origins.get(0)));
464441
match ccx.vtables.borrow().find(&hash_id) {
465442
Some(&val) => { return val }
466443
None => { }

branches/snap-stage3/src/librustc/middle/trans/monomorphize.rs

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,51 @@ pub fn monomorphic_fn(ccx: &CrateContext,
4747
self_vtables.repr(ccx.tcx()),
4848
ref_id);
4949

50-
assert!(real_substs.tps.iter().all(|t| !ty::type_needs_infer(*t)));
50+
assert!(real_substs.tps.iter().all(|t| {
51+
!ty::type_needs_infer(*t) && !ty::type_has_params(*t)
52+
}));
53+
5154
let _icx = push_ctxt("monomorphic_fn");
5255

56+
let substs_iter = real_substs.self_ty.iter().chain(real_substs.tps.iter());
57+
let param_ids: Vec<MonoParamId> = match vtables {
58+
Some(ref vts) => {
59+
debug!("make_mono_id vtables={} psubsts={}",
60+
vts.repr(ccx.tcx()), real_substs.tps.repr(ccx.tcx()));
61+
let vts_iter = self_vtables.iter().chain(vts.iter());
62+
vts_iter.zip(substs_iter).map(|(vtable, subst)| MonoParamId {
63+
subst: *subst,
64+
// Do we really need the vtables to be hashed? Isn't the type enough?
65+
vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect()
66+
}).collect()
67+
}
68+
None => substs_iter.map(|subst| MonoParamId {
69+
subst: *subst,
70+
vtables: Vec::new()
71+
}).collect()
72+
};
73+
74+
let hash_id = @mono_id_ {
75+
def: fn_id,
76+
params: param_ids
77+
};
78+
79+
match ccx.monomorphized.borrow().find(&hash_id) {
80+
Some(&val) => {
81+
debug!("leaving monomorphic fn {}",
82+
ty::item_path_str(ccx.tcx(), fn_id));
83+
return (val, false);
84+
}
85+
None => ()
86+
}
87+
5388
let psubsts = @param_substs {
5489
tys: real_substs.tps.clone(),
5590
vtables: vtables,
5691
self_ty: real_substs.self_ty.clone(),
5792
self_vtables: self_vtables
5893
};
5994

60-
for s in real_substs.tps.iter() { assert!(!ty::type_has_params(*s)); }
61-
for s in psubsts.tys.iter() { assert!(!ty::type_has_params(*s)); }
62-
63-
let hash_id = make_mono_id(ccx, fn_id, &*psubsts);
64-
6595
debug!("monomorphic_fn(\
6696
fn_id={}, \
6797
psubsts={}, \
@@ -70,15 +100,6 @@ pub fn monomorphic_fn(ccx: &CrateContext,
70100
psubsts.repr(ccx.tcx()),
71101
hash_id);
72102

73-
match ccx.monomorphized.borrow().find(&hash_id) {
74-
Some(&val) => {
75-
debug!("leaving monomorphic fn {}",
76-
ty::item_path_str(ccx.tcx(), fn_id));
77-
return (val, false);
78-
}
79-
None => ()
80-
}
81-
82103
let tpt = ty::lookup_item_type(ccx.tcx(), fn_id);
83104
let llitem_ty = tpt.ty;
84105

@@ -117,8 +138,8 @@ pub fn monomorphic_fn(ccx: &CrateContext,
117138

118139
debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx()));
119140
let mono_ty = match is_static_provided {
120-
None => ty::subst_tps(ccx.tcx(), psubsts.tys.as_slice(),
121-
psubsts.self_ty, llitem_ty),
141+
None => ty::subst_tps(ccx.tcx(), real_substs.tps.as_slice(),
142+
real_substs.self_ty, llitem_ty),
122143
Some(num_method_ty_params) => {
123144
// Static default methods are a little unfortunate, in
124145
// that the "internal" and "external" type of them differ.
@@ -134,9 +155,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
134155
// stick a substitution for the self type in.
135156
// This is a bit unfortunate.
136157

137-
let idx = psubsts.tys.len() - num_method_ty_params;
138-
let substs = psubsts.tys.slice(0, idx) +
139-
&[psubsts.self_ty.unwrap()] + psubsts.tys.tailn(idx);
158+
let idx = real_substs.tps.len() - num_method_ty_params;
159+
let substs = real_substs.tps.slice(0, idx) +
160+
&[real_substs.self_ty.unwrap()] + real_substs.tps.tailn(idx);
140161
debug!("static default: changed substitution to {}",
141162
substs.repr(ccx.tcx()));
142163

@@ -284,28 +305,25 @@ pub fn monomorphic_fn(ccx: &CrateContext,
284305
(lldecl, false)
285306
}
286307

287-
pub fn make_mono_id(ccx: &CrateContext,
288-
item: ast::DefId,
289-
substs: &param_substs) -> mono_id {
290-
let substs_iter = substs.self_ty.iter().chain(substs.tys.iter());
291-
let param_ids: Vec<MonoParamId> = match substs.vtables {
292-
Some(ref vts) => {
293-
debug!("make_mono_id vtables={} substs={}",
294-
vts.repr(ccx.tcx()), substs.tys.repr(ccx.tcx()));
295-
let vts_iter = substs.self_vtables.iter().chain(vts.iter());
296-
vts_iter.zip(substs_iter).map(|(vtable, subst)| MonoParamId {
297-
subst: *subst,
298-
vtables: vtable.iter().map(|vt| meth::vtable_id(ccx, vt)).collect()
299-
}).collect()
308+
pub fn make_vtable_id(ccx: &CrateContext,
309+
origin: &typeck::vtable_origin)
310+
-> mono_id {
311+
match origin {
312+
&typeck::vtable_static(impl_id, ref substs, ref sub_vtables) => {
313+
let param_ids = sub_vtables.iter().zip(substs.iter()).map(|(vtable, subst)| {
314+
MonoParamId {
315+
subst: *subst,
316+
vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect()
317+
}
318+
}).collect();
319+
320+
@mono_id_ {
321+
def: impl_id,
322+
params: param_ids
323+
}
300324
}
301-
None => substs_iter.map(|subst| MonoParamId {
302-
subst: *subst,
303-
vtables: Vec::new()
304-
}).collect()
305-
};
306325

307-
@mono_id_ {
308-
def: item,
309-
params: param_ids
326+
// can't this be checked at the callee?
327+
_ => fail!("make_vtable_id needs vtable_static")
310328
}
311329
}

0 commit comments

Comments
 (0)