@@ -2248,16 +2248,20 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
2248
2248
2249
2249
let r = match datum. ty . sty {
2250
2250
ty:: ty_uniq( content_ty) => {
2251
+ // Make sure we have an lvalue datum here to get the
2252
+ // proper cleanups scheduled
2253
+ let datum = unpack_datum ! (
2254
+ bcx, datum. to_lvalue_datum( bcx, "deref" , expr. id) ) ;
2255
+
2251
2256
if type_is_sized ( bcx. tcx ( ) , content_ty) {
2252
- deref_owned_pointer ( bcx, expr, datum, content_ty)
2257
+ let ptr = load_ty ( bcx, datum. val , datum. ty ) ;
2258
+ DatumBlock :: new ( bcx, Datum :: new ( ptr, content_ty, LvalueExpr ) )
2253
2259
} else {
2254
2260
// A fat pointer and a DST lvalue have the same representation
2255
2261
// just different types. Since there is no temporary for `*e`
2256
2262
// here (because it is unsized), we cannot emulate the sized
2257
2263
// object code path for running drop glue and free. Instead,
2258
2264
// we schedule cleanup for `e`, turning it into an lvalue.
2259
- let datum = unpack_datum ! (
2260
- bcx, datum. to_lvalue_datum( bcx, "deref" , expr. id) ) ;
2261
2265
2262
2266
let datum = Datum :: new ( datum. val , content_ty, LvalueExpr ) ;
2263
2267
DatumBlock :: new ( bcx, datum)
@@ -2294,53 +2298,6 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
2294
2298
expr. id, method_call, r. datum. to_string( ccx) ) ;
2295
2299
2296
2300
return r;
2297
-
2298
- /// We microoptimize derefs of owned pointers a bit here. Basically, the idea is to make the
2299
- /// deref of an rvalue result in an rvalue. This helps to avoid intermediate stack slots in the
2300
- /// resulting LLVM. The idea here is that, if the `Box<T>` pointer is an rvalue, then we can
2301
- /// schedule a *shallow* free of the `Box<T>` pointer, and then return a ByRef rvalue into the
2302
- /// pointer. Because the free is shallow, it is legit to return an rvalue, because we know that
2303
- /// the contents are not yet scheduled to be freed. The language rules ensure that the contents
2304
- /// will be used (or moved) before the free occurs.
2305
- fn deref_owned_pointer < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
2306
- expr : & ast:: Expr ,
2307
- datum : Datum < ' tcx , Expr > ,
2308
- content_ty : Ty < ' tcx > )
2309
- -> DatumBlock < ' blk , ' tcx , Expr > {
2310
- match datum. kind {
2311
- RvalueExpr ( Rvalue { mode : ByRef } ) => {
2312
- let scope = cleanup:: temporary_scope ( bcx. tcx ( ) , expr. id ) ;
2313
- let ptr = Load ( bcx, datum. val ) ;
2314
- if !type_is_zero_size ( bcx. ccx ( ) , content_ty) {
2315
- bcx. fcx . schedule_free_value ( scope, ptr, cleanup:: HeapExchange , content_ty) ;
2316
- }
2317
- }
2318
- RvalueExpr ( Rvalue { mode : ByValue } ) => {
2319
- let scope = cleanup:: temporary_scope ( bcx. tcx ( ) , expr. id ) ;
2320
- if !type_is_zero_size ( bcx. ccx ( ) , content_ty) {
2321
- bcx. fcx . schedule_free_value ( scope, datum. val , cleanup:: HeapExchange ,
2322
- content_ty) ;
2323
- }
2324
- }
2325
- LvalueExpr => { }
2326
- }
2327
-
2328
- // If we had an rvalue in, we produce an rvalue out.
2329
- let ( llptr, kind) = match datum. kind {
2330
- LvalueExpr => {
2331
- ( Load ( bcx, datum. val ) , LvalueExpr )
2332
- }
2333
- RvalueExpr ( Rvalue { mode : ByRef } ) => {
2334
- ( Load ( bcx, datum. val ) , RvalueExpr ( Rvalue :: new ( ByRef ) ) )
2335
- }
2336
- RvalueExpr ( Rvalue { mode : ByValue } ) => {
2337
- ( datum. val , RvalueExpr ( Rvalue :: new ( ByRef ) ) )
2338
- }
2339
- } ;
2340
-
2341
- let datum = Datum { ty : content_ty, val : llptr, kind : kind } ;
2342
- DatumBlock { bcx : bcx, datum : datum }
2343
- }
2344
2301
}
2345
2302
2346
2303
#[ derive( Debug ) ]
0 commit comments