Skip to content

Commit 2f39cfb

Browse files
lthlschambart
authored andcommitted
Review comments
1 parent 0f05c84 commit 2f39cfb

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

middle_end/flambda/types/env/typing_env_level.rec.ml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,28 @@ let join_types ~env_at_fork envs_with_levels =
195195
consistency of binding time order in the branches and the result.
196196
In addition, this also aggregates the code age relations of the branches.
197197
*)
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
204204
else
205205
let kind = Variable.Map.find var level.defined_vars in
206-
Typing_env.add_definition env
206+
Typing_env.add_definition base_env
207207
(Name_in_binding_pos.var
208208
(Var_in_binding_pos.create var Name_mode.in_types))
209209
kind)
210210
vars
211-
env)
211+
base_env)
212212
level.binding_times
213-
env_at_fork
213+
base_env
214214
in
215215
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)
217217
(Typing_env.code_age_relation env_at_use)
218218
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)
220220
env_at_fork
221221
envs_with_levels
222222
in
@@ -225,7 +225,10 @@ let join_types ~env_at_fork envs_with_levels =
225225
~init:(Name.Map.empty, true)
226226
~f:(fun (joined_types, is_first_join) (env_at_use, _, _, t) ->
227227
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
229232
(Typing_env_extension.from_map joined_types)
230233
in
231234
let join_types name joined_ty use_ty =
@@ -236,17 +239,17 @@ let join_types ~env_at_fork envs_with_levels =
236239
Compilation_unit.equal (Name.compilation_unit name)
237240
(Compilation_unit.get_current_exn ())
238241
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"
241244
Name.print name
242-
Typing_env.print env_at_fork
245+
Typing_env.print base_env
243246
end;
244247
(* If [name] is that of a lifted constant symbol generated during one
245248
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
247250
environment.
248251
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.
250253
While it is possible that its type could be refined by all of the
251254
branches, it is unlikely. *)
252255
if Name.is_symbol name then None
@@ -272,11 +275,11 @@ let join_types ~env_at_fork envs_with_levels =
272275
to case split. *)
273276
else
274277
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
276279
in
277280
(* Recall: the order of environments matters for [join]. *)
278281
let join_env =
279-
Join_env.create env_at_fork
282+
Join_env.create base_env
280283
~left_env
281284
~right_env:env_at_use
282285
in
@@ -287,14 +290,14 @@ let join_types ~env_at_fork envs_with_levels =
287290
the current level for [name]. However we have seen an
288291
equation for [name] on a previous level. We need to get the
289292
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. *)
291294
assert (not is_first_join);
292295
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
294297
let join_env =
295-
Join_env.create env_at_fork
298+
Join_env.create base_env
296299
~left_env
297-
~right_env:env_at_fork
300+
~right_env:base_env
298301
in
299302
Type_grammar.join ~bound_name:name
300303
join_env joined_ty right_ty
@@ -304,7 +307,7 @@ let join_types ~env_at_fork envs_with_levels =
304307
equation for [name] on the current level. *)
305308
assert (not is_first_join);
306309
let join_env =
307-
Join_env.create env_at_fork
310+
Join_env.create base_env
308311
~left_env
309312
~right_env:env_at_use
310313
in

0 commit comments

Comments
 (0)