Skip to content

Commit

Permalink
Simplify grammar & syntax (parens) of first class modules (#1949)
Browse files Browse the repository at this point in the history
* Simplify grammar & syntax of first-class modules.

* document and backport error for 4.02.3 package_type_of_module_type

* Undeprecate `let module` + further simplify grammar.

Also update the printer: insert `module` even when
a UIDENT suffices to parse a Ptyp_package.
Motivation: it will be super confusing for newcomers who
might confuse it with a variant

* Print Ptyp_package constraint in line with js formatting

* add extra document for pacakge_type_of_module_type

* Deprecate UIDENT Ptyp_package syntax for now.
Might cause too much confusion for newcomers and people not using refmt.
  • Loading branch information
IwanKaramazow authored and chenglou committed Jun 3, 2018
1 parent 7ade7ef commit fe79b90
Show file tree
Hide file tree
Showing 7 changed files with 4,951 additions and 4,904 deletions.
69 changes: 69 additions & 0 deletions formatTest/unit_tests/expected_output/firstClassModules.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module Modifier = (
val Db.Hashtbl.create():
Db.Sig with type t = Mods.t
);
module Modifier = (
val Db.Hashtbl.create():
Db.Sig with type t = Mods.t
);
module Modifier = (
val Db.Hashtbl.create():
Db.Sig with type t = Mods.t
);
module Modifier = (
val Db.Hashtbl.create():
Db.Sig with type t = Mods.t
);
module Modifier = (val Db.Hashtbl.create());
module Modifier = (
val Db.Hashtbl.create():
Db.Sig with
type t = Mods.t and
type s = Mods.s and
type z = Mods.z
);

module Lowercase = (val stuff: lowercase);
module Lowercase = (
val stuff: Foo.Bar.lowercase
);
module Lowercase = (
val stuff:
Foo.Bar.lowercase with type t = Mods.t
);

module T = (
val (module FirstClass): myLowercaseModule
);

module Three = (val three: X_int);

let thing: module Thing = (module MyModule);
let thing: module Foo.Bar.Thing =
(module MyModule);

let smallThing: module lowercase = (module Mod);
let smallThing: module lowercase = (module Mod);
let smallThing: module Foo.Bar.lowercase =
(module Mod);
let smallThing: module Foo.Bar.lowercase =
(module Mod);

let f = (module Add: S.Z, x) => Add.add(x);

let join_iter =
(
type ta,
type tb,
module A: Sig with type t = ta,
module B: Sig with type t = tb,
module C: Sig with type t = tb,
module D:
Sig with
type t = tb and
type s = tc and
type x = td and
type z = te,
fn,
) =>
fn(A.value + B.value);
31 changes: 14 additions & 17 deletions formatTest/unit_tests/expected_output/modules.re
Original file line number Diff line number Diff line change
Expand Up @@ -483,24 +483,24 @@ module MyModule = {
let x = 10;
};

let myFirstClass: (module HasInt) =
let myFirstClass: module HasInt =
(module MyModule);

let myFirstClassWillBeFormattedAs: (module HasInt) =
let myFirstClassWillBeFormattedAs: module HasInt =
(module MyModule);

let acceptsAndUnpacksFirstClass =
((module M: HasInt)) =>
(module M: HasInt) =>
M.x + M.x;

let acceptsAndUnpacksFirstClass =
((module M: HasInt)) =>
(module M: HasInt) =>
M.x + M.x;

module SecondClass = (val myFirstClass);

module SecondClass2 = (
val ((module MyModule): (module HasInt))
val (module MyModule): HasInt
);

let p = SecondClass.x;
Expand Down Expand Up @@ -593,21 +593,18 @@ module X = [%test extension];
module type T = [%test extension];

let foo =
(type a, (module X: X_t with type t = a)) => X.a;
(type a, module X: X_t with type t = a) => X.a;

let f =
(
(module M: M with type x = x and type y = y),
) => M.x;
(module M: M with type x = x and type y = y) => M.x;

let foo =
(
(module X
: X_t with
type t = a and
type s = a and
type z = a
),
(module Y: Y_t with type t = a),
(module Z: Z_t with type t = a),
module X:
X_t with
type t = a and
type s = a and
type z = a,
module Y: Y_t with type t = a,
module Z: Z_t with type t = a,
) => X.a;
16 changes: 7 additions & 9 deletions formatTest/unit_tests/expected_output/modules_no_semi.re
Original file line number Diff line number Diff line change
Expand Up @@ -483,24 +483,24 @@ module MyModule = {
let x = 10;
};

let myFirstClass: (module HasInt) =
let myFirstClass: module HasInt =
(module MyModule);

let myFirstClassWillBeFormattedAs: (module HasInt) =
let myFirstClassWillBeFormattedAs: module HasInt =
(module MyModule);

let acceptsAndUnpacksFirstClass =
((module M: HasInt)) =>
(module M: HasInt) =>
M.x + M.x;

let acceptsAndUnpacksFirstClass =
((module M: HasInt)) =>
(module M: HasInt) =>
M.x + M.x;

module SecondClass = (val myFirstClass);

module SecondClass2 = (
val ((module MyModule): (module HasInt))
val (module MyModule): HasInt
);

let p = SecondClass.x;
Expand Down Expand Up @@ -593,9 +593,7 @@ module X = [%test extension];
module type T = [%test extension];

let foo =
(type a, (module X: X_t with type t = a)) => X.a;
(type a, module X: X_t with type t = a) => X.a;

let f =
(
(module M: M with type x = x and type y = y),
) => M.x;
(module M: M with type x = x and type y = y) => M.x;
34 changes: 34 additions & 0 deletions formatTest/unit_tests/input/firstClassModules.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Modifier = (val ((Db.Hashtbl.create ()): (module Db.Sig with type t = Mods.t)));
module Modifier = (val (Db.Hashtbl.create ()): (Db.Sig with type t = Mods.t));
module Modifier = (val (Db.Hashtbl.create (): module Db.Sig with type t = Mods.t));
module Modifier = (val Db.Hashtbl.create (): Db.Sig with type t = Mods.t);
module Modifier = (val Db.Hashtbl.create ());
module Modifier = (val Db.Hashtbl.create ():
Db.Sig with type t = Mods.t and type s = Mods.s and
type z = Mods.z);

module Lowercase = (val stuff: lowercase);
module Lowercase = (val stuff: Foo.Bar.lowercase);
module Lowercase = (val stuff: Foo.Bar.lowercase with type t = Mods.t);

module T = (val (module FirstClass): myLowercaseModule);

module Three = (val three: X_int);

let thing: module Thing = (module MyModule);
let thing: module Foo.Bar.Thing = (module MyModule);

let smallThing: (module lowercase) = (module Mod);
let smallThing: module lowercase = (module Mod);
let smallThing: (module Foo.Bar.lowercase) = (module Mod);
let smallThing: module Foo.Bar.lowercase = (module Mod);

let f = ((module Add : S.Z), x) => Add.add(x);

let join_iter =
(type ta, type tb,
((module A): (module Sig with type t=ta)),
(module B): (module Sig with type t=tb),
module C: module Sig with type t=tb,
module D: Sig with type t=tb and type s =tc and type x = td and type z = te,
fn) => fn(A.value + B.value);
Loading

0 comments on commit fe79b90

Please sign in to comment.