Skip to content

Commit 94e4c3c

Browse files
committed
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 6547720 commit 94e4c3c

File tree

10 files changed

+29
-58
lines changed

10 files changed

+29
-58
lines changed

lib/Ast.ml

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

143-
let is_string_const_trivial str =
144-
let is_char_trivial = function
145-
| ' ' | '\t' | '\n' | '\x00' .. '\x1f' | '\x7f' .. '\xff' -> false
146-
| _ -> true
147-
in
148-
let len = String.length str in
149-
len < 5 || (len < 20 && String.for_all ~f:is_char_trivial str)
150-
151143
let rec is_trivial exp =
152144
match exp.pexp_desc with
153145
(* String literals using the heavy syntax are not trivial. *)
154146
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
155-
(* Some short strings are trivial. *)
147+
(* Short strings are trivial. *)
156148
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
157-
is_string_const_trivial str
149+
String.length str < 30
158150
| Pexp_constant _ | Pexp_field _ | Pexp_ident _ | Pexp_send _ -> true
159151
| Pexp_construct (_, exp) -> Option.for_all exp ~f:is_trivial
160152
| 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: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,7 @@ and fmt_fun_args c args =
12821282
cbox 0
12831283
(wrap "?(" ")"
12841284
( fmt_pattern c ~parens:false ~box:true xpat
1285-
$ fmt " =@;<1 2>"
1286-
$ fmt_expression c xexp ) )
1285+
$ fmt " =@;<1 2>" $ fmt_expression c xexp ) )
12871286
| Val (Optional l, xpat, Some xexp) ->
12881287
let parens =
12891288
match xpat.ast.ppat_desc with
@@ -1294,8 +1293,7 @@ and fmt_fun_args c args =
12941293
( str "?" $ str l.txt
12951294
$ wrap_k (fmt ":@,(") (str ")")
12961295
( fmt_pattern c ?parens ~box:true xpat
1297-
$ fmt " =@;<1 2>"
1298-
$ fmt_expression c xexp ) )
1296+
$ fmt " =@;<1 2>" $ fmt_expression c xexp ) )
12991297
| Val ((Labelled _ | Nolabel), _, Some _) ->
13001298
impossible "not accepted by parser"
13011299
| Newtypes [] -> impossible "not accepted by parser"
@@ -1717,8 +1715,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
17171715
(wrap "[" "]"
17181716
( str "%"
17191717
$ hovbox 2
1720-
( fmt_str_loc c name
1721-
$ str " fun "
1718+
( fmt_str_loc c name $ str " fun "
17221719
$ fmt_attributes c ~suf:" " call.pexp_attributes
17231720
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr $ fmt "@ ->"
17241721
)
@@ -1747,8 +1744,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
17471744
(wrap "[" "]"
17481745
( str "%"
17491746
$ hovbox 2
1750-
( fmt_str_loc c name
1751-
$ str " fun "
1747+
( fmt_str_loc c name $ str " fun "
17521748
$ fmt_attributes c ~suf:" " retn.pexp_attributes
17531749
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr $ fmt "@ ->"
17541750
)
@@ -1778,8 +1774,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
17781774
hvbox 0
17791775
( hvbox 0 (fmt_expression c (sub_exp ~ctx r) $ cmts_before)
17801776
$ str " :=" )
1781-
$ fmt "@;<1 2>"
1782-
$ cmts_after
1777+
$ fmt "@;<1 2>" $ cmts_after
17831778
$ hvbox 2 (fmt_expression c (sub_exp ~ctx v)) ) )
17841779
| Pexp_prefix ({txt= ("~-" | "~-." | "~+" | "~+.") as op; loc}, e1) ->
17851780
let op =
@@ -2372,8 +2367,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
23722367
$ break 1 (-2)
23732368
$ hvbox 0
23742369
( hvbox 0
2375-
( fmt "with@ "
2376-
$ leading_cmt
2370+
( fmt "with@ " $ leading_cmt
23772371
$ hvbox 0
23782372
( fmt_pattern c ~pro:(if_newline "| ")
23792373
(sub_pat ~ctx pc_lhs)
@@ -3540,9 +3534,7 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
35403534
pro=
35413535
Some
35423536
( Cmts.fmt_before c pmty_loc
3543-
$ fmt_if parens "("
3544-
$ str "module type of "
3545-
$ pro )
3537+
$ fmt_if parens "(" $ str "module type of " $ pro )
35463538
; epi= Some epi }
35473539
| _ ->
35483540
{ blk with
@@ -3900,17 +3892,14 @@ and fmt_with_constraint c ctx ~pre = function
39003892
| Pwith_type (lid, td) ->
39013893
fmt_type_declaration ~pre:(pre ^ " type") c ~name:lid (sub_td ~ctx td)
39023894
| Pwith_module (m1, m2) ->
3903-
str pre
3904-
$ str " module "
3905-
$ fmt_longident_loc c m1 $ str " = " $ fmt_longident_loc c m2
3895+
str pre $ str " module " $ fmt_longident_loc c m1 $ str " = "
3896+
$ fmt_longident_loc c m2
39063897
| Pwith_typesubst (lid, td) ->
3907-
fmt_type_declaration
3908-
~pre:(pre ^ " type")
3909-
c ~eq:":=" ~name:lid (sub_td ~ctx td)
3898+
fmt_type_declaration ~pre:(pre ^ " type") c ~eq:":=" ~name:lid
3899+
(sub_td ~ctx td)
39103900
| Pwith_modsubst (m1, m2) ->
3911-
str pre
3912-
$ str " module "
3913-
$ fmt_longident_loc c m1 $ str " := " $ fmt_longident_loc c m2
3901+
str pre $ str " module " $ fmt_longident_loc c m1 $ str " := "
3902+
$ fmt_longident_loc c m2
39143903
| Pwith_modtype (m1, m2) ->
39153904
let m1 = {m1 with txt= Some (str_longident m1.txt)} in
39163905
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
@@ -403,8 +403,7 @@ let collection_expr (c : Conf.t) ~space_around opn cls =
403403
else box_collec c 0 (wrap_collec c ~space_around opn cls k) )
404404
; sep_before= noop
405405
; sep_after_non_final=
406-
fmt_or_k dock
407-
(fmt ";@;<1 0>")
406+
fmt_or_k dock (fmt ";@;<1 0>")
408407
(char ';' $ break 1 (String.length opn + 1))
409408
; sep_after_final= fmt_if_k dock (fits_breaks ~level:1 "" ";") }
410409

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)