@@ -722,63 +722,21 @@ struct RegionAndOrigin {
722
722
origin : SubregionOrigin ,
723
723
}
724
724
725
- type Graph = graph:: Graph < ( ) , Constraint > ;
726
- type GraphNode = graph:: Node < ( ) > ;
727
- type GraphEdge = graph:: Edge < Constraint > ;
725
+ type RegionGraph = graph:: Graph < ( ) , Constraint > ;
728
726
729
727
impl RegionVarBindings {
730
- fn infer_variable_values ( & mut self ,
728
+ fn infer_variable_values ( & self ,
731
729
errors : & mut OptVec < RegionResolutionError > )
732
730
-> ~[ VarValue ] {
733
731
let mut var_data = self . construct_var_data ( ) ;
734
732
self . expansion ( var_data) ;
735
733
self . contraction ( var_data) ;
736
- let graph = self . construct_graph ( ) ;
737
- self . collect_concrete_region_errors ( & graph, errors) ;
738
- self . extract_values_and_collect_conflicts ( & graph, var_data, errors)
734
+ self . collect_concrete_region_errors ( errors) ;
735
+ self . extract_values_and_collect_conflicts ( var_data, errors)
739
736
}
740
737
741
- fn construct_graph ( & mut self ) -> Graph {
742
- let num_vars = self . num_vars ( ) ;
743
- let num_edges = self . constraints . len ( ) ;
744
-
745
- let mut graph = graph:: Graph :: with_capacity ( num_vars + 1 ,
746
- num_edges) ;
747
-
748
- for uint:: range( 0 , num_vars) |var_idx| {
749
- graph. add_node ( ( ) ) ;
750
- }
751
- let dummy_idx = graph. add_node ( ( ) ) ;
752
-
753
- for self . constraints. iter( ) . advance |( constraint, _) | {
754
- match * constraint {
755
- ConstrainVarSubVar ( a_id, b_id) => {
756
- graph. add_edge( NodeIndex ( a_id. to_uint( ) ) ,
757
- NodeIndex ( b_id. to_uint( ) ) ,
758
- * constraint) ;
759
- }
760
- ConstrainRegSubVar ( _, b_id) => {
761
- graph. add_edge( dummy_idx,
762
- NodeIndex ( b_id. to_uint( ) ) ,
763
- * constraint) ;
764
- }
765
- ConstrainVarSubReg ( a_id, _) => {
766
- graph. add_edge( NodeIndex ( a_id. to_uint( ) ) ,
767
- dummy_idx,
768
- * constraint) ;
769
- }
770
- ConstrainRegSubReg ( * ) => {
771
- // Relations between two concrete regions do not
772
- // require an edge in the graph.
773
- }
774
- }
775
- }
776
-
777
- return graph;
778
- }
779
-
780
- fn construct_var_data( & mut self ) -> ~[ VarData ] {
781
- vec:: from_fn( self . num_vars( ) , |var_idx| {
738
+ fn construct_var_data ( & self ) -> ~[ VarData ] {
739
+ vec:: from_fn ( self . num_vars ( ) , |_| {
782
740
VarData {
783
741
// All nodes are initially classified as contracting; during
784
742
// the expansion phase, we will shift the classification for
@@ -790,7 +748,7 @@ impl RegionVarBindings {
790
748
} )
791
749
}
792
750
793
- fn expansion( & mut self , var_data: & mut [ VarData ] ) {
751
+ fn expansion ( & self , var_data : & mut [ VarData ] ) {
794
752
do self . iterate_until_fixed_point ( "Expansion" ) |constraint| {
795
753
match * constraint {
796
754
ConstrainRegSubVar ( a_region, b_vid) => {
@@ -957,7 +915,6 @@ impl RegionVarBindings {
957
915
958
916
fn collect_concrete_region_errors (
959
917
& self ,
960
- graph : & Graph ,
961
918
errors : & mut OptVec < RegionResolutionError > )
962
919
{
963
920
for self . constraints. iter( ) . advance |( constraint, _) | {
@@ -985,7 +942,6 @@ impl RegionVarBindings {
985
942
986
943
fn extract_values_and_collect_conflicts (
987
944
& self ,
988
- graph : & Graph ,
989
945
var_data : & [ VarData ] ,
990
946
errors : & mut OptVec < RegionResolutionError > )
991
947
-> ~[ VarValue ]
@@ -1005,6 +961,8 @@ impl RegionVarBindings {
1005
961
// overlapping locations.
1006
962
let mut dup_vec = vec:: from_elem ( self . num_vars ( ) , uint:: max_value) ;
1007
963
964
+ let mut opt_graph = None ;
965
+
1008
966
for uint:: range( 0 , self . num_vars( ) ) |idx| {
1009
967
match var_data[ idx] . value {
1010
968
Value ( _) => {
@@ -1040,6 +998,11 @@ impl RegionVarBindings {
1040
998
starts to create problems we'll have to revisit
1041
999
this portion of the code and think hard about it. =) */
1042
1000
1001
+ if opt_graph. is_none ( ) {
1002
+ opt_graph = Some ( self . construct_graph ( ) ) ;
1003
+ }
1004
+ let graph = opt_graph. get_ref ( ) ;
1005
+
1043
1006
let node_vid = RegionVid { id : idx } ;
1044
1007
match var_data[ idx] . classification {
1045
1008
Expanding => {
@@ -1058,9 +1021,48 @@ impl RegionVarBindings {
1058
1021
vec:: from_fn ( self . num_vars ( ) , |idx| var_data[ idx] . value )
1059
1022
}
1060
1023
1024
+ fn construct_graph ( & self ) -> RegionGraph {
1025
+ let num_vars = self . num_vars ( ) ;
1026
+ let num_edges = self . constraints . len ( ) ;
1027
+
1028
+ let mut graph = graph:: Graph :: with_capacity ( num_vars + 1 ,
1029
+ num_edges) ;
1030
+
1031
+ for uint:: range( 0 , num_vars) |_| {
1032
+ graph. add_node ( ( ) ) ;
1033
+ }
1034
+ let dummy_idx = graph. add_node ( ( ) ) ;
1035
+
1036
+ for self . constraints. iter( ) . advance |( constraint, _) | {
1037
+ match * constraint {
1038
+ ConstrainVarSubVar ( a_id, b_id) => {
1039
+ graph. add_edge( NodeIndex ( a_id. to_uint( ) ) ,
1040
+ NodeIndex ( b_id. to_uint( ) ) ,
1041
+ * constraint) ;
1042
+ }
1043
+ ConstrainRegSubVar ( _, b_id) => {
1044
+ graph. add_edge( dummy_idx,
1045
+ NodeIndex ( b_id. to_uint( ) ) ,
1046
+ * constraint) ;
1047
+ }
1048
+ ConstrainVarSubReg ( a_id, _) => {
1049
+ graph. add_edge( NodeIndex ( a_id. to_uint( ) ) ,
1050
+ dummy_idx,
1051
+ * constraint) ;
1052
+ }
1053
+ ConstrainRegSubReg ( * ) => {
1054
+ // Relations between two concrete regions do not
1055
+ // require an edge in the graph.
1056
+ }
1057
+ }
1058
+ }
1059
+
1060
+ return graph;
1061
+ }
1062
+
1061
1063
fn collect_error_for_expanding_node(
1062
1064
& self ,
1063
- graph : & Graph ,
1065
+ graph: & RegionGraph ,
1064
1066
var_data: & [ VarData ] ,
1065
1067
dup_vec: & mut [ uint] ,
1066
1068
node_idx: RegionVid ,
@@ -1105,7 +1107,7 @@ impl RegionVarBindings {
1105
1107
1106
1108
fn collect_error_for_contracting_node(
1107
1109
& self ,
1108
- graph : & Graph ,
1110
+ graph: & RegionGraph ,
1109
1111
var_data: & [ VarData ] ,
1110
1112
dup_vec: & mut [ uint] ,
1111
1113
node_idx: RegionVid ,
@@ -1148,7 +1150,7 @@ impl RegionVarBindings {
1148
1150
}
1149
1151
1150
1152
fn collect_concrete_regions( & self ,
1151
- graph : & Graph ,
1153
+ graph: & RegionGraph ,
1152
1154
var_data: & [ VarData ] ,
1153
1155
orig_node_idx: RegionVid ,
1154
1156
dir: Direction ,
@@ -1202,7 +1204,7 @@ impl RegionVarBindings {
1202
1204
1203
1205
fn process_edges( this: & RegionVarBindings ,
1204
1206
state: & mut WalkState ,
1205
- graph : & Graph ,
1207
+ graph: & RegionGraph ,
1206
1208
source_vid: RegionVid ,
1207
1209
dir: Direction ) {
1208
1210
debug ! ( "process_edges(source_vid=%?, dir=%?)" , source_vid, dir) ;
0 commit comments