Skip to content

Commit 40a6b38

Browse files
Julowgpetiot
authored andcommitted
More permissive is_trivial for strings
String of a length less than 30 are trivial. This is still more restrictive than on main.
1 parent b7ef600 commit 40a6b38

File tree

10 files changed

+23
-46
lines changed

10 files changed

+23
-46
lines changed

lib/Ast.ml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,13 @@ module Exp = struct
146146
false
147147
| _ -> List.exists pexp_attributes ~f:(Fn.non Attr.is_doc)
148148

149-
let is_string_const_trivial str =
150-
let is_char_trivial = function
151-
| ' ' | '\t' | '\n' | '\x00' .. '\x1f' | '\x7f' .. '\xff' -> false
152-
| _ -> true
153-
in
154-
let len = String.length str in
155-
len < 5 || (len < 20 && String.for_all ~f:is_char_trivial str)
156-
157149
let rec is_trivial exp =
158150
match exp.pexp_desc with
159151
(* String literals using the heavy syntax are not trivial. *)
160152
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
161-
(* Some short strings are trivial. *)
153+
(* Short strings are trivial. *)
162154
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
163-
is_string_const_trivial str
155+
String.length str < 30
164156
| Pexp_constant _ | Pexp_field _ | Pexp_ident _ | Pexp_send _ -> true
165157
| Pexp_construct (_, exp) -> Option.for_all exp ~f:is_trivial
166158
| Pexp_prefix (_, e) -> is_trivial e

lib/Cmts.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ let rec place t loc_tree ?prev_loc ?deep_loc locs cmts =
303303
(** Relocate comments, for Ast transformations such as sugaring. *)
304304
let relocate (t : t) ~src ~before ~after =
305305
if t.debug then
306-
Format.eprintf "relocate %a to %a and %a@\n%!"
307-
Location.fmt src Location.fmt before Location.fmt after ;
306+
Format.eprintf "relocate %a to %a and %a@\n%!" Location.fmt src
307+
Location.fmt before Location.fmt after ;
308308
let merge_and_sort x y =
309309
List.rev_append x y
310310
|> List.sort ~compare:(Comparable.lift Location.compare_start ~f:Cmt.loc)

lib/Conf_decl.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ let rec pp_from fs = function
187187
| `Profile (s, p) -> Format.fprintf fs " (profile %s%a)" s pp_from_src p
188188
| `Updated (x, None) -> pp_from_src fs x
189189
| `Updated (x, Some r) ->
190-
Format.fprintf fs "%a -- Warning (redundant): %a"
191-
pp_from_src x pp_from r
190+
Format.fprintf fs "%a -- Warning (redundant): %a" pp_from_src x pp_from
191+
r
192192

193193
let loc_udapted_from = function
194194
| `Commandline -> Location.in_file "<command-line>"

lib/Fmt_ast.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,9 +3657,7 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
36573657
pro=
36583658
Some
36593659
( Cmts.fmt_before c pmty_loc
3660-
$ fmt_if parens "("
3661-
$ str "module type of "
3662-
$ pro )
3660+
$ fmt_if parens "(" $ str "module type of " $ pro )
36633661
; epi= Some epi }
36643662
| _ ->
36653663
{ blk with
@@ -4014,17 +4012,14 @@ and fmt_with_constraint c ctx ~pre = function
40144012
| Pwith_type (lid, td) ->
40154013
fmt_type_declaration ~pre:(pre ^ " type") c ~name:lid (sub_td ~ctx td)
40164014
| Pwith_module (m1, m2) ->
4017-
str pre
4018-
$ str " module "
4019-
$ fmt_longident_loc c m1 $ str " = " $ fmt_longident_loc c m2
4015+
str pre $ str " module " $ fmt_longident_loc c m1 $ str " = "
4016+
$ fmt_longident_loc c m2
40204017
| Pwith_typesubst (lid, td) ->
4021-
fmt_type_declaration
4022-
~pre:(pre ^ " type")
4023-
c ~eq:":=" ~name:lid (sub_td ~ctx td)
4018+
fmt_type_declaration ~pre:(pre ^ " type") c ~eq:":=" ~name:lid
4019+
(sub_td ~ctx td)
40244020
| Pwith_modsubst (m1, m2) ->
4025-
str pre
4026-
$ str " module "
4027-
$ fmt_longident_loc c m1 $ str " := " $ fmt_longident_loc c m2
4021+
str pre $ str " module " $ fmt_longident_loc c m1 $ str " := "
4022+
$ fmt_longident_loc c m2
40284023
| Pwith_modtype (m1, m2) ->
40294024
let m1 = {m1 with txt= Some (str_longident m1.txt)} in
40304025
let m2 = Some (sub_mty ~ctx m2) in

lib/Params.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ let collection_expr (c : Conf.t) ~space_around opn cls =
409409
else box_collec c 0 (wrap_collec c ~space_around opn cls k) )
410410
; sep_before= noop
411411
; sep_after_non_final=
412-
fmt_or_k dock
413-
(fmt ";@;<1 0>")
412+
fmt_or_k dock (fmt ";@;<1 0>")
414413
(char ';' $ break 1 (String.length opn + 1))
415414
; sep_after_final= fmt_if_k dock (fits_breaks ~level:1 "" ";") }
416415

test/passing/tests/infix_arg_grouping.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ hvbox 0
5757
$ wrap "(" ")"
5858
( str txt
5959
$ opt mt (fun _ ->
60-
fmt "@ : " $ Option.call ~f:pro_t $ psp_t
61-
$ fmt "@;<1 2>"
62-
$ bdy_t $ esp_t $ Option.call ~f:epi_t ) )
63-
$ fmt " ->@ "
64-
$ Option.call ~f:pro_e $ psp_e $ bdy_e $ esp_e $ Option.call ~f:epi_e )
60+
fmt "@ : " $ Option.call ~f:pro_t $ psp_t $ fmt "@;<1 2>" $ bdy_t
61+
$ esp_t $ Option.call ~f:epi_t ) )
62+
$ fmt " ->@ " $ Option.call ~f:pro_e $ psp_e $ bdy_e $ esp_e
63+
$ Option.call ~f:epi_e )
6564

6665
let to_json {integers; floats; strings} =
6766
`Assoc

test/passing/tests/issue77.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ let div =
22
[ div
33
~a:
44
[ Reactive.a_style
5-
(React.S.map
6-
(sprintf "height: %dpx")
5+
(React.S.map (sprintf "height: %dpx")
76
(State.player_height_signal app_state) )
87
(* ksprintf a_style "%s" (if_smth "min-height: 300px;" ""); *) ]
98
content ]

test/rpc/rpc_test.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ let close_client () =
100100
| Errored -> ()
101101

102102
let config c =
103-
get_client ()
104-
>>= fun cl ->
105-
log "[ocf] Config\n%!" ;
106-
Ocf.config c cl
103+
get_client () >>= fun cl -> log "[ocf] Config\n%!" ; Ocf.config c cl
107104

108105
let format ?(format_args = empty_args) ?versions x =
109106
get_client ?versions ()

test/rpc/rpc_test_fail.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ let close_client () =
9898
| Errored -> ()
9999

100100
let config c =
101-
get_client ()
102-
>>= fun cl ->
103-
log "[ocf] Config\n%!" ;
104-
Ocf.config c cl
101+
get_client () >>= fun cl -> log "[ocf] Config\n%!" ; Ocf.config c cl
105102

106103
let format x =
107104
get_client ()

test/unit/test_literal_lexer.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ let tests_string =
2525
in
2626
let test name s ~expected_preserve ~expected_normalize =
2727
[ test_one (name ^ " (preserve)") s `Preserve ~expected:expected_preserve
28-
; test_one
29-
(name ^ " (normalize)")
30-
s `Normalize ~expected:expected_normalize ]
28+
; test_one (name ^ " (normalize)") s `Normalize
29+
~expected:expected_normalize ]
3130
in
3231
List.concat
3332
[ [test_opt "string: not a string" {|hello|} `Preserve ~expected:None]

0 commit comments

Comments
 (0)