Skip to content

Commit cead593

Browse files
authored
-dparsetree should print kind annotations (ocaml-flambda#3517)
This makes `-dparsetree` print kind annotations in type declarations There is also a test for a particular case we were interested in, confirming it parses the way we believe.
1 parent 82410eb commit cead593

8 files changed

+152
-1
lines changed

parsing/printast.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ and type_declaration i ppf x =
575575
type_kind (i+1) ppf x.ptype_kind;
576576
line i ppf "ptype_private = %a\n" fmt_private_flag x.ptype_private;
577577
line i ppf "ptype_manifest =\n";
578-
option (i+1) core_type ppf x.ptype_manifest
578+
option (i+1) core_type ppf x.ptype_manifest;
579+
line i ppf "ptype_jkind_annotation =\n";
580+
option (i+1) jkind_annotation ppf x.ptype_jkind_annotation
579581

580582
and attribute i ppf k a =
581583
line i ppf "%s \"%s\"\n" k a.attr_name.txt;

testsuite/tests/parsetree/locations_test.compilers.reference

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Ptop_def
5858
]
5959
Ptyp_constr "int" (//toplevel//[2,1+9]..[2,1+12])
6060
[]
61+
ptype_jkind_annotation =
62+
None
6163
]
6264
]
6365

@@ -158,6 +160,8 @@ Ptop_def
158160
ptype_private = Public
159161
ptype_manifest =
160162
None
163+
ptype_jkind_annotation =
164+
None
161165
]
162166
]
163167
]
@@ -186,6 +190,8 @@ Ptop_def
186190
core_type (//toplevel//[2,1+34]..[2,1+37])
187191
Ptyp_constr "int" (//toplevel//[2,1+34]..[2,1+37])
188192
[]
193+
ptype_jkind_annotation =
194+
None
189195
]
190196
]
191197

@@ -213,6 +219,8 @@ Ptop_def
213219
core_type (//toplevel//[2,1+35]..[2,1+38])
214220
Ptyp_constr "int" (//toplevel//[2,1+35]..[2,1+38])
215221
[]
222+
ptype_jkind_annotation =
223+
None
216224
]
217225
]
218226

testsuite/tests/parsing/attributes.compilers.reference

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
ptype_private = Public
9191
ptype_manifest =
9292
None
93+
ptype_jkind_annotation =
94+
None
9395
]
9496
structure_item (attributes.ml[21,302+0]..[21,302+8])
9597
Pstr_attribute "foo"
@@ -132,6 +134,8 @@
132134
ptype_private = Public
133135
ptype_manifest =
134136
None
137+
ptype_jkind_annotation =
138+
None
135139
]
136140
structure_item (attributes.ml[31,399+2]..[31,399+10])
137141
Pstr_attribute "foo"
@@ -198,6 +202,8 @@
198202
core_type (attributes.ml[39,498+58]..[39,498+61])
199203
Ptyp_constr "M.t" (attributes.ml[39,498+58]..[39,498+61])
200204
[]
205+
ptype_jkind_annotation =
206+
None
201207
]
202208
attribute "foo"
203209
[]
@@ -226,6 +232,8 @@
226232
ptype_private = Public
227233
ptype_manifest =
228234
None
235+
ptype_jkind_annotation =
236+
None
229237
]
230238
]
231239
structure_item (attributes.ml[51,652+0]..[51,652+27])
@@ -267,6 +275,8 @@
267275
core_type (attributes.ml[53,681+34]..[53,681+37])
268276
Ptyp_constr "int" (attributes.ml[53,681+34]..[53,681+37])
269277
[]
278+
ptype_jkind_annotation =
279+
None
270280
]
271281
structure_item (attributes.ml[55,728+0]..[55,728+31])
272282
Pstr_value Nonrec

testsuite/tests/parsing/extensions.compilers.reference

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
core_type (extensions.ml[13,251+41]..[13,251+42])
109109
Ptyp_constr "t" (extensions.ml[13,251+41]..[13,251+42])
110110
[]
111+
ptype_jkind_annotation =
112+
None
111113
]
112114
]
113115
expression (extensions.ml[13,251+47]..[13,251+74])
@@ -272,6 +274,8 @@
272274
core_type (extensions.ml[23,534+35]..[23,534+36])
273275
Ptyp_constr "t" (extensions.ml[23,534+35]..[23,534+36])
274276
[]
277+
ptype_jkind_annotation =
278+
None
275279
]
276280
]
277281
core_type (extensions.ml[24,573+4]..[24,573+32])
@@ -311,6 +315,8 @@
311315
core_type (extensions.ml[25,606+20]..[25,606+21])
312316
Ptyp_constr "t" (extensions.ml[25,606+20]..[25,606+21])
313317
[]
318+
ptype_jkind_annotation =
319+
None
314320
]
315321
]
316322
]

testsuite/tests/parsing/hash_ambiguity.compilers.reference

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
Ptyp_constr "int" (hash_ambiguity.ml[9,169+12]..[9,169+15])
4444
[]
4545
]
46+
ptype_jkind_annotation =
47+
None
4648
]
4749
structure_item (hash_ambiguity.ml[15,425+0]..[15,425+26])
4850
Pstr_type Rec
@@ -75,6 +77,8 @@
7577
ptype_private = Public
7678
ptype_manifest =
7779
None
80+
ptype_jkind_annotation =
81+
None
7882
]
7983
structure_item (hash_ambiguity.ml[17,453+0]..[17,453+32])
8084
Pstr_type Rec
@@ -111,6 +115,8 @@
111115
ptype_private = Public
112116
ptype_manifest =
113117
None
118+
ptype_jkind_annotation =
119+
None
114120
]
115121
]
116122

testsuite/tests/parsing/shortcut_ext_attr.compilers.reference

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@
514514
[]
515515
Ptyp_package "M" (shortcut_ext_attr.ml[61,1304+20]..[61,1304+21])
516516
[]
517+
ptype_jkind_annotation =
518+
None
517519
]
518520
structure_item (shortcut_ext_attr.ml[64,1353+0]..[67,1409+22])
519521
Pstr_module
@@ -601,6 +603,8 @@
601603
core_type (shortcut_ext_attr.ml[79,1615+19]..[79,1615+22])
602604
Ptyp_constr "int" (shortcut_ext_attr.ml[79,1615+19]..[79,1615+22])
603605
[]
606+
ptype_jkind_annotation =
607+
None
604608
type_declaration "t" (shortcut_ext_attr.ml[80,1638+10]..[80,1638+11]) (shortcut_ext_attr.ml[80,1638+0]..[80,1638+17])
605609
attribute "foo"
606610
[]
@@ -616,6 +620,8 @@
616620
core_type (shortcut_ext_attr.ml[80,1638+14]..[80,1638+17])
617621
Ptyp_constr "int" (shortcut_ext_attr.ml[80,1638+14]..[80,1638+17])
618622
[]
623+
ptype_jkind_annotation =
624+
None
619625
]
620626
]
621627
structure_item (shortcut_ext_attr.ml[81,1656+0]..[81,1656+21]) ghost
@@ -831,6 +837,8 @@
831837
core_type (shortcut_ext_attr.ml[101,2020+21]..[101,2020+24])
832838
Ptyp_constr "int" (shortcut_ext_attr.ml[101,2020+21]..[101,2020+24])
833839
[]
840+
ptype_jkind_annotation =
841+
None
834842
type_declaration "t'" (shortcut_ext_attr.ml[102,2045+12]..[102,2045+14]) (shortcut_ext_attr.ml[102,2045+2]..[102,2045+20])
835843
attribute "foo"
836844
[]
@@ -846,6 +854,8 @@
846854
core_type (shortcut_ext_attr.ml[102,2045+17]..[102,2045+20])
847855
Ptyp_constr "int" (shortcut_ext_attr.ml[102,2045+17]..[102,2045+20])
848856
[]
857+
ptype_jkind_annotation =
858+
None
849859
]
850860
]
851861
signature_item (shortcut_ext_attr.ml[103,2066+2]..[103,2066+23]) ghost
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
[
2+
structure_item (parsing_ambiguous_product.ml[12,327+0]..[12,327+49])
3+
Pstr_type Rec
4+
[
5+
type_declaration "t1" (parsing_ambiguous_product.ml[12,327+5]..[12,327+7]) (parsing_ambiguous_product.ml[12,327+0]..[12,327+49])
6+
ptype_params =
7+
[]
8+
ptype_cstrs =
9+
[]
10+
ptype_kind =
11+
Ptype_abstract
12+
ptype_private = Public
13+
ptype_manifest =
14+
None
15+
ptype_jkind_annotation =
16+
Some
17+
jkind (parsing_ambiguous_product.ml[12,327+10]..[12,327+49])
18+
Product
19+
[
20+
jkind (parsing_ambiguous_product.ml[12,327+10]..[12,327+28])
21+
Mod
22+
jkind (parsing_ambiguous_product.ml[12,327+11]..[12,327+16])
23+
Abbreviation "value"
24+
mode "global" (parsing_ambiguous_product.ml[12,327+21]..[12,327+27])
25+
jkind (parsing_ambiguous_product.ml[12,327+31]..[12,327+49])
26+
Mod
27+
jkind (parsing_ambiguous_product.ml[12,327+32]..[12,327+37])
28+
Abbreviation "value"
29+
mode "global" (parsing_ambiguous_product.ml[12,327+42]..[12,327+48])
30+
]
31+
]
32+
structure_item (parsing_ambiguous_product.ml[14,380+0]..[14,380+45])
33+
Pstr_type Rec
34+
[
35+
type_declaration "t2" (parsing_ambiguous_product.ml[14,380+5]..[14,380+7]) (parsing_ambiguous_product.ml[14,380+0]..[14,380+45])
36+
ptype_params =
37+
[]
38+
ptype_cstrs =
39+
[]
40+
ptype_kind =
41+
Ptype_abstract
42+
ptype_private = Public
43+
ptype_manifest =
44+
None
45+
ptype_jkind_annotation =
46+
Some
47+
jkind (parsing_ambiguous_product.ml[14,380+10]..[14,380+45])
48+
Mod
49+
jkind (parsing_ambiguous_product.ml[14,380+10]..[14,380+34])
50+
Product
51+
[
52+
jkind (parsing_ambiguous_product.ml[14,380+10]..[14,380+26])
53+
Mod
54+
jkind (parsing_ambiguous_product.ml[14,380+10]..[14,380+15])
55+
Abbreviation "value"
56+
mode "global" (parsing_ambiguous_product.ml[14,380+20]..[14,380+26])
57+
jkind (parsing_ambiguous_product.ml[14,380+29]..[14,380+34])
58+
Abbreviation "value"
59+
]
60+
mode "global" (parsing_ambiguous_product.ml[14,380+39]..[14,380+45])
61+
]
62+
structure_item (parsing_ambiguous_product.ml[16,429+0]..[16,429+47])
63+
Pstr_type Rec
64+
[
65+
type_declaration "t3" (parsing_ambiguous_product.ml[16,429+5]..[16,429+7]) (parsing_ambiguous_product.ml[16,429+0]..[16,429+47])
66+
ptype_params =
67+
[]
68+
ptype_cstrs =
69+
[]
70+
ptype_kind =
71+
Ptype_abstract
72+
ptype_private = Public
73+
ptype_manifest =
74+
None
75+
ptype_jkind_annotation =
76+
Some
77+
jkind (parsing_ambiguous_product.ml[16,429+10]..[16,429+47])
78+
Mod
79+
jkind (parsing_ambiguous_product.ml[16,429+10]..[16,429+36])
80+
Product
81+
[
82+
jkind (parsing_ambiguous_product.ml[16,429+11]..[16,429+27])
83+
Mod
84+
jkind (parsing_ambiguous_product.ml[16,429+11]..[16,429+16])
85+
Abbreviation "value"
86+
mode "global" (parsing_ambiguous_product.ml[16,429+21]..[16,429+27])
87+
jkind (parsing_ambiguous_product.ml[16,429+30]..[16,429+35])
88+
Abbreviation "value"
89+
]
90+
mode "global" (parsing_ambiguous_product.ml[16,429+41]..[16,429+47])
91+
]
92+
]
93+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(* TEST
2+
flags = "-stop-after parsing -dparsetree";
3+
setup-ocamlc.byte-build-env;
4+
ocamlc.byte;
5+
check-ocamlc.byte-output;
6+
*)
7+
8+
(* This test is to check that (a) type decl kind annotations get printed
9+
appropriately and (b) product kinds are associated the way we think, and you
10+
can see that in the parse tree. *)
11+
12+
type t1 : (value mod global) & (value mod global);;
13+
14+
type t2 : value mod global & value mod global;;
15+
16+
type t3 : (value mod global & value) mod global

0 commit comments

Comments
 (0)