@@ -2257,6 +2257,7 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
2257
2257
ret { bcx : bcx, val : val, kind : owned} ;
2258
2258
}
2259
2259
2260
+
2260
2261
fn trans_index ( cx : block , ex : @ast:: expr , base : @ast:: expr ,
2261
2262
idx : @ast:: expr ) -> lval_result {
2262
2263
let _icx = cx. insn_ctxt ( "trans_index" ) ;
@@ -2286,43 +2287,17 @@ fn trans_index(cx: block, ex: @ast::expr, base: @ast::expr,
2286
2287
let scaled_ix = Mul ( bcx, ix_val, unit_sz) ;
2287
2288
maybe_name_value ( cx. ccx ( ) , scaled_ix, "scaled_ix" ) ;
2288
2289
2289
- let ( lim, body) = alt ty:: get ( base_ty) . struct {
2290
- ty:: ty_estr ( ty:: vstore_fixed ( n) ) |
2291
- ty:: ty_evec ( _, ty:: vstore_fixed ( n) ) {
2292
- // FIXME: support static bounds-check elimination
2293
- // and/or error checking here.
2294
- let lim = C_uint ( bcx. ccx ( ) , n) ;
2295
- let body = GEPi ( bcx, v, [ 0 , 0 ] ) ;
2296
- ( lim, body)
2297
- }
2298
-
2299
- ty:: ty_estr ( ty:: vstore_slice ( _) ) |
2300
- ty:: ty_evec ( _, ty:: vstore_slice ( _) ) {
2301
- let body = Load ( bcx, GEPi ( bcx, v, [ 0 , abi:: slice_elt_base] ) ) ;
2302
- let lim = Load ( bcx, GEPi ( bcx, v, [ 0 , abi:: slice_elt_len] ) ) ;
2303
- ( lim, body)
2304
- }
2305
-
2306
- ty:: ty_estr ( ty:: vstore_box) | ty:: ty_evec ( _, ty:: vstore_box) {
2307
- bcx. sess ( ) . unimpl ( #fmt ( "unsupported evec/estr type trans_index" ) ) ;
2308
- }
2309
-
2310
- _ {
2311
- let lim = tvec:: get_fill ( bcx, v) ;
2312
- let body = tvec:: get_dataptr ( bcx, v, type_of ( ccx, unit_ty) ) ;
2313
- ( lim, body)
2314
- }
2315
- } ;
2290
+ let ( base, len) = tvec:: get_base_and_len ( bcx, v, base_ty) ;
2316
2291
2317
- #debug ( "trans_index: lim %s" , val_str ( bcx. ccx ( ) . tn , lim ) ) ;
2318
- #debug ( "trans_index: body %s" , val_str ( bcx. ccx ( ) . tn , body ) ) ;
2292
+ #debug ( "trans_index: base %s" , val_str ( bcx. ccx ( ) . tn , base ) ) ;
2293
+ #debug ( "trans_index: len %s" , val_str ( bcx. ccx ( ) . tn , len ) ) ;
2319
2294
2320
- let bounds_check = ICmp ( bcx, lib:: llvm:: IntUGE , scaled_ix, lim ) ;
2295
+ let bounds_check = ICmp ( bcx, lib:: llvm:: IntUGE , scaled_ix, len ) ;
2321
2296
let bcx = with_cond ( bcx, bounds_check) { |bcx|
2322
2297
// fail: bad bounds check.
2323
2298
trans_fail ( bcx, some ( ex. span ) , "bounds check" )
2324
2299
} ;
2325
- let elt = InBoundsGEP ( bcx, body , [ ix_val] ) ;
2300
+ let elt = InBoundsGEP ( bcx, base , [ ix_val] ) ;
2326
2301
ret lval_owned( bcx, PointerCast ( bcx, elt, T_ptr ( llunitty) ) ) ;
2327
2302
}
2328
2303
@@ -2543,6 +2518,7 @@ fn trans_loop_body(bcx: block, e: @ast::expr, ret_flag: option<ValueRef>,
2543
2518
fn trans_arg_expr ( cx : block , arg : ty:: arg , lldestty : TypeRef , e : @ast:: expr ,
2544
2519
& temp_cleanups: [ ValueRef ] , ret_flag : option < ValueRef > )
2545
2520
-> result {
2521
+ #debug ( "+++ trans_arg_expr on %s" , expr_to_str ( e) ) ;
2546
2522
let _icx = cx. insn_ctxt ( "trans_arg_expr" ) ;
2547
2523
let ccx = cx. ccx ( ) ;
2548
2524
let e_ty = expr_ty ( cx, e) ;
@@ -2563,6 +2539,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
2563
2539
let lv = adapt_borrowed_value ( lv, arg, e) ;
2564
2540
let mut bcx = lv. bcx ;
2565
2541
let mut val = lv. val ;
2542
+ #debug ( " adapted value: %s" , val_str ( bcx. ccx ( ) . tn , val) ) ;
2566
2543
let arg_mode = ty:: resolved_mode ( ccx. tcx , arg. mode ) ;
2567
2544
if is_bot {
2568
2545
// For values of type _|_, we generate an
@@ -2572,50 +2549,52 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
2572
2549
val = llvm:: LLVMGetUndef ( lldestty) ;
2573
2550
} else if arg_mode == ast:: by_ref || arg_mode == ast:: by_val {
2574
2551
let mut copied = false ;
2575
- let imm = ty:: type_is_immediate ( e_ty ) ;
2552
+ let imm = ty:: type_is_immediate ( arg . ty ) ;
2576
2553
if arg_mode == ast:: by_ref && lv. kind != owned && imm {
2577
2554
val = do_spill_noroot ( bcx, val) ;
2578
2555
copied = true ;
2579
2556
}
2580
2557
if ccx. maps . copy_map . contains_key ( e. id ) && lv. kind != temporary {
2581
2558
if !copied {
2582
- let alloc = alloc_ty ( bcx, e_ty ) ;
2559
+ let alloc = alloc_ty ( bcx, arg . ty ) ;
2583
2560
bcx = copy_val ( bcx, INIT , alloc,
2584
- load_if_immediate ( bcx, val, e_ty ) , e_ty ) ;
2561
+ load_if_immediate ( bcx, val, arg . ty ) , arg . ty ) ;
2585
2562
val = alloc;
2586
- } else { bcx = take_ty ( bcx, val, e_ty ) ; }
2587
- add_clean ( bcx, val, e_ty ) ;
2563
+ } else { bcx = take_ty ( bcx, val, arg . ty ) ; }
2564
+ add_clean ( bcx, val, arg . ty ) ;
2588
2565
}
2589
2566
if arg_mode == ast:: by_val && ( lv. kind == owned || !imm) {
2590
2567
val = Load ( bcx, val) ;
2591
2568
}
2592
2569
} else if arg_mode == ast:: by_copy || arg_mode == ast:: by_move {
2593
- let alloc = alloc_ty ( bcx, e_ty ) ;
2570
+ let alloc = alloc_ty ( bcx, arg . ty ) ;
2594
2571
let move_out = arg_mode == ast:: by_move ||
2595
2572
ccx. maps . last_uses . contains_key ( e. id ) ;
2596
2573
if lv. kind == temporary { revoke_clean ( bcx, val) ; }
2597
- if lv. kind == owned || !ty:: type_is_immediate ( e_ty ) {
2598
- memmove_ty ( bcx, alloc, val, e_ty ) ;
2599
- if move_out && ty:: type_needs_drop ( ccx. tcx , e_ty ) {
2600
- bcx = zero_alloca ( bcx, val, e_ty ) ;
2574
+ if lv. kind == owned || !ty:: type_is_immediate ( arg . ty ) {
2575
+ memmove_ty ( bcx, alloc, val, arg . ty ) ;
2576
+ if move_out && ty:: type_needs_drop ( ccx. tcx , arg . ty ) {
2577
+ bcx = zero_alloca ( bcx, val, arg . ty ) ;
2601
2578
}
2602
2579
} else { Store ( bcx, val, alloc) ; }
2603
2580
val = alloc;
2604
2581
if lv. kind != temporary && !move_out {
2605
- bcx = take_ty ( bcx, val, e_ty ) ;
2582
+ bcx = take_ty ( bcx, val, arg . ty ) ;
2606
2583
}
2607
2584
2608
2585
// In the event that failure occurs before the call actually
2609
2586
// happens, have to cleanup this copy:
2610
- add_clean_temp_mem ( bcx, val, e_ty ) ;
2587
+ add_clean_temp_mem ( bcx, val, arg . ty ) ;
2611
2588
temp_cleanups += [ val] ;
2612
- } else if ty:: type_is_immediate ( e_ty ) && lv. kind != owned {
2613
- val = do_spill ( bcx, val, e_ty ) ;
2589
+ } else if ty:: type_is_immediate ( arg . ty ) && lv. kind != owned {
2590
+ val = do_spill ( bcx, val, arg . ty ) ;
2614
2591
}
2615
2592
2616
2593
if !is_bot && arg. ty != e_ty || ty:: type_has_params ( arg. ty ) {
2594
+ #debug ( " casting from %s" , val_str ( bcx. ccx ( ) . tn , val) ) ;
2617
2595
val = PointerCast ( bcx, val, lldestty) ;
2618
2596
}
2597
+ #debug ( "--- trans_arg_expr passing %s" , val_str ( bcx. ccx ( ) . tn , val) ) ;
2619
2598
ret rslt( bcx, val) ;
2620
2599
}
2621
2600
@@ -2642,25 +2621,17 @@ fn adapt_borrowed_value(lv: lval_result, _arg: ty::arg,
2642
2621
ret lv; // no change needed at runtime (I think)
2643
2622
}
2644
2623
2645
- ty:: ty_estr ( ty:: vstore_box) |
2646
- ty:: ty_evec ( _, ty:: vstore_box) {
2647
- bcx. tcx ( ) . sess . span_unimpl (
2648
- e. span , #fmt[ "borrowing a value of type %s" ,
2649
- ty_to_str ( bcx. tcx ( ) , e_ty) ] ) ;
2650
- }
2651
-
2652
- ty:: ty_estr ( ty:: vstore_uniq) |
2653
- ty:: ty_evec ( _, ty:: vstore_uniq) {
2654
- bcx. tcx ( ) . sess . span_unimpl (
2655
- e. span , #fmt[ "borrowing a value of type %s" ,
2656
- ty_to_str ( bcx. tcx ( ) , e_ty) ] ) ;
2657
- }
2658
-
2659
- ty:: ty_estr ( ty:: vstore_fixed ( _) ) |
2660
- ty:: ty_evec ( _, ty:: vstore_fixed ( _) ) {
2661
- bcx. tcx ( ) . sess . span_unimpl (
2662
- e. span , #fmt[ "borrowing a value of type %s" ,
2663
- ty_to_str ( bcx. tcx ( ) , e_ty) ] ) ;
2624
+ ty:: ty_str | ty:: ty_vec ( _) |
2625
+ ty:: ty_estr ( _) |
2626
+ ty:: ty_evec ( _, _) {
2627
+ let ccx = bcx. ccx ( ) ;
2628
+ let unit_ty = ty:: sequence_element_type ( ccx. tcx , e_ty) ;
2629
+ let llunit_ty = type_of ( ccx, unit_ty) ;
2630
+ let ( base, len) = tvec:: get_base_and_len ( bcx, lv. val , e_ty) ;
2631
+ let p = alloca ( bcx, T_struct ( [ T_ptr ( llunit_ty) , ccx. int_type ] ) ) ;
2632
+ Store ( bcx, base, GEPi ( bcx, p, [ 0 , abi:: slice_elt_base] ) ) ;
2633
+ Store ( bcx, len, GEPi ( bcx, p, [ 0 , abi:: slice_elt_len] ) ) ;
2634
+ ret lval_temp( bcx, p) ;
2664
2635
}
2665
2636
2666
2637
_ {
0 commit comments