@@ -43,16 +43,16 @@ module Cached : sig
43
43
-> Type_grammar. t
44
44
-> Binding_time. t
45
45
-> Name_mode. t
46
- -> new_aliases:Aliases. t
47
46
-> t
48
47
49
48
val replace_variable_binding
50
49
: t
51
50
-> Variable. t
52
51
-> Type_grammar. t
53
- -> new_aliases:Aliases. t
54
52
-> t
55
53
54
+ val with_aliases : t -> aliases :Aliases .t -> t
55
+
56
56
val add_symbol_projection : t -> Variable .t -> Symbol_projection .t -> t
57
57
58
58
val find_symbol_projection : t -> Variable .t -> Symbol_projection .t option
@@ -131,27 +131,30 @@ end = struct
131
131
(used to be add-or-replace), the [names_to_types] map addition was a
132
132
major source of allocation. *)
133
133
134
- let add_or_replace_binding t (name : Name.t ) ty binding_time name_mode ~ new_aliases =
134
+ let add_or_replace_binding t (name : Name.t ) ty binding_time name_mode =
135
135
let names_to_types =
136
136
Name.Map. add name (ty, binding_time, name_mode) t.names_to_types
137
137
in
138
138
{ names_to_types;
139
- aliases = new_aliases ;
139
+ aliases = t.aliases ;
140
140
symbol_projections = t.symbol_projections;
141
141
}
142
142
143
- let replace_variable_binding t var ty ~ new_aliases =
143
+ let replace_variable_binding t var ty =
144
144
let names_to_types =
145
145
Name.Map. replace (Name. var var)
146
146
(function (_old_ty , binding_time , name_mode ) ->
147
147
ty, binding_time, name_mode)
148
148
t.names_to_types
149
149
in
150
150
{ names_to_types;
151
- aliases = new_aliases ;
151
+ aliases = t.aliases ;
152
152
symbol_projections = t.symbol_projections;
153
153
}
154
154
155
+ let with_aliases t ~aliases =
156
+ { t with aliases; }
157
+
155
158
let add_symbol_projection t var proj =
156
159
let symbol_projections = Variable.Map. add var proj t.symbol_projections in
157
160
{ t with symbol_projections; }
@@ -260,6 +263,12 @@ module One_level = struct
260
263
let level t = t.level
261
264
let just_after_level t = t.just_after_level
262
265
266
+ let with_aliases t ~aliases =
267
+ let just_after_level =
268
+ Cached. with_aliases t.just_after_level ~aliases
269
+ in
270
+ { t with just_after_level; }
271
+
263
272
let is_empty t = Typing_env_level. is_empty t.level
264
273
265
274
(*
@@ -781,6 +790,12 @@ let with_current_level_and_next_binding_time t ~current_level
781
790
invariant t;
782
791
t
783
792
793
+ let with_aliases t ~aliases =
794
+ let current_level =
795
+ One_level. with_aliases t.current_level ~aliases
796
+ in
797
+ with_current_level t ~current_level
798
+
784
799
let cached t = One_level. just_after_level t.current_level
785
800
786
801
let add_variable_definition t var kind name_mode =
@@ -810,7 +825,6 @@ let add_variable_definition t var kind name_mode =
810
825
Cached. add_or_replace_binding (cached t)
811
826
name (Type_grammar. unknown kind)
812
827
t.next_binding_time name_mode
813
- ~new_aliases: (aliases t)
814
828
in
815
829
let current_level =
816
830
One_level. create (current_scope t) level ~just_after_level
@@ -911,7 +925,7 @@ let invariant_for_new_equation t aliases name ty =
911
925
end
912
926
end
913
927
914
- let rec add_equation0 t aliases name ty =
928
+ let rec add_equation0 t name ty =
915
929
if ! Clflags.Flambda.Debug. concrete_types_only_on_canonicals then begin
916
930
let is_concrete =
917
931
match Type_grammar. get_alias_exn ty with
@@ -943,20 +957,18 @@ let rec add_equation0 t aliases name ty =
943
957
then
944
958
Cached. replace_variable_binding
945
959
(One_level. just_after_level t.current_level)
946
- var ty ~new_aliases: aliases
960
+ var ty
947
961
else
948
962
Cached. add_or_replace_binding
949
963
(One_level. just_after_level t.current_level)
950
964
name ty Binding_time. imported_variables Name_mode. in_types
951
- ~new_aliases: aliases
952
965
in
953
966
just_after_level)
954
967
~symbol: (fun _ ->
955
968
let just_after_level =
956
969
Cached. add_or_replace_binding
957
970
(One_level. just_after_level t.current_level)
958
971
name ty Binding_time. symbols Name_mode. normal
959
- ~new_aliases: aliases
960
972
in
961
973
just_after_level)
962
974
in
@@ -1011,15 +1023,15 @@ and add_equation t name ty =
1011
1023
end )
1012
1024
~const: (fun _ -> () )
1013
1025
end ;
1014
- let aliases, simple, t, ty =
1026
+ let simple, t, ty =
1015
1027
let aliases = aliases t in
1016
1028
match Type_grammar. get_alias_exn ty with
1017
1029
| exception Not_found ->
1018
1030
(* Equations giving concrete types may only be added to the canonical
1019
1031
element as known by the alias tracker (the actual canonical, ignoring
1020
1032
any name modes). *)
1021
1033
let canonical = Aliases. get_canonical_ignoring_name_mode aliases name in
1022
- aliases, canonical, t, ty
1034
+ canonical, t, ty
1023
1035
| alias_of ->
1024
1036
let alias_of = Simple. without_coercion alias_of in
1025
1037
let alias = Simple. name name in
@@ -1033,10 +1045,11 @@ and add_equation t name ty =
1033
1045
Aliases. add aliases alias binding_time_and_mode_alias
1034
1046
alias_of binding_time_and_mode_alias_of
1035
1047
in
1048
+ let t = with_aliases t ~aliases in
1036
1049
let ty =
1037
1050
Type_grammar. alias_type_of kind canonical_element
1038
1051
in
1039
- aliases, alias_of_demoted_element , t, ty
1052
+ alias_of , t, ty
1040
1053
in
1041
1054
(* Beware: if we're about to add the equation on a name which is different
1042
1055
from the one that the caller passed in, then we need to make sure that the
@@ -1064,7 +1077,15 @@ and add_equation t name ty =
1064
1077
in
1065
1078
Simple. pattern_match simple ~name ~const: (fun _ -> ty, t)
1066
1079
in
1067
- let [@ inline always] name name = add_equation0 t aliases name ty in
1080
+ let ty =
1081
+ match rec_info with
1082
+ | None -> ty
1083
+ | Some rec_info ->
1084
+ match Type_grammar. apply_rec_info ty rec_info with
1085
+ | Bottom -> Type_grammar. bottom (Type_grammar. kind ty)
1086
+ | Ok ty -> ty
1087
+ in
1088
+ let [@ inline always] name name = add_equation0 t name ty in
1068
1089
Simple. pattern_match simple ~name ~const: (fun _ -> t)
1069
1090
1070
1091
and add_env_extension t (env_extension : Typing_env_extension.t ) =
0 commit comments