@@ -619,6 +619,14 @@ fn trans_rvalue_datum_unadjusted<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
619
619
return tvec:: trans_uniq_or_managed_vstore ( bcx, heap,
620
620
expr, contents) ;
621
621
}
622
+ ast:: ExprBox ( _, contents) => {
623
+ // Special case for `~T`. (The other case, for GC, is handled in
624
+ // `trans_rvalue_dps_unadjusted`.)
625
+ let box_ty = expr_ty ( bcx, expr) ;
626
+ let contents_ty = expr_ty ( bcx, contents) ;
627
+ let heap = heap_for_unique ( bcx, contents_ty) ;
628
+ return trans_boxed_expr ( bcx, box_ty, contents, contents_ty, heap)
629
+ }
622
630
ast:: ExprLit ( lit) => {
623
631
return trans_immediate_lit ( bcx, expr, * lit) ;
624
632
}
@@ -828,6 +836,11 @@ fn trans_rvalue_dps_unadjusted<'a>(
828
836
ast:: ExprAssignOp ( callee_id, op, dst, src) => {
829
837
return trans_assign_op ( bcx, expr, callee_id, op, dst, src) ;
830
838
}
839
+ ast:: ExprBox ( _, contents) => {
840
+ // Special case for `Gc<T>` for now. The other case, for unique
841
+ // pointers, is handled in `trans_rvalue_datum_unadjusted`.
842
+ return trans_gc ( bcx, expr, contents, dest)
843
+ }
831
844
_ => {
832
845
bcx. tcx ( ) . sess . span_bug (
833
846
expr. span ,
@@ -1463,35 +1476,35 @@ fn trans_unary_datum<'a>(
1463
1476
trans_unary_datum()")
1464
1477
}
1465
1478
} ;
1479
+ }
1466
1480
1467
- fn trans_boxed_expr < ' a > (
1468
- bcx : & ' a Block < ' a > ,
1469
- box_ty : ty:: t ,
1470
- contents : & ast:: Expr ,
1471
- contents_ty : ty:: t ,
1472
- heap : heap )
1473
- -> DatumBlock < ' a > {
1474
- let _icx = push_ctxt ( "trans_boxed_expr" ) ;
1475
- if heap == heap_exchange {
1476
- let llty = type_of:: type_of ( bcx. ccx ( ) , contents_ty) ;
1477
- let size = llsize_of ( bcx. ccx ( ) , llty) ;
1478
- let Result { bcx : bcx, val : val } = malloc_raw_dyn ( bcx, contents_ty,
1479
- heap_exchange, size) ;
1480
- add_clean_free ( bcx, val, heap_exchange) ;
1481
- let bcx = trans_into ( bcx, contents, SaveIn ( val) ) ;
1482
- revoke_clean ( bcx, val) ;
1483
- return immediate_rvalue_bcx ( bcx, val, box_ty) ;
1484
- } else {
1485
- let base:: MallocResult {
1486
- bcx,
1487
- smart_ptr : bx,
1488
- body
1489
- } = base:: malloc_general ( bcx, contents_ty, heap) ;
1490
- add_clean_free ( bcx, bx, heap) ;
1491
- let bcx = trans_into ( bcx, contents, SaveIn ( body) ) ;
1492
- revoke_clean ( bcx, bx) ;
1493
- return immediate_rvalue_bcx ( bcx, bx, box_ty) ;
1494
- }
1481
+ fn trans_boxed_expr < ' a > (
1482
+ bcx : & ' a Block < ' a > ,
1483
+ box_ty : ty:: t ,
1484
+ contents : & ast:: Expr ,
1485
+ contents_ty : ty:: t ,
1486
+ heap : heap )
1487
+ -> DatumBlock < ' a > {
1488
+ let _icx = push_ctxt ( "trans_boxed_expr" ) ;
1489
+ if heap == heap_exchange {
1490
+ let llty = type_of:: type_of ( bcx. ccx ( ) , contents_ty) ;
1491
+ let size = llsize_of ( bcx. ccx ( ) , llty) ;
1492
+ let Result { bcx : bcx, val : val } = malloc_raw_dyn ( bcx, contents_ty,
1493
+ heap_exchange, size) ;
1494
+ add_clean_free ( bcx, val, heap_exchange) ;
1495
+ let bcx = trans_into ( bcx, contents, SaveIn ( val) ) ;
1496
+ revoke_clean ( bcx, val) ;
1497
+ return immediate_rvalue_bcx ( bcx, val, box_ty) ;
1498
+ } else {
1499
+ let base:: MallocResult {
1500
+ bcx,
1501
+ smart_ptr : bx,
1502
+ body
1503
+ } = base:: malloc_general ( bcx, contents_ty, heap) ;
1504
+ add_clean_free ( bcx, bx, heap) ;
1505
+ let bcx = trans_into ( bcx, contents, SaveIn ( body) ) ;
1506
+ revoke_clean ( bcx, bx) ;
1507
+ return immediate_rvalue_bcx ( bcx, bx, box_ty) ;
1495
1508
}
1496
1509
}
1497
1510
@@ -1507,6 +1520,42 @@ fn trans_addr_of<'a>(
1507
1520
return immediate_rvalue_bcx ( bcx, llval, expr_ty ( bcx, expr) ) ;
1508
1521
}
1509
1522
1523
+ pub fn trans_gc < ' a > (
1524
+ mut bcx : & ' a Block < ' a > ,
1525
+ expr : & ast:: Expr ,
1526
+ contents : & ast:: Expr ,
1527
+ dest : Dest )
1528
+ -> & ' a Block < ' a > {
1529
+ let contents_ty = expr_ty ( bcx, contents) ;
1530
+ let box_ty = ty:: mk_box ( bcx. tcx ( ) , contents_ty) ;
1531
+ let expr_ty = expr_ty ( bcx, expr) ;
1532
+
1533
+ let addr = match dest {
1534
+ Ignore => {
1535
+ return trans_boxed_expr ( bcx,
1536
+ box_ty,
1537
+ contents,
1538
+ contents_ty,
1539
+ heap_managed) . bcx
1540
+ }
1541
+ SaveIn ( addr) => addr,
1542
+ } ;
1543
+
1544
+ let repr = adt:: represent_type ( bcx. ccx ( ) , expr_ty) ;
1545
+ adt:: trans_start_init ( bcx, repr, addr, 0 ) ;
1546
+ let field_dest = adt:: trans_field_ptr ( bcx, repr, addr, 0 , 0 ) ;
1547
+ let contents_datum_block = trans_boxed_expr ( bcx,
1548
+ box_ty,
1549
+ contents,
1550
+ contents_ty,
1551
+ heap_managed) ;
1552
+ bcx = contents_datum_block. bcx ;
1553
+ bcx = contents_datum_block. datum . move_to ( bcx, INIT , field_dest) ;
1554
+
1555
+ // Next, wrap it up in the struct.
1556
+ bcx
1557
+ }
1558
+
1510
1559
// Important to get types for both lhs and rhs, because one might be _|_
1511
1560
// and the other not.
1512
1561
fn trans_eager_binop < ' a > (
0 commit comments