Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ocamlformat to 0.26.1 #6493

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,23 @@ jobs:

- name: Use OCaml ${{matrix.ocaml_compiler}}
uses: ocaml/setup-ocaml@v2
if: matrix.os != 'windows-latest'
with:
ocaml-compiler: ${{matrix.ocaml_compiler}}
opam-pin: false
opam-depext: false

- name: Use OCaml ${{matrix.ocaml_compiler}} (Win)
uses: ocaml/setup-ocaml@v2
if: matrix.os == 'windows-latest'
with:
ocaml-compiler: ${{matrix.ocaml_compiler}}
opam-pin: false
opam-depext: false
opam-repositories: |
opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
default: https://github.com/ocaml/opam-repository.git

- name: "Install OPAM dependencies"
run: opam install . --deps-only

Expand Down
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
profile = default
version = 0.22.4
version = 0.26.1

field-space = tight-decl
break-cases = toplevel
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(ocaml
(>= 4.10))
(ocamlformat
(= 0.22.4))
(= 0.26.1))
(cppo
(= 1.6.9))
(js_of_ocaml-compiler
Expand Down
4 changes: 2 additions & 2 deletions jscomp/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ let process_method_attributes_rev (attrs : t) =
| None -> true
| Some e -> Ast_payload.assert_bool_lit e),
undefined )
| "undefined" -> (
| "undefined" ->
( null,
match opt_expr with
| None -> true
| Some e -> Ast_payload.assert_bool_lit e ))
| Some e -> Ast_payload.assert_bool_lit e )
| "nullable" -> (
match opt_expr with
| None -> (true, true)
Expand Down
8 changes: 4 additions & 4 deletions jscomp/frontend/ast_derive_abstract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ let handleTdcl light (tdcl : Parsetree.type_declaration) :
Ext_list.fold_right label_declarations
( [],
(if has_optional_field then
Ast_compatible.arrow ~loc (Ast_literal.type_unit ()) core_type
else core_type),
Ast_compatible.arrow ~loc (Ast_literal.type_unit ()) core_type
else core_type),
[] )
(fun ({
pld_name = {txt = label_name; loc = label_loc} as pld_name;
Expand All @@ -109,15 +109,15 @@ let handleTdcl light (tdcl : Parsetree.type_declaration) :
( Ast_compatible.opt_arrow ~loc:pld_loc label_name pld_type maker,
Val.mk ~loc:pld_loc
(if light then pld_name
else {pld_name with txt = pld_name.txt ^ "Get"})
else {pld_name with txt = pld_name.txt ^ "Get"})
~attrs:get_optional_attrs ~prim
(Ast_compatible.arrow ~loc core_type optional_type)
:: acc )
else
( Ast_compatible.label_arrow ~loc:pld_loc label_name pld_type maker,
Val.mk ~loc:pld_loc
(if light then pld_name
else {pld_name with txt = pld_name.txt ^ "Get"})
else {pld_name with txt = pld_name.txt ^ "Get"})
~attrs:get_attrs
~prim:
((* Not needed actually*)
Expand Down
25 changes: 13 additions & 12 deletions jscomp/frontend/ast_derive_js_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ let init () =
Ast_comb.single_non_rec_value patFromJs
(Ast_compatible.fun_ (Pat.var pat_param)
(if createType then
Exp.let_ Nonrecursive
[Vb.mk (Pat.var pat_param) (exp_param +: newType)]
(Exp.constraint_ obj_exp core_type)
else Exp.constraint_ obj_exp core_type))
Exp.let_ Nonrecursive
[Vb.mk (Pat.var pat_param) (exp_param +: newType)]
(Exp.constraint_ obj_exp core_type)
else Exp.constraint_ obj_exp core_type))
in
let rest = [toJs; fromJs] in
if createType then eraseTypeStr :: newTypeStr :: rest else rest
Expand All @@ -239,16 +239,17 @@ let init () =
));
Ast_comb.single_non_rec_value {loc; txt = revMap}
(if has_bs_as then
Exp.extension
( {txt = "raw"; loc},
PStr
[Str.eval (Exp.constant (Const.string revData))]
)
else expMap);
Exp.extension
( {txt = "raw"; loc},
PStr
[
Str.eval (Exp.constant (Const.string revData));
] )
else expMap);
toJsBody
(if has_bs_as then
app2 unsafeIndexGetExp expMap exp_param
else app1 eraseTypeExp exp_param);
app2 unsafeIndexGetExp expMap exp_param
else app1 eraseTypeExp exp_param);
Ast_comb.single_non_rec_value patFromJs
(Ast_compatible.fun_ (Pat.var pat_param)
(let result =
Expand Down
53 changes: 27 additions & 26 deletions jscomp/frontend/ast_derive_projector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,33 @@ let init () =
Ast_comb.single_non_rec_value
{loc; txt = little_con_name}
(if arity = 0 then
(*TODO: add a prefix, better inter-op with FFI *)
Exp.constraint_
(Exp.construct
{loc; txt = Longident.Lident con_name}
None)
annotate_type
else
let vars =
Ext_list.init arity (fun x ->
"param_" ^ string_of_int x)
in
let exp =
Exp.constraint_
(Exp.construct
{loc; txt = Longident.Lident con_name}
@@ Some
(if arity = 1 then
Exp.ident {loc; txt = Lident (List.hd vars)}
else
Exp.tuple
(Ext_list.map vars (fun x ->
Exp.ident {loc; txt = Lident x}))))
annotate_type
in
Ext_list.fold_right vars exp (fun var b ->
Ast_compatible.fun_ (Pat.var {loc; txt = var}) b)))
(*TODO: add a prefix, better inter-op with FFI *)
Exp.constraint_
(Exp.construct
{loc; txt = Longident.Lident con_name}
None)
annotate_type
else
let vars =
Ext_list.init arity (fun x ->
"param_" ^ string_of_int x)
in
let exp =
Exp.constraint_
(Exp.construct
{loc; txt = Longident.Lident con_name}
@@ Some
(if arity = 1 then
Exp.ident
{loc; txt = Lident (List.hd vars)}
else
Exp.tuple
(Ext_list.map vars (fun x ->
Exp.ident {loc; txt = Lident x}))))
annotate_type
in
Ext_list.fold_right vars exp (fun var b ->
Ast_compatible.fun_ (Pat.var {loc; txt = var}) b)))
| Ptype_abstract | Ptype_open ->
Ast_derive_util.notApplicable tdcl.ptype_loc derivingName;
[]
Expand Down
33 changes: 16 additions & 17 deletions jscomp/frontend/ast_external_process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -896,22 +896,22 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type)
let arg_label = param_type.label in
let ty = param_type.ty in
(if i = 0 && splice then
match arg_label with
| Optional _ ->
Location.raise_errorf ~loc
"%@variadic expect the last type to be a non optional"
| Labelled _ | Nolabel -> (
if ty.ptyp_desc = Ptyp_any then
match arg_label with
| Optional _ ->
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array";
if spec_of_ptyp true ty <> Nothing then
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array";
match ty.ptyp_desc with
| Ptyp_constr ({txt = Lident "array"; _}, [_]) -> ()
| _ ->
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array"));
"%@variadic expect the last type to be a non optional"
| Labelled _ | Nolabel -> (
if ty.ptyp_desc = Ptyp_any then
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array";
if spec_of_ptyp true ty <> Nothing then
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array";
match ty.ptyp_desc with
| Ptyp_constr ({txt = Lident "array"; _}, [_]) -> ()
| _ ->
Location.raise_errorf ~loc
"%@variadic expect the last type to be an array"));
let ( (arg_label : External_arg_spec.label_noname),
arg_type,
new_arg_types ) =
Expand Down Expand Up @@ -988,8 +988,7 @@ let pval_prim_of_option_labels (labels : (bool * string Asttypes.loc) list)
(ends_with_unit : bool) =
let arg_kinds =
Ext_list.fold_right labels
(if ends_with_unit then [External_arg_spec.empty_kind Extern_unit]
else [])
(if ends_with_unit then [External_arg_spec.empty_kind Extern_unit] else [])
(fun (is_option, p) arg_kinds ->
let label_name = p.txt in
let obj_arg_label =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
(* Dynamic import of module transformation: module M = @res.await Belt.List *)
| Pstr_module
({pmb_expr = {pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me}
as mb)
as mb)
when Res_parsetree_viewer.hasAwaitAttribute pmod_attributes ->
let item = self.structure_item self item in
let safe_module_type_name = local_module_type_name txt in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/frontend/external_ffi_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ let inline_float_primitive (i : string) : string list =
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
match params with
| {arg_type = Nothing; arg_label = Arg_empty}
(* same as External_arg_spec.dummy*)
(* same as External_arg_spec.dummy*)
:: rest ->
ffi_bs_aux (acc + 1) rest
| _ :: _ -> -1
Expand Down
6 changes: 3 additions & 3 deletions jscomp/gentype/EmitJs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
match type_ with
| Function
({argTypes = [{aType = Object (closedFlag, fields); aName}]; retType}
as function_)
as function_)
when retType |> EmitType.isTypeFunctionComponent ~fields ->
(* JSX V3 *)
let fields =
Expand All @@ -178,7 +178,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
Function function_
| Function
({argTypes = [{aType = Ident {name} as propsType; aName}]; retType} as
function_)
function_)
when Filename.check_suffix name "props"
&& retType |> EmitType.isTypeFunctionComponent ~fields:[] -> (
match inlineOneLevel propsType with
Expand Down Expand Up @@ -305,7 +305,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
Some {HookType.propsType; resolvedTypeName; typeVars} )
| Function
({argTypes = [{aType = Ident {name} as propsType}]; retType} as
function_)
function_)
when Filename.check_suffix name "props"
&& retType |> EmitType.isTypeFunctionComponent ~fields:[] ->
let compType =
Expand Down
7 changes: 4 additions & 3 deletions jscomp/gentype/EmitType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ let emitExportType ~(config : Config.t) ~emitters ~nameAs ~opaque ~type_
|> Emitters.export ~emitters
else
(if isInterface && config.exportInterfaces then
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString ^ " "
else
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString
^ " "
else
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
^ (match type_ with
| _ -> type_ |> typeToString ~config ~typeNameIsInterface)
^ ";" ^ exportNameAs
Expand Down
2 changes: 1 addition & 1 deletion jscomp/gentype/GenTypeCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type labelJS =
| IntLabel of string
| StringLabel of string

type case = {label: string; labelJS: labelJS}
type case = {label: string; [@dead "case.label"] labelJS: labelJS}

let isJSSafePropertyName name =
name = ""
Expand Down
2 changes: 1 addition & 1 deletion jscomp/gentype/GenTypeMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ let processCmtFile cmt =
else (
outputFile |> GeneratedFiles.logFileAction NoMatch;
if Sys.file_exists outputFile then Sys.remove outputFile)
[@@live]
[@@live]
6 changes: 3 additions & 3 deletions jscomp/gentype/TranslateCoreType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ and translateCoreType_ ~config ~typeVarsGen
| Ttyp_object (tObj, closedFlag) ->
let getFieldType objectField =
match objectField with
| Typedtree.OTtag ({txt = name}, _, t) -> (
| Typedtree.OTtag ({txt = name}, _, t) ->
( name,
match name |> Runtime.isMutableObjectField with
| true -> {dependencies = []; type_ = ident ""}
| false -> t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv ))
| false -> t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv )
| OTinherit t ->
("Inherit", t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv)
in
Expand Down Expand Up @@ -210,7 +210,7 @@ and translateCoreType_ ~config ~typeVarsGen
label;
labelJS =
(if isNumber label then IntLabel label
else StringLabel label);
else StringLabel label);
};
t = translation.type_;
})
Expand Down
2 changes: 1 addition & 1 deletion jscomp/gentype/TranslateStructure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ and addAnnotationsToFields ~config (expr : Typedtree.expression)
in
({field with nameJS = name} :: nextFields1, types1)
| _ -> (fields, argTypes)
[@@live]
[@@live]

(** Recover from expr the renaming annotations on named arguments. *)
let addAnnotationsToFunctionType ~config (expr : Typedtree.expression)
Expand Down
4 changes: 2 additions & 2 deletions jscomp/gentype/TranslateTypeDeclarations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
let fields =
fieldTranslations
|> List.map
(fun (name, mutable_, {TranslateTypeExprFromTypes.type_}, docString)
->
(fun
(name, mutable_, {TranslateTypeExprFromTypes.type_}, docString) ->
let optional, type1 =
match type_ with
| Option type1 when isOptional name -> (Optional, type1)
Expand Down
3 changes: 1 addition & 2 deletions jscomp/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ and translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
{
label;
labelJS =
(if isNumber label then IntLabel label
else StringLabel label);
(if isNumber label then IntLabel label else StringLabel label);
})
in
let type_ =
Expand Down
6 changes: 3 additions & 3 deletions jscomp/syntax/cli/res_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module Color = struct
| Format.String_tag "dim" -> [Dim]
| Format.String_tag "filename" -> [FG Cyan]
| _ -> raise Not_found
[@@raises Not_found]
[@@raises Not_found]

let color_enabled = ref true

Expand Down Expand Up @@ -305,7 +305,7 @@ module CliArgProcessor = struct
in
printEngine.printImplementation ~width ~filename
~comments:parseResult.comments parsetree
[@@raises exit]
[@@raises exit]
end

let () =
Expand All @@ -317,4 +317,4 @@ let () =
~jsxVersion:!ResClflags.jsxVersion ~jsxModule:!ResClflags.jsxModule
~jsxMode:!ResClflags.jsxMode ~typechecker:!ResClflags.typechecker
!ResClflags.file)
[@@raises exit]
[@@raises exit]
Loading