Skip to content

Commit 7178588

Browse files
committed
---
yaml --- r: 15791 b: refs/heads/try c: d899c3a h: refs/heads/master i: 15789: 7fa439d 15787: d8d305c 15783: f09eaf2 15775: 1f4ace9 v: v3
1 parent 0bbda83 commit 7178588

File tree

4 files changed

+167
-163
lines changed

4 files changed

+167
-163
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 5428a22b95ccd8c84a402e2f5cb4aa53ddc6f4d4
5+
refs/heads/try: d899c3a5792da29ac2bf71caf76b56017b5f42d0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/trans/impl.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,13 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
6464
}
6565
}
6666
typeck::method_iface(_, off) {
67-
trans_iface_callee(bcx, self, callee_id, off)
67+
let {bcx, val} = trans_temp_expr(bcx, self);
68+
let fty = node_id_type(bcx, callee_id);
69+
trans_iface_callee(bcx, val, fty, off)
6870
}
6971
}
7072
}
7173

72-
fn trans_vtable_callee(bcx: block, env: callee_env, vtable: ValueRef,
73-
callee_id: ast::node_id, n_method: uint)
74-
-> lval_maybe_callee {
75-
let _icx = bcx.insn_ctxt("impl::trans_vtable_callee");
76-
let bcx = bcx, ccx = bcx.ccx();
77-
let fty = node_id_type(bcx, callee_id);
78-
let llfty = type_of::type_of_fn_from_ty(ccx, fty);
79-
let vtable = PointerCast(bcx, vtable,
80-
T_ptr(T_array(T_ptr(llfty), n_method + 1u)));
81-
let mptr = Load(bcx, GEPi(bcx, vtable, [0u, n_method]));
82-
{bcx: bcx, val: mptr, kind: owned, env: env}
83-
}
84-
8574
fn method_from_methods(ms: [@ast::method], name: ast::ident) -> ast::def_id {
8675
local_def(option::get(vec::find(ms, {|m| m.ident == name})).id)
8776
}
@@ -139,7 +128,9 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
139128
with lval}
140129
}
141130
typeck::vtable_iface(iid, tps) {
142-
trans_iface_callee(bcx, base, callee_id, n_method)
131+
let {bcx, val} = trans_temp_expr(bcx, base);
132+
let fty = node_id_type(bcx, callee_id);
133+
trans_iface_callee(bcx, val, fty, n_method)
143134
}
144135
typeck::vtable_param(n_param, n_bound) {
145136
fail "vtable_param left in monomorphized function's vtable substs";
@@ -148,18 +139,22 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
148139
}
149140

150141
// Method callee where the vtable comes from a boxed iface
151-
fn trans_iface_callee(bcx: block, base: @ast::expr,
152-
callee_id: ast::node_id, n_method: uint)
142+
fn trans_iface_callee(bcx: block, val: ValueRef,
143+
callee_ty: ty::t, n_method: uint)
153144
-> lval_maybe_callee {
154145
let _icx = bcx.insn_ctxt("impl::trans_iface_callee");
155-
let {bcx, val} = trans_temp_expr(bcx, base);
146+
let ccx = bcx.ccx();
156147
let vtable = Load(bcx, PointerCast(bcx, GEPi(bcx, val, [0u, 0u]),
157-
T_ptr(T_ptr(T_vtable()))));
148+
T_ptr(T_ptr(T_vtable()))));
158149
let box = Load(bcx, GEPi(bcx, val, [0u, 1u]));
159150
// FIXME[impl] I doubt this is alignment-safe
160151
let self = GEPi(bcx, box, [0u, abi::box_field_body]);
161152
let env = self_env(self, ty::mk_opaque_box(bcx.tcx()), some(box));
162-
trans_vtable_callee(bcx, env, vtable, callee_id, n_method)
153+
let llfty = type_of::type_of_fn_from_ty(ccx, callee_ty);
154+
let vtable = PointerCast(bcx, vtable,
155+
T_ptr(T_array(T_ptr(llfty), n_method + 1u)));
156+
let mptr = Load(bcx, GEPi(bcx, vtable, [0u, n_method]));
157+
{bcx: bcx, val: mptr, kind: owned, env: env}
163158
}
164159

165160
fn find_vtable_in_fn_ctxt(ps: param_substs, n_param: uint, n_bound: uint)

branches/try/src/rustc/middle/trans/native.rs

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import lib::llvm::{ llvm, TypeRef, ValueRef,
1010
StructRetAttribute, ByValAttribute
1111
};
1212
import syntax::{ast, ast_util};
13-
import back::link;
13+
import back::{link, abi};
1414
import common::*;
1515
import build::*;
1616
import base::*;
@@ -842,63 +842,65 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
842842
let vp_ty = substs.tys[1];
843843
let visitor = get_param(decl, first_real_arg);
844844

845-
// We're going to synthesize a monomorphized vtbl call here much
846-
// like what impl::trans_monomorphized_callee does, but without
847-
// having quite as much source machinery to go on.
845+
let (tyname, args) = alt ty::get(tp_ty).struct {
846+
ty::ty_bot { ("bot", []) }
847+
ty::ty_nil { ("nil", []) }
848+
ty::ty_bool { ("bool", []) }
849+
ty::ty_int(ast::ty_i) { ("int", []) }
850+
ty::ty_int(ast::ty_char) { ("char", []) }
851+
ty::ty_int(ast::ty_i8) { ("i8", []) }
852+
ty::ty_int(ast::ty_i16) { ("i16", []) }
853+
ty::ty_int(ast::ty_i32) { ("i32", []) }
854+
ty::ty_int(ast::ty_i64) { ("i64", []) }
855+
ty::ty_uint(ast::ty_u) { ("uint", []) }
856+
ty::ty_uint(ast::ty_u8) { ("u8", []) }
857+
ty::ty_uint(ast::ty_u16) { ("u16", []) }
858+
ty::ty_uint(ast::ty_u32) { ("u32", []) }
859+
ty::ty_uint(ast::ty_u64) { ("u64", []) }
860+
ty::ty_float(ast::ty_f) { ("float", []) }
861+
ty::ty_float(ast::ty_f32) { ("f32", []) }
862+
ty::ty_float(ast::ty_f64) { ("f64", []) }
863+
ty::ty_str { ("str", []) }
864+
_ {
865+
bcx.sess().unimpl("trans::native::visit_ty on "
866+
+ ty_to_str(ccx.tcx, tp_ty));
867+
}
868+
};
869+
870+
let mth_name = "visit_" + tyname;
871+
let dest = ignore;
848872

849873
alt impl::find_vtable_in_fn_ctxt(substs,
850874
1u, /* n_param */
851875
0u /* n_bound */ ) {
852876

853877
typeck::vtable_static(impl_did, impl_substs, sub_origins) {
854-
855-
let (tyname, args) = alt ty::get(tp_ty).struct {
856-
ty::ty_bot { ("bot", []) }
857-
ty::ty_nil { ("nil", []) }
858-
ty::ty_bool { ("bool", []) }
859-
ty::ty_int(ast::ty_i) { ("int", []) }
860-
ty::ty_int(ast::ty_char) { ("char", []) }
861-
ty::ty_int(ast::ty_i8) { ("i8", []) }
862-
ty::ty_int(ast::ty_i16) { ("i16", []) }
863-
ty::ty_int(ast::ty_i32) { ("i32", []) }
864-
ty::ty_int(ast::ty_i64) { ("i64", []) }
865-
ty::ty_uint(ast::ty_u) { ("uint", []) }
866-
ty::ty_uint(ast::ty_u8) { ("u8", []) }
867-
ty::ty_uint(ast::ty_u16) { ("u16", []) }
868-
ty::ty_uint(ast::ty_u32) { ("u32", []) }
869-
ty::ty_uint(ast::ty_u64) { ("u64", []) }
870-
ty::ty_float(ast::ty_f) { ("float", []) }
871-
ty::ty_float(ast::ty_f32) { ("f32", []) }
872-
ty::ty_float(ast::ty_f64) { ("f64", []) }
873-
ty::ty_str { ("str", []) }
874-
_ {
875-
bcx.sess().unimpl("trans::native::visit_ty on "
876-
+ ty_to_str(ccx.tcx, tp_ty));
877-
}
878-
};
879-
880-
let mth_id = impl::method_with_name(ccx, impl_did,
881-
"visit_" + tyname);
878+
let mth_id = impl::method_with_name(ccx, impl_did, mth_name);
882879
let mth_ty = ty::lookup_item_type(ccx.tcx, mth_id).ty;
883-
884880
// FIXME: is this safe? There is no callee AST node,
885881
// we're synthesizing it.
886882
let callee_id = (-1) as ast::node_id;
883+
let get_lval = {|bcx|
884+
let lval = lval_static_fn_inner(bcx, mth_id, callee_id,
885+
impl_substs,
886+
some(sub_origins));
887+
{env: self_env(visitor, vp_ty, none) with lval}
888+
};
889+
bcx = trans_call_inner(bcx, mth_ty, ty::mk_bool(ccx.tcx),
890+
get_lval, arg_vals(args), dest);
891+
}
887892

888-
let dest = ignore;
889-
890-
bcx = trans_call_inner(bcx,
891-
mth_ty,
892-
ty::mk_nil(ccx.tcx),
893-
{|bcx|
894-
let lval =
895-
lval_static_fn_inner
896-
(bcx, mth_id, callee_id,
897-
impl_substs, some(sub_origins));
898-
{env: self_env(visitor, vp_ty, none)
899-
with lval}
900-
}, arg_vals(args), dest);
893+
typeck::vtable_iface(iid, _tps) {
894+
let methods = ty::iface_methods(ccx.tcx, iid);
895+
let mth_idx = option::get(ty::method_idx(mth_name, *methods));
896+
let mth_ty = ty::mk_fn(ccx.tcx, methods[mth_idx].fty);
897+
let get_lval = {|bcx|
898+
impl::trans_iface_callee(bcx, visitor, mth_ty, mth_idx)
899+
};
900+
bcx = trans_call_inner(bcx, mth_ty, ty::mk_bool(ccx.tcx),
901+
get_lval, arg_vals(args), dest);
901902
}
903+
902904
_ {
903905
ccx.sess.span_bug(item.span,
904906
"non-static callee in 'visit_ty' intrinsinc");

0 commit comments

Comments
 (0)