@@ -655,26 +655,20 @@ where
655
655
///
656
656
/// ```text
657
657
/// loop-block:
658
- /// can_go = cur == length_or_end
658
+ /// can_go = cur == len
659
659
/// if can_go then succ else drop-block
660
660
/// drop-block:
661
- /// if ptr_based {
662
- /// ptr = cur
663
- /// cur = cur.offset(1)
664
- /// } else {
665
- /// ptr = &raw mut P[cur]
666
- /// cur = cur + 1
667
- /// }
661
+ /// ptr = &raw mut P[cur]
662
+ /// cur = cur + 1
668
663
/// drop(ptr)
669
664
/// ```
670
665
fn drop_loop (
671
666
& mut self ,
672
667
succ : BasicBlock ,
673
668
cur : Local ,
674
- length_or_end : Place < ' tcx > ,
669
+ len : Local ,
675
670
ety : Ty < ' tcx > ,
676
671
unwind : Unwind ,
677
- ptr_based : bool ,
678
672
) -> BasicBlock {
679
673
let copy = |place : Place < ' tcx > | Operand :: Copy ( place) ;
680
674
let move_ = |place : Place < ' tcx > | Operand :: Move ( place) ;
@@ -683,22 +677,19 @@ where
683
677
let ptr_ty = tcx. mk_ptr ( ty:: TypeAndMut { ty : ety, mutbl : hir:: Mutability :: Mut } ) ;
684
678
let ptr = Place :: from ( self . new_temp ( ptr_ty) ) ;
685
679
let can_go = Place :: from ( self . new_temp ( tcx. types . bool ) ) ;
686
-
687
680
let one = self . constant_usize ( 1 ) ;
688
- let ( ptr_next, cur_next) = if ptr_based {
689
- (
690
- Rvalue :: Use ( copy ( cur. into ( ) ) ) ,
691
- Rvalue :: BinaryOp ( BinOp :: Offset , Box :: new ( ( move_ ( cur. into ( ) ) , one) ) ) ,
692
- )
693
- } else {
694
- (
695
- Rvalue :: AddressOf ( Mutability :: Mut , tcx. mk_place_index ( self . place , cur) ) ,
696
- Rvalue :: BinaryOp ( BinOp :: Add , Box :: new ( ( move_ ( cur. into ( ) ) , one) ) ) ,
697
- )
698
- } ;
699
681
700
682
let drop_block = BasicBlockData {
701
- statements : vec ! [ self . assign( ptr, ptr_next) , self . assign( Place :: from( cur) , cur_next) ] ,
683
+ statements : vec ! [
684
+ self . assign(
685
+ ptr,
686
+ Rvalue :: AddressOf ( Mutability :: Mut , tcx. mk_place_index( self . place, cur) ) ,
687
+ ) ,
688
+ self . assign(
689
+ cur. into( ) ,
690
+ Rvalue :: BinaryOp ( BinOp :: Add , Box :: new( ( move_( cur. into( ) ) , one) ) ) ,
691
+ ) ,
692
+ ] ,
702
693
is_cleanup : unwind. is_cleanup ( ) ,
703
694
terminator : Some ( Terminator {
704
695
source_info : self . source_info ,
@@ -711,10 +702,7 @@ where
711
702
let loop_block = BasicBlockData {
712
703
statements : vec ! [ self . assign(
713
704
can_go,
714
- Rvalue :: BinaryOp (
715
- BinOp :: Eq ,
716
- Box :: new( ( copy( Place :: from( cur) ) , copy( length_or_end) ) ) ,
717
- ) ,
705
+ Rvalue :: BinaryOp ( BinOp :: Eq , Box :: new( ( copy( Place :: from( cur) ) , copy( len. into( ) ) ) ) ) ,
718
706
) ] ,
719
707
is_cleanup : unwind. is_cleanup ( ) ,
720
708
terminator : Some ( Terminator {
@@ -738,13 +726,6 @@ where
738
726
739
727
fn open_drop_for_array ( & mut self , ety : Ty < ' tcx > , opt_size : Option < u64 > ) -> BasicBlock {
740
728
debug ! ( "open_drop_for_array({:?}, {:?})" , ety, opt_size) ;
741
-
742
- // if size_of::<ety>() == 0 {
743
- // index_based_loop
744
- // } else {
745
- // ptr_based_loop
746
- // }
747
-
748
729
let tcx = self . tcx ( ) ;
749
730
750
731
if let Some ( size) = opt_size {
@@ -770,86 +751,36 @@ where
770
751
}
771
752
}
772
753
773
- let move_ = |place : Place < ' tcx > | Operand :: Move ( place) ;
774
- let elem_size = Place :: from ( self . new_temp ( tcx. types . usize ) ) ;
775
- let len = Place :: from ( self . new_temp ( tcx. types . usize ) ) ;
776
-
777
- let base_block = BasicBlockData {
778
- statements : vec ! [
779
- self . assign( elem_size, Rvalue :: NullaryOp ( NullOp :: SizeOf , ety) ) ,
780
- self . assign( len, Rvalue :: Len ( self . place) ) ,
781
- ] ,
782
- is_cleanup : self . unwind . is_cleanup ( ) ,
783
- terminator : Some ( Terminator {
784
- source_info : self . source_info ,
785
- kind : TerminatorKind :: SwitchInt {
786
- discr : move_ ( elem_size) ,
787
- targets : SwitchTargets :: static_if (
788
- 0 ,
789
- self . drop_loop_pair ( ety, false , len) ,
790
- self . drop_loop_pair ( ety, true , len) ,
791
- ) ,
792
- } ,
793
- } ) ,
794
- } ;
795
- self . elaborator . patch ( ) . new_block ( base_block)
754
+ self . drop_loop_pair ( ety)
796
755
}
797
756
798
757
/// Creates a pair of drop-loops of `place`, which drops its contents, even
799
- /// in the case of 1 panic. If `ptr_based`, creates a pointer loop,
800
- /// otherwise create an index loop.
801
- fn drop_loop_pair (
802
- & mut self ,
803
- ety : Ty < ' tcx > ,
804
- ptr_based : bool ,
805
- length : Place < ' tcx > ,
806
- ) -> BasicBlock {
807
- debug ! ( "drop_loop_pair({:?}, {:?})" , ety, ptr_based) ;
758
+ /// in the case of 1 panic.
759
+ fn drop_loop_pair ( & mut self , ety : Ty < ' tcx > ) -> BasicBlock {
760
+ debug ! ( "drop_loop_pair({:?})" , ety) ;
808
761
let tcx = self . tcx ( ) ;
809
- let iter_ty = if ptr_based { tcx. mk_mut_ptr ( ety) } else { tcx. types . usize } ;
762
+ let len = self . new_temp ( tcx. types . usize ) ;
763
+ let cur = self . new_temp ( tcx. types . usize ) ;
810
764
811
- let cur = self . new_temp ( iter_ty ) ;
812
- let length_or_end = if ptr_based { Place :: from ( self . new_temp ( iter_ty ) ) } else { length } ;
765
+ let unwind =
766
+ self . unwind . map ( |unwind| self . drop_loop ( unwind , cur , len , ety , Unwind :: InCleanup ) ) ;
813
767
814
- let unwind = self . unwind . map ( |unwind| {
815
- self . drop_loop ( unwind, cur, length_or_end, ety, Unwind :: InCleanup , ptr_based)
816
- } ) ;
768
+ let loop_block = self . drop_loop ( self . succ , cur, len, ety, unwind) ;
817
769
818
- let loop_block = self . drop_loop ( self . succ , cur, length_or_end, ety, unwind, ptr_based) ;
819
-
820
- let cur = Place :: from ( cur) ;
821
- let drop_block_stmts = if ptr_based {
822
- let tmp_ty = tcx. mk_mut_ptr ( self . place_ty ( self . place ) ) ;
823
- let tmp = Place :: from ( self . new_temp ( tmp_ty) ) ;
824
- // tmp = &raw mut P;
825
- // cur = tmp as *mut T;
826
- // end = Offset(cur, len);
827
- let mir_cast_kind = ty:: cast:: mir_cast_kind ( iter_ty, tmp_ty) ;
828
- vec ! [
829
- self . assign( tmp, Rvalue :: AddressOf ( Mutability :: Mut , self . place) ) ,
830
- self . assign( cur, Rvalue :: Cast ( mir_cast_kind, Operand :: Move ( tmp) , iter_ty) ) ,
831
- self . assign(
832
- length_or_end,
833
- Rvalue :: BinaryOp (
834
- BinOp :: Offset ,
835
- Box :: new( ( Operand :: Copy ( cur) , Operand :: Move ( length) ) ) ,
836
- ) ,
837
- ) ,
838
- ]
839
- } else {
840
- // cur = 0 (length already pushed)
841
- let zero = self . constant_usize ( 0 ) ;
842
- vec ! [ self . assign( cur, Rvalue :: Use ( zero) ) ]
843
- } ;
844
- let drop_block = self . elaborator . patch ( ) . new_block ( BasicBlockData {
845
- statements : drop_block_stmts,
770
+ let zero = self . constant_usize ( 0 ) ;
771
+ let block = BasicBlockData {
772
+ statements : vec ! [
773
+ self . assign( len. into( ) , Rvalue :: Len ( self . place) ) ,
774
+ self . assign( cur. into( ) , Rvalue :: Use ( zero) ) ,
775
+ ] ,
846
776
is_cleanup : unwind. is_cleanup ( ) ,
847
777
terminator : Some ( Terminator {
848
778
source_info : self . source_info ,
849
779
kind : TerminatorKind :: Goto { target : loop_block } ,
850
780
} ) ,
851
- } ) ;
781
+ } ;
852
782
783
+ let drop_block = self . elaborator . patch ( ) . new_block ( block) ;
853
784
// FIXME(#34708): handle partially-dropped array/slice elements.
854
785
let reset_block = self . drop_flag_reset_block ( DropFlagMode :: Deep , drop_block, unwind) ;
855
786
self . drop_flag_test_block ( reset_block, self . succ , unwind)
0 commit comments