Skip to content
This repository was archived by the owner on Nov 12, 2020. It is now read-only.

Commit d8b413f

Browse files
committed
Expose a more explicit 'copy types' operation in Env (with a representation in summary), instead of a more generic 'update_value'.
1 parent acedb1e commit d8b413f

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

typing/env.ml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type summary =
120120
| Env_open of summary * Path.t
121121
| Env_functor_arg of summary * Ident.t
122122
| Env_constraints of summary * type_declaration PathMap.t
123+
| Env_copy_types of summary * string list
123124

124125
module EnvTbl =
125126
struct
@@ -315,29 +316,25 @@ module EnvTbl2 =
315316

316317
let find_name name tbl = find_name true name tbl
317318

318-
let rec update name f tbl summary =
319+
let rec update name f tbl =
319320
try
320321
let (id, desc) = Ident.find_name name tbl.current in
321322
let new_desc = f desc in
322-
{tbl with current = Ident.add id new_desc tbl.current},
323-
Env_value (summary, id, new_desc)
323+
{tbl with current = Ident.add id new_desc tbl.current}
324324
with Not_found ->
325325
begin match tbl.opened with
326326
| Some {root; using; next; components} ->
327327
begin try
328328
let (desc, pos) = Tbl.find_str name components in
329329
let new_desc = f desc in
330330
let components = Tbl.add name (new_desc, pos) components in
331-
{tbl with opened = Some {root; using; next; components}},
332-
summary (* ?? *)
331+
{tbl with opened = Some {root; using; next; components}}
333332
with Not_found ->
334-
let next, summary = update name f next summary in
335-
{tbl with opened = Some {root; using; next; components}},
336-
summary
333+
let next = update name f next in
334+
{tbl with opened = Some {root; using; next; components}}
337335
end
338336
| None ->
339-
tbl,
340-
summary
337+
tbl
341338
end
342339

343340

@@ -1204,9 +1201,10 @@ let lookup_class =
12041201
let lookup_cltype =
12051202
lookup (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes)
12061203

1207-
let update_value s f env =
1208-
let values, summary = EnvTbl2.update s f env.values env.summary in
1209-
{env with values; summary}
1204+
let copy_types l env =
1205+
let f desc = {desc with val_type = Subst.type_expr Subst.identity desc.val_type} in
1206+
let values = List.fold_left (fun env s -> EnvTbl2.update s f env) env.values l in
1207+
{env with values; summary = Env_copy_types (env.summary, l)}
12101208

12111209
let mark_value_used env name vd =
12121210
if not (is_implicit_coercion env) then

typing/env.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type summary =
3232
| Env_open of summary * Path.t
3333
| Env_functor_arg of summary * Ident.t
3434
| Env_constraints of summary * type_declaration PathMap.t
35+
| Env_copy_types of summary * string list
3536

3637
type t
3738

@@ -123,8 +124,7 @@ val lookup_class:
123124
val lookup_cltype:
124125
?loc:Location.t -> Longident.t -> t -> Path.t * class_type_declaration
125126

126-
val update_value:
127-
string -> (value_description -> value_description) -> t -> t
127+
val copy_types: string list -> t -> t
128128
(* Used only in Typecore.duplicate_ident_types. *)
129129

130130
exception Recmodule

typing/envaux.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ let rec env_from_summary sum subst =
7878
Env.add_local_type (Subst.type_path subst path)
7979
(Subst.type_declaration subst info))
8080
map (env_from_summary s subst)
81+
| Env_copy_types (s, sl) ->
82+
Env.copy_types sl (env_from_summary s subst)
8183
in
8284
Hashtbl.add env_cache (sum, subst) env;
8385
env

typing/typecore.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,12 +1883,7 @@ let check_absent_variant env =
18831883
let duplicate_ident_types caselist env =
18841884
let caselist =
18851885
List.filter (fun {pc_lhs} -> contains_gadt env pc_lhs) caselist in
1886-
let idents = all_idents_cases caselist in
1887-
let upd desc = {desc with val_type = correct_levels desc.val_type} in
1888-
(* Be careful not the mark the original value as being used, and
1889-
to keep the same internal 'slot' to track unused opens. *)
1890-
List.fold_left (fun env s -> Env.update_value s upd env) env idents
1891-
1886+
Env.copy_types (all_idents_cases caselist) env
18921887

18931888
(* Getting proper location of already typed expressions.
18941889

0 commit comments

Comments
 (0)