Skip to content

Commit d78b9d5

Browse files
authored
Upgrade to OCaml 4.14.1 #1557
from voodoos/update-to-4.14.1
2 parents 478d99b + 91cbd41 commit d78b9d5

28 files changed

+191
-95
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
merlin 4.8
2+
==========
3+
unreleased
4+
5+
+ merlin binary
6+
- Update internal typer to match OCaml 4.14.1 release. (#1557)
7+
18
merlin 4.7
29
==========
310
Thu Nov 24 13:31:42 CEST 2022

src/ocaml/typing/env.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ let add_label_usage lu usage =
104104
lu.lu_mutation <- true;
105105
lu.lu_construct <- true
106106

107+
let is_mutating_label_usage = function
108+
| Mutation -> true
109+
| (Projection | Construct | Exported_private | Exported) -> false
110+
107111
let label_usages () =
108112
{lu_projection = false; lu_mutation = false; lu_construct = false}
109113

@@ -2308,6 +2312,14 @@ and add_cltype ?shape id ty env =
23082312
let add_module ?arg ?shape id presence mty env =
23092313
add_module_declaration ~check:false ?arg ?shape id presence (md mty) env
23102314

2315+
let add_module_lazy ~update_summary id presence mty env =
2316+
let md = Subst.Lazy.{mdl_type = mty;
2317+
mdl_attributes = [];
2318+
mdl_loc = Location.none;
2319+
mdl_uid = Uid.internal_not_actually_unique}
2320+
in
2321+
add_module_declaration_lazy ~update_summary id presence md env
2322+
23112323
let add_local_type path info env =
23122324
{ env with
23132325
local_constraints = Path.Map.add path info env.local_constraints }
@@ -2842,7 +2854,10 @@ let use_cltype ~use ~loc path desc =
28422854
let use_label ~use ~loc usage env lbl =
28432855
if use then begin
28442856
mark_label_description_used usage env lbl;
2845-
Builtin_attributes.check_alerts loc lbl.lbl_attributes lbl.lbl_name
2857+
Builtin_attributes.check_alerts loc lbl.lbl_attributes lbl.lbl_name;
2858+
if is_mutating_label_usage usage then
2859+
Builtin_attributes.check_deprecated_mutable loc lbl.lbl_attributes
2860+
lbl.lbl_name
28462861
end
28472862

28482863
let use_constructor_desc ~use ~loc usage env cstr =

src/ocaml/typing/env.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ val add_extension:
289289
check:bool -> rebind:bool -> Ident.t -> extension_constructor -> t -> t
290290
val add_module: ?arg:bool -> ?shape:Shape.t ->
291291
Ident.t -> module_presence -> module_type -> t -> t
292+
val add_module_lazy: update_summary:bool ->
293+
Ident.t -> module_presence -> Subst.Lazy.modtype -> t -> t
292294
val add_module_declaration: ?arg:bool -> ?shape:Shape.t -> check:bool ->
293295
Ident.t -> module_presence -> module_declaration -> t -> t
294296
val add_module_declaration_lazy: update_summary:bool ->

src/ocaml/typing/includemod_errorprinter.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,16 @@ let rec module_type ~expansion_token ~eqmode ~env ~before ~ctx diff =
710710
functor_params ~expansion_token ~env ~before ~ctx d
711711
| _ ->
712712
let inner = if eqmode then eq_module_types else module_types in
713-
let next = dwith_context_and_elision ctx inner diff in
713+
let next =
714+
match diff.symptom with
715+
| Mt_core _ ->
716+
(* In those cases, the refined error messages for the current error
717+
will at most add some minor comments on the current error.
718+
It is thus better to avoid eliding the current error message.
719+
*)
720+
dwith_context ctx (inner diff)
721+
| _ -> dwith_context_and_elision ctx inner diff
722+
in
714723
let before = next :: before in
715724
module_type_symptom ~eqmode ~expansion_token ~env ~before ~ctx
716725
diff.symptom

src/ocaml/typing/mtype.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ let rec strengthen_lazy ~aliasable env mty p =
4646
MtyL_signature(strengthen_lazy_sig ~aliasable env sg p)
4747
| MtyL_functor(Named (Some param, arg), res)
4848
when !Clflags.applicative_functors ->
49+
let env =
50+
Env.add_module_lazy ~update_summary:false param Mp_present arg env
51+
in
4952
MtyL_functor(Named (Some param, arg),
5053
strengthen_lazy ~aliasable:false env res (Papply(p, Pident param)))
5154
| MtyL_functor(Named (None, arg), res)

src/ocaml/typing/printtyp.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,10 @@ let reset () =
10071007
reset_except_context ()
10081008

10091009
let prepare_for_printing tyl =
1010-
reset_except_context (); List.iter prepare_type tyl
1010+
reset_except_context ();
1011+
List.iter prepare_type tyl
1012+
1013+
let add_type_to_preparation = prepare_type
10111014

10121015
(* Disabled in classic mode when printing an unification error *)
10131016
let print_labels = ref true
@@ -1416,10 +1419,13 @@ and tree_of_label l =
14161419

14171420
let constructor ppf c =
14181421
reset_except_context ();
1422+
prepare_type_constructor_arguments c.cd_args;
1423+
Option.iter prepare_type c.cd_res;
14191424
!Oprint.out_constr ppf (tree_of_constructor c)
14201425

14211426
let label ppf l =
14221427
reset_except_context ();
1428+
prepare_type l.ld_type;
14231429
!Oprint.out_label ppf (tree_of_label l)
14241430

14251431
let tree_of_type_declaration id decl rs =
@@ -1488,6 +1494,8 @@ let extension_constructor id ppf ext =
14881494

14891495
let extension_only_constructor id ppf ext =
14901496
reset_except_context ();
1497+
prepare_type_constructor_arguments ext.ext_args;
1498+
Option.iter prepare_type ext.ext_ret_type;
14911499
let name = Ident.name id in
14921500
let args, ret =
14931501
extension_constructor_args_and_ret_type_subtree

src/ocaml/typing/printtyp.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ val type_expr: formatter -> type_expr -> unit
112112
Any type variables that are shared between multiple types in the input list
113113
will be given the same name when printed with [prepared_type_expr]. *)
114114
val prepare_for_printing: type_expr list -> unit
115+
116+
(** [add_type_to_preparation ty] extend a previous type expression preparation
117+
to the type expression [ty]
118+
*)
119+
val add_type_to_preparation: type_expr -> unit
120+
115121
val prepared_type_expr: formatter -> type_expr -> unit
116122
(** The function [prepared_type_expr] is a less-safe but more-flexible version
117123
of [type_expr] that should only be called on [type_expr]s that have been

src/ocaml/typing/tast_mapper.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,10 @@ let module_type sub x =
461461
let with_constraint sub = function
462462
| Twith_type decl -> Twith_type (sub.type_declaration sub decl)
463463
| Twith_typesubst decl -> Twith_typesubst (sub.type_declaration sub decl)
464+
| Twith_modtype mty -> Twith_modtype (sub.module_type sub mty)
465+
| Twith_modtypesubst mty -> Twith_modtypesubst (sub.module_type sub mty)
464466
| Twith_module _
465-
| Twith_modsubst _
466-
| Twith_modtype _
467-
| Twith_modtypesubst _ as d -> d
467+
| Twith_modsubst _ as d -> d
468468

469469
let open_description sub od =
470470
{od with open_env = sub.env sub od.open_env}

src/ocaml/typing/typeclass.ml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ let check_virtual loc env virt kind sign =
177177
| meths, vars ->
178178
raise(Error(loc, env, Virtual_class(kind, meths, vars)))
179179

180+
let rec check_virtual_clty loc env virt kind clty =
181+
match clty with
182+
| Cty_constr(_, _, clty) | Cty_arrow(_, _, clty) ->
183+
check_virtual_clty loc env virt kind clty
184+
| Cty_signature sign ->
185+
check_virtual loc env virt kind sign
186+
180187
(* Return the constructor type associated to a class type *)
181188
let rec constructor_type constr cty =
182189
match cty with
@@ -398,6 +405,8 @@ and class_type_aux env virt self_scope scty =
398405
) styl params
399406
in
400407
let typ = Cty_constr (path, params, clty) in
408+
(* Check for unexpected virtual methods *)
409+
check_virtual_clty scty.pcty_loc env virt Class_type typ;
401410
cltyp (Tcty_constr ( path, lid , ctys)) typ
402411

403412
| Pcty_signature pcsig ->
@@ -552,12 +561,11 @@ type first_pass_accummulater =
552561
concrete_vals : VarSet.t;
553562
local_meths : MethSet.t;
554563
local_vals : VarSet.t;
555-
vars : Ident.t Vars.t;
556-
meths : Ident.t Meths.t; }
564+
vars : Ident.t Vars.t; }
557565

558566
let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
559567
let { rev_fields; val_env; par_env; concrete_meths; concrete_vals;
560-
local_meths; local_vals; vars; meths } = acc
568+
local_meths; local_vals; vars } = acc
561569
in
562570
let loc = cf.pcf_loc in
563571
let attributes = cf.pcf_attributes in
@@ -612,13 +620,6 @@ let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
612620
(val_env, par_env, inherited_vars, vars))
613621
parent_sign.csig_vars (val_env, par_env, [], vars)
614622
in
615-
let meths =
616-
Meths.fold
617-
(fun label _ meths ->
618-
if Meths.mem label meths then meths
619-
else Meths.add label (Ident.create_local label) meths)
620-
parent_sign.csig_meths meths
621-
in
622623
(* Methods available through super *)
623624
let super_meths =
624625
MethSet.fold
@@ -641,7 +642,7 @@ let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
641642
in
642643
let rev_fields = field :: rev_fields in
643644
{ acc with rev_fields; val_env; par_env;
644-
concrete_meths; concrete_vals; vars; meths })
645+
concrete_meths; concrete_vals; vars })
645646
| Pcf_val (label, mut, Cfk_virtual styp) ->
646647
with_attrs
647648
(fun () ->
@@ -723,15 +724,11 @@ let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
723724
let cty = transl_simple_type val_env false sty in
724725
let ty = cty.ctyp_type in
725726
add_method loc val_env label.txt priv Virtual ty sign;
726-
let meths =
727-
if Meths.mem label.txt meths then meths
728-
else Meths.add label.txt (Ident.create_local label.txt) meths
729-
in
730727
let field =
731728
Virtual_method { label; priv; cty; loc; attributes }
732729
in
733730
let rev_fields = field :: rev_fields in
734-
{ acc with rev_fields; meths })
731+
{ acc with rev_fields })
735732

736733
| Pcf_method (label, priv, Cfk_concrete (override, expr)) ->
737734
with_attrs
@@ -785,10 +782,6 @@ let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
785782
raise(Error(loc, val_env,
786783
Field_type_mismatch ("method", label.txt, err)))
787784
end;
788-
let meths =
789-
if Meths.mem label.txt meths then meths
790-
else Meths.add label.txt (Ident.create_local label.txt) meths
791-
in
792785
let sdefinition = make_method self_loc cl_num expr in
793786
let warning_state = Warnings.backup () in
794787
let field =
@@ -799,7 +792,7 @@ let rec class_field_first_pass self_loc cl_num sign self_scope acc cf =
799792
let rev_fields = field :: rev_fields in
800793
let concrete_meths = MethSet.add label.txt concrete_meths in
801794
let local_meths = MethSet.add label.txt local_meths in
802-
{ acc with rev_fields; concrete_meths; local_meths; meths })
795+
{ acc with rev_fields; concrete_meths; local_meths })
803796

804797
| Pcf_constraint (sty1, sty2) ->
805798
with_attrs
@@ -837,11 +830,10 @@ and class_fields_first_pass self_loc cl_num sign self_scope
837830
let local_meths = MethSet.empty in
838831
let local_vals = VarSet.empty in
839832
let vars = Vars.empty in
840-
let meths = Meths.empty in
841833
let init_acc =
842834
{ rev_fields; val_env; par_env;
843835
concrete_meths; concrete_vals;
844-
local_meths; local_vals; vars; meths }
836+
local_meths; local_vals; vars }
845837
in
846838
let acc =
847839
Builtin_attributes.warning_scope []
@@ -850,7 +842,7 @@ and class_fields_first_pass self_loc cl_num sign self_scope
850842
(class_field_first_pass self_loc cl_num sign self_scope)
851843
init_acc cfs)
852844
in
853-
List.rev acc.rev_fields, acc.vars, acc.meths
845+
List.rev acc.rev_fields, acc.vars
854846

855847
and class_field_second_pass cl_num sign met_env field =
856848
let mkcf desc loc attrs =
@@ -1003,7 +995,7 @@ and class_structure cl_num virt self_scope final val_env met_env loc
1003995
end;
1004996

1005997
(* Typing of class fields *)
1006-
let (fields, vars, meths) =
998+
let (fields, vars) =
1007999
class_fields_first_pass self_loc cl_num sign self_scope
10081000
val_env par_env str
10091001
in
@@ -1016,6 +1008,13 @@ and class_structure cl_num virt self_scope final val_env met_env loc
10161008
update_class_signature loc val_env
10171009
~warn_implicit_public:false virt kind sign;
10181010

1011+
let meths =
1012+
Meths.fold
1013+
(fun label _ meths ->
1014+
Meths.add label (Ident.create_local label) meths)
1015+
sign.csig_meths Meths.empty
1016+
in
1017+
10191018
(* Close the signature if it is final *)
10201019
begin match final with
10211020
| Not_final -> ()
@@ -1087,6 +1086,8 @@ and class_expr_aux cl_num val_env met_env virt self_scope scl =
10871086
try Ctype.unify val_env ty' ty with Ctype.Unify err ->
10881087
raise(Error(cty'.ctyp_loc, val_env, Parameter_mismatch err)))
10891088
tyl params;
1089+
(* Check for unexpected virtual methods *)
1090+
check_virtual_clty scl.pcl_loc val_env virt Class clty';
10901091
let cl =
10911092
rc {cl_desc = Tcl_ident (path, lid, tyl);
10921093
cl_loc = scl.pcl_loc;
@@ -1972,7 +1973,6 @@ let report_error env ppf = function
19721973
(function ppf ->
19731974
fprintf ppf "but is expected to have type")
19741975
| Unexpected_field (ty, lab) ->
1975-
Printtyp.prepare_for_printing [ty];
19761976
fprintf ppf
19771977
"@[@[<2>This object is expected to have type :@ %a@]\
19781978
@ This type does not have a method %s."
@@ -2057,12 +2057,12 @@ let report_error env ppf = function
20572057
Includeclass.report_error Type ppf error
20582058
| Unbound_val lab ->
20592059
fprintf ppf "Unbound instance variable %s" lab
2060-
| Unbound_type_var (printer, (ty0, real, lab, ty)) ->
2061-
let ty1 =
2062-
if real then ty0 else Btype.newgenty(Tobject(ty0, ref None))
2063-
in
2064-
Printtyp.prepare_for_printing [ty; ty1];
2065-
let print_reason ppf (ty0, lab, ty) =
2060+
| Unbound_type_var (printer, reason) ->
2061+
let print_reason ppf (ty0, real, lab, ty) =
2062+
let ty1 =
2063+
if real then ty0 else Btype.newgenty(Tobject(ty0, ref None)) in
2064+
Printtyp.add_type_to_preparation ty;
2065+
Printtyp.add_type_to_preparation ty1;
20662066
fprintf ppf
20672067
"The method %s@ has type@;<1 2>%a@ where@ %a@ is unbound"
20682068
lab
@@ -2072,7 +2072,7 @@ let report_error env ppf = function
20722072
fprintf ppf
20732073
"@[<v>@[Some type variables are unbound in this type:@;<1 2>%t@]@ \
20742074
@[%a@]@]"
2075-
printer print_reason (ty0, lab, ty)
2075+
printer print_reason reason
20762076
| Non_generalizable_class (id, clty) ->
20772077
fprintf ppf
20782078
"@[The type of this class,@ %a,@ \

src/ocaml/typing/typedecl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ let rec parse_native_repr_attributes env core_type ty ~global_repr =
13381338
parse_native_repr_attributes env ct2 t2 ~global_repr
13391339
in
13401340
(repr_arg :: repr_args, repr_res)
1341-
| Ptyp_poly (_, t), _, _ ->
1341+
| (Ptyp_poly (_, t) | Ptyp_alias (t, _)), _, _ ->
13421342
parse_native_repr_attributes env t ty ~global_repr
13431343
| Ptyp_arrow _, _, _ | _, Tarrow _, _ -> assert false
13441344
| _ -> ([], make_native_repr env core_type ty ~global_repr)

0 commit comments

Comments
 (0)