Skip to content

Commit

Permalink
Eliminate unnecessary parens
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin committed Jun 14, 2024
1 parent d68154d commit ec56a39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,13 @@ end = struct
| { ast= {ptyp_desc= Ptyp_poly _; _}
; ctx= Typ {ptyp_desc= Ptyp_arrow _; _} } ->
true
| { ast= {ptyp_desc= Ptyp_var (_, _) | Ptyp_any; _}
; ctx= Typ {ptyp_desc= Ptyp_constr (_, args); _} }
when List.length args > 1 ->
(* Type variables and _ do not need parens when they appear as an
argument to a multi-parameter type constructor, even if they have
layout annotations. *)
false
| {ast= {ptyp_desc= Ptyp_var (_, l); _}; ctx= _} when Option.is_some l ->
true
| { ast= {ptyp_desc= Ptyp_tuple ((Some _, _) :: _); _}
Expand Down
8 changes: 4 additions & 4 deletions test/passing/tests/layout_annotation-erased.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4
type 'a t5 = (('a : float64), int, bool) t4
type 'a t5 = ('a : float64, int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42
let f : ('a, _ : value, bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4
type ('a, 'b, 'c) t6 = ('a, 'b, 'c : bits32) t4

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -208,7 +208,7 @@ let f_val : ('a : value). 'a -> 'a = fun x -> f_imm x

type (_ : value) g = MkG : ('a : immediate). 'a g
type t = int as (_ : immediate)
type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2
type ('a, 'b) t = ('a : value) * ('b : value)

class c : object
Expand Down
8 changes: 4 additions & 4 deletions test/passing/tests/layout_annotation.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4
type 'a t5 = (('a : float64), int, bool) t4
type 'a t5 = ('a : float64, int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42
let f : ('a, _ : value, bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4
type ('a, 'b, 'c) t6 = ('a, 'b, 'c : bits32) t4

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -208,7 +208,7 @@ let f_val : ('a : value). 'a -> 'a = fun x -> f_imm x

type (_ : value) g = MkG : ('a : immediate). 'a g
type t = int as (_ : immediate)
type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2
type ('a, 'b) t = ('a : value) * ('b : value)

class c : object
Expand Down
8 changes: 4 additions & 4 deletions test/passing/tests/layout_annotation.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4

type 'a t5 = (('a : float64), int, bool) t4
type 'a t5 = ('a : float64, int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42
let f : ('a, _ : value, bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4
type ('a, 'b, 'c) t6 = ('a, 'b, 'c : bits32) t4

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -260,7 +260,7 @@ type (_ : value) g = MkG : ('a : immediate). 'a g

type t = int as (_ : immediate)

type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2

type ('a, 'b) t = ('a : value) * ('b : value)

Expand Down

0 comments on commit ec56a39

Please sign in to comment.