Skip to content

Commit 96d24a5

Browse files
committed
rustc: remove MethodOrigin::Object and use traits::VtableObject instead.
1 parent a5447e1 commit 96d24a5

File tree

9 files changed

+144
-227
lines changed

9 files changed

+144
-227
lines changed

src/librustc/middle/ty.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,8 @@ pub enum MethodOrigin {
630630
/// Inherent impl method call.
631631
Inherent,
632632

633-
/// Statically dispatched trait method call.
634-
Trait,
635-
636-
/// Dynamically dispatched trait method call.
637-
/// The usize is the index into the actual runtime vtable.
638-
/// The vtable is formed by concatenating together the method lists of
639-
/// the base object trait and all supertraits; this is the index into
640-
/// that vtable.
641-
Object(usize)
633+
/// Trait method call.
634+
Trait
642635
}
643636

644637
#[derive(Clone, Debug)]

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
852852
}
853853
// Trait methods are always all public. The only controlling factor
854854
// is whether the trait itself is accessible or not.
855-
ty::MethodOrigin::Trait | ty::MethodOrigin::Object(_) => {
855+
ty::MethodOrigin::Trait => {
856856
let method = self.tcx.impl_or_trait_item(callee.def_id);
857857
self.report_error(self.ensure_public(span, method.container().id(),
858858
None, "source trait"));

src/librustc_trans/save/dump_csv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
892892
ty::MethodOrigin::Inherent => {
893893
(Some(method_callee.def_id), None)
894894
}
895-
ty::MethodOrigin::Trait | ty::MethodOrigin::Object(_) => {
895+
ty::MethodOrigin::Trait => {
896896
(None, Some(method_callee.def_id))
897897
}
898898
};

src/librustc_trans/trans/callee.rs

+50-89
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use arena::TypedArena;
2222
use back::link;
2323
use session;
2424
use llvm::{self, ValueRef, get_params};
25-
use metadata::csearch;
2625
use middle::def;
2726
use middle::subst;
2827
use middle::subst::{Subst, Substs};
@@ -66,7 +65,7 @@ pub struct MethodData {
6665
pub enum CalleeData<'tcx> {
6766
// Constructor for enum variant/tuple-like-struct
6867
// i.e. Some, Ok
69-
NamedTupleConstructor(subst::Substs<'tcx>, ty::Disr),
68+
NamedTupleConstructor(ty::Disr),
7069

7170
// Represents a (possibly monomorphized) top-level fn item or method
7271
// item. Note that this is just the fn-ptr and is not a Rust closure
@@ -81,6 +80,7 @@ pub enum CalleeData<'tcx> {
8180
pub struct Callee<'blk, 'tcx: 'blk> {
8281
pub bcx: Block<'blk, 'tcx>,
8382
pub data: CalleeData<'tcx>,
83+
pub ty: Ty<'tcx>
8484
}
8585

8686
fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
@@ -104,11 +104,11 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
104104
let DatumBlock { bcx, datum, .. } = expr::trans(bcx, expr);
105105
match datum.ty.sty {
106106
ty::TyBareFn(..) => {
107-
let llval = datum.to_llscalarish(bcx);
108-
return Callee {
107+
Callee {
109108
bcx: bcx,
110-
data: Fn(llval),
111-
};
109+
ty: datum.ty,
110+
data: Fn(datum.to_llscalarish(bcx))
111+
}
112112
}
113113
_ => {
114114
bcx.tcx().sess.span_bug(
@@ -119,12 +119,13 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
119119
}
120120
}
121121

122-
fn fn_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llfn: ValueRef)
122+
fn fn_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, datum: Datum<'tcx, Rvalue>)
123123
-> Callee<'blk, 'tcx> {
124-
return Callee {
124+
Callee {
125125
bcx: bcx,
126-
data: Fn(llfn),
127-
};
126+
data: Fn(datum.val),
127+
ty: datum.ty
128+
}
128129
}
129130

130131
fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
@@ -143,12 +144,10 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
143144
_ => false
144145
}
145146
} => {
146-
let substs = common::node_id_substs(bcx.ccx(),
147-
ExprId(ref_expr.id),
148-
bcx.fcx.param_substs);
149147
Callee {
150148
bcx: bcx,
151-
data: NamedTupleConstructor(substs, 0)
149+
data: NamedTupleConstructor(0),
150+
ty: expr_ty
152151
}
153152
}
154153
def::DefFn(did, _) if match expr_ty.sty {
@@ -159,40 +158,36 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
159158
ExprId(ref_expr.id),
160159
bcx.fcx.param_substs);
161160
let def_id = inline::maybe_instantiate_inline(bcx.ccx(), did);
162-
Callee { bcx: bcx, data: Intrinsic(def_id.node, substs) }
161+
Callee { bcx: bcx, data: Intrinsic(def_id.node, substs), ty: expr_ty }
163162
}
164163
def::DefFn(did, _) | def::DefMethod(did, def::FromImpl(_)) => {
165164
fn_callee(bcx, trans_fn_ref(bcx.ccx(), did, ExprId(ref_expr.id),
166-
bcx.fcx.param_substs).val)
165+
bcx.fcx.param_substs))
167166
}
168167
def::DefMethod(meth_did, def::FromTrait(trait_did)) => {
169168
fn_callee(bcx, meth::trans_static_method_callee(bcx.ccx(),
170169
meth_did,
171170
trait_did,
172171
ref_expr.id,
173-
bcx.fcx.param_substs).val)
172+
bcx.fcx.param_substs))
174173
}
175174
def::DefVariant(tid, vid, _) => {
176175
let vinfo = bcx.tcx().enum_variant_with_id(tid, vid);
177-
let substs = common::node_id_substs(bcx.ccx(),
178-
ExprId(ref_expr.id),
179-
bcx.fcx.param_substs);
180176

181177
// Nullary variants are not callable
182178
assert!(!vinfo.args.is_empty());
183179

184180
Callee {
185181
bcx: bcx,
186-
data: NamedTupleConstructor(substs, vinfo.disr_val)
182+
data: NamedTupleConstructor(vinfo.disr_val),
183+
ty: expr_ty
187184
}
188185
}
189186
def::DefStruct(_) => {
190-
let substs = common::node_id_substs(bcx.ccx(),
191-
ExprId(ref_expr.id),
192-
bcx.fcx.param_substs);
193187
Callee {
194188
bcx: bcx,
195-
data: NamedTupleConstructor(substs, 0)
189+
data: NamedTupleConstructor(0),
190+
ty: expr_ty
196191
}
197192
}
198193
def::DefStatic(..) |
@@ -232,21 +227,6 @@ pub fn trans_fn_ref<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
232227
trans_fn_ref_with_substs(ccx, def_id, node, param_substs, substs)
233228
}
234229

235-
fn trans_fn_ref_with_substs_to_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
236-
def_id: ast::DefId,
237-
ref_id: ast::NodeId,
238-
substs: subst::Substs<'tcx>)
239-
-> Callee<'blk, 'tcx> {
240-
Callee {
241-
bcx: bcx,
242-
data: Fn(trans_fn_ref_with_substs(bcx.ccx(),
243-
def_id,
244-
ExprId(ref_id),
245-
bcx.fcx.param_substs,
246-
substs).val),
247-
}
248-
}
249-
250230
/// Translates an adapter that implements the `Fn` trait for a fn
251231
/// pointer. This is basically the equivalent of something like:
252232
///
@@ -356,12 +336,13 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
356336
expr::SaveIn(fcx.get_ret_slot(bcx, sig.output, "ret_slot"))
357337
);
358338

359-
bcx = trans_call_inner(bcx,
360-
DebugLoc::None,
361-
bare_fn_ty,
362-
|bcx, _| Callee { bcx: bcx, data: Fn(llfnpointer) },
363-
ArgVals(&llargs[(self_idx + 1)..]),
364-
dest).bcx;
339+
bcx = trans_call_inner(bcx, DebugLoc::None, |bcx, _| {
340+
Callee {
341+
bcx: bcx,
342+
data: Fn(llfnpointer),
343+
ty: bare_fn_ty
344+
}
345+
}, ArgVals(&llargs[(self_idx + 1)..]), dest).bcx;
365346

366347
finish_fn(&fcx, bcx, sig.output, DebugLoc::None);
367348

@@ -586,17 +567,16 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
586567
// ______________________________________________________________________
587568
// Translating calls
588569

589-
pub fn trans_call<'a, 'blk, 'tcx>(in_cx: Block<'blk, 'tcx>,
570+
pub fn trans_call<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
590571
call_expr: &ast::Expr,
591572
f: &ast::Expr,
592573
args: CallArgs<'a, 'tcx>,
593574
dest: expr::Dest)
594575
-> Block<'blk, 'tcx> {
595576
let _icx = push_ctxt("trans_call");
596-
trans_call_inner(in_cx,
577+
trans_call_inner(bcx,
597578
call_expr.debug_loc(),
598-
common::expr_ty_adjusted(in_cx, f),
599-
|cx, _| trans(cx, f),
579+
|bcx, _| trans(bcx, f),
600580
args,
601581
Some(dest)).bcx
602582
}
@@ -610,22 +590,9 @@ pub fn trans_method_call<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
610590
let _icx = push_ctxt("trans_method_call");
611591
debug!("trans_method_call(call_expr={:?})", call_expr);
612592
let method_call = MethodCall::expr(call_expr.id);
613-
let method_ty = match bcx.tcx().tables.borrow().method_map.get(&method_call) {
614-
Some(method) => match method.origin {
615-
ty::MethodOrigin::Object(_) => match method.ty.sty {
616-
ty::TyBareFn(_, ref fty) => {
617-
bcx.tcx().mk_fn(None, meth::opaque_method_ty(bcx.tcx(), fty))
618-
}
619-
_ => method.ty
620-
},
621-
_ => method.ty
622-
},
623-
None => panic!("method not found in trans_method_call")
624-
};
625593
trans_call_inner(
626594
bcx,
627595
call_expr.debug_loc(),
628-
common::monomorphize_type(bcx, method_ty),
629596
|cx, arg_cleanup_scope| {
630597
meth::trans_method_callee(cx, method_call, Some(rcvr), arg_cleanup_scope)
631598
},
@@ -639,22 +606,18 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
639606
dest: Option<expr::Dest>,
640607
debug_loc: DebugLoc)
641608
-> Result<'blk, 'tcx> {
642-
let fty = if did.krate == ast::LOCAL_CRATE {
643-
bcx.tcx().node_id_to_type(did.node)
644-
} else {
645-
csearch::get_type(bcx.tcx(), did).ty
646-
};
647-
callee::trans_call_inner(bcx,
648-
debug_loc,
649-
fty,
650-
|bcx, _| {
651-
trans_fn_ref_with_substs_to_callee(bcx,
652-
did,
653-
0,
654-
subst::Substs::trans_empty())
655-
},
656-
ArgVals(args),
657-
dest)
609+
callee::trans_call_inner(bcx, debug_loc, |bcx, _| {
610+
let datum = trans_fn_ref_with_substs(bcx.ccx(),
611+
did,
612+
ExprId(0),
613+
bcx.fcx.param_substs,
614+
subst::Substs::trans_empty());
615+
Callee {
616+
bcx: bcx,
617+
data: Fn(datum.val),
618+
ty: datum.ty
619+
}
620+
}, ArgVals(args), dest)
658621
}
659622

660623
/// This behemoth of a function translates function calls. Unfortunately, in order to generate more
@@ -669,7 +632,6 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
669632
/// somewhere. Nonetheless we return the actual return value of the function.
670633
pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
671634
debug_loc: DebugLoc,
672-
callee_ty: Ty<'tcx>,
673635
get_callee: F,
674636
args: CallArgs<'a, 'tcx>,
675637
dest: Option<expr::Dest>)
@@ -690,7 +652,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
690652
let callee = get_callee(bcx, cleanup::CustomScope(arg_cleanup_scope));
691653
let mut bcx = callee.bcx;
692654

693-
let (abi, ret_ty) = match callee_ty.sty {
655+
let (abi, ret_ty) = match callee.ty.sty {
694656
ty::TyBareFn(_, ref f) => {
695657
let output = bcx.tcx().erase_late_bound_regions(&f.sig.output());
696658
(f.abi, output)
@@ -716,18 +678,17 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
716678
}
717679
};
718680

719-
return intrinsic::trans_intrinsic_call(bcx, node, callee_ty,
681+
return intrinsic::trans_intrinsic_call(bcx, node, callee.ty,
720682
arg_cleanup_scope, args,
721683
dest.unwrap(), substs,
722684
call_info);
723685
}
724-
NamedTupleConstructor(substs, disr) => {
686+
NamedTupleConstructor(disr) => {
725687
assert!(dest.is_some());
726688
fcx.pop_custom_cleanup_scope(arg_cleanup_scope);
727689

728-
let ctor_ty = callee_ty.subst(bcx.tcx(), &substs);
729690
return base::trans_named_tuple_constructor(bcx,
730-
ctor_ty,
691+
callee.ty,
731692
disr,
732693
args,
733694
dest.unwrap(),
@@ -802,7 +763,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
802763
// Push the arguments.
803764
bcx = trans_args(bcx,
804765
args,
805-
callee_ty,
766+
callee.ty,
806767
&mut llargs,
807768
cleanup::CustomScope(arg_cleanup_scope),
808769
llself.is_some(),
@@ -814,7 +775,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
814775
let (llret, b) = base::invoke(bcx,
815776
llfn,
816777
&llargs[..],
817-
callee_ty,
778+
callee.ty,
818779
debug_loc);
819780
bcx = b;
820781
llresult = llret;
@@ -843,15 +804,15 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
843804
};
844805
bcx = trans_args(bcx,
845806
args,
846-
callee_ty,
807+
callee.ty,
847808
&mut llargs,
848809
cleanup::CustomScope(arg_cleanup_scope),
849810
false,
850811
abi);
851812
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
852813

853814
bcx = foreign::trans_native_call(bcx,
854-
callee_ty,
815+
callee.ty,
855816
llfn,
856817
opt_llretslot.unwrap(),
857818
&llargs[..],

src/librustc_trans/trans/closure.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
429429
let callee_data = TraitItem(MethodData { llfn: llreffn,
430430
llself: env_datum.val });
431431

432-
bcx = callee::trans_call_inner(bcx,
433-
DebugLoc::None,
434-
llref_fn_ty,
435-
|bcx, _| Callee { bcx: bcx, data: callee_data },
436-
ArgVals(&llargs[(self_idx + 1)..]),
437-
dest).bcx;
432+
bcx = callee::trans_call_inner(bcx, DebugLoc::None, |bcx, _| {
433+
Callee {
434+
bcx: bcx,
435+
data: callee_data,
436+
ty: llref_fn_ty
437+
}
438+
}, ArgVals(&llargs[(self_idx + 1)..]), dest).bcx;
438439

439440
fcx.pop_custom_cleanup_scope(self_scope);
440441

0 commit comments

Comments
 (0)