Skip to content

Commit 1d7091e

Browse files
committed
---
yaml --- r: 33118 b: refs/heads/dist-snap c: 38aab8e h: refs/heads/master v: v3
1 parent 1d8de58 commit 1d7091e

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: d8287f0e41be93fa0c902cac71637cbcb1632a50
10+
refs/heads/dist-snap: 38aab8e40034ae21b7c801ae8532ec1f5ae5022d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/rustc/middle/trans/base.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,19 +1848,25 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18481848
}
18491849
}
18501850
ast::item_impl(tps, trait_refs, _, ms) => {
1851-
meth::trans_impl(ccx, *path, item.ident, ms, tps);
1851+
meth::trans_impl(ccx, *path, item.ident, ms, tps, None);
18521852

18531853
// Translate any methods that have provided implementations.
18541854
for trait_refs.each |trait_ref_ptr| {
18551855
let trait_def = ccx.tcx.def_map.get(trait_ref_ptr.ref_id);
18561856

18571857
// XXX: Cross-crate default methods.
1858-
match ccx.tcx.items.get(def_id_of_def(trait_def).node) {
1858+
let trait_id = def_id_of_def(trait_def);
1859+
if trait_id.crate != ast::local_crate {
1860+
loop;
1861+
}
1862+
1863+
match ccx.tcx.items.get(trait_id.node) {
18591864
ast_map::node_item(trait_item, _) => {
18601865
match trait_item.node {
18611866
ast::item_trait(tps, _, trait_methods) => {
1867+
// XXX: ty_self is wrong here. Get the real type.
18621868
trans_trait(ccx, tps, trait_methods, path,
1863-
item.ident);
1869+
item.ident, ty::mk_self(ccx.tcx));
18641870
}
18651871
_ => {
18661872
ccx.tcx.sess.impossible_case(item.span,
@@ -1922,15 +1928,16 @@ fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
19221928
// If there are ty params, the ctor will get monomorphized
19231929

19241930
// Translate methods
1925-
meth::trans_impl(ccx, *path, ident, struct_def.methods, tps);
1931+
meth::trans_impl(ccx, *path, ident, struct_def.methods, tps, None);
19261932
}
19271933

19281934
fn trans_trait(ccx: @crate_ctxt, tps: ~[ast::ty_param],
19291935
trait_methods: ~[ast::trait_method],
1930-
path: @ast_map::path, ident: ast::ident) {
1936+
path: @ast_map::path, ident: ast::ident,
1937+
self_ty: ty::t) {
19311938
// Translate any methods that have provided implementations
19321939
let (_, provided_methods) = ast_util::split_trait_methods(trait_methods);
1933-
meth::trans_impl(ccx, *path, ident, provided_methods, tps);
1940+
meth::trans_impl(ccx, *path, ident, provided_methods, tps, Some(self_ty));
19341941
}
19351942

19361943
// Translate a module. Doing this amounts to translating the items in the

branches/dist-snap/src/rustc/middle/trans/meth.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ be generated once they are invoked with specific type parameters,
2727
see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
2828
*/
2929
fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
30-
methods: ~[@ast::method], tps: ~[ast::ty_param]) {
30+
methods: ~[@ast::method], tps: ~[ast::ty_param],
31+
self_ty: Option<ty::t>) {
3132
let _icx = ccx.insn_ctxt("impl::trans_impl");
3233
if tps.len() > 0u { return; }
3334
let sub_path = vec::append_one(path, path_name(name));
3435
for vec::each(methods) |method| {
3536
if method.tps.len() == 0u {
3637
let llfn = get_item_val(ccx, method.id);
3738
let path = vec::append_one(sub_path, path_name(method.ident));
38-
trans_method(ccx, path, *method, None, llfn);
39+
trans_method(ccx, path, *method, None, self_ty, llfn);
3940
}
4041
}
4142
}
@@ -49,12 +50,16 @@ Translates a (possibly monomorphized) method body.
4950
- `method`: the AST node for the method
5051
- `param_substs`: if this is a generic method, the current values for
5152
type parameters and so forth, else none
53+
- `base_self_ty`: optionally, the explicit self type for this method. This
54+
will be none if this is not a default method and must always be present
55+
if this is a default method.
5256
- `llfn`: the LLVM ValueRef for the method
5357
*/
5458
fn trans_method(ccx: @crate_ctxt,
5559
path: path,
5660
method: &ast::method,
5761
param_substs: Option<param_substs>,
62+
base_self_ty: Option<ty::t>,
5863
llfn: ValueRef) {
5964

6065
// figure out how self is being passed
@@ -65,7 +70,11 @@ fn trans_method(ccx: @crate_ctxt,
6570
_ => {
6671
// determine the (monomorphized) type that `self` maps to for
6772
// this method
68-
let self_ty = ty::node_id_to_type(ccx.tcx, method.self_id);
73+
let self_ty;
74+
match base_self_ty {
75+
None => self_ty = ty::node_id_to_type(ccx.tcx, method.self_id),
76+
Some(provided_self_ty) => self_ty = provided_self_ty
77+
}
6978
let self_ty = match param_substs {
7079
None => self_ty,
7180
Some({tys: ref tys, _}) => ty::subst_tps(ccx.tcx, *tys, self_ty)

branches/dist-snap/src/rustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ fn monomorphic_fn(ccx: @crate_ctxt,
156156
d
157157
}
158158
ast_map::node_method(mth, _, _) => {
159+
// XXX: What should the self type be here?
159160
let d = mk_lldecl();
160161
set_inline_hint_if_appr(mth.attrs, d);
161-
meth::trans_method(ccx, pt, mth, psubsts, d);
162+
meth::trans_method(ccx, pt, mth, psubsts, None, d);
162163
d
163164
}
164165
ast_map::node_ctor(_, tps, ctor, parent_id, _) => {

0 commit comments

Comments
 (0)