87
87
88
88
use lib;
89
89
use lib:: llvm:: ValueRef ;
90
- use middle:: borrowck:: { RootInfo , root_map_key, DynaImm , DynaMut } ;
91
90
use middle:: trans:: adt;
92
91
use middle:: trans:: base:: * ;
93
92
use middle:: trans:: build:: * ;
94
- use middle:: trans:: callee;
95
93
use middle:: trans:: common:: * ;
96
94
use middle:: trans:: common;
97
95
use middle:: trans:: expr;
98
96
use middle:: trans:: glue;
99
97
use middle:: trans:: tvec;
100
98
use middle:: trans:: type_of;
99
+ use middle:: trans:: write_guard;
101
100
use middle:: ty;
102
101
use util:: common:: indenter;
103
102
use util:: ppaux:: ty_to_str;
104
- use driver:: session;
105
103
106
104
use core:: container:: Set ; // XXX: this should not be necessary
107
105
use core:: to_bytes;
@@ -518,113 +516,6 @@ pub impl Datum {
518
516
}
519
517
}
520
518
521
- fn root ( & self , mut bcx : block , span : span ,
522
- root_key : root_map_key , root_info : RootInfo ) -> block {
523
- /*!
524
- *
525
- * In some cases, borrowck will decide that an @T/@[]/@str
526
- * value must be rooted for the program to be safe. In that
527
- * case, we will call this function, which will stash a copy
528
- * away until we exit the scope `scope_id`. */
529
-
530
- debug ! ( "root(root_map_key=%?, root_info=%?, self=%?)" ,
531
- root_key, root_info, self . to_str( bcx. ccx( ) ) ) ;
532
-
533
- if bcx. sess ( ) . trace ( ) {
534
- trans_trace (
535
- bcx, None ,
536
- @fmt ! ( "preserving until end of scope %d" ,
537
- root_info. scope) ) ;
538
- }
539
-
540
- // First, root the datum. Note that we must zero this value,
541
- // because sometimes we root on one path but not another.
542
- // See e.g. #4904.
543
- let scratch = scratch_datum ( bcx, self . ty , true ) ;
544
- self . copy_to_datum ( bcx, INIT , scratch) ;
545
- let cleanup_bcx = find_bcx_for_scope ( bcx, root_info. scope ) ;
546
- add_clean_temp_mem ( cleanup_bcx, scratch. val , scratch. ty ) ;
547
-
548
- // Now, consider also freezing it.
549
- match root_info. freeze {
550
- None => { }
551
- Some ( freeze_kind) => {
552
- let loc = bcx. sess ( ) . parse_sess . cm . lookup_char_pos ( span. lo ) ;
553
- let line = C_int ( bcx. ccx ( ) , loc. line as int ) ;
554
- let filename_cstr = C_cstr ( bcx. ccx ( ) , @/* bad* /copy loc. file . name ) ;
555
- let filename = PointerCast ( bcx, filename_cstr, T_ptr ( T_i8 ( ) ) ) ;
556
-
557
- // in this case, we don't have to zero, because
558
- // scratch.val will be NULL should the cleanup get
559
- // called without the freezing actually occurring, and
560
- // return_to_mut checks for this condition.
561
- let scratch_bits = scratch_datum ( bcx, ty:: mk_uint ( ) , false ) ;
562
-
563
- let freeze_did = match freeze_kind {
564
- DynaImm => bcx. tcx ( ) . lang_items . borrow_as_imm_fn ( ) ,
565
- DynaMut => bcx. tcx ( ) . lang_items . borrow_as_mut_fn ( ) ,
566
- } ;
567
-
568
- let box_ptr = Load ( bcx,
569
- PointerCast ( bcx,
570
- scratch. val ,
571
- T_ptr ( T_ptr ( T_i8 ( ) ) ) ) ) ;
572
-
573
- bcx = callee:: trans_lang_call (
574
- bcx,
575
- freeze_did,
576
- ~[
577
- box_ptr,
578
- filename,
579
- line
580
- ] ,
581
- expr:: SaveIn ( scratch_bits. val ) ) ;
582
-
583
- if bcx. tcx ( ) . sess . opts . optimize == session:: No {
584
- bcx = callee:: trans_lang_call (
585
- bcx,
586
- bcx. tcx ( ) . lang_items . record_borrow_fn ( ) ,
587
- ~[
588
- box_ptr,
589
- Load ( bcx, scratch_bits. val ) ,
590
- filename,
591
- line
592
- ] ,
593
- expr:: Ignore ) ;
594
- }
595
-
596
- add_clean_return_to_mut (
597
- cleanup_bcx, scratch. val , scratch_bits. val ,
598
- filename, line) ;
599
- }
600
- }
601
-
602
- bcx
603
- }
604
-
605
- fn perform_write_guard ( & self , bcx : block , span : span ) -> block {
606
- debug ! ( "perform_write_guard" ) ;
607
-
608
- // Create scratch space, but do not root it.
609
- let llval = match self . mode {
610
- ByValue => self . val ,
611
- ByRef => Load ( bcx, self . val ) ,
612
- } ;
613
-
614
- let loc = bcx. sess ( ) . parse_sess . cm . lookup_char_pos ( span. lo ) ;
615
- let line = C_int ( bcx. ccx ( ) , loc. line as int ) ;
616
- let filename_cstr = C_cstr ( bcx. ccx ( ) , @/* bad* /copy loc. file . name ) ;
617
- let filename = PointerCast ( bcx, filename_cstr, T_ptr ( T_i8 ( ) ) ) ;
618
-
619
- callee:: trans_lang_call (
620
- bcx,
621
- bcx. tcx ( ) . lang_items . check_not_borrowed_fn ( ) ,
622
- ~[ PointerCast ( bcx, llval, T_ptr ( T_i8 ( ) ) ) ,
623
- filename,
624
- line] ,
625
- expr:: Ignore )
626
- }
627
-
628
519
fn drop_val ( & self , bcx : block ) -> block {
629
520
if !ty:: type_needs_drop ( bcx. tcx ( ) , self . ty ) {
630
521
return bcx;
@@ -687,7 +578,9 @@ pub impl Datum {
687
578
debug ! ( "try_deref(expr_id=%?, derefs=%?, is_auto=%b, self=%?)" ,
688
579
expr_id, derefs, is_auto, self . to_str( bcx. ccx( ) ) ) ;
689
580
690
- let bcx = self . root_and_write_guard ( bcx, span, expr_id, derefs) ;
581
+ let bcx =
582
+ write_guard:: root_and_write_guard (
583
+ self , bcx, span, expr_id, derefs) ;
691
584
692
585
match ty:: get ( self . ty ) . sty {
693
586
ty:: ty_box( _) | ty:: ty_uniq( _) => {
@@ -841,33 +734,6 @@ pub impl Datum {
841
734
DatumBlock { bcx : bcx, datum : datum }
842
735
}
843
736
844
- fn root_and_write_guard ( & self ,
845
- mut bcx : block ,
846
- span : span ,
847
- expr_id : ast:: node_id ,
848
- derefs : uint ) -> block {
849
- let key = root_map_key { id : expr_id, derefs : derefs } ;
850
- debug ! ( "root_and_write_guard(key=%?)" , key) ;
851
-
852
- // root the autoderef'd value, if necessary:
853
- //
854
- // (Note: root'd values are always boxes)
855
- let ccx = bcx. ccx ( ) ;
856
- bcx = match ccx. maps . root_map . find ( & key) {
857
- None => bcx,
858
- Some ( & root_info) => self . root ( bcx, span, key, root_info)
859
- } ;
860
-
861
- // Perform the write guard, if necessary.
862
- //
863
- // (Note: write-guarded values are always boxes)
864
- if ccx. maps . write_guard_map . contains ( & key) {
865
- self . perform_write_guard ( bcx, span)
866
- } else {
867
- bcx
868
- }
869
- }
870
-
871
737
fn get_vec_base_and_len ( & self ,
872
738
mut bcx : block ,
873
739
span : span ,
@@ -877,7 +743,7 @@ pub impl Datum {
877
743
//! and write guards checks.
878
744
879
745
// only imp't for @[] and @str, but harmless
880
- bcx = self . root_and_write_guard ( bcx, span, expr_id, 0 ) ;
746
+ bcx = write_guard :: root_and_write_guard ( self , bcx, span, expr_id, 0 ) ;
881
747
let ( base, len) = self . get_vec_base_and_len_no_root ( bcx) ;
882
748
( bcx, base, len)
883
749
}
@@ -890,6 +756,14 @@ pub impl Datum {
890
756
tvec:: get_base_and_len ( bcx, llval, self . ty )
891
757
}
892
758
759
+ fn root_and_write_guard ( & self ,
760
+ bcx : block ,
761
+ span : span ,
762
+ expr_id : ast:: node_id ,
763
+ derefs : uint ) -> block {
764
+ write_guard:: root_and_write_guard ( self , bcx, span, expr_id, derefs)
765
+ }
766
+
893
767
fn to_result ( & self , bcx : block ) -> common:: Result {
894
768
rslt ( bcx, self . to_appropriate_llval ( bcx) )
895
769
}
0 commit comments