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