From 5d347edcf5d86b0522c0c41a0d68838e99323cb7 Mon Sep 17 00:00:00 2001 From: butterunderflow Date: Sat, 24 Aug 2024 21:15:00 +0800 Subject: [PATCH 1/2] simplify type definition syntax --- lib/syntax/parser.mly | 5 +++++ .../test_dirs/interval_functor.t/test_interval.fun | 2 +- tests/cram/test_dirs/match.t/test_match.fun | 10 +++++----- tests/cram/test_dirs/sort.t/test_sort.fun | 2 +- tests/regular/parse_test.ml | 14 +++++++++++++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/syntax/parser.mly b/lib/syntax/parser.mly index 80c663c..eda7b19 100644 --- a/lib/syntax/parser.mly +++ b/lib/syntax/parser.mly @@ -158,6 +158,9 @@ type_def: | UNIT n=IDENT EQ OR? vs=separated_list(OR, variant) %prec over_TOP { TDAdt (n, [], vs) } + | n=IDENT EQ + OR? vs=separated_list(OR, variant) %prec over_TOP + { TDAdt (n, [], vs) } | tv=TYPEVAR n=IDENT EQ OR? vs=separated_list(OR, variant) %prec over_TOP { TDAdt (n, [ Ident.from tv ], vs) } @@ -288,6 +291,8 @@ sig_comp: { SpecAbstTy (t, (List.map Ident.from tvs)) } | TYPE UNIT t=IDENT { SpecAbstTy (t, []) } + | TYPE t=IDENT + { SpecAbstTy (t, []) } | def=type_def_group { SpecManiTy def } | MODULE m_name=MIDENT COLON mt=mod_type { SpecMod (m_name, mt) } | MODULE TYPE m_name=MIDENT EQ mt=mod_type { SpecModSig (m_name, mt) } diff --git a/tests/cram/test_dirs/interval_functor.t/test_interval.fun b/tests/cram/test_dirs/interval_functor.t/test_interval.fun index 091809f..4f564a3 100644 --- a/tests/cram/test_dirs/interval_functor.t/test_interval.fun +++ b/tests/cram/test_dirs/interval_functor.t/test_interval.fun @@ -7,7 +7,7 @@ external compare : int -> int -> int = "ff_builtin_minus" external greater : int -> int -> bool = "ff_builtin_greater" module type Comparable = sig - type () t + type t val compare : t -> t -> int end diff --git a/tests/cram/test_dirs/match.t/test_match.fun b/tests/cram/test_dirs/match.t/test_match.fun index 5c0d64b..f36a0c1 100644 --- a/tests/cram/test_dirs/match.t/test_match.fun +++ b/tests/cram/test_dirs/match.t/test_match.fun @@ -1,8 +1,8 @@ external print_int : int -> int = "ff_builtin_print_int" -type () int_l -= Cons of int -| Nil +type int_l = + | Cons of int + | Nil let x = Nil let f = (fun x -> @@ -15,8 +15,8 @@ let n = (f Nil) let n = (f (Cons 998)) -type () int_tu -= Tu of (int * int) +type int_tu = + | Tu of (int * int) let n = Tu (10, 22) diff --git a/tests/cram/test_dirs/sort.t/test_sort.fun b/tests/cram/test_dirs/sort.t/test_sort.fun index 9abf1ff..31e7dbc 100644 --- a/tests/cram/test_dirs/sort.t/test_sort.fun +++ b/tests/cram/test_dirs/sort.t/test_sort.fun @@ -5,7 +5,7 @@ external print_int : int -> unit = "ff_builtin_print_int" external print_string : string -> unit = "ff_builtin_print_str" module type Cmp = sig - type () t + type t val compare : t -> t -> bool end diff --git a/tests/regular/parse_test.ml b/tests/regular/parse_test.ml index fbe5d32..b65e40f 100644 --- a/tests/regular/parse_test.ml +++ b/tests/regular/parse_test.ml @@ -1351,7 +1351,19 @@ let x = 1 (start_loc ((pos_fname "") (pos_lnum 4) (pos_bol 33) (pos_cnum 41))) (end_loc ((pos_fname "") (pos_lnum 4) (pos_bol 33) (pos_cnum 42))) (attrs ())))) - |}] + |}]; + + print_parsed_program + {| + module type X = sig + type t + end + |}; + [%expect {| ((TopModSig X (MTSig ((SpecAbstTy t ()))))) |}]; + print_parsed_program {| + type t = | Nil + |}; + [%expect {| ((TopTypeDef ((TDAdt t () ((Nil ())))))) |}] let%expect_test "Test: path parsing" = print_parsed_mod_expr {|X|}; From 96410efdd22af0be9448a4b3e8ddb1eb8a47f310 Mon Sep 17 00:00:00 2001 From: butterunderflow Date: Sat, 24 Aug 2024 21:34:11 +0800 Subject: [PATCH 2/2] remove an unused binding --- lib/typing/env.ml | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/typing/env.ml b/lib/typing/env.ml index f7b0a93..f3d3263 100644 --- a/lib/typing/env.ml +++ b/lib/typing/env.ml @@ -188,8 +188,6 @@ let captured_scope (s : scope) (tpv : Types_in.tv ref) = let captured (env : t) tpv = List.exists (fun s -> captured_scope s tpv) env -let size = List.length - (**********Debug Function*************) let dbg (env : t) = let scope_values s =