Skip to content

Commit 74076f2

Browse files
committed
Upgrade Merlin's vendored compiler
1 parent 238a727 commit 74076f2

File tree

15 files changed

+115
-61
lines changed

15 files changed

+115
-61
lines changed

src/ocaml/parsing/pprintast.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@ let prepare_error err =
17611761
"broken invariant in parsetree: %s" s
17621762
| Invalid_package_type (loc, s) ->
17631763
Location.errorf ~source ~loc "invalid package type: %s" s
1764+
| Removed_string_set loc ->
1765+
Location.errorf ~loc
1766+
"Syntax error: strings are immutable, there is no assignment \
1767+
syntax for them.\n\
1768+
Hint: Mutable sequences of bytes are available in the Bytes module.\n\
1769+
Hint: Did you mean to use 'Bytes.set'?"
17641770

17651771
let () =
17661772
Location.register_error_of_exn

src/ocaml/parsing/syntaxerr.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type error =
2424
| Other of Location.t
2525
| Ill_formed_ast of Location.t * string
2626
| Invalid_package_type of Location.t * string
27+
| Removed_string_set of Location.t
2728

2829
exception Error of error
2930
exception Escape_error
@@ -36,7 +37,8 @@ let location_of_error = function
3637
| Not_expecting (l, _)
3738
| Ill_formed_ast (l, _)
3839
| Invalid_package_type (l, _)
39-
| Expecting (l, _) -> l
40+
| Expecting (l, _)
41+
| Removed_string_set l -> l
4042

4143

4244
let ill_formed_ast loc s =

src/ocaml/parsing/syntaxerr.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type error =
2929
| Other of Location.t
3030
| Ill_formed_ast of Location.t * string
3131
| Invalid_package_type of Location.t * string
32+
| Removed_string_set of Location.t
3233

3334
exception Error of error
3435
exception Escape_error

src/ocaml/preprocess/parser_raw.mly

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ let mkpat_opt_constraint ~loc p = function
227227
(*let syntax_error () =
228228
raise Syntaxerr.Escape_error*)
229229

230+
let removed_string_set loc =
231+
raise_error Syntaxerr.(Error(Syntaxerr.Removed_string_set(make_loc loc)))
230232

231233
(* Using the function [not_expecting] in a semantic action means that this
232234
syntactic form is recognized by the parser but is in fact incorrect. This
@@ -312,7 +314,9 @@ let builtin_arraylike_name loc _ ~assign paren_kind n =
312314
let opname = if !Clflags.fast then "unsafe_" ^ opname else opname in
313315
let prefix = match paren_kind with
314316
| Paren -> Lident "Array"
315-
| Bracket -> Lident "String"
317+
| Bracket ->
318+
if assign then removed_string_set loc;
319+
Lident "String"
316320
| Brace ->
317321
let submodule_name = match n with
318322
| One -> "Array1"

src/ocaml/typing/env.ml

Lines changed: 8 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

@@ -2842,7 +2846,10 @@ let use_cltype ~use ~loc path desc =
28422846
let use_label ~use ~loc usage env lbl =
28432847
if use then begin
28442848
mark_label_description_used usage env lbl;
2845-
Builtin_attributes.check_alerts loc lbl.lbl_attributes lbl.lbl_name
2849+
Builtin_attributes.check_alerts loc lbl.lbl_attributes lbl.lbl_name;
2850+
if is_mutating_label_usage usage then
2851+
Builtin_attributes.check_deprecated_mutable loc lbl.lbl_attributes
2852+
lbl.lbl_name
28462853
end
28472854

28482855
let use_constructor_desc ~use ~loc usage env cstr =

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/predef.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ and ident_sys_blocked_io = ident_create "Sys_blocked_io"
9696
and ident_assert_failure = ident_create "Assert_failure"
9797
and ident_undefined_recursive_module =
9898
ident_create "Undefined_recursive_module"
99-
and ident_continuation_already_taken =
100-
ident_create "Continuation_already_taken"
101-
and ident_unhandled = ident_create "Unhandled"
10299

103100
let all_predef_exns = [
104101
ident_match_failure;
@@ -113,8 +110,6 @@ let all_predef_exns = [
113110
ident_sys_blocked_io;
114111
ident_assert_failure;
115112
ident_undefined_recursive_module;
116-
ident_continuation_already_taken;
117-
ident_unhandled;
118113
]
119114

120115
let path_match_failure = Pident ident_match_failure
@@ -237,7 +232,6 @@ let build_initial_env add_type add_extension empty_env =
237232
(* Predefined exceptions - alphabetical order *)
238233
|> add_extension ident_assert_failure
239234
[newgenty (Ttuple[type_string; type_int; type_int])]
240-
|> add_extension ident_continuation_already_taken []
241235
|> add_extension ident_division_by_zero []
242236
|> add_extension ident_end_of_file []
243237
|> add_extension ident_failure [type_string]
@@ -251,7 +245,6 @@ let build_initial_env add_type add_extension empty_env =
251245
|> add_extension ident_sys_error [type_string]
252246
|> add_extension ident_undefined_recursive_module
253247
[newgenty (Ttuple[type_string; type_int; type_int])]
254-
|> add_extension ident_unhandled []
255248

256249
let builtin_values =
257250
List.map (fun id -> (Ident.name id, id)) all_predef_exns

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}

0 commit comments

Comments
 (0)