1
1
import std:: smallintmap;
2
2
import std:: smallintmap:: smallintmap;
3
3
import std:: smallintmap:: map;
4
+ import std:: map:: hashmap;
4
5
import middle:: ty;
5
6
import middle:: ty:: { ty_vid, region_vid, vid} ;
6
7
import syntax:: ast;
@@ -77,11 +78,12 @@ fn mk_eqty(cx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
77
78
indent { || cx. commit { || cx. eq_tys ( a, b) } } . to_ures ( )
78
79
}
79
80
80
- fn mk_assignty ( cx : infer_ctxt , encl_node_id : ast:: node_id ,
81
+ fn mk_assignty ( cx : infer_ctxt , a_node_id : ast:: node_id ,
81
82
a : ty:: t , b : ty:: t ) -> ures {
82
- #debug[ "mk_assignty(%s <: %s)" , a. to_str ( cx) , b. to_str ( cx) ] ;
83
+ #debug[ "mk_assignty(%? / %s <: %s)" ,
84
+ a_node_id, a. to_str ( cx) , b. to_str ( cx) ] ;
83
85
indent { || cx. commit { ||
84
- cx. assign_tys ( encl_node_id , a, b)
86
+ cx. assign_tys ( a_node_id , a, b)
85
87
} } . to_ures ( )
86
88
}
87
89
@@ -686,7 +688,7 @@ impl resolve_methods for infer_ctxt {
686
688
// Type assignment
687
689
//
688
690
// True if rvalues of type `a` can be assigned to lvalues of type `b`.
689
- // This may cause borrowing to the region scope for `encl_node_id `.
691
+ // This may cause borrowing to the region scope enclosing `a_node_id `.
690
692
//
691
693
// The strategy here is somewhat non-obvious. The problem is
692
694
// that the constraint we wish to contend with is not a subtyping
@@ -730,7 +732,7 @@ impl resolve_methods for infer_ctxt {
730
732
// this upper-bound might be stricter than what is truly needed.
731
733
732
734
impl assignment for infer_ctxt {
733
- fn assign_tys( encl_node_id : ast:: node_id,
735
+ fn assign_tys( a_node_id : ast:: node_id,
734
736
a : ty:: t, b : ty:: t) -> ures {
735
737
736
738
fn select( fst: option < ty:: t > , snd : option < ty:: t > ) -> option < ty:: t > {
@@ -745,8 +747,8 @@ impl assignment for infer_ctxt {
745
747
}
746
748
}
747
749
748
- #debug[ "assign_tys(encl_node_id =%?, %s -> %s)" ,
749
- encl_node_id , a. to_str( self ) , b. to_str( self ) ] ;
750
+ #debug[ "assign_tys(a_node_id =%?, %s -> %s)" ,
751
+ a_node_id , a. to_str( self ) , b. to_str( self ) ] ;
750
752
let _r = indenter( ) ;
751
753
752
754
alt ( ty:: get( a) . struct , ty:: get( b) . struct ) {
@@ -759,34 +761,34 @@ impl assignment for infer_ctxt {
759
761
let { root: _, bounds: b_bounds} = self . get( self . vb, b_id) ;
760
762
let a_bnd = select( a_bounds. ub, a_bounds. lb) ;
761
763
let b_bnd = select( b_bounds. lb, b_bounds. ub) ;
762
- self . assign_tys_or_sub( encl_node_id , a, b, a_bnd, b_bnd)
764
+ self . assign_tys_or_sub( a_node_id , a, b, a_bnd, b_bnd)
763
765
}
764
766
765
767
( ty:: ty_var( a_id) , _) {
766
768
let { root: _, bounds: a_bounds} = self . get( self . vb, a_id) ;
767
769
let a_bnd = select( a_bounds. ub, a_bounds. lb) ;
768
- self . assign_tys_or_sub( encl_node_id , a, b, a_bnd, some( b) )
770
+ self . assign_tys_or_sub( a_node_id , a, b, a_bnd, some( b) )
769
771
}
770
772
771
773
( _, ty:: ty_var( b_id) ) {
772
774
let { root: _, bounds: b_bounds} = self . get( self . vb, b_id) ;
773
775
let b_bnd = select( b_bounds. lb, b_bounds. ub) ;
774
- self . assign_tys_or_sub( encl_node_id , a, b, some( a) , b_bnd)
776
+ self . assign_tys_or_sub( a_node_id , a, b, some( a) , b_bnd)
775
777
}
776
778
777
779
( _, _) {
778
- self . assign_tys_or_sub( encl_node_id , a, b, some( a) , some( b) )
780
+ self . assign_tys_or_sub( a_node_id , a, b, some( a) , some( b) )
779
781
}
780
782
}
781
783
}
782
784
783
785
fn assign_tys_or_sub(
784
- encl_node_id : ast:: node_id,
786
+ a_node_id : ast:: node_id,
785
787
a: ty:: t, b: ty:: t,
786
788
a_bnd: option < ty:: t > , b_bnd: option < ty:: t > ) -> ures {
787
789
788
- #debug[ "assign_tys_or_sub(encl_node_id =%?, %s -> %s, %s -> %s)" ,
789
- encl_node_id , a. to_str( self ) , b. to_str( self ) ,
790
+ #debug[ "assign_tys_or_sub(a_node_id =%?, %s -> %s, %s -> %s)" ,
791
+ a_node_id , a. to_str( self ) , b. to_str( self ) ,
790
792
a_bnd. to_str( self ) , b_bnd. to_str( self ) ] ;
791
793
let _r = indenter( ) ;
792
794
@@ -802,17 +804,17 @@ impl assignment for infer_ctxt {
802
804
alt ( ty:: get( a_bnd) . struct , ty:: get( b_bnd) . struct ) {
803
805
( ty:: ty_box( mt_a) , ty:: ty_rptr( r_b, mt_b) ) {
804
806
let nr_b = ty:: mk_box( self . tcx, mt_b) ;
805
- self . crosspolinate( encl_node_id , a, nr_b, r_b)
807
+ self . crosspolinate( a_node_id , a, nr_b, r_b)
806
808
}
807
809
( ty:: ty_uniq( mt_a) , ty:: ty_rptr( r_b, mt_b) ) {
808
810
let nr_b = ty:: mk_uniq( self . tcx, mt_b) ;
809
- self . crosspolinate( encl_node_id , a, nr_b, r_b)
811
+ self . crosspolinate( a_node_id , a, nr_b, r_b)
810
812
}
811
813
( ty:: ty_evec( mt_a, vs_a) ,
812
814
ty:: ty_evec( mt_b, ty:: vstore_slice( r_b) ) )
813
815
if is_borrowable( vs_a) {
814
816
let nr_b = ty:: mk_evec( self . tcx, mt_b, vs_a) ;
815
- self . crosspolinate( encl_node_id , a, nr_b, r_b)
817
+ self . crosspolinate( a_node_id , a, nr_b, r_b)
816
818
}
817
819
_ {
818
820
self . sub_tys( a, b)
@@ -825,17 +827,26 @@ impl assignment for infer_ctxt {
825
827
}
826
828
}
827
829
828
- fn crosspolinate( encl_node_id: ast:: node_id,
829
- a: ty:: t, nr_b: ty:: t, r_b: ty:: region) -> ures {
830
+ fn crosspolinate( a_node_id: ast:: node_id,
831
+ a: ty:: t,
832
+ nr_b: ty:: t,
833
+ r_b: ty:: region) -> ures {
830
834
831
- #debug[ "crosspolinate(encl_node_id =%?, a=%s, nr_b=%s, r_b=%s)" ,
832
- encl_node_id , a. to_str( self ) , nr_b. to_str( self ) ,
835
+ #debug[ "crosspolinate(a_node_id =%?, a=%s, nr_b=%s, r_b=%s)" ,
836
+ a_node_id , a. to_str( self ) , nr_b. to_str( self ) ,
833
837
r_b. to_str( self ) ] ;
834
838
835
839
indent { ||
836
840
self . sub_tys( a, nr_b) . then { ||
837
- let r_a = ty:: re_scope( encl_node_id) ;
838
- sub( self ) . contraregions( r_a, r_b) . to_ures( )
841
+ let a_scope_id = self . tcx. region_map. parents. get( a_node_id) ;
842
+ let r_a = ty:: re_scope( a_scope_id) ;
843
+ #debug[ "a_scope_id=%?" , a_scope_id] ;
844
+ sub( self ) . contraregions( r_a, r_b) . chain { |_r|
845
+ // if successful, add an entry indicating that
846
+ // borrowing occurred
847
+ self . tcx. borrowings. insert( a_node_id, ( ) ) ;
848
+ uok( )
849
+ }
839
850
}
840
851
}
841
852
}
0 commit comments