Source file typedtree.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
open Asttypes
open Types
open Mode
type constant =
Const_int of int
| Const_char of char
| Const_untagged_char of char
| Const_string of string * Location.t * string option
| Const_float of string
| Const_float32 of string
| Const_unboxed_float of string
| Const_unboxed_float32 of string
| Const_int8 of int
| Const_int16 of int
| Const_int32 of int32
| Const_int64 of int64
| Const_nativeint of nativeint
| Const_untagged_int of int
| Const_untagged_int8 of int
| Const_untagged_int16 of int
| Const_unboxed_int32 of int32
| Const_unboxed_int64 of int64
| Const_unboxed_nativeint of nativeint
module Uid = Shape.Uid
type 'a modes = 'a Typemode.modes =
{ mode_modes : 'a;
mode_desc : Mode.Alloc.atom Location.loc list
}
type modalities = Typemode.modalities =
{ moda_modalities : Mode.Modality.Const.t;
moda_desc : Mode.Modality.atom Location.loc list
}
type partial = Partial | Total
type attribute = Parsetree.attribute
type attributes = attribute list
type value = Value_pattern
type computation = Computation_pattern
type _ pattern_category =
| Value : value pattern_category
| Computation : computation pattern_category
module Unique_barrier = struct
type barrier =
| Enabled of Mode.Uniqueness.lr
| Resolved of Mode.Uniqueness.Const.t
| Not_computed
type t = barrier ref
let not_computed () = ref Not_computed
let enable barrier = match !barrier with
| Not_computed ->
barrier := Enabled (Uniqueness.newvar ())
| _ -> Misc.fatal_error "Unique barrier was enabled twice"
let add_upper_bound uniq barrier =
match !barrier with
| Enabled barrier -> Uniqueness.submode_exn barrier uniq
| _ -> Misc.fatal_error "Unique barrier got an upper bound in the wrong state"
let resolve barrier =
match !barrier with
| Enabled uniq ->
let zapped = Uniqueness.zap_to_ceil uniq in
barrier := Resolved zapped;
zapped
| Resolved barrier -> barrier
| Not_computed ->
Uniqueness.Const.legacy
let print ppf t =
let open Format in
let print = function
| Enabled u ->
fprintf ppf "Enabled(%a)"
(Format_doc.compat (Mode.Uniqueness.print ())) u
| Resolved uc ->
fprintf ppf "Resolved(%a)"
(Format_doc.compat Mode.Uniqueness.Const.print) uc
| Not_computed -> fprintf ppf "Not_computed"
in
print !t
end
type unique_use = Mode.Uniqueness.r * Mode.Linearity.l
let print_unique_use ppf (u,l) =
let open Format in
fprintf ppf "@[(%a,@ %a)@]"
(Format_doc.compat (Mode.Uniqueness.print ())) u
(Format_doc.compat (Mode.Linearity.print ())) l
type alloc_mode = Mode.Alloc.r
type texp_field_boxing =
| Boxing of alloc_mode * unique_use
| Non_boxing of unique_use
let aliased_many_use =
( Mode.Uniqueness.disallow_left Mode.Uniqueness.aliased,
Mode.Linearity.disallow_right Mode.Linearity.many )
type label_ambiguity =
| Ambiguous of { path: Path.t; arity : int }
| Unambiguous
type _ type_inspection =
| Label_disambiguation : label_ambiguity -> [< `pat | `exp ] type_inspection
| Polymorphic_parameter : 'a poly_param -> 'a type_inspection
and _ poly_param =
| Param : type_expr -> [`pat] poly_param
| Arrow : (arg_label * type_expr option) list -> [`exp] poly_param
| Method : string loc * type_expr -> [`exp] poly_param
type pattern = value general_pattern
and 'k general_pattern = 'k pattern_desc pattern_data
and 'a pattern_data =
{ pat_desc: 'a;
pat_loc: Location.t;
pat_extra : (pat_extra * Location.t * attribute list) list;
pat_type: type_expr;
pat_env: Env.t;
pat_attributes: attribute list;
pat_unique_barrier : Unique_barrier.t;
}
and 'k pattern_desc =
| Tpat_any : value pattern_desc
| Tpat_var : {
id: Ident.t;
name: string loc;
uid: Uid.t;
sort: Jkind_types.Sort.t;
mode: Mode.Value.l;
} -> value pattern_desc
| Tpat_alias : {
pattern: value general_pattern;
id: Ident.t;
name: string loc;
uid: Uid.t;
sort: Jkind_types.Sort.t;
mode: Mode.Value.l;
type_expr: Types.type_expr;
} -> value pattern_desc
| Tpat_fun_layout : {
id: Ident.t;
name: string loc;
uid: Uid.t;
sort: Jkind_types.Sort.t;
mode: Mode.Value.l;
lpoly: Lpoly.t;
env_alloc_mode: alloc_mode;
} -> value pattern_desc
| Tpat_constant : constant -> value pattern_desc
| Tpat_unboxed_unit : value pattern_desc
| Tpat_unboxed_bool : bool -> value pattern_desc
| Tpat_tuple : (string option * value general_pattern) list -> value pattern_desc
| Tpat_unboxed_tuple :
(string option * value general_pattern * Jkind.sort) list ->
value pattern_desc
| Tpat_construct :
Longident.t loc * Types.constructor_description *
value general_pattern list *
((Ident.t loc * Parsetree.jkind_annotation option) list * core_type)
option ->
value pattern_desc
| Tpat_variant :
label * value general_pattern option * row_desc ref ->
value pattern_desc
| Tpat_record :
(Longident.t loc * label_description * value general_pattern) list *
closed_flag ->
value pattern_desc
| Tpat_record_unboxed_product :
(Longident.t loc * unboxed_label_description * value general_pattern) list
* closed_flag ->
value pattern_desc
| Tpat_array :
mutability * Jkind.sort * value general_pattern list -> value pattern_desc
| Tpat_lazy : value general_pattern -> value pattern_desc
| Tpat_value : tpat_value_argument -> computation pattern_desc
| Tpat_exception : value general_pattern -> computation pattern_desc
| Tpat_or :
'k general_pattern * 'k general_pattern * row_desc option ->
'k pattern_desc
and tpat_value_argument = value general_pattern
and expression =
{ exp_desc: expression_desc;
exp_loc: Location.t;
exp_extra: (exp_extra * Location.t * attribute list) list;
exp_type: type_expr;
exp_env: Env.t;
exp_attributes: attribute list;
}
and arg_label = Types.arg_label =
| Nolabel
| Labelled of string
| Optional of string
| Position of string
and expression_desc =
Texp_ident of
{ path : Path.t;
lid : Longident.t loc;
desc : Types.value_description;
kind : ident_kind;
unique_use : unique_use;
mode : Mode.Value.l }
| Texp_apply_layout of expression * Jkind_types.Sort.var list
| Texp_constant of constant
| Texp_let of rec_flag * value_binding list * expression
| Texp_letmutable of value_binding * expression
| Texp_function of
{ params : function_param list;
body : function_body;
ret_mode : Mode.Alloc.l modes;
ret_sort : Jkind.sort;
alloc_mode : alloc_mode;
zero_alloc : Zero_alloc.t;
}
| Texp_apply of
expression * (arg_label * apply_arg) list * apply_position *
Mode.Locality.l * Zero_alloc.assume option
| Texp_match of expression * Jkind.sort * computation case list * partial
| Texp_try of expression * value case list
| Texp_unboxed_unit
| Texp_unboxed_bool of bool
| Texp_tuple of (string option * expression) list * alloc_mode
| Texp_unboxed_tuple of (string option * expression * Jkind.sort) list
| Texp_construct of
Longident.t loc * constructor_description * expression list * alloc_mode option
| Texp_variant of label * (expression * alloc_mode) option
| Texp_record of {
fields : ( Types.label_description * record_label_definition ) array;
representation : Types.record_representation;
extended_expression : (expression * Jkind.sort * Unique_barrier.t) option;
alloc_mode : alloc_mode option
}
| Texp_record_unboxed_product of {
fields :
( Types.unboxed_label_description * record_label_definition ) array;
representation : Types.record_unboxed_product_representation;
extended_expression : (expression * Jkind.sort) option;
}
| Texp_atomic_loc of
expression * Jkind.sort * Longident.t loc * label_description *
alloc_mode
| Texp_field of
expression * Jkind.sort * Longident.t loc * label_description *
texp_field_boxing * Unique_barrier.t
| Texp_unboxed_field of
expression * Jkind.sort * Longident.t loc * unboxed_label_description *
unique_use
| Texp_setfield of
expression * Mode.Locality.l * Longident.t loc * label_description * expression
| Texp_array of mutability * Jkind.Sort.t * expression list * alloc_mode
| Texp_idx of block_access * unboxed_access list
| Texp_list_comprehension of comprehension
| Texp_array_comprehension of mutability * Jkind.sort * comprehension
| Texp_ifthenelse of expression * expression * expression option
| Texp_sequence of expression * Jkind.sort * expression
| Texp_while of {
wh_cond : expression;
wh_body : expression;
wh_body_sort : Jkind.sort
}
| Texp_for of {
for_id : Ident.t;
for_debug_uid: Shape.Uid.t;
for_pat : Parsetree.pattern;
for_from : expression;
for_to : expression;
for_dir : direction_flag;
for_body : expression;
for_body_sort : Jkind.sort;
}
| Texp_send of expression * meth * apply_position
| Texp_new of
Path.t * Longident.t loc * Types.class_declaration * apply_position
| Texp_instvar of Path.t * Path.t * string loc
| Texp_mutvar of Ident.t loc
| Texp_setinstvar of Path.t * Path.t * string loc * expression
| Texp_setmutvar of Ident.t loc * Jkind.sort * expression
| Texp_override of Path.t * (Ident.t * string loc * expression) list
| Texp_letmodule of
Ident.t option * string option loc * Types.module_presence * module_expr *
expression
| Texp_letexception of extension_constructor * expression
| Texp_assert of expression * Location.t
| Texp_lazy of expression
| Texp_object of class_structure * string list
| Texp_pack of module_expr
| Texp_letop of {
let_ : binding_op;
ands : binding_op list;
param : Ident.t;
param_debug_uid : Shape.Uid.t;
param_sort : Jkind.sort;
body : value case;
body_sort : Jkind.sort;
partial : partial;
}
| Texp_unreachable
| Texp_extension_constructor of Longident.t loc * Path.t
| Texp_open of open_declaration * expression
| Texp_probe of { name:string; handler:expression; enabled_at_init:bool; }
| Texp_probe_is_enabled of { name:string }
| Texp_exclave of expression
| Texp_src_pos
| Texp_overwrite of expression * expression
| Texp_hole of unique_use
| Texp_quotation of expression
| Texp_antiquotation of expression
| Texp_typed_hole
and ident_kind =
| Id_value
| Id_prim of Mode.Locality.l option * Jkind.Sort.t option
and meth =
| Tmeth_name of string
| Tmeth_val of Ident.t
| Tmeth_ancestor of Ident.t * Path.t
and block_access =
| Baccess_field of Longident.t loc * Types.label_description
| Baccess_block of mutable_flag * expression
and unboxed_access =
| Uaccess_unboxed_field of Longident.t loc * Types.unboxed_label_description
and comprehension =
{
comp_body : expression;
comp_clauses : comprehension_clause list
}
and comprehension_clause =
| Texp_comp_for of comprehension_clause_binding list
| Texp_comp_when of expression
and comprehension_clause_binding =
{
comp_cb_iterator : comprehension_iterator;
comp_cb_attributes : attribute list
}
and comprehension_iterator =
| Texp_comp_range of
{ ident : Ident.t
; ident_debug_uid : Shape.Uid.t
; pattern : Parsetree.pattern
; start : expression
; stop : expression
; direction : direction_flag }
| Texp_comp_in of
{ pattern : pattern
; sequence : expression }
and 'k case =
{
c_lhs: 'k general_pattern;
c_guard: expression option;
c_rhs: expression;
}
and function_curry =
| More_args of { partial_mode : Mode.Alloc.l }
| Final_arg
and function_param =
{
fp_arg_label: arg_label;
fp_param: Ident.t;
fp_param_debug_uid : Shape.Uid.t;
fp_partial: partial;
fp_kind: function_param_kind;
fp_sort: Jkind.sort;
fp_mode: Mode.Alloc.l modes;
fp_curry: function_curry;
fp_newtypes: (Ident.t * string loc *
Parsetree.jkind_annotation option * Uid.t) list;
fp_loc: Location.t;
}
and function_param_kind =
| Tparam_pat of pattern
| Tparam_optional_default of pattern * expression * Jkind.sort
and function_body =
| Tfunction_body of expression
| Tfunction_cases of function_cases
and function_cases =
{ fc_cases: value case list;
fc_env : Env.t;
fc_arg_mode: Mode.Alloc.l;
fc_arg_sort: Jkind.sort;
fc_ret_type : Types.type_expr;
fc_partial: partial;
fc_param: Ident.t;
fc_param_debug_uid: Shape.Uid.t;
fc_loc: Location.t;
fc_exp_extra: exp_extra list;
fc_attributes: attributes;
}
and record_label_definition =
| Kept of Types.type_expr * mutability * unique_use
| Overridden of Longident.t loc * expression
and binding_op =
{
bop_op_path : Path.t;
bop_op_name : string loc;
bop_op_val : Types.value_description;
bop_op_type : Types.type_expr;
bop_op_return_sort : Jkind.sort;
bop_exp : expression;
bop_exp_sort : Jkind.sort;
bop_loc : Location.t;
}
and ('a, 'b) arg_or_omitted =
| Arg of 'a
| Omitted of 'b
and omitted_parameter =
{ mode_closure : Mode.Alloc.r;
mode_arg : Mode.Alloc.l;
mode_ret : Mode.Alloc.l;
sort_arg : Jkind.sort;
sort_ret : Jkind.sort }
and apply_arg = (expression * Jkind.sort, omitted_parameter) arg_or_omitted
and apply_position =
| Tail
| Nontail
| Default
and class_expr =
{
cl_desc: class_expr_desc;
cl_loc: Location.t;
cl_type: Types.class_type;
cl_env: Env.t;
cl_attributes: attribute list;
}
and class_expr_desc =
Tcl_ident of Path.t * Longident.t loc * core_type list
| Tcl_structure of class_structure
| Tcl_fun of
arg_label * pattern * (Ident.t * expression) list
* class_expr * partial
| Tcl_apply of class_expr * (arg_label * apply_arg) list
| Tcl_let of rec_flag * value_binding list *
(Ident.t * expression) list * class_expr
| Tcl_constraint of
class_expr * class_type option * string list * string list * MethSet.t
| Tcl_open of open_description * class_expr
and class_structure =
{
cstr_self: pattern;
cstr_fields: class_field list;
cstr_type: Types.class_signature;
cstr_meths: Ident.t Meths.t;
}
and class_field =
{
cf_desc: class_field_desc;
cf_loc: Location.t;
cf_attributes: attribute list;
}
and class_field_kind =
| Tcfk_virtual of core_type
| Tcfk_concrete of override_flag * expression
and class_field_desc =
Tcf_inherit of
override_flag * class_expr * string option * (string * Ident.t) list *
(string * Ident.t) list
| Tcf_val of string loc * mutable_flag * Ident.t * class_field_kind * bool
| Tcf_method of string loc * private_flag * class_field_kind
| Tcf_constraint of core_type * core_type
| Tcf_initializer of expression
| Tcf_attribute of attribute
and held_locks = Env.locks * Longident.t * Location.t
and mode_with_locks = Mode.Value.l * held_locks option
and module_expr =
{ mod_desc: module_expr_desc;
mod_loc: Location.t;
mod_type: Types.module_type;
mod_mode : mode_with_locks;
mod_env: Env.t;
mod_attributes: attribute list;
}
and module_type_constraint =
Tmodtype_implicit
| Tmodtype_explicit of module_type * Mode.Value.lr modes
and functor_parameter =
| Unit
| Named of Ident.t option * string option loc * module_type *
Mode.Alloc.Const.t modes
and module_expr_desc =
Tmod_ident of Path.t * Longident.t loc
| Tmod_structure of structure
| Tmod_functor of functor_parameter * module_expr
| Tmod_apply of module_expr * module_expr * module_coercion
| Tmod_apply_unit of module_expr
| Tmod_constraint of
module_expr * Types.module_type * module_type_constraint * module_coercion
| Tmod_unpack of expression * Types.module_type
| Tmod_typed_hole
and structure = {
str_items : structure_item list;
str_type : Types.signature;
str_final_env : Env.t;
}
and structure_item =
{ str_desc : structure_item_desc;
str_loc : Location.t;
str_env : Env.t
}
and structure_item_desc =
Tstr_eval of expression * Jkind.sort * attributes
| Tstr_value of rec_flag * value_binding list
| Tstr_primitive of value_description
| Tstr_type of rec_flag * type_declaration list
| Tstr_typext of type_extension
| Tstr_exception of type_exception
| Tstr_module of module_binding
| Tstr_recmodule of module_binding list
| Tstr_modtype of module_type_declaration
| Tstr_open of open_declaration
| Tstr_class of (class_declaration * string list) list
| Tstr_class_type of (Ident.t * string loc * class_type_declaration) list
| Tstr_include of include_declaration
| Tstr_attribute of attribute
| Tstr_jkind of jkind_declaration
and module_binding =
{
mb_id: Ident.t option;
mb_name: string option loc;
mb_uid: Uid.t;
mb_presence: module_presence;
mb_expr: module_expr;
mb_attributes: attribute list;
mb_loc: Location.t;
}
and value_binding =
{
vb_pat: pattern;
vb_expr: expression;
vb_rec_kind: Value_rec_types.recursive_binding_kind;
vb_sort: Jkind.sort;
vb_attributes: attributes;
vb_loc: Location.t;
}
and module_coercion =
Tcoerce_none
| Tcoerce_structure of
{ input_repr : Types.module_representation
; output_repr : Types.module_representation
; pos_cc_list : (int * module_coercion) list
; id_pos_list : (Ident.t * int * module_coercion) list
}
| Tcoerce_functor of module_coercion * module_coercion
| Tcoerce_primitive of primitive_coercion
| Tcoerce_alias of Env.t * Path.t * module_coercion
and module_type =
{ mty_desc: module_type_desc;
mty_type : Types.module_type;
mty_env : Env.t;
mty_loc: Location.t;
mty_attributes: attribute list;
}
and module_type_desc =
Tmty_ident of Path.t * Longident.t loc
| Tmty_signature of signature
| Tmty_functor of functor_parameter * module_type * Mode.Alloc.Const.t modes
| Tmty_with of module_type * (Path.t * Longident.t loc * with_constraint) list
| Tmty_typeof of module_expr
| Tmty_alias of Path.t * Longident.t loc
| Tmty_strengthen of module_type * Path.t * Longident.t loc
and primitive_coercion =
{
pc_desc: Primitive.description;
pc_type: type_expr;
pc_poly_mode: Mode.Locality.l option;
pc_poly_sort: Jkind.Sort.t option;
pc_env: Env.t;
pc_loc : Location.t;
}
and signature = {
sig_items : signature_item list;
sig_modalities : modalities;
sig_type : Types.signature;
sig_final_env : Env.t;
sig_sloc : Location.t;
}
and signature_item =
{ sig_desc: signature_item_desc;
sig_env : Env.t;
sig_loc: Location.t }
and signature_item_desc =
Tsig_value of value_description
| Tsig_type of rec_flag * type_declaration list
| Tsig_typesubst of type_declaration list
| Tsig_typext of type_extension
| Tsig_exception of type_exception
| Tsig_module of module_declaration
| Tsig_modsubst of module_substitution
| Tsig_recmodule of module_declaration list
| Tsig_modtype of module_type_declaration
| Tsig_modtypesubst of module_type_declaration
| Tsig_open of open_description
| Tsig_include of include_description * modalities
| Tsig_class of class_description list
| Tsig_class_type of class_type_declaration list
| Tsig_attribute of attribute
| Tsig_jkind of jkind_declaration
and module_declaration =
{
md_id: Ident.t option;
md_name: string option loc;
md_uid: Uid.t;
md_presence: module_presence;
md_type: module_type;
md_modalities: modalities;
md_attributes: attribute list;
md_loc: Location.t;
}
and module_substitution =
{
ms_id: Ident.t;
ms_name: string loc;
ms_uid: Uid.t;
ms_manifest: Path.t;
ms_txt: Longident.t loc;
ms_attributes: attributes;
ms_loc: Location.t;
}
and module_type_declaration =
{
mtd_id: Ident.t;
mtd_name: string loc;
mtd_uid: Uid.t;
mtd_type: module_type option;
mtd_attributes: attribute list;
mtd_loc: Location.t;
}
and 'a open_infos =
{
open_expr: 'a;
open_bound_items: Types.signature;
open_items_repr: Types.module_representation;
open_override: override_flag;
open_env: Env.t;
open_loc: Location.t;
open_attributes: attribute list;
}
and open_description = (Path.t * Longident.t loc) open_infos
and open_declaration = module_expr open_infos
and include_kind =
| Tincl_structure
| Tincl_functor of
{ input_coercion : (Ident.t * module_coercion) list
; input_repr : Types.module_representation
}
| Tincl_gen_functor of
{ input_coercion : (Ident.t * module_coercion) list
; input_repr : Types.module_representation
}
and 'a include_infos =
{
incl_mod: 'a;
incl_type: Types.signature;
incl_repr: Types.module_representation;
incl_loc: Location.t;
incl_kind: include_kind;
incl_attributes: attribute list;
}
and include_description = module_type include_infos
and include_declaration = module_expr include_infos
and with_constraint =
Twith_type of type_declaration
| Twith_module of Path.t * Longident.t loc
| Twith_modtype of module_type
| Twith_jkind of jkind_declaration
| Twith_typesubst of type_declaration
| Twith_modsubst of Path.t * Longident.t loc
| Twith_modtypesubst of module_type
| Twith_jkindsubst of jkind_declaration
and core_type =
{ mutable ctyp_desc : core_type_desc;
mutable ctyp_type : type_expr;
ctyp_env : Env.t;
ctyp_loc : Location.t;
ctyp_attributes: attribute list;
}
and core_type_desc =
| Ttyp_var of string option * Parsetree.jkind_annotation option
| Ttyp_arrow of arg_label * core_type * Mode.Alloc.Const.t modes *
core_type * Mode.Alloc.Const.t modes
| Ttyp_tuple of (string option * core_type) list
| Ttyp_unboxed_tuple of (string option * core_type) list
| Ttyp_constr of Path.t * Longident.t loc * core_type list
| Ttyp_object of object_field list * closed_flag
| Ttyp_class of Path.t * Longident.t loc * core_type list
| Ttyp_alias of core_type * string loc option *
Parsetree.jkind_annotation option
| Ttyp_variant of row_field list * closed_flag * label list option
| Ttyp_poly of (string * Parsetree.jkind_annotation option) list * core_type
| Ttyp_package of package_type
| Ttyp_open of Path.t * Longident.t loc * core_type
| Ttyp_quote of core_type
| Ttyp_splice of core_type
| Ttyp_repr of string list * core_type
| Ttyp_newlayout of string loc list * core_type
| Ttyp_of_kind of Parsetree.jkind_annotation
| Ttyp_call_pos
and package_type = {
pack_path : Path.t;
pack_fields : (Longident.t loc * core_type) list;
pack_type : Types.module_type;
pack_txt : Longident.t loc;
}
and row_field = {
rf_desc : row_field_desc;
rf_loc : Location.t;
rf_attributes : attributes;
}
and row_field_desc =
Ttag of string loc * bool * core_type list
| Tinherit of core_type
and object_field = {
of_desc : object_field_desc;
of_loc : Location.t;
of_attributes : attributes;
}
and object_field_desc =
| OTtag of string loc * core_type
| OTinherit of core_type
and value_description_modal_info =
| Valmi_sig_value of modalities
| Valmi_str_primitive of Mode.Alloc.Const.Option.t modes
and value_description =
{ val_id: Ident.t;
val_name: string loc;
val_desc: core_type;
val_val: Types.value_description;
val_modal_info: value_description_modal_info;
val_prim: string list;
val_loc: Location.t;
val_attributes: attribute list;
}
and type_declaration =
{ typ_id: Ident.t;
typ_name: string loc;
typ_params: (core_type * (variance * injectivity)) list;
typ_type: Types.type_declaration;
typ_cstrs: (core_type * core_type * Location.t) list;
typ_kind: type_kind;
typ_private: private_flag;
typ_manifest: core_type option;
typ_loc: Location.t;
typ_attributes: attribute list;
typ_jkind_annotation: Parsetree.jkind_annotation option;
}
and type_kind =
Ttype_abstract
| Ttype_variant of constructor_declaration list
| Ttype_record of label_declaration list
| Ttype_record_unboxed_product of label_declaration list
| Ttype_open
and label_declaration =
{
ld_id: Ident.t;
ld_name: string loc;
ld_uid: Uid.t;
ld_mutable: mutability;
ld_modalities: modalities;
ld_type: core_type;
ld_loc: Location.t;
ld_attributes: attribute list;
}
and constructor_declaration =
{
cd_id: Ident.t;
cd_name: string loc;
cd_uid: Uid.t;
cd_vars: (string * Parsetree.jkind_annotation option) list;
cd_args: constructor_arguments;
cd_res: core_type option;
cd_loc: Location.t;
cd_attributes: attribute list;
}
and constructor_argument =
{
ca_modalities: modalities;
ca_type: core_type;
ca_loc: Location.t;
}
and constructor_arguments =
| Cstr_tuple of constructor_argument list
| Cstr_record of label_declaration list
and type_extension =
{
tyext_path: Path.t;
tyext_txt: Longident.t loc;
tyext_params: (core_type * (variance * injectivity)) list;
tyext_constructors: extension_constructor list;
tyext_private: private_flag;
tyext_loc: Location.t;
tyext_attributes: attribute list;
}
and type_exception =
{
tyexn_constructor: extension_constructor;
tyexn_loc: Location.t;
tyexn_attributes: attribute list;
}
and extension_constructor =
{
ext_id: Ident.t;
ext_name: string loc;
ext_type: Types.extension_constructor;
ext_kind: extension_constructor_kind;
ext_loc: Location.t;
ext_attributes: attribute list;
}
and extension_constructor_kind =
Text_decl of (string * Parsetree.jkind_annotation option) list *
constructor_arguments *
core_type option
| Text_rebind of Path.t * Longident.t loc
and class_type =
{
cltyp_desc: class_type_desc;
cltyp_type: Types.class_type;
cltyp_env: Env.t;
cltyp_loc: Location.t;
cltyp_attributes: attribute list;
}
and class_type_desc =
Tcty_constr of Path.t * Longident.t loc * core_type list
| Tcty_signature of class_signature
| Tcty_arrow of arg_label * core_type * class_type
| Tcty_open of open_description * class_type
and class_signature = {
csig_self: core_type;
csig_fields: class_type_field list;
csig_type: Types.class_signature;
}
and class_type_field = {
ctf_desc: class_type_field_desc;
ctf_loc: Location.t;
ctf_attributes: attribute list;
}
and class_type_field_desc =
| Tctf_inherit of class_type
| Tctf_val of (string * mutable_flag * virtual_flag * core_type)
| Tctf_method of (string * private_flag * virtual_flag * core_type)
| Tctf_constraint of (core_type * core_type)
| Tctf_attribute of attribute
and class_declaration =
class_expr class_infos
and class_description =
class_type class_infos
and class_type_declaration =
class_type class_infos
and 'a class_infos =
{ ci_virt: virtual_flag;
ci_params: (core_type * (variance * injectivity)) list;
ci_id_name: string loc;
ci_id_class: Ident.t;
ci_id_class_type: Ident.t;
ci_id_object: Ident.t;
ci_expr: 'a;
ci_decl: Types.class_declaration;
ci_type_decl: Types.class_type_declaration;
ci_loc: Location.t;
ci_attributes: attribute list;
}
and jkind_declaration =
{ jkind_id: Ident.t;
jkind_name: string loc;
jkind_jkind: Types.jkind_declaration;
jkind_annotation: Parsetree.jkind_annotation option;
jkind_attributes: attribute list;
jkind_loc: Location.t
}
type argument_interface = {
ai_signature: Types.signature;
ai_coercion_from_primary: module_coercion;
}
type implementation = {
structure: structure;
coercion: module_coercion;
signature: Types.signature;
argument_interface: argument_interface option;
shape: Shape.t;
}
type item_declaration =
| Value of value_description
| Value_binding of value_binding
| Type of type_declaration
| Constructor of constructor_declaration
| Extension_constructor of extension_constructor
| Label of label_declaration
| Module of module_declaration
| Module_substitution of module_substitution
| Module_binding of module_binding
| Module_type of module_type_declaration
| Class of class_declaration
| Class_type of class_type_declaration
| Jkind of jkind_declaration
let as_computation_pattern (p : pattern) : computation general_pattern =
{
pat_desc = Tpat_value p;
pat_loc = p.pat_loc;
pat_extra = [];
pat_type = p.pat_type;
pat_env = p.pat_env;
pat_attributes = [];
pat_unique_barrier = p.pat_unique_barrier;
}
let function_arity params body =
List.length params +
match body with
| Tfunction_body _ -> 0
| Tfunction_cases _ -> 1
let rec classify_pattern_desc : type k . k pattern_desc -> k pattern_category =
function
| Tpat_alias _ -> Value
| Tpat_fun_layout _ -> Value
| Tpat_unboxed_unit -> Value
| Tpat_unboxed_bool _ -> Value
| Tpat_tuple _ -> Value
| Tpat_unboxed_tuple _ -> Value
| Tpat_construct _ -> Value
| Tpat_variant _ -> Value
| Tpat_record _ -> Value
| Tpat_record_unboxed_product _ -> Value
| Tpat_array _ -> Value
| Tpat_lazy _ -> Value
| Tpat_any -> Value
| Tpat_var _ -> Value
| Tpat_constant _ -> Value
| Tpat_value _ -> Computation
| Tpat_exception _ -> Computation
| Tpat_or(p1, p2, _) ->
begin match classify_pattern p1, classify_pattern p2 with
| Value, Value -> Value
| Computation, Computation -> Computation
end
and classify_pattern
: type k . k general_pattern -> k pattern_category
= fun pat ->
classify_pattern_desc pat.pat_desc
type pattern_action =
{ f : 'k . 'k general_pattern -> unit }
let shallow_iter_pattern_desc
: type k . pattern_action -> k pattern_desc -> unit
= fun f -> function
| Tpat_alias { pattern = p; _ } -> f.f p
| Tpat_fun_layout _ -> ()
| Tpat_tuple patl -> List.iter (fun (_, p) -> f.f p) patl
| Tpat_unboxed_tuple patl -> List.iter (fun (_, p, _) -> f.f p) patl
| Tpat_construct(_, _, patl, _) -> List.iter f.f patl
| Tpat_variant(_, pat, _) -> Option.iter f.f pat
| Tpat_record (lbl_pat_list, _) ->
List.iter (fun (_, _, pat) -> f.f pat) lbl_pat_list
| Tpat_record_unboxed_product (lbl_pat_list, _) ->
List.iter (fun (_, _, pat) -> f.f pat) lbl_pat_list
| Tpat_array (_, _, patl) -> List.iter f.f patl
| Tpat_lazy p -> f.f p
| Tpat_any
| Tpat_var _
| Tpat_constant _
| Tpat_unboxed_unit
| Tpat_unboxed_bool _ -> ()
| Tpat_value p -> f.f p
| Tpat_exception p -> f.f p
| Tpat_or(p1, p2, _) -> f.f p1; f.f p2
type pattern_transformation =
{ f : 'k . 'k general_pattern -> 'k general_pattern }
let shallow_map_pattern_desc
: type k . pattern_transformation -> k pattern_desc -> k pattern_desc
= fun f d -> match d with
| Tpat_alias { pattern = p1; id; name = s; uid; sort; mode = m;
type_expr = ty } ->
Tpat_alias { pattern = f.f p1; id; name = s; uid; sort; mode = m;
type_expr = ty }
| Tpat_tuple pats ->
Tpat_tuple (List.map (fun (label, pat) -> label, f.f pat) pats)
| Tpat_unboxed_tuple pats ->
Tpat_unboxed_tuple
(List.map (fun (label, pat, sort) -> label, f.f pat, sort) pats)
| Tpat_record (lpats, closed) ->
Tpat_record (List.map (fun (lid, l,p) -> lid, l, f.f p) lpats, closed)
| Tpat_record_unboxed_product (lpats, closed) ->
Tpat_record_unboxed_product
(List.map (fun (lid, l,p) -> lid, l, f.f p) lpats, closed)
| Tpat_construct (lid, c, pats, ty) ->
Tpat_construct (lid, c, List.map f.f pats, ty)
| Tpat_array (am, arg_sort, pats) ->
Tpat_array (am, arg_sort, List.map f.f pats)
| Tpat_lazy p1 -> Tpat_lazy (f.f p1)
| Tpat_variant (x1, Some p1, x2) ->
Tpat_variant (x1, Some (f.f p1), x2)
| Tpat_var _
| Tpat_fun_layout _
| Tpat_constant _
| Tpat_unboxed_unit
| Tpat_unboxed_bool _
| Tpat_any
| Tpat_variant (_,None,_) -> d
| Tpat_value p -> Tpat_value (f.f p)
| Tpat_exception p -> Tpat_exception (f.f p)
| Tpat_or (p1,p2,path) ->
Tpat_or (f.f p1, f.f p2, path)
let rec iter_general_pattern
: type k . pattern_action -> k general_pattern -> unit
= fun f p ->
f.f p;
shallow_iter_pattern_desc
{ f = fun p -> iter_general_pattern f p }
p.pat_desc
let iter_pattern (f : pattern -> unit) =
iter_general_pattern
{ f = fun (type k) (p : k general_pattern) ->
match classify_pattern p with
| Value -> f p
| Computation -> () }
type pattern_predicate = { f : 'k . 'k general_pattern -> bool }
let exists_general_pattern (f : pattern_predicate) p =
let exception Found in
match
iter_general_pattern
{ f = fun p -> if f.f p then raise Found else () }
p
with
| exception Found -> true
| () -> false
let exists_pattern (f : pattern -> bool) =
exists_general_pattern
{ f = fun (type k) (p : k general_pattern) ->
match classify_pattern p with
| Value -> f p
| Computation -> false }
let rec iter_bound_idents
: type k . _ -> k general_pattern -> _
= fun f pat ->
match pat.pat_desc with
| Tpat_var { id; name = s; uid; sort; _ } ->
f (id, s, pat.pat_type, sort, uid)
| Tpat_fun_layout { id; name = s; uid; sort; _ } ->
f (id, s, pat.pat_type, sort, uid)
| Tpat_alias { pattern = p; id; name = s; uid; sort; type_expr = ty; _ } ->
iter_bound_idents f p;
f (id, s, ty, sort, uid)
| Tpat_or(p1, _, _) ->
iter_bound_idents f p1
| d ->
shallow_iter_pattern_desc
{ f = fun p -> iter_bound_idents f p }
d
type 'sort full_bound_ident_action =
Ident.t -> string loc -> type_expr -> Uid.t -> Mode.Value.l -> 'sort -> unit
let for_transl f =
f ~of_sort:Jkind.Sort.default_for_transl_and_get ~of_const_sort:Fun.id
let for_typing f =
f ~of_sort:Fun.id ~of_const_sort:Jkind.Sort.of_const
let iter_pattern_full ~of_sort ~of_const_sort:_ ~both_sides_of_or f pat =
let rec loop :
type k . 'sort full_bound_ident_action -> k general_pattern -> _ =
fun f pat ->
match pat.pat_desc with
| Tpat_var { id; name = s; uid; sort; mode } ->
f id s pat.pat_type uid mode (of_sort sort)
| Tpat_fun_layout { id; name = s; uid; sort; mode; _ } ->
f id s pat.pat_type uid mode (of_sort sort)
| Tpat_alias { pattern = p; id; name = s; uid; sort; mode;
type_expr = ty } ->
loop f p;
f id s ty uid mode (of_sort sort)
| Tpat_or (p1, p2, _) ->
if both_sides_of_or then (loop f p1; loop f p2)
else loop f p1
| Tpat_value p -> loop f p
| Tpat_construct(_, _, patl, _) ->
List.iter (loop f) patl
| Tpat_record (lbl_pat_list, _) ->
List.iter (fun (_, _, pat) -> (loop f) pat) lbl_pat_list
| Tpat_record_unboxed_product (lbl_pat_list, _) ->
List.iter (fun (_, _, pat) -> (loop f) pat) lbl_pat_list
| Tpat_variant (_, pat, _) -> Option.iter (loop f) pat
| Tpat_tuple patl ->
List.iter (fun (_, pat) -> loop f pat) patl
| Tpat_unboxed_tuple patl ->
List.iter (fun (_, pat, _) -> loop f pat) patl
| Tpat_array (_, _, patl) ->
List.iter (loop f) patl
| Tpat_lazy p | Tpat_exception p -> loop f p
| Tpat_any | Tpat_constant _ | Tpat_unboxed_unit | Tpat_unboxed_bool _ ->
()
in
loop f pat
let rev_pat_bound_idents_full ~of_sort ~of_const_sort pat =
let idents_full = ref [] in
let add id sloc typ uid _ sort =
idents_full := (id, sloc, typ, uid, sort) :: !idents_full
in
iter_pattern_full
~both_sides_of_or:false ~of_sort ~of_const_sort
add pat;
!idents_full
let rev_only_idents idents_full =
List.rev_map (fun (id,_,_,_,_) -> id) idents_full
let pat_bound_idents_full pat =
List.rev (for_transl rev_pat_bound_idents_full pat)
let pat_bound_idents pat =
rev_only_idents
(for_typing rev_pat_bound_idents_full pat)
let rev_let_bound_idents_full bindings =
let idents_full = ref [] in
let add id_full = idents_full := id_full :: !idents_full in
List.iter (fun vb -> iter_bound_idents add vb.vb_pat) bindings;
!idents_full
let let_bound_idents_with_modes_sorts_and_checks bindings =
let modes_and_sorts = Ident.Tbl.create 3 in
let f id sloc _ _uid mode sort =
Ident.Tbl.add modes_and_sorts id (sloc.loc, mode, sort)
in
let checks =
List.fold_left (fun checks vb ->
for_typing iter_pattern_full
~both_sides_of_or:true
f vb.vb_pat;
match vb.vb_pat.pat_desc, vb.vb_expr.exp_desc with
| Tpat_var { id; _ }, Texp_function fn ->
let zero_alloc =
match Zero_alloc.get fn.zero_alloc with
| Default_zero_alloc ->
let arity = function_arity fn.params fn.body in
if arity <= 0 then
fn.zero_alloc
else
let create_const ~opt =
Zero_alloc.create_const
(Check { strict = false;
arity;
custom_error_msg = None;
loc = Location.none;
opt })
in
(match !Clflags.zero_alloc_assert with
| Assert_default -> fn.zero_alloc
| Assert_all -> create_const ~opt:false
| Assert_all_opt -> create_const ~opt:true)
| Ignore_assert_all | Check _ | Assume _ -> fn.zero_alloc
in
Ident.Map.add id zero_alloc checks
| _ -> checks
) Ident.Map.empty bindings
in
List.rev_map
(fun (id, _, _, _, _) ->
let zero_alloc =
Option.value (Ident.Map.find_opt id checks) ~default:Zero_alloc.default
in
id, List.rev (Ident.Tbl.find_all modes_and_sorts id), zero_alloc)
(rev_let_bound_idents_full bindings)
let let_bound_idents_full bindings =
List.rev (rev_let_bound_idents_full bindings)
let let_bound_idents_with_sorts pat =
List.rev_map (fun (id,_,_,sort,_) -> (id, sort))
(rev_let_bound_idents_full pat)
let let_bound_idents pat =
List.rev_map (fun (id,_,_,_,_) -> id) (rev_let_bound_idents_full pat)
let alpha_var env id = List.assoc id env
let rec alpha_pat
: type k . _ -> k general_pattern -> k general_pattern
= fun env p -> match p.pat_desc with
| Tpat_var { id; name = s; uid; sort; mode } ->
{p with pat_desc =
try Tpat_var { id = alpha_var env id; name = s; uid; sort; mode } with
| Not_found -> Tpat_any}
| Tpat_alias { pattern = p1; id; name = s; uid; sort; mode;
type_expr = ty } ->
let new_p = alpha_pat env p1 in
begin try
{p with pat_desc =
Tpat_alias { pattern = new_p; id = alpha_var env id;
name = s; uid; sort; mode; type_expr = ty }}
with
| Not_found -> new_p
end
| d ->
let pat_desc =
shallow_map_pattern_desc { f = fun p -> alpha_pat env p } d in
{p with pat_desc}
let mkloc = Location.mkloc
let mknoloc = Location.mknoloc
let split_pattern pat =
let combine_opts merge p1 p2 =
match p1, p2 with
| None, None -> None
| Some p, None
| None, Some p ->
Some p
| Some p1, Some p2 ->
Some (merge p1 p2)
in
let into pat p1 p2 =
{ pat with pat_desc = Tpat_or (p1, p2, None) } in
let rec split_pattern cpat =
match cpat.pat_desc with
| Tpat_value p ->
Some p, None
| Tpat_exception p ->
None, Some p
| Tpat_or (cp1, cp2, _) ->
let vals1, exns1 = split_pattern cp1 in
let vals2, exns2 = split_pattern cp2 in
combine_opts (into cpat) vals1 vals2,
combine_opts (into cpat) exns1 exns2
in
split_pattern pat
let nominal_exp_doc lid t =
let open Format_doc.Doc in
let longident l = Format_doc.doc_printer lid l.Location.txt in
let rec nominal_exp_doc doc exp =
match exp.exp_desc with
| _ when exp.exp_attributes <> [] -> None
| Texp_ident { lid; _ } ->
Some (longident lid doc)
| Texp_instvar (_,_,s) ->
Some (string s.Location.txt doc)
| Texp_constant _ -> assert false
| Texp_variant (lbl, None) ->
Some (printf "`%s" lbl doc)
| Texp_construct (l, _, [], _) -> Some (longident l doc)
| Texp_field (parent, _, lbl, _, _, _) ->
Option.map
(printf ".%t" (longident lbl))
(nominal_exp_doc doc parent)
| Texp_send (parent, meth, _) ->
let name = match meth with
| Tmeth_name name -> name
| Tmeth_val id | Tmeth_ancestor (id,_) -> Ident.name id in
Option.map
(printf "#%s" name)
(nominal_exp_doc doc parent)
| _ -> None
in
nominal_exp_doc empty t
let loc_of_decl ~uid =
let of_option { txt; loc } =
match txt with
| Some txt -> { txt; loc }
| None -> { txt = ""; loc }
in
function
| Value vd -> vd.val_name
| Value_binding vb ->
let bound_idents = let_bound_idents_full [vb] in
let name = ListLabels.find_map
~f:(fun (_, name, _, _, uid') -> if uid = uid' then Some name else None)
bound_idents in
(match name with
| Some name -> name
| None ->
{ txt = ""; loc = vb.vb_pat.pat_loc })
| Type td -> td.typ_name
| Constructor cd -> cd.cd_name
| Extension_constructor ec -> ec.ext_name
| Label ld -> ld.ld_name
| Module md -> of_option md.md_name
| Module_binding mb -> of_option mb.mb_name
| Module_type mtd -> mtd.mtd_name
| Module_substitution msd -> msd.ms_name
| Class cd -> cd.ci_id_name
| Class_type ctd -> ctd.ci_id_name
| Jkind jd -> jd.jkind_name
let min_mode_with_locks = (Mode.Value.(disallow_right legacy), None)
let mode_without_locks_exn = function
| (_, Some _) -> assert false
| (m, None) -> m
let rec fold_antiquote_exp f acc exp =
match exp.exp_desc with
| Texp_ident _ | Texp_constant _ | Texp_unboxed_unit | Texp_unboxed_bool _ ->
acc
| Texp_apply_layout (exp, _) -> fold_antiquote_exp f acc exp
| Texp_let (_, vbs, exp) ->
let acc = fold_antiquote_value_bindings f acc vbs in
fold_antiquote_exp f acc exp
| Texp_function { params; body; _ } ->
let acc = fold_antiquote_fun_params f acc params in
fold_antiquote_function_body f acc body
| Texp_apply (exp, list, _, _, _) ->
let acc = fold_antiquote_exp f acc exp in
fold_antiquote_args f acc list
| Texp_match (exp, _, cases, _) ->
let acc = fold_antiquote_exp f acc exp in
fold_antiquote_cases f acc cases
| Texp_try (exp, cases) ->
let acc = fold_antiquote_exp f acc exp in
fold_antiquote_cases f acc cases
| Texp_tuple (list, _) ->
List.fold_left (fun acc (_, e) -> fold_antiquote_exp f acc e) acc list
| Texp_unboxed_tuple list ->
List.fold_left (fun acc (_, e, _) -> fold_antiquote_exp f acc e) acc list
| Texp_construct (_, _, args, _) ->
fold_antiquote_exps f acc args
| Texp_variant (_, expo) ->
Option.fold
~none:acc
~some:(fun (e, _) -> fold_antiquote_exp f acc e)
expo
| Texp_record { fields; extended_expression; _} ->
let acc = Array.fold_left (fold_antiquote_field f) acc fields in
Option.fold
~none:acc
~some:(fun (e, _, _) -> fold_antiquote_exp f acc e)
extended_expression
| Texp_record_unboxed_product { fields; extended_expression; _} ->
let acc = Array.fold_left (fold_antiquote_field f) acc fields in
Option.fold
~none:acc
~some:(fun (e, _) -> fold_antiquote_exp f acc e)
extended_expression
| Texp_field (exp, _, _, _, _, _) ->
fold_antiquote_exp f acc exp
| Texp_unboxed_field (exp, _, _, _, _) ->
fold_antiquote_exp f acc exp
| Texp_setfield (exp1, _, _, _, exp2) ->
let acc = fold_antiquote_exp f acc exp1 in
fold_antiquote_exp f acc exp2
| Texp_array (_, _, list, _) ->
fold_antiquote_exps f acc list
| Texp_list_comprehension { comp_body; comp_clauses }
| Texp_array_comprehension (_, _, { comp_body; comp_clauses }) ->
let acc = fold_antiquote_exp f acc comp_body in
fold_antiquote_comprehension_clauses f acc comp_clauses
| Texp_ifthenelse (exp1, exp2, expo) ->
let acc = fold_antiquote_exp f acc exp1 in
let acc = fold_antiquote_exp f acc exp2 in
fold_antiquote_exp_opt f acc expo
| Texp_sequence (exp1, _, exp2) ->
let acc = fold_antiquote_exp f acc exp1 in
fold_antiquote_exp f acc exp2
| Texp_while { wh_cond; wh_body } ->
let acc = fold_antiquote_exp f acc wh_cond in
fold_antiquote_exp f acc wh_body
| Texp_for {for_from; for_to; for_body} ->
let acc = fold_antiquote_exp f acc for_from in
let acc = fold_antiquote_exp f acc for_to in
fold_antiquote_exp f acc for_body
| Texp_send (exp, _, _) -> fold_antiquote_exp f acc exp
| Texp_new (_, _, _, _) -> acc
| Texp_instvar (_, _, _) -> acc
| Texp_setinstvar (_, _, _, exp) -> fold_antiquote_exp f acc exp
| Texp_override (_, list) ->
List.fold_left (fun acc (_, _, e) -> fold_antiquote_exp f acc e) acc list
| Texp_letmodule (_, _, _, _, exp) -> fold_antiquote_exp f acc exp
| Texp_letexception (_, exp) -> fold_antiquote_exp f acc exp
| Texp_assert (exp, _) -> fold_antiquote_exp f acc exp
| Texp_lazy exp -> fold_antiquote_exp f acc exp
| Texp_object (_, _) -> acc
| Texp_pack _ -> acc
| Texp_letop {let_ = l; ands; body; _} ->
let acc = fold_antiquote_binding_op f acc l in
let acc = List.fold_left (fold_antiquote_binding_op f) acc ands in
fold_antiquote_case f acc body
| Texp_unreachable -> acc
| Texp_extension_constructor (_, _) -> acc
| Texp_open (_, e) -> fold_antiquote_exp f acc e
| Texp_probe {handler;_} -> fold_antiquote_exp f acc handler
| Texp_probe_is_enabled _ -> acc
| Texp_exclave exp -> fold_antiquote_exp f acc exp
| Texp_src_pos -> acc
| Texp_overwrite (exp1, exp2) ->
let acc = fold_antiquote_exp f acc exp1 in
fold_antiquote_exp f acc exp2
| Texp_hole _ -> acc
| Texp_letmutable (_, exp) -> fold_antiquote_exp f acc exp
| Texp_mutvar _ -> acc
| Texp_setmutvar (_, _, exp) -> fold_antiquote_exp f acc exp
| Texp_atomic_loc (exp, _, _, _, _) -> fold_antiquote_exp f acc exp
| Texp_idx (_, _) -> acc
| Texp_quotation exp ->
fold_antiquote_exp (fold_antiquote_exp f) acc exp
| Texp_antiquotation exp -> f acc exp
| Texp_typed_hole -> acc
and fold_antiquote_exp_opt f acc = function
| None -> acc
| Some exp -> fold_antiquote_exp f acc exp
and fold_antiquote_exps f acc exps =
List.fold_left (fold_antiquote_exp f) acc exps
and fold_antiquote_value_bindings f acc vbs =
List.fold_left (fun acc vb -> fold_antiquote_exp f acc vb.vb_expr) acc vbs
and fold_antiquote_fun_param f acc fp =
match fp.fp_kind with
| Tparam_pat _ -> acc
| Tparam_optional_default(_, exp, _) -> fold_antiquote_exp f acc exp
and fold_antiquote_fun_params f acc fps =
List.fold_left (fold_antiquote_fun_param f) acc fps
and fold_antiquote_function_body f acc = function
| Tfunction_body exp -> fold_antiquote_exp f acc exp
| Tfunction_cases fc -> fold_antiquote_cases f acc fc.fc_cases
and fold_antiquote_case : 'k. _ -> _ -> 'k case -> _ =
fun f acc c ->
let acc = fold_antiquote_exp_opt f acc c.c_guard in
fold_antiquote_exp f acc c.c_rhs
and fold_antiquote_cases : 'k. _ -> _ -> 'k case list -> _ =
fun f acc cases ->
List.fold_left (fold_antiquote_case f) acc cases
and fold_antiquote_arg f acc (_, arg) =
match arg with
| Omitted _ -> acc
| Arg (exp, _) -> fold_antiquote_exp f acc exp
and fold_antiquote_args f acc args =
List.fold_left (fold_antiquote_arg f) acc args
and fold_antiquote_field : 'l. _ -> _ -> 'l * _ -> _ =
fun f acc -> function
| _, Kept _ -> acc
| _, Overridden (_, exp) -> fold_antiquote_exp f acc exp
and fold_antiquote_comprehension_clause f acc = function
| Texp_comp_for bindings ->
List.fold_left
(fun acc { comp_cb_iterator; _ } ->
match comp_cb_iterator with
| Texp_comp_range { ident = _; start; stop; direction = _ } ->
let acc = fold_antiquote_exp f acc start in
fold_antiquote_exp f acc stop
| Texp_comp_in { pattern = _; sequence } ->
fold_antiquote_exp f acc sequence)
acc bindings
| Texp_comp_when exp ->
fold_antiquote_exp f acc exp
and fold_antiquote_comprehension_clauses f acc ccs =
List.fold_left (fold_antiquote_comprehension_clause f) acc ccs
and fold_antiquote_binding_op f acc op =
fold_antiquote_exp f acc op.bop_exp