11use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder } ;
22use rustc_middle:: ty:: { self , ConstVid , FloatVid , IntVid , RegionVid , Ty , TyCtxt , TyVid } ;
33
4- use super :: region_constraints:: RegionSnapshot ;
5- use super :: type_variable:: { self , TypeVariableOrigin } ;
4+ use super :: type_variable:: TypeVariableOrigin ;
65use super :: InferCtxt ;
7- use super :: { CombinedSnapshot , ConstVariableOrigin , RegionVariableOrigin , UnificationTable } ;
6+ use super :: { ConstVariableOrigin , RegionVariableOrigin , UnificationTable } ;
87
98use rustc_data_structures:: snapshot_vec as sv;
109use rustc_data_structures:: unify as ut;
@@ -14,13 +13,13 @@ use std::ops::Range;
1413
1514fn vars_since_snapshot < ' tcx , T > (
1615 table : & mut UnificationTable < ' _ , ' tcx , T > ,
17- snapshot : usize ,
16+ snapshot_var_len : usize ,
1817) -> Range < T >
1918where
2019 T : UnifyKey ,
2120 super :: UndoLog < ' tcx > : From < sv:: UndoLog < ut:: Delegate < T > > > ,
2221{
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 )
2423}
2524
2625fn const_vars_since_snapshot < ' tcx > (
@@ -36,41 +35,23 @@ fn const_vars_since_snapshot<'tcx>(
3635 )
3736}
3837
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 ,
4540 const_var_len : usize ,
4641 int_var_len : usize ,
4742 float_var_len : usize ,
43+ region_constraints_len : usize ,
4844}
4945
5046impl < ' 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 {
6648 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 ( ) ,
7051 const_var_len : inner. const_unification_table ( ) . len ( ) ,
7152 int_var_len : inner. int_unification_table ( ) . len ( ) ,
7253 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 ( ) ,
7455 }
7556 }
7657
@@ -120,7 +101,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
120101 {
121102 debug ! ( "fudge_inference_if_ok()" ) ;
122103
123- let ( mut fudger, value) = self . probe_fudge ( |snapshot| {
104+ let variable_lengths = self . variable_lengths ( ) ;
105+ let ( mut fudger, value) = self . probe ( |_| {
124106 match f ( ) {
125107 Ok ( value) => {
126108 let value = self . resolve_vars_if_possible ( & value) ;
@@ -133,21 +115,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
133115
134116 let mut inner = self . inner . borrow_mut ( ) ;
135117 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 ) ;
137119 let int_vars = vars_since_snapshot (
138120 & mut inner. int_unification_table ( ) ,
139- snapshot . int_var_len ,
121+ variable_lengths . int_var_len ,
140122 ) ;
141123 let float_vars = vars_since_snapshot (
142124 & mut inner. float_unification_table ( ) ,
143- snapshot . float_var_len ,
125+ variable_lengths . float_var_len ,
144126 ) ;
145127 let region_vars = inner
146128 . unwrap_region_constraints ( )
147- . vars_since_snapshot ( & snapshot . region_constraints_snapshot ) ;
129+ . vars_since_snapshot ( variable_lengths . region_constraints_len ) ;
148130 let const_vars = const_vars_since_snapshot (
149131 & mut inner. const_unification_table ( ) ,
150- snapshot . const_var_len ,
132+ variable_lengths . const_var_len ,
151133 ) ;
152134
153135 let fudger = InferenceFudger {
0 commit comments