@@ -557,7 +557,7 @@ module Typeconst_analysis : sig
557557 t ->
558558 Typing_defs_core .decl_phase Typing_defs_core .ty ->
559559 Typing_env_types .env ->
560- Subst .t
560+ Typing_env_types .env * Subst .t
561561end = struct
562562 (* * Helper to accumulate the path of projections on a given root type *)
563563 let rec access_path root prefix =
@@ -1249,26 +1249,16 @@ end = struct
12491249 lower_bound : Typing_defs_core .decl_phase Typing_defs_core .ty option ;
12501250 }
12511251
1252- (* * Generate locally fresh names for generics *)
1253- let fresh_name names prefix =
1254- let n =
1255- match SMap. find_opt prefix names with
1256- | Some n -> n + 1
1257- | None -> 0
1258- in
1259- let name = Format. sprintf {|% s#% d| } prefix n in
1260- (SMap. add prefix n names, name)
1261-
12621252 (* -- Build substitution for concrete type constants -------------------- *)
12631253
1264- let class_subst_help trie names generics =
1254+ let class_subst_help trie env generics =
12651255 let rec aux Trie. { base; children } (const_name , rev_path ) acc =
12661256 let acc =
12671257 match base with
12681258 | Typeconst { typeconst = Typing_defs. (TCConcrete { tc_type } ); _ } ->
1269- let (subst, names , generics) = acc in
1259+ let (subst, env , generics) = acc in
12701260 let key = String. concat ~sep: " ::" (List. rev rev_path) in
1271- (SMap. add key tc_type subst, names , generics)
1261+ (SMap. add key tc_type subst, env , generics)
12721262 | Typeconst
12731263 {
12741264 typeconst =
@@ -1282,8 +1272,10 @@ end = struct
12821272 pos;
12831273 _;
12841274 } ->
1285- let (subst, names, generics) = acc in
1286- let (names, generic_name) = fresh_name names const_name in
1275+ let (subst, env, generics) = acc in
1276+ let (env, generic_name) =
1277+ Typing_env. fresh_param_name env const_name
1278+ in
12871279 let subst =
12881280 let key = String. concat ~sep: " ::" (List. rev rev_path) in
12891281 let reason = Typing_reason. witness_from_decl pos in
@@ -1293,7 +1285,7 @@ end = struct
12931285 let generics =
12941286 SMap. add generic_name { pos; upper_bound; lower_bound } generics
12951287 in
1296- (subst, names , generics)
1288+ (subst, env , generics)
12971289 | Root -> acc
12981290 in
12991291 SMap. fold
@@ -1304,15 +1296,15 @@ end = struct
13041296 children
13051297 acc
13061298 in
1307- aux trie (" " , [] ) (SMap. empty, names , generics)
1299+ aux trie (" " , [] ) (SMap. empty, env , generics)
13081300
1309- let class_subst { tries; _ } names generics =
1301+ let class_subst { tries; _ } env generics =
13101302 SMap. fold
1311- (fun class_name (_ty , trie ) (tries , names , generics ) ->
1312- let (subst, names , generics) = class_subst_help trie names generics in
1313- (SMap. add class_name subst tries, names , generics))
1303+ (fun class_name (_ty , trie ) (tries , env , generics ) ->
1304+ let (subst, env , generics) = class_subst_help trie env generics in
1305+ (SMap. add class_name subst tries, env , generics))
13141306 tries
1315- (SMap. empty, names , generics)
1307+ (SMap. empty, env , generics)
13161308
13171309 (* -- Build substitution for abstract type constants -------------------- *)
13181310
@@ -1365,15 +1357,15 @@ end = struct
13651357 let update acc ~key ~typeconst ~pos ~children ~path =
13661358 match typeconst with
13671359 | Typing_defs. (TCConcrete { tc_type } ) ->
1368- let (subst, names , generics) = acc in
1360+ let (subst, env , generics) = acc in
13691361 let subst =
13701362 SMap. add (String. concat (List. rev path) ~sep: " ::" ) tc_type subst
13711363 in
1372- (subst, names , generics)
1364+ (subst, env , generics)
13731365 | Typing_defs. (TCAbstract { atc_as_constraint; atc_super_constraint; _ })
13741366 ->
1375- let (subst, names , generics) = acc in
1376- let (names , generic_name) = fresh_name names key in
1367+ let (subst, env , generics) = acc in
1368+ let (env , generic_name) = Typing_env. fresh_param_name env key in
13771369 let subst =
13781370 let key = String. concat (List. rev path) ~sep: " ::" in
13791371 let reason = Typing_reason. witness_from_decl pos in
@@ -1390,9 +1382,9 @@ end = struct
13901382 let generics =
13911383 SMap. add generic_name { pos; upper_bound; lower_bound } generics
13921384 in
1393- (subst, names , generics)
1385+ (subst, env , generics)
13941386
1395- let this_subst { this_trie; _ } names generics =
1387+ let this_subst { this_trie; _ } env generics =
13961388 let Trie. { base; children } = this_trie in
13971389 let rec aux children ~path ~init =
13981390 SMap. fold
@@ -1410,7 +1402,7 @@ end = struct
14101402 children
14111403 init
14121404 in
1413- let init = (SMap. empty, names , generics) in
1405+ let init = (SMap. empty, env , generics) in
14141406 match base with
14151407 | Trie. Root -> aux children ~path: [] ~init
14161408 | _ -> init
@@ -1497,21 +1489,17 @@ end = struct
14971489 mk_tparam pos name tp_constraints)
14981490
14991491 let of_typeconst_analysis analysis this_name this_ty env =
1500- let (this_subst, class_subst, generics) =
1501- let names = SMap. empty and generics = SMap. empty in
1502- let (this_subst, names, generics) =
1503- this_subst analysis names generics
1504- in
1505- let (class_subst, _names, generics) =
1506- class_subst analysis names generics
1507- in
1508- (this_subst, class_subst, generics)
1492+ let (this_subst, class_subst, generics, env) =
1493+ let generics = SMap. empty in
1494+ let (this_subst, env, generics) = this_subst analysis env generics in
1495+ let (class_subst, env, generics) = class_subst analysis env generics in
1496+ (this_subst, class_subst, generics, env)
15091497 in
15101498 let tparams = mk_tparams generics env in
15111499 let subst = { this_name; this_ty; this_subst; class_subst; tparams } in
15121500 (* Apply refinements to [this] to ensure it lines up with any abstract constants *)
15131501 let this_ty = refine_this this_ty this_subst (this_constants analysis) in
1514- { subst with this_ty }
1502+ (env, { subst with this_ty })
15151503 end
15161504
15171505 let to_subst t this_ty env =
@@ -1698,7 +1686,7 @@ let extract_static_method fun_ty ~class_name ~folded_class ~env =
16981686 substitution from to be applied to [Taccess] types and a refined version
16991687 of [this] with equalities to generics standing in for abstract type
17001688 constants *)
1701- let subst = Typeconst_analysis. to_subst analysis this_ty env in
1689+ let (env, subst) = Typeconst_analysis. to_subst analysis this_ty env in
17021690
17031691 (* Add class-level generics, the generics for [this] and any generics
17041692 for abstract type constants; some of these may end up not being used
@@ -1823,7 +1811,7 @@ let extract_static_method fun_ty ~class_name ~folded_class ~env =
18231811 we need to keep the original type params if they are marked as reify *)
18241812 let fun_ty = drop_unused_generics fun_ty ~names: original_tparam_names in
18251813
1826- fun_ty
1814+ (env, fun_ty)
18271815
18281816let extract_instance_method fun_ty ~class_name ~folded_class ~env =
18291817 let self_param =
0 commit comments