1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -18,6 +18,7 @@ use middle::trans::base::{trans_enum_variant, push_ctxt, get_item_val};
18
18
use middle:: trans:: base:: { trans_fn, decl_internal_rust_fn} ;
19
19
use middle:: trans:: base;
20
20
use middle:: trans:: common:: * ;
21
+ use middle:: trans:: foreign;
21
22
use middle:: ty;
22
23
use middle:: typeck;
23
24
use util:: ppaux:: Repr ;
@@ -123,19 +124,29 @@ pub fn monomorphic_fn(ccx: &CrateContext,
123
124
monomorphizing. insert ( fn_id, depth + 1 ) ;
124
125
}
125
126
126
- let s = ccx. tcx . map . with_path ( fn_id. node , |path| {
127
+ let hash;
128
+ let s = {
127
129
let mut state = sip:: SipState :: new ( ) ;
128
130
hash_id. hash ( & mut state) ;
129
131
mono_ty. hash ( & mut state) ;
130
132
131
- exported_name ( path, format ! ( "h{}" , state. result( ) ) . as_slice ( ) )
132
- } ) ;
133
+ hash = format ! ( "h{}" , state. result( ) ) ;
134
+ ccx. tcx . map . with_path ( fn_id. node , |path| {
135
+ exported_name ( path, hash. as_slice ( ) )
136
+ } )
137
+ } ;
138
+
133
139
debug ! ( "monomorphize_fn mangled to {}" , s) ;
134
140
135
141
// This shouldn't need to option dance.
136
142
let mut hash_id = Some ( hash_id) ;
137
- let mk_lldecl = || {
138
- let lldecl = decl_internal_rust_fn ( ccx, mono_ty, s. as_slice ( ) ) ;
143
+ let mk_lldecl = |abi : abi:: Abi | {
144
+ let lldecl = if abi != abi:: Rust {
145
+ foreign:: decl_rust_fn_with_foreign_abi ( ccx, mono_ty, s. as_slice ( ) )
146
+ } else {
147
+ decl_internal_rust_fn ( ccx, mono_ty, s. as_slice ( ) )
148
+ } ;
149
+
139
150
ccx. monomorphized . borrow_mut ( ) . insert ( hash_id. take_unwrap ( ) , lldecl) ;
140
151
lldecl
141
152
} ;
@@ -144,13 +155,21 @@ pub fn monomorphic_fn(ccx: &CrateContext,
144
155
ast_map:: NodeItem ( i) => {
145
156
match * i {
146
157
ast:: Item {
147
- node : ast:: ItemFn ( ref decl, _, _ , _, ref body) ,
158
+ node : ast:: ItemFn ( ref decl, _, abi , _, ref body) ,
148
159
..
149
160
} => {
150
- let d = mk_lldecl ( ) ;
161
+ let d = mk_lldecl ( abi ) ;
151
162
set_llvm_fn_attrs ( i. attrs . as_slice ( ) , d) ;
152
- trans_fn ( ccx, & * * decl, & * * body, d, & psubsts, fn_id. node , [ ] ,
153
- IgnoreItems ) ;
163
+
164
+ if abi != abi:: Rust {
165
+ foreign:: trans_rust_fn_with_foreign_abi (
166
+ ccx, & * * decl, & * * body, [ ] , d, & psubsts, fn_id. node ,
167
+ Some ( hash. as_slice ( ) ) ) ;
168
+ } else {
169
+ trans_fn ( ccx, & * * decl, & * * body, d, & psubsts, fn_id. node , [ ] ,
170
+ IgnoreItems ) ;
171
+ }
172
+
154
173
d
155
174
}
156
175
_ => {
@@ -162,7 +181,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
162
181
let parent = ccx. tcx . map . get_parent ( fn_id. node ) ;
163
182
let tvs = ty:: enum_variants ( ccx. tcx ( ) , local_def ( parent) ) ;
164
183
let this_tv = tvs. iter ( ) . find ( |tv| { tv. id . node == fn_id. node } ) . unwrap ( ) ;
165
- let d = mk_lldecl ( ) ;
184
+ let d = mk_lldecl ( abi :: Rust ) ;
166
185
set_inline_hint ( d) ;
167
186
match v. node . kind {
168
187
ast:: TupleVariantKind ( ref args) => {
@@ -180,7 +199,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
180
199
d
181
200
}
182
201
ast_map:: NodeMethod ( mth) => {
183
- let d = mk_lldecl ( ) ;
202
+ let d = mk_lldecl ( abi :: Rust ) ;
184
203
set_llvm_fn_attrs ( mth. attrs . as_slice ( ) , d) ;
185
204
trans_fn ( ccx, & * mth. pe_fn_decl ( ) , & * mth. pe_body ( ) , d, & psubsts, mth. id , [ ] ,
186
205
IgnoreItems ) ;
@@ -189,7 +208,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
189
208
ast_map:: NodeTraitMethod ( method) => {
190
209
match * method {
191
210
ast:: Provided ( mth) => {
192
- let d = mk_lldecl ( ) ;
211
+ let d = mk_lldecl ( abi :: Rust ) ;
193
212
set_llvm_fn_attrs ( mth. attrs . as_slice ( ) , d) ;
194
213
trans_fn ( ccx, & * mth. pe_fn_decl ( ) , & * mth. pe_body ( ) , d,
195
214
& psubsts, mth. id , [ ] , IgnoreItems ) ;
@@ -202,7 +221,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
202
221
}
203
222
}
204
223
ast_map:: NodeStructCtor ( struct_def) => {
205
- let d = mk_lldecl ( ) ;
224
+ let d = mk_lldecl ( abi :: Rust ) ;
206
225
set_inline_hint ( d) ;
207
226
base:: trans_tuple_struct ( ccx,
208
227
struct_def. fields . as_slice ( ) ,
@@ -230,7 +249,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
230
249
ccx. monomorphizing . borrow_mut ( ) . insert ( fn_id, depth) ;
231
250
232
251
debug ! ( "leaving monomorphic fn {}" , ty:: item_path_str( ccx. tcx( ) , fn_id) ) ;
233
- ( lldecl, false )
252
+ ( lldecl, true )
234
253
}
235
254
236
255
// Used to identify cached monomorphized functions and vtables
0 commit comments