@@ -25,6 +25,7 @@ type ('p,'t) item = {
2525 typedtree_items : 't list * Types .signature_item list ;
2626 part_snapshot : Types .snapshot ;
2727 part_stamp : int ;
28+ part_uid : int ;
2829 part_env : Env .t ;
2930 part_errors : exn list ;
3031 part_checks : Typecore .delayed_check list ;
@@ -49,6 +50,7 @@ type 'a cache_result = {
4950 env : Env .t ;
5051 snapshot : Types .snapshot ;
5152 ident_stamp : int ;
53+ uid_stamp : int ;
5254 value : 'a ;
5355 index : (Shape.Uid .t * Longident .t Location .loc , unit ) Stamped_hashtable .t ;
5456}
@@ -60,15 +62,16 @@ let fresh_env config =
6062 let env0 = Extension. register Mconfig. (config.merlin.extensions) env0 in
6163 let snap0 = Btype. snapshot () in
6264 let stamp0 = Ident. get_currentstamp () in
63- (env0, snap0, stamp0)
65+ let uid0 = Shape.Uid. get_current_stamp () in
66+ (env0, snap0, stamp0, uid0)
6467
6568let get_cache config =
6669 match ! cache with
6770 | Some ({ snapshot; _ } as c ) when Types. is_valid snapshot -> c
6871 | Some _ | None ->
69- let env, snapshot, ident_stamp = fresh_env config in
72+ let env, snapshot, ident_stamp, uid_stamp = fresh_env config in
7073 let index = Stamped_hashtable. create ! index_changelog 256 in
71- { env; snapshot; ident_stamp; value = None ; index }
74+ { env; snapshot; ident_stamp; uid_stamp; value = None ; index }
7275
7376let return_and_cache status =
7477 cache := Some ({ status with value = Some status.value });
@@ -80,6 +83,7 @@ type result = {
8083 initial_snapshot : Types .snapshot ;
8184 initial_stamp : int ;
8285 stamp : int ;
86+ initial_uid_stamp : int ;
8387 typedtree : typedtree_items ;
8488 index : (Shape.Uid .t * Longident .t Location .loc , unit ) Stamped_hashtable .t ;
8589 cache_stat : typer_cache_stats
@@ -116,6 +120,7 @@ let rec type_structure caught env = function
116120 parsetree_item; typedtree_items; part_env;
117121 part_snapshot = Btype. snapshot () ;
118122 part_stamp = Ident. get_currentstamp () ;
123+ part_uid = Shape.Uid. get_current_stamp () ;
119124 part_errors = ! caught;
120125 part_checks = ! Typecore. delayed_checks;
121126 part_warnings = Warnings. backup () ;
@@ -131,6 +136,7 @@ let rec type_signature caught env = function
131136 parsetree_item; typedtree_items = (sig_items, sig_type); part_env;
132137 part_snapshot = Btype. snapshot () ;
133138 part_stamp = Ident. get_currentstamp () ;
139+ part_uid = Shape.Uid. get_current_stamp () ;
134140 part_errors = ! caught;
135141 part_checks = ! Typecore. delayed_checks;
136142 part_warnings = Warnings. backup () ;
@@ -139,60 +145,70 @@ let rec type_signature caught env = function
139145 | [] -> []
140146
141147let type_implementation config caught parsetree =
142- let { env; snapshot; ident_stamp; value = prefix; index; _ } = get_cache config in
148+ let { env; snapshot; ident_stamp; uid_stamp; value = prefix; index; _ } =
149+ get_cache config
150+ in
143151 let prefix, parsetree, cache_stats =
144152 match prefix with
145153 | Some (`Implementation items ) -> compatible_prefix items parsetree
146154 | Some (`Interface _ ) | None -> ([] , parsetree, Miss )
147155 in
148- let env', snap', stamp', warn' = match prefix with
149- | [] -> (env, snapshot, ident_stamp, Warnings. backup () )
156+ let env', snap', stamp', uid_stamp', warn' = match prefix with
157+ | [] -> (env, snapshot, ident_stamp, uid_stamp, Warnings. backup () )
150158 | x :: _ ->
151159 caught := x.part_errors;
152160 Typecore. delayed_checks := x.part_checks;
153- (x.part_env, x.part_snapshot, x.part_stamp, x.part_warnings)
161+ (x.part_env, x.part_snapshot, x.part_stamp, x.part_uid, x. part_warnings)
154162 in
155163 Btype. backtrack snap';
156164 Warnings. restore warn';
157165 Env. cleanup_functor_caches ~stamp: stamp';
158166 let stamp = List. length prefix - 1 in
159167 Stamped_hashtable. backtrack ! index_changelog ~stamp ;
168+ Env. cleanup_usage_tables ~stamp: uid_stamp';
169+ Shape.Uid. restore_stamp uid_stamp';
160170 let suffix = type_structure caught env' parsetree in
161171 let () =
162172 List. iteri ~f: (fun i { typedtree_items = (items , _ ); _ } ->
163173 let stamp = stamp + i + 1 in
164174 ! index_items ~index ~stamp config (`Impl items)) suffix
165175 in
166176 let value = `Implementation (List. rev_append prefix suffix) in
167- return_and_cache { env; snapshot; ident_stamp; value; index }, cache_stats
177+ return_and_cache { env; snapshot; ident_stamp; uid_stamp; value; index },
178+ cache_stats
168179
169180let type_interface config caught parsetree =
170- let { env; snapshot; ident_stamp; value = prefix; index; _ } = get_cache config in
181+ let { env; snapshot; ident_stamp; uid_stamp; value = prefix; index; _ } =
182+ get_cache config
183+ in
171184 let prefix, parsetree, cache_stats =
172185 match prefix with
173186 | Some (`Interface items ) -> compatible_prefix items parsetree
174187 | Some (`Implementation _ ) | None -> ([] , parsetree, Miss )
175188 in
176- let env', snap', stamp', warn' = match prefix with
177- | [] -> (env, snapshot, ident_stamp, Warnings. backup () )
189+ let env', snap', stamp', uid_stamp', warn' = match prefix with
190+ | [] -> (env, snapshot, ident_stamp, uid_stamp, Warnings. backup () )
178191 | x :: _ ->
179192 caught := x.part_errors;
180193 Typecore. delayed_checks := x.part_checks;
181- (x.part_env, x.part_snapshot, x.part_stamp, x.part_warnings)
194+ (x.part_env, x.part_snapshot, x.part_stamp, x.part_uid, x. part_warnings)
182195 in
183196 Btype. backtrack snap';
184197 Warnings. restore warn';
185198 Env. cleanup_functor_caches ~stamp: stamp';
186199 let stamp = List. length prefix in
187200 Stamped_hashtable. backtrack ! index_changelog ~stamp ;
201+ Env. cleanup_usage_tables ~stamp: uid_stamp';
202+ Shape.Uid. restore_stamp uid_stamp';
188203 let suffix = type_signature caught env' parsetree in
189204 let () =
190205 List. iteri ~f: (fun i { typedtree_items = (items , _ ); _ } ->
191206 let stamp = stamp + i + 1 in
192207 ! index_items ~index ~stamp config (`Intf items)) suffix
193208 in
194209 let value = `Interface (List. rev_append prefix suffix) in
195- return_and_cache { env; snapshot; ident_stamp; value; index}, cache_stats
210+ return_and_cache { env; snapshot; ident_stamp; uid_stamp; value; index},
211+ cache_stats
196212
197213let run config parsetree =
198214 if not (Env. check_state_consistency () ) then (
@@ -219,6 +235,7 @@ let run config parsetree =
219235 initial_snapshot = cached_result.snapshot;
220236 initial_stamp = cached_result.ident_stamp;
221237 stamp;
238+ initial_uid_stamp = cached_result.uid_stamp;
222239 typedtree = cached_result.value;
223240 index = cached_result.index;
224241 cache_stat;
0 commit comments