1
1
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder } ;
2
2
use rustc_middle:: ty:: { self , ConstVid , FloatVid , IntVid , RegionVid , Ty , TyCtxt , TyVid } ;
3
3
4
- use super :: region_constraints:: RegionSnapshot ;
5
- use super :: type_variable:: { self , TypeVariableOrigin } ;
4
+ use super :: type_variable:: TypeVariableOrigin ;
6
5
use super :: InferCtxt ;
7
- use super :: { CombinedSnapshot , ConstVariableOrigin , RegionVariableOrigin , UnificationTable } ;
6
+ use super :: { ConstVariableOrigin , RegionVariableOrigin , UnificationTable } ;
8
7
9
8
use rustc_data_structures:: snapshot_vec as sv;
10
9
use rustc_data_structures:: unify as ut;
@@ -14,13 +13,13 @@ use std::ops::Range;
14
13
15
14
fn vars_since_snapshot < ' tcx , T > (
16
15
table : & mut UnificationTable < ' _ , ' tcx , T > ,
17
- snapshot : usize ,
16
+ snapshot_var_len : usize ,
18
17
) -> Range < T >
19
18
where
20
19
T : UnifyKey ,
21
20
super :: UndoLog < ' tcx > : From < sv:: UndoLog < ut:: Delegate < T > > > ,
22
21
{
23
- T :: from_index ( snapshot as u32 ) ..T :: from_index ( table. len ( ) as u32 )
22
+ T :: from_index ( snapshot_var_len as u32 ) ..T :: from_index ( table. len ( ) as u32 )
24
23
}
25
24
26
25
fn const_vars_since_snapshot < ' tcx > (
@@ -36,41 +35,23 @@ fn const_vars_since_snapshot<'tcx>(
36
35
)
37
36
}
38
37
39
- /// Extends `CombinedSnapshot` by tracking which variables were added in the snapshot
40
- #[ must_use = "once you start a snapshot, you should always consume it" ]
41
- struct FudgeSnapshot < ' a , ' tcx > {
42
- snapshot : CombinedSnapshot < ' a , ' tcx > ,
43
- region_constraints_snapshot : RegionSnapshot ,
44
- type_snapshot : type_variable:: Snapshot < ' tcx > ,
38
+ struct VariableLengths {
39
+ type_var_len : usize ,
45
40
const_var_len : usize ,
46
41
int_var_len : usize ,
47
42
float_var_len : usize ,
43
+ region_constraints_len : usize ,
48
44
}
49
45
50
46
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
51
- /// Like `probe` but provides information about which variables were created in the snapshot,
52
- /// allowing for inference fudging
53
- fn probe_fudge < R , F > ( & self , f : F ) -> R
54
- where
55
- F : FnOnce ( & FudgeSnapshot < ' a , ' tcx > ) -> R ,
56
- {
57
- debug ! ( "probe()" ) ;
58
- let snapshot = self . start_fudge_snapshot ( ) ;
59
- let r = f ( & snapshot) ;
60
- self . rollback_to ( "probe" , snapshot. snapshot ) ;
61
- r
62
- }
63
-
64
- fn start_fudge_snapshot ( & self ) -> FudgeSnapshot < ' a , ' tcx > {
65
- let snapshot = self . start_snapshot ( ) ;
47
+ fn variable_lengths ( & self ) -> VariableLengths {
66
48
let mut inner = self . inner . borrow_mut ( ) ;
67
- FudgeSnapshot {
68
- snapshot,
69
- type_snapshot : inner. type_variables ( ) . snapshot ( ) ,
49
+ VariableLengths {
50
+ type_var_len : inner. type_variables ( ) . num_vars ( ) ,
70
51
const_var_len : inner. const_unification_table ( ) . len ( ) ,
71
52
int_var_len : inner. int_unification_table ( ) . len ( ) ,
72
53
float_var_len : inner. float_unification_table ( ) . len ( ) ,
73
- region_constraints_snapshot : inner. unwrap_region_constraints ( ) . start_snapshot ( ) ,
54
+ region_constraints_len : inner. unwrap_region_constraints ( ) . num_region_vars ( ) ,
74
55
}
75
56
}
76
57
@@ -120,7 +101,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
120
101
{
121
102
debug ! ( "fudge_inference_if_ok()" ) ;
122
103
123
- let ( mut fudger, value) = self . probe_fudge ( |snapshot| {
104
+ let variable_lengths = self . variable_lengths ( ) ;
105
+ let ( mut fudger, value) = self . probe ( |_| {
124
106
match f ( ) {
125
107
Ok ( value) => {
126
108
let value = self . resolve_vars_if_possible ( & value) ;
@@ -133,21 +115,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
133
115
134
116
let mut inner = self . inner . borrow_mut ( ) ;
135
117
let type_vars =
136
- inner. type_variables ( ) . vars_since_snapshot ( & snapshot . type_snapshot ) ;
118
+ inner. type_variables ( ) . vars_since_snapshot ( variable_lengths . type_var_len ) ;
137
119
let int_vars = vars_since_snapshot (
138
120
& mut inner. int_unification_table ( ) ,
139
- snapshot . int_var_len ,
121
+ variable_lengths . int_var_len ,
140
122
) ;
141
123
let float_vars = vars_since_snapshot (
142
124
& mut inner. float_unification_table ( ) ,
143
- snapshot . float_var_len ,
125
+ variable_lengths . float_var_len ,
144
126
) ;
145
127
let region_vars = inner
146
128
. unwrap_region_constraints ( )
147
- . vars_since_snapshot ( & snapshot . region_constraints_snapshot ) ;
129
+ . vars_since_snapshot ( variable_lengths . region_constraints_len ) ;
148
130
let const_vars = const_vars_since_snapshot (
149
131
& mut inner. const_unification_table ( ) ,
150
- snapshot . const_var_len ,
132
+ variable_lengths . const_var_len ,
151
133
) ;
152
134
153
135
let fudger = InferenceFudger {
0 commit comments