From ec43ce12c2c06adfd17711aaebd88f7e44da6a49 Mon Sep 17 00:00:00 2001 From: Nick Roberts Date: Tue, 5 Dec 2023 13:17:03 -0500 Subject: [PATCH] Correct order of printed quantified type vars --- ocaml/testsuite/tests/typing-layouts/annots.ml | 10 +++++----- ocaml/testsuite/tests/typing-layouts/basics.ml | 4 ++-- ocaml/testsuite/tests/typing-layouts/basics_alpha.ml | 2 +- ocaml/typing/printtyp.ml | 4 ++++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ocaml/testsuite/tests/typing-layouts/annots.ml b/ocaml/testsuite/tests/typing-layouts/annots.ml index 379ae4c50c9..19376c6ccee 100644 --- a/ocaml/testsuite/tests/typing-layouts/annots.ml +++ b/ocaml/testsuite/tests/typing-layouts/annots.ml @@ -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 = -val g : ('b : immediate) 'a. 'a -> 'b = +val f : ('a : immediate) 'b. 'a -> 'b = +val g : 'a ('b : immediate). 'a -> 'b = |}] (********************************************) @@ -551,13 +551,13 @@ val f : ('a : immediate). 'a -> 'a = let f = fun x y (type (a : immediate)) (z : a) -> z [%%expect{| -val f : ('a : immediate) 'c 'b. 'b -> 'c -> 'a -> 'a = +val f : 'b 'c ('a : immediate). 'b -> 'c -> 'a -> 'a = |}] let f = fun x y (type a : immediate) (z : a) -> z [%%expect{| -val f : ('a : immediate) 'c 'b. 'b -> 'c -> 'a -> 'a = +val f : 'b 'c ('a : immediate). 'b -> 'c -> 'a -> 'a = |}] (* CR layouts: canonicalizing the order of quantification here would reduce wibbles in error messages *) @@ -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 |}] diff --git a/ocaml/testsuite/tests/typing-layouts/basics.ml b/ocaml/testsuite/tests/typing-layouts/basics.ml index 721fef021c3..5f857be21e6 100644 --- a/ocaml/testsuite/tests/typing-layouts/basics.ml +++ b/ocaml/testsuite/tests/typing-layouts/basics.ml @@ -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 |}];; @@ -1265,7 +1265,7 @@ let q () = () [%%expect{| -val ( let* ) : 'b ('a : float64). 'a -> 'b -> unit = +val ( let* ) : ('a : float64) 'b. 'a -> 'b -> unit = val ( and* ) : 'a -> 'b -> t_float64 = val q : unit -> unit = |}] diff --git a/ocaml/testsuite/tests/typing-layouts/basics_alpha.ml b/ocaml/testsuite/tests/typing-layouts/basics_alpha.ml index 0378d54be22..f29391a1889 100644 --- a/ocaml/testsuite/tests/typing-layouts/basics_alpha.ml +++ b/ocaml/testsuite/tests/typing-layouts/basics_alpha.ml @@ -1455,7 +1455,7 @@ let q () = () [%%expect{| -val ( let* ) : 'b ('a : float64). 'a -> 'b -> unit = +val ( let* ) : ('a : float64) 'b. 'a -> 'b -> unit = val ( and* ) : 'a -> 'b -> t_float64 = val q : unit -> unit = |}] diff --git a/ocaml/typing/printtyp.ml b/ocaml/typing/printtyp.ml index be6eae91d8b..bef5e0c2280 100644 --- a/ocaml/typing/printtyp.ml +++ b/ocaml/typing/printtyp.ml @@ -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