Skip to content

Correct order of printed quantified type vars #2126

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

Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions ocaml/testsuite/tests/typing-layouts/annots.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

[%%expect {|
val f : 'b ('a : immediate). 'a -> 'b = <fun>
val g : ('b : immediate) 'a. 'a -> 'b = <fun>
val f : ('a : immediate) 'b. 'a -> 'b = <fun>
val g : 'a ('b : immediate). 'a -> 'b = <fun>
|}]

(********************************************)
Expand Down Expand Up @@ -551,13 +551,13 @@ val f : ('a : immediate). 'a -> 'a = <fun>
let f = fun x y (type (a : immediate)) (z : a) -> z

[%%expect{|
val f : ('a : immediate) 'c 'b. 'b -> 'c -> 'a -> 'a = <fun>
val f : 'b 'c ('a : immediate). 'b -> 'c -> 'a -> 'a = <fun>
|}]

let f = fun x y (type a : immediate) (z : a) -> z

[%%expect{|
val f : ('a : immediate) 'c 'b. 'b -> 'c -> 'a -> 'a = <fun>
val f : 'b 'c ('a : immediate). 'b -> 'c -> 'a -> 'a = <fun>
|}]
(* CR layouts: canonicalizing the order of quantification here
would reduce wibbles in error messages *)
Expand All @@ -574,7 +574,7 @@ exception E : ('a : immediate) ('b : any). 'b t2_any * 'a list -> exn

[%%expect{|
type (_ : any) t2_any
exception E : ('a : immediate) ('b : any). 'b t2_any * 'a list -> exn
exception E : ('b : any) ('a : immediate). 'b t2_any * 'a list -> exn
|}]


Expand Down
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-layouts/basics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ end;;
module M11_3f :
sig
type ('a : float64) t = 'a
val foo : 'b ('a : float64). < usefloat : 'a t -> 'b; .. > -> 'a t -> 'b
val foo : ('a : float64) 'b. < usefloat : 'a t -> 'b; .. > -> 'a t -> 'b
end
|}];;

Expand Down Expand Up @@ -1265,7 +1265,7 @@ let q () =
()

[%%expect{|
val ( let* ) : 'b ('a : float64). 'a -> 'b -> unit = <fun>
val ( let* ) : ('a : float64) 'b. 'a -> 'b -> unit = <fun>
val ( and* ) : 'a -> 'b -> t_float64 = <fun>
val q : unit -> unit = <fun>
|}]
Expand Down
2 changes: 1 addition & 1 deletion ocaml/testsuite/tests/typing-layouts/basics_alpha.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ let q () =
()

[%%expect{|
val ( let* ) : 'b ('a : float64). 'a -> 'b -> unit = <fun>
val ( let* ) : ('a : float64) 'b. 'a -> 'b -> unit = <fun>
val ( and* ) : 'a -> 'b -> t_float64 = <fun>
val q : unit -> unit = <fun>
|}]
Expand Down
4 changes: 4 additions & 0 deletions ocaml/typing/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,10 @@ let zap_qtvs_if_boring qtvs =
This implements Case (C3) from Note [When to print jkind annotations]. *)
let extract_qtvs tyl =
let fvs = Ctype.free_non_row_variables_of_list tyl in
(* The [Ctype.free*variables] family of functions returns the free
variables in reverse order they were encountered in the list of types.
*)
let fvs = List.rev fvs in
let tfvs = List.map Transient_expr.repr fvs in
let vars_jkinds = tree_of_qtvs tfvs in
zap_qtvs_if_boring vars_jkinds
Expand Down