@@ -20,8 +20,7 @@ use middle::subst;
20
20
use middle:: traits:: { self , ProjectionMode } ;
21
21
use trans:: base:: * ;
22
22
use trans:: build:: * ;
23
- use trans:: callee:: { Callee , Virtual , ArgVals ,
24
- trans_fn_pointer_shim, trans_fn_ref_with_substs} ;
23
+ use trans:: callee:: { Callee , Virtual , ArgVals , trans_fn_pointer_shim} ;
25
24
use trans:: closure;
26
25
use trans:: common:: * ;
27
26
use trans:: consts;
@@ -37,130 +36,11 @@ use trans::value::Value;
37
36
use middle:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
38
37
39
38
use syntax:: ast:: { self , Name } ;
40
- use syntax:: attr;
41
39
use syntax:: codemap:: DUMMY_SP ;
42
40
43
- use rustc_front:: hir;
44
-
45
41
// drop_glue pointer, size, align.
46
42
const VTABLE_OFFSET : usize = 3 ;
47
43
48
- /// The main "translation" pass for methods. Generates code
49
- /// for non-monomorphized methods only. Other methods will
50
- /// be generated once they are invoked with specific type parameters,
51
- /// see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
52
- pub fn trans_impl ( ccx : & CrateContext ,
53
- name : ast:: Name ,
54
- impl_items : & [ hir:: ImplItem ] ,
55
- generics : & hir:: Generics ,
56
- id : ast:: NodeId ) {
57
- let _icx = push_ctxt ( "meth::trans_impl" ) ;
58
- let tcx = ccx. tcx ( ) ;
59
-
60
- debug ! ( "trans_impl(name={}, id={})" , name, id) ;
61
-
62
- // Both here and below with generic methods, be sure to recurse and look for
63
- // items that we need to translate.
64
- if !generics. ty_params . is_empty ( ) {
65
- return ;
66
- }
67
-
68
- for impl_item in impl_items {
69
- match impl_item. node {
70
- hir:: ImplItemKind :: Method ( ref sig, ref body) => {
71
- if sig. generics . ty_params . is_empty ( ) {
72
- let trans_everywhere = attr:: requests_inline ( & impl_item. attrs ) ;
73
- for ( ref ccx, is_origin) in ccx. maybe_iter ( trans_everywhere) {
74
- let llfn = get_item_val ( ccx, impl_item. id ) ;
75
- let empty_substs = tcx. mk_substs ( Substs :: trans_empty ( ) ) ;
76
- trans_fn ( ccx,
77
- & sig. decl ,
78
- body,
79
- llfn,
80
- empty_substs,
81
- impl_item. id ,
82
- & impl_item. attrs ) ;
83
- update_linkage ( ccx,
84
- llfn,
85
- Some ( impl_item. id ) ,
86
- if is_origin { OriginalTranslation } else { InlinedCopy } ) ;
87
- }
88
- }
89
- }
90
- _ => { }
91
- }
92
- }
93
- }
94
-
95
- /// Compute the appropriate callee, give na method's ID, trait ID,
96
- /// substitutions and a Vtable for that trait.
97
- pub fn callee_for_trait_impl < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
98
- method_id : DefId ,
99
- substs : & ' tcx subst:: Substs < ' tcx > ,
100
- trait_id : DefId ,
101
- method_ty : Ty < ' tcx > ,
102
- vtable : traits:: Vtable < ' tcx , ( ) > )
103
- -> Callee < ' tcx > {
104
- let _icx = push_ctxt ( "meth::callee_for_trait_impl" ) ;
105
- match vtable {
106
- traits:: VtableImpl ( vtable_impl) => {
107
- let impl_did = vtable_impl. impl_def_id ;
108
- let mname = ccx. tcx ( ) . item_name ( method_id) ;
109
- // create a concatenated set of substitutions which includes
110
- // those from the impl and those from the method:
111
- let impl_substs = vtable_impl. substs . with_method_from ( & substs) ;
112
- let substs = ccx. tcx ( ) . mk_substs ( impl_substs) ;
113
- let mth = get_impl_method ( ccx. tcx ( ) , impl_did, substs, mname) ;
114
-
115
- // Translate the function, bypassing Callee::def.
116
- // That is because default methods have the same ID as the
117
- // trait method used to look up the impl method that ended
118
- // up here, so calling Callee::def would infinitely recurse.
119
- Callee :: ptr ( trans_fn_ref_with_substs ( ccx, mth. method . def_id ,
120
- Some ( method_ty) , mth. substs ) )
121
- }
122
- traits:: VtableClosure ( vtable_closure) => {
123
- // The substitutions should have no type parameters remaining
124
- // after passing through fulfill_obligation
125
- let trait_closure_kind = ccx. tcx ( ) . lang_items . fn_trait_kind ( trait_id) . unwrap ( ) ;
126
- let llfn = closure:: trans_closure_method ( ccx,
127
- vtable_closure. closure_def_id ,
128
- vtable_closure. substs ,
129
- trait_closure_kind) ;
130
- let fn_ptr_ty = match method_ty. sty {
131
- ty:: TyFnDef ( _, _, fty) => ccx. tcx ( ) . mk_ty ( ty:: TyFnPtr ( fty) ) ,
132
- _ => unreachable ! ( "expected fn item type, found {}" ,
133
- method_ty)
134
- } ;
135
- Callee :: ptr ( immediate_rvalue ( llfn, fn_ptr_ty) )
136
- }
137
- traits:: VtableFnPointer ( fn_ty) => {
138
- let trait_closure_kind = ccx. tcx ( ) . lang_items . fn_trait_kind ( trait_id) . unwrap ( ) ;
139
- let llfn = trans_fn_pointer_shim ( ccx, trait_closure_kind, fn_ty) ;
140
- let fn_ptr_ty = match method_ty. sty {
141
- ty:: TyFnDef ( _, _, fty) => ccx. tcx ( ) . mk_ty ( ty:: TyFnPtr ( fty) ) ,
142
- _ => unreachable ! ( "expected fn item type, found {}" ,
143
- method_ty)
144
- } ;
145
- Callee :: ptr ( immediate_rvalue ( llfn, fn_ptr_ty) )
146
- }
147
- traits:: VtableObject ( ref data) => {
148
- Callee {
149
- data : Virtual ( traits:: get_vtable_index_of_object_method (
150
- ccx. tcx ( ) , data, method_id) ) ,
151
- ty : method_ty
152
- }
153
- }
154
- traits:: VtableBuiltin ( ..) |
155
- traits:: VtableDefaultImpl ( ..) |
156
- traits:: VtableParam ( ..) => {
157
- ccx. sess ( ) . bug (
158
- & format ! ( "resolved vtable bad vtable {:?} in trans" ,
159
- vtable) ) ;
160
- }
161
- }
162
- }
163
-
164
44
/// Extracts a method from a trait object's vtable, at the
165
45
/// specified index, and casts it to the given type.
166
46
pub fn get_virtual_method < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
0 commit comments