@@ -195,28 +195,28 @@ let join_types ~env_at_fork envs_with_levels =
195
195
consistency of binding time order in the branches and the result.
196
196
In addition, this also aggregates the code age relations of the branches.
197
197
*)
198
- let env_at_fork =
199
- List. fold_left (fun env_at_fork (env_at_use , _ , _ , level ) ->
200
- let env_with_variables =
201
- Binding_time.Map. fold (fun _ vars env ->
202
- Variable.Set. fold (fun var env ->
203
- if Typing_env. mem env (Name. var var) then env
198
+ let base_env =
199
+ List. fold_left (fun base_env (env_at_use , _ , _ , level ) ->
200
+ let base_env =
201
+ Binding_time.Map. fold (fun _ vars base_env ->
202
+ Variable.Set. fold (fun var base_env ->
203
+ if Typing_env. mem base_env (Name. var var) then base_env
204
204
else
205
205
let kind = Variable.Map. find var level.defined_vars in
206
- Typing_env. add_definition env
206
+ Typing_env. add_definition base_env
207
207
(Name_in_binding_pos. var
208
208
(Var_in_binding_pos. create var Name_mode. in_types))
209
209
kind)
210
210
vars
211
- env )
211
+ base_env )
212
212
level.binding_times
213
- env_at_fork
213
+ base_env
214
214
in
215
215
let code_age_relation =
216
- Code_age_relation. union (Typing_env. code_age_relation env_at_fork )
216
+ Code_age_relation. union (Typing_env. code_age_relation base_env )
217
217
(Typing_env. code_age_relation env_at_use)
218
218
in
219
- Typing_env. with_code_age_relation env_with_variables code_age_relation)
219
+ Typing_env. with_code_age_relation base_env code_age_relation)
220
220
env_at_fork
221
221
envs_with_levels
222
222
in
@@ -225,7 +225,10 @@ let join_types ~env_at_fork envs_with_levels =
225
225
~init: (Name.Map. empty, true )
226
226
~f: (fun (joined_types , is_first_join ) (env_at_use , _ , _ , t ) ->
227
227
let left_env =
228
- Typing_env. add_env_extension env_at_fork
228
+ (* CR vlaviron: This is very likely quadratic (number of uses times
229
+ number of variables in all uses).
230
+ However it's hard to know how we could do better. *)
231
+ Typing_env. add_env_extension base_env
229
232
(Typing_env_extension. from_map joined_types)
230
233
in
231
234
let join_types name joined_ty use_ty =
@@ -236,17 +239,17 @@ let join_types ~env_at_fork envs_with_levels =
236
239
Compilation_unit. equal (Name. compilation_unit name)
237
240
(Compilation_unit. get_current_exn () )
238
241
in
239
- if same_unit && not (Typing_env. mem env_at_fork name) then begin
240
- Misc. fatal_errorf " Name %a not defined in [env_at_fork ]:@ %a"
242
+ if same_unit && not (Typing_env. mem base_env name) then begin
243
+ Misc. fatal_errorf " Name %a not defined in [base_env ]:@ %a"
241
244
Name. print name
242
- Typing_env. print env_at_fork
245
+ Typing_env. print base_env
243
246
end ;
244
247
(* If [name] is that of a lifted constant symbol generated during one
245
248
of the levels, then ignore it. [Simplify_expr] will already have
246
- made its type suitable for [env_at_fork ] and inserted it into that
249
+ made its type suitable for [base_env ] and inserted it into that
247
250
environment.
248
251
If [name] is a symbol that is not a lifted constant, then it was
249
- defined before the fork and already has an equation in env_at_fork .
252
+ defined before the fork and already has an equation in base_env .
250
253
While it is possible that its type could be refined by all of the
251
254
branches, it is unlikely. *)
252
255
if Name. is_symbol name then None
@@ -272,11 +275,11 @@ let join_types ~env_at_fork envs_with_levels =
272
275
to case split. *)
273
276
else
274
277
let expected_kind = Some (Type_grammar. kind use_ty) in
275
- Typing_env. find env_at_fork name expected_kind
278
+ Typing_env. find base_env name expected_kind
276
279
in
277
280
(* Recall: the order of environments matters for [join]. *)
278
281
let join_env =
279
- Join_env. create env_at_fork
282
+ Join_env. create base_env
280
283
~left_env
281
284
~right_env: env_at_use
282
285
in
@@ -287,14 +290,14 @@ let join_types ~env_at_fork envs_with_levels =
287
290
the current level for [name]. However we have seen an
288
291
equation for [name] on a previous level. We need to get the
289
292
best type we can for [name] on the current level, from
290
- [env_at_fork ], similarly to the previous case. *)
293
+ [base_env ], similarly to the previous case. *)
291
294
assert (not is_first_join);
292
295
let expected_kind = Some (Type_grammar. kind joined_ty) in
293
- let right_ty = Typing_env. find env_at_fork name expected_kind in
296
+ let right_ty = Typing_env. find base_env name expected_kind in
294
297
let join_env =
295
- Join_env. create env_at_fork
298
+ Join_env. create base_env
296
299
~left_env
297
- ~right_env: env_at_fork
300
+ ~right_env: base_env
298
301
in
299
302
Type_grammar. join ~bound_name: name
300
303
join_env joined_ty right_ty
@@ -304,7 +307,7 @@ let join_types ~env_at_fork envs_with_levels =
304
307
equation for [name] on the current level. *)
305
308
assert (not is_first_join);
306
309
let join_env =
307
- Join_env. create env_at_fork
310
+ Join_env. create base_env
308
311
~left_env
309
312
~right_env: env_at_use
310
313
in
0 commit comments