Skip to content

Commit e8e1ba3

Browse files
committed
Respond to review comments, and making threading through of loc variable a little more surgical
1 parent b1e1904 commit e8e1ba3

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

ocaml/typing/subst.ml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type additional_action =
3737
(* The [Prepare_for_saving] function should be applied to all layouts when
3838
saving; this commons them up, truncates their histories, and runs
3939
a check that all unconstrained variables have been defaulted to value. *)
40-
| Copy_types
40+
| Duplicate_variables
4141
| No_action
4242

4343
type t =
@@ -77,7 +77,7 @@ let add_modtype_path p ty s =
7777
let add_modtype id ty s = add_modtype_path (Pident id) ty s
7878

7979
type additional_action_config =
80-
| Copy_types
80+
| Duplicate_variables
8181
| Prepare_for_saving
8282

8383
let with_additional_action (config : additional_action_config) s =
@@ -93,7 +93,7 @@ let with_additional_action (config : additional_action_config) s =
9393
*)
9494
let additional_action : additional_action =
9595
match config with
96-
| Copy_types -> Copy_types
96+
| Duplicate_variables -> Duplicate_variables
9797
| Prepare_for_saving ->
9898
let reason = Layout.Imported in
9999
let any = Layout.of_const Any ~why:reason in
@@ -122,7 +122,7 @@ let with_additional_action (config : additional_action_config) s =
122122
let apply_prepare_layout s lay loc =
123123
match s.additional_action with
124124
| Prepare_for_saving prepare_layout -> prepare_layout loc lay
125-
| Copy_types | No_action -> lay
125+
| Duplicate_variables | No_action -> lay
126126

127127
let change_locs s loc = { s with loc = Some loc; last_compose = None }
128128

@@ -131,7 +131,7 @@ let loc s x =
131131
| Some l -> l
132132
| None -> begin
133133
match s.additional_action with
134-
| Prepare_for_saving _ | Copy_types ->
134+
| Prepare_for_saving _ | Duplicate_variables ->
135135
if not !Clflags.keep_locs then Location.none else x
136136
| No_action -> x
137137
end
@@ -148,21 +148,21 @@ let is_not_doc = function
148148
| _ -> true
149149

150150
let attrs s x =
151-
(* Now that we track [Copy_types] and [Prepare_for_saving] as
152-
separate states, we should reconsider whether the [Copy_types]
151+
(* Now that we track [Duplicate_variables] and [Prepare_for_saving] as
152+
separate states, we should reconsider whether the [Duplicate_variables]
153153
callsites really need to scrub docs and locations. For now, we're keeping
154154
the scrubbing behavior for backward compatibility.
155155
*)
156156
let x =
157157
match s.additional_action with
158-
| Prepare_for_saving _ | Copy_types ->
158+
| Prepare_for_saving _ | Duplicate_variables ->
159159
if not !Clflags.keep_docs
160160
then List.filter is_not_doc x
161161
else x
162162
| No_action -> x
163163
in
164164
match s.additional_action with
165-
| Prepare_for_saving _ | Copy_types ->
165+
| Prepare_for_saving _ | Duplicate_variables ->
166166
if not !Clflags.keep_locs
167167
then remove_loc.Ast_mapper.attributes remove_loc x
168168
else x
@@ -248,18 +248,18 @@ let ctype_apply_env_empty = ref (fun _ -> assert false)
248248

249249
(* Similar to [Ctype.nondep_type_rec]. *)
250250
let rec typexp copy_scope s ty =
251-
let should_copy_types =
251+
let should_duplicate_vars =
252252
match s.additional_action with
253-
| Copy_types | Prepare_for_saving _ -> true
253+
| Duplicate_variables | Prepare_for_saving _ -> true
254254
| No_action -> false
255255
in
256256
let desc = get_desc ty in
257257
match desc with
258258
Tvar _ | Tunivar _ ->
259-
if should_copy_types || get_id ty < 0 then
259+
if should_duplicate_vars || get_id ty < 0 then
260260
let ty' =
261261
match s.additional_action with
262-
| Copy_types -> newpersty desc
262+
| Duplicate_variables -> newpersty desc
263263
| Prepare_for_saving prepare_layout ->
264264
newpersty (norm desc ~prepare_layout)
265265
| No_action -> newty2 ~level:(get_level ty) desc
@@ -269,7 +269,7 @@ let rec typexp copy_scope s ty =
269269
else ty
270270
| Tsubst (ty, _) ->
271271
ty
272-
| Tfield (m, k, _t1, _t2) when not should_copy_types && m = dummy_method
272+
| Tfield (m, k, _t1, _t2) when not should_duplicate_vars && m = dummy_method
273273
&& field_kind_repr k <> Fabsent && get_level ty < generic_level ->
274274
(* do not copy the type of self when it is not generalized *)
275275
ty
@@ -284,7 +284,7 @@ let rec typexp copy_scope s ty =
284284
(* Make a stub *)
285285
let layout = Layout.any ~why:Dummy_layout in
286286
let ty' =
287-
if should_copy_types then newpersty (Tvar {name = None; layout})
287+
if should_duplicate_vars then newpersty (Tvar {name = None; layout})
288288
else newgenstub ~scope:(get_scope ty) layout
289289
in
290290
For_copy.redirect_desc copy_scope ty (Tsubst (ty', None));
@@ -331,15 +331,15 @@ let rec typexp copy_scope s ty =
331331
Tlink ty2
332332
| _ ->
333333
let dup =
334-
should_copy_types || get_level more = generic_level ||
334+
should_duplicate_vars || get_level more = generic_level ||
335335
static_row row || is_Tconstr more in
336336
(* Various cases for the row variable *)
337337
let more' =
338338
match mored with
339339
Tsubst (ty, None) -> ty
340340
| Tconstr _ | Tnil -> typexp copy_scope s more
341341
| Tunivar _ | Tvar _ ->
342-
if should_copy_types then newpersty mored
342+
if should_duplicate_vars then newpersty mored
343343
else if dup && is_Tvar more then newgenty mored
344344
else more
345345
| _ -> assert false
@@ -446,7 +446,7 @@ let type_declaration' copy_scope s decl =
446446
| Type_variant (cstrs, rep) ->
447447
let rep =
448448
match s.additional_action with
449-
| No_action | Copy_types -> rep
449+
| No_action | Duplicate_variables -> rep
450450
| Prepare_for_saving prepare_layout ->
451451
variant_representation ~prepare_layout decl.type_loc rep
452452
in
@@ -455,7 +455,7 @@ let type_declaration' copy_scope s decl =
455455
| Type_record(lbls, rep) ->
456456
let rep =
457457
match s.additional_action with
458-
| No_action | Copy_types -> rep
458+
| No_action | Duplicate_variables -> rep
459459
| Prepare_for_saving prepare_layout ->
460460
record_representation ~prepare_layout decl.type_loc rep
461461
in
@@ -473,7 +473,7 @@ let type_declaration' copy_scope s decl =
473473
match s.additional_action with
474474
| Prepare_for_saving prepare_layout ->
475475
prepare_layout decl.type_loc decl.type_layout
476-
| Copy_types | No_action -> decl.type_layout
476+
| Duplicate_variables | No_action -> decl.type_layout
477477
end;
478478
type_private = decl.type_private;
479479
type_variance = decl.type_variance;
@@ -558,15 +558,15 @@ let extension_constructor' copy_scope s ext =
558558
ext_arg_layouts = begin match s.additional_action with
559559
| Prepare_for_saving prepare_layout ->
560560
Array.map (prepare_layout ext.ext_loc) ext.ext_arg_layouts
561-
| Copy_types | No_action -> ext.ext_arg_layouts
561+
| Duplicate_variables | No_action -> ext.ext_arg_layouts
562562
end;
563563
ext_constant = ext.ext_constant;
564564
ext_ret_type =
565565
Option.map (typexp copy_scope s ext.ext_loc) ext.ext_ret_type;
566566
ext_private = ext.ext_private;
567567
ext_attributes = attrs s ext.ext_attributes;
568568
ext_loc = begin match s.additional_action with
569-
| Prepare_for_saving _ | Copy_types -> Location.none
569+
| Prepare_for_saving _ | Duplicate_variables -> Location.none
570570
| No_action -> ext.ext_loc
571571
end;
572572
ext_uid = ext.ext_uid;
@@ -821,13 +821,13 @@ and compose s1 s2 =
821821
additional_action = begin
822822
match s1.additional_action, s2.additional_action with
823823
| action, No_action | No_action, action -> action
824-
| Copy_types, Copy_types -> Copy_types
824+
| Duplicate_variables, Duplicate_variables -> Duplicate_variables
825825

826826
(* Preparing for saving runs a superset of the things involved with
827827
copying variables, so we prefer that if composing substitutions.
828828
*)
829-
| (Prepare_for_saving _ as prepare), Copy_types
830-
| Copy_types, (Prepare_for_saving _ as prepare)
829+
| (Prepare_for_saving _ as prepare), Duplicate_variables
830+
| Duplicate_variables, (Prepare_for_saving _ as prepare)
831831
-> prepare
832832

833833
(* Note [Preparing_for_saving always the same]

ocaml/typing/subst.mli

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ val add_modtype: Ident.t -> module_type -> t -> t
4343
val add_modtype_path: Path.t -> module_type -> t -> t
4444

4545
type additional_action_config =
46-
| Copy_types
47-
(* CR nroberts: I have low confidence in this comment. *)
48-
(* [Copy_types] makes it so any substitution will replace all types
49-
with copies unrelated to the original type. *)
46+
| Duplicate_variables
47+
(* [Duplicate_variables] makes it so that any substitution will duplicate
48+
variable nodes. Substitution already duplicates non-variable nodes;
49+
refer to the comment at the top of [subst.mli].
50+
*)
5051
| Prepare_for_saving
5152
(* [Prepare_for_saving] performs all actions associated with
52-
[Copy_types] and additionally prepares layouts for saving by
53+
[Duplicate_variables] and additionally prepares layouts for saving by
5354
commoning them up, truncating their histories, and performing
5455
a check that all unconstrained layouts have been defaulted to value.
5556
*)

ocaml/typing/typecore.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6849,12 +6849,12 @@ and type_cases
68496849
(* Hack: use the [Subst] machinery to copy types, even though
68506850
we don't intend on persisting the type to disk.
68516851
6852-
We added a new [Copy_types] variant specifically for this
6853-
callsite, but it's still a bit of a hack (e.g. the type
6854-
IDs are all negative, like they are in cmi files).
6852+
We added a new [Duplicate_variables] variant specifically for this
6853+
callsite, but it's still a bit of a hack (e.g. the type IDs produced
6854+
for duplicated nodes are all negative, like they are in cmi files).
68556855
*)
68566856
Subst.type_expr
6857-
(Subst.with_additional_action Copy_types Subst.identity)
6857+
(Subst.with_additional_action Duplicate_variables Subst.identity)
68586858
ty_arg'
68596859
else ty_arg'
68606860
in

0 commit comments

Comments
 (0)