oxilean-std 0.1.2

OxiLean standard library
Documentation
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
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use std::collections::{BTreeSet, HashSet, VecDeque};

use super::types::{
    AndersenPTA, ConstPropState, EraserState, FixpointSolver, IFCTracker, Interval, NullTracker,
    Nullability, PDGraph, SecurityLevel, Sign, TaintState, TypestateAutomaton,
};

pub fn app(f: Expr, a: Expr) -> Expr {
    Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
    app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
    app(app2(f, a, b), c)
}
pub fn cst(s: &str) -> Expr {
    Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
    Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
    Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
    Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
    pi(BinderInfo::Default, "_", a, b)
}
pub fn bvar(n: u32) -> Expr {
    Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
    cst("Nat")
}
pub fn bool_ty() -> Expr {
    cst("Bool")
}
pub fn string_ty() -> Expr {
    cst("String")
}
pub fn list_ty(elem: Expr) -> Expr {
    app(cst("List"), elem)
}
pub fn option_ty(elem: Expr) -> Expr {
    app(cst("Option"), elem)
}
pub fn set_ty(elem: Expr) -> Expr {
    app(cst("Set"), elem)
}
pub fn pair_ty(a: Expr, b: Expr) -> Expr {
    app2(cst("Prod"), a, b)
}
/// `Lattice : Type → Type` — A complete lattice on a carrier type.
pub fn lattice_ty() -> Expr {
    arrow(type0(), type0())
}
/// `LatticeBottom : ∀ L, Lattice L → L` — Bottom element ⊥.
pub fn lattice_bottom_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(app(cst("Lattice"), bvar(0)), bvar(1)),
    )
}
/// `LatticeTop : ∀ L, Lattice L → L` — Top element ⊤.
pub fn lattice_top_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(app(cst("Lattice"), bvar(0)), bvar(1)),
    )
}
/// `LatticeJoin : ∀ L, Lattice L → L → L → L` — Join operator ⊔.
pub fn lattice_join_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(
            app(cst("Lattice"), bvar(0)),
            arrow(bvar(1), arrow(bvar(2), bvar(3))),
        ),
    )
}
/// `LatticeMeet : ∀ L, Lattice L → L → L → L` — Meet operator ⊓.
pub fn lattice_meet_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(
            app(cst("Lattice"), bvar(0)),
            arrow(bvar(1), arrow(bvar(2), bvar(3))),
        ),
    )
}
/// `LatticeLeq : ∀ L, Lattice L → L → L → Prop` — Partial order ⊑.
pub fn lattice_leq_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(
            app(cst("Lattice"), bvar(0)),
            arrow(bvar(1), arrow(bvar(2), prop())),
        ),
    )
}
/// `MooreFamily : Set (Set A) → Prop` — Closed under arbitrary intersection.
pub fn moore_family_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "A",
        type0(),
        arrow(set_ty(set_ty(bvar(0))), prop()),
    )
}
/// `CompleteLattice_GaloisConnection : every Galois connection yields a complete lattice`
pub fn complete_lattice_galois_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "L",
        type0(),
        arrow(
            app(cst("GaloisConn"), bvar(0)),
            app(cst("CompleteLattice"), bvar(1)),
        ),
    )
}
/// `ConcreteSemantics : Program → Set State` — Collecting semantics.
pub fn concrete_semantics_ty() -> Expr {
    arrow(cst("Program"), set_ty(cst("ConcreteState")))
}
/// `AbstractSemantics : Program → AbsDom` — Abstract semantics over an abstract domain.
pub fn abstract_semantics_ty() -> Expr {
    arrow(cst("Program"), cst("AbsDom"))
}
/// `GaloisConnection : (C → A) × (A → C) → Prop`
/// (α, γ) form a Galois connection: α(c) ⊑ a ↔ c ⊆ γ(a).
pub fn galois_connection_ty() -> Expr {
    pair_ty(
        arrow(cst("ConcreteState"), cst("AbsDom")),
        arrow(cst("AbsDom"), cst("ConcreteState")),
    )
}
/// `Abstraction : ConcreteSemantics → AbsDom` — Abstraction function α.
pub fn abstraction_ty() -> Expr {
    arrow(concrete_semantics_ty(), cst("AbsDom"))
}
/// `Concretization : AbsDom → ConcreteSemantics` — Concretization function γ.
pub fn concretization_ty() -> Expr {
    arrow(cst("AbsDom"), concrete_semantics_ty())
}
/// `GaloisInsertion : GaloisConnection → Prop` — α∘γ = id (optimal abstraction).
pub fn galois_insertion_ty() -> Expr {
    arrow(galois_connection_ty(), prop())
}
/// `Widening : AbsDom → AbsDom → AbsDom` — Widening operator ▽.
pub fn widening_ty() -> Expr {
    arrow(cst("AbsDom"), arrow(cst("AbsDom"), cst("AbsDom")))
}
/// `Narrowing : AbsDom → AbsDom → AbsDom` — Narrowing operator △.
pub fn narrowing_ty() -> Expr {
    arrow(cst("AbsDom"), arrow(cst("AbsDom"), cst("AbsDom")))
}
/// `Widening_Terminates : widening guarantees termination of iteration`
pub fn widening_terminates_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "f",
        arrow(cst("AbsDom"), cst("AbsDom")),
        app(
            cst("Terminates"),
            app2(cst("fixpoint_widen"), bvar(0), cst("Widening")),
        ),
    )
}
/// `AbstractInterp_Sound : ∀ prog, α(collect prog) ⊑ abs_semantics prog`
pub fn abstract_interp_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(
            app(cst("Leq"), app(cst("α"), app(cst("collect"), bvar(0)))),
            app(cst("abs_semantics"), bvar(0)),
        ),
    )
}
/// `Narrowing_RefinesPost : ∀ x y, y ⊑ x → y △ (f x) ⊑ x`
pub fn narrowing_refines_post_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "x",
        cst("AbsDom"),
        pi(
            BinderInfo::Default,
            "y",
            cst("AbsDom"),
            arrow(
                app2(cst("Leq"), bvar(0), bvar(1)),
                app(
                    app(
                        cst("Leq"),
                        app2(cst("Narrowing"), bvar(1), app(cst("f"), bvar(2))),
                    ),
                    bvar(2),
                ),
            ),
        ),
    )
}
/// `HeapGraph : Type` — A shape graph: nodes are abstract heap cells.
pub fn heap_graph_ty() -> Expr {
    type0()
}
/// `HeapNode : Type` — An abstract heap node (summary or concrete).
pub fn heap_node_ty() -> Expr {
    type0()
}
/// `SharingPred : HeapGraph → HeapNode → HeapNode → Prop`
/// May-sharing: two nodes may alias through some path.
pub fn sharing_pred_ty() -> Expr {
    arrow(
        heap_graph_ty(),
        arrow(heap_node_ty(), arrow(heap_node_ty(), prop())),
    )
}
/// `CyclicPred : HeapGraph → HeapNode → Prop`
/// A node may be part of a cyclic structure.
pub fn cyclic_pred_ty() -> Expr {
    arrow(heap_graph_ty(), arrow(heap_node_ty(), prop()))
}
/// `ShapeDescriptor : Type` — An abstract shape: tree, dag, list, cyclic-list, graph.
pub fn shape_descriptor_ty() -> Expr {
    type0()
}
/// `shape_join : ShapeDescriptor → ShapeDescriptor → ShapeDescriptor`
pub fn shape_join_ty() -> Expr {
    arrow(
        shape_descriptor_ty(),
        arrow(shape_descriptor_ty(), shape_descriptor_ty()),
    )
}
/// `shape_transfer : HeapOp → ShapeDescriptor → ShapeDescriptor`
pub fn shape_transfer_ty() -> Expr {
    arrow(
        cst("HeapOp"),
        arrow(shape_descriptor_ty(), shape_descriptor_ty()),
    )
}
/// `ShapeSound : ∀ op s, shape_transfer op s over-approximates concrete shapes`
pub fn shape_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "op",
        cst("HeapOp"),
        pi(
            BinderInfo::Default,
            "s",
            shape_descriptor_ty(),
            app(
                cst("OverApprox"),
                app2(cst("shape_transfer"), bvar(1), bvar(0)),
            ),
        ),
    )
}
/// `ThreeValued : Type` — Three-valued logic {True, False, Maybe} for must/may.
pub fn three_valued_ty() -> Expr {
    type0()
}
/// `MustAlias : HeapGraph → HeapNode → HeapNode → ThreeValued`
pub fn must_alias_ty() -> Expr {
    arrow(
        heap_graph_ty(),
        arrow(heap_node_ty(), arrow(heap_node_ty(), three_valued_ty())),
    )
}
/// `AllocSite : Type` — An allocation site (abstract heap location).
pub fn alloc_site_ty() -> Expr {
    nat_ty()
}
/// `PointsTo : Var → Set AllocSite` — Points-to set for a variable.
pub fn points_to_ty() -> Expr {
    arrow(cst("Var"), set_ty(alloc_site_ty()))
}
/// `AndersenAnalysis : Program → PointsTo` — Andersen inclusion-based pointer analysis.
pub fn andersen_analysis_ty() -> Expr {
    arrow(cst("Program"), points_to_ty())
}
/// `SteensgaardAnalysis : Program → (Var → Var)` — Steensgaard unification-based analysis.
/// Returns equivalence classes (union-find representative).
pub fn steensgaard_analysis_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), cst("Var")))
}
/// `Andersen_Sound : ∀ prog, andersen is a sound over-approximation`
pub fn andersen_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(cst("Sound"), app(cst("AndersenAnalysis"), bvar(0))),
    )
}
/// `Steensgaard_SubAndersen : Steensgaard ⊑ Andersen (less precise but O(n α(n)))`
pub fn steensgaard_sub_andersen_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(
            app(cst("Leq"), app(cst("SteensgaardAnalysis"), bvar(0))),
            app(cst("AndersenAnalysis"), bvar(0)),
        ),
    )
}
/// `Andersen_Cubic : Andersen analysis is O(n³) in the worst case`
pub fn andersen_cubic_ty() -> Expr {
    app(
        cst("TimeComplexity"),
        app(cst("CubicN"), cst("AndersenAnalysis")),
    )
}
/// `Steensgaard_AlmostLinear : Steensgaard is nearly O(n) via union-find`
pub fn steensgaard_almost_linear_ty() -> Expr {
    app(
        cst("TimeComplexity"),
        app(cst("InvAckermann"), cst("SteensgaardAnalysis")),
    )
}
/// `AliasResult : Var → Var → Prop` — Two variables may alias.
pub fn alias_result_ty() -> Expr {
    arrow(cst("Var"), arrow(cst("Var"), prop()))
}
/// `MayAlias : Program → Var → Var → Bool`
pub fn may_alias_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(cst("Var"), arrow(cst("Var"), bool_ty())),
    )
}
/// `MustAliasPair : Program → Var → Var → Bool`
pub fn must_alias_pair_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(cst("Var"), arrow(cst("Var"), bool_ty())),
    )
}
/// `TypeBasedAlias : Type → Type → Bool` — TBAA: types determine alias potential.
pub fn type_based_alias_ty() -> Expr {
    arrow(cst("IRType"), arrow(cst("IRType"), bool_ty()))
}
/// `NoAlias : Var → Var → Prop` — Two variables definitely do not alias.
pub fn no_alias_ty() -> Expr {
    arrow(cst("Var"), arrow(cst("Var"), prop()))
}
/// `Alias_Undecidable : alias analysis is undecidable in general`
pub fn alias_undecidable_ty() -> Expr {
    app(cst("Undecidable"), cst("ExactAliasAnalysis"))
}
/// `SoftType : Type` — A soft type: a type that may be violated at runtime.
pub fn soft_type_ty() -> Expr {
    type0()
}
/// `SoftTypeCheck : Program → SoftType → Bool`
pub fn soft_type_check_ty() -> Expr {
    arrow(cst("Program"), arrow(soft_type_ty(), bool_ty()))
}
/// `RefinementType : Type → Pred → Type` — `{x : T | P(x)}`.
pub fn refinement_type_ty() -> Expr {
    arrow(type0(), arrow(arrow(bvar(0), prop()), type0()))
}
/// `EffectType : Type → EffectSet → Type` — A type annotated with an effect.
pub fn effect_type_ty() -> Expr {
    arrow(type0(), arrow(cst("EffectSet"), type0()))
}
/// `EffectSubtype : EffectType → EffectType → Prop` — Subtyping with effects.
pub fn effect_subtype_ty() -> Expr {
    arrow(effect_type_ty(), arrow(effect_type_ty(), prop()))
}
/// `Liquid_Haskell_Sound : ∀ prog, liquid_type_check prog → no_runtime_type_errors prog`
pub fn liquid_haskell_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("liquid_type_check"), bvar(0)),
            app(cst("no_runtime_errors"), bvar(1)),
        ),
    )
}
/// `CallSite : Type` — A call site in the program.
pub fn call_site_ty() -> Expr {
    nat_ty()
}
/// `AbstractClosure : Type` — An abstract closure: (lambda, env).
pub fn abstract_closure_ty() -> Expr {
    type0()
}
/// `ZeroCFA : Program → CallSite → Set AbstractClosure`
/// 0-CFA: context-insensitive closure analysis.
pub fn zero_cfa_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(call_site_ty(), set_ty(abstract_closure_ty())),
    )
}
/// `KCFA : Nat → Program → (CallSite × List CallSite) → Set AbstractClosure`
/// k-CFA: context-sensitive with call-string depth k.
pub fn k_cfa_ty() -> Expr {
    arrow(
        nat_ty(),
        arrow(
            cst("Program"),
            arrow(
                pair_ty(call_site_ty(), list_ty(call_site_ty())),
                set_ty(abstract_closure_ty()),
            ),
        ),
    )
}
/// `CFA_Overapprox : ∀ k prog, k_cfa k prog ⊇ actual call targets`
pub fn cfa_overapprox_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "prog",
            cst("Program"),
            app(cst("Overapproximates"), app2(cst("KCFA"), bvar(1), bvar(0))),
        ),
    )
}
/// `CFA_Monotone_in_k : 0-CFA ⊑ 1-CFA ⊑ 2-CFA ⊑ …`
pub fn cfa_monotone_k_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        app(
            app(cst("Leq"), app2(cst("KCFA"), bvar(0), cst("prog"))),
            app2(cst("KCFA"), app(cst("Succ"), bvar(0)), cst("prog")),
        ),
    )
}
/// `KCFA_Complexity : k-CFA is EXPTIME-complete for k ≥ 1`
pub fn k_cfa_complexity_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        arrow(
            app(cst("Ge"), app2(cst("Ge"), bvar(0), nat_ty())),
            app(cst("EXPTIMEComplete"), app(cst("KCFA"), bvar(1))),
        ),
    )
}
/// `Effect : Type` — An abstract program effect (read, write, alloc, throw, io).
pub fn effect_ty() -> Expr {
    type0()
}
/// `EffectSet : Type` — A set of effects annotating an expression or function.
pub fn effect_set_ty() -> Expr {
    set_ty(effect_ty())
}
/// `ReadEffect : Var → Effect` — Reading from variable.
pub fn read_effect_ty() -> Expr {
    arrow(cst("Var"), effect_ty())
}
/// `WriteEffect : Var → Effect` — Writing to variable.
pub fn write_effect_ty() -> Expr {
    arrow(cst("Var"), effect_ty())
}
/// `ExnEffect : ExnType → Effect` — Raising an exception.
pub fn exn_effect_ty() -> Expr {
    arrow(cst("ExnType"), effect_ty())
}
/// `infer_effects : Program → EffectMap` — Effect inference over a whole program.
pub fn infer_effects_ty() -> Expr {
    arrow(cst("Program"), cst("EffectMap"))
}
/// `EffectSound : ∀ prog, infer_effects prog ⊇ actual_effects prog`
pub fn effect_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(
            app(cst("Superset"), app(cst("infer_effects"), bvar(0))),
            app(cst("actual_effects"), bvar(0)),
        ),
    )
}
/// `PureFunction : Expr → Prop` — A function with empty effect set.
pub fn pure_function_ty() -> Expr {
    arrow(cst("Expr"), prop())
}
/// `ResourceType : Type` — A linear/affine resource type.
pub fn resource_type_ty() -> Expr {
    type0()
}
/// `UsageAnnotation : Type` — Usage count: 0, 1, or ω (unrestricted).
pub fn usage_annotation_ty() -> Expr {
    type0()
}
/// `LinearType : ResourceType → Prop` — Resource must be used exactly once.
pub fn linear_type_ty() -> Expr {
    arrow(resource_type_ty(), prop())
}
/// `AffineType : ResourceType → Prop` — Resource used at most once.
pub fn affine_type_ty() -> Expr {
    arrow(resource_type_ty(), prop())
}
/// `ResourceUsageAnalysis : Program → Var → UsageAnnotation`
/// Infers usage count (0, 1, ω) for each variable.
pub fn resource_usage_analysis_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), usage_annotation_ty()))
}
/// `LeakFreedom : Program → Prop` — All acquired resources are released.
pub fn leak_freedom_ty() -> Expr {
    arrow(cst("Program"), prop())
}
/// `LinearType_LeakFree : ∀ prog, well_typed_linear prog → LeakFreedom prog`
pub fn linear_type_leak_free_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("WellTypedLinear"), bvar(0)),
            app(cst("LeakFreedom"), bvar(1)),
        ),
    )
}
/// `UsageCount_Sound : usage analysis is a sound over-approximation of actual usage`
pub fn usage_count_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(cst("Sound"), app(cst("ResourceUsageAnalysis"), bvar(0))),
    )
}
/// `Thread : Type` — An abstract thread identifier.
pub fn thread_ty() -> Expr {
    nat_ty()
}
/// `LockSet : Type` — The set of locks held by a thread.
pub fn lock_set_ty() -> Expr {
    set_ty(nat_ty())
}
/// `HappensBefore : Event → Event → Prop` — The happens-before partial order.
pub fn happens_before_ty() -> Expr {
    arrow(cst("Event"), arrow(cst("Event"), prop()))
}
/// `DataRace : Event → Event → Prop`
/// Two events form a data race if they access the same location, at least
/// one is a write, they are from different threads, and not ordered by HB.
pub fn data_race_ty() -> Expr {
    arrow(cst("Event"), arrow(cst("Event"), prop()))
}
/// `EraserLockSet : Thread → MemLoc → Set Lock`
/// Eraser algorithm: track C(v) = intersection of lock sets for variable v.
pub fn eraser_lock_set_ty() -> Expr {
    arrow(thread_ty(), arrow(cst("MemLoc"), lock_set_ty()))
}
/// `Eraser_Invariant : C(v) ≠ ∅ → no data race on v`
pub fn eraser_invariant_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "v",
        cst("MemLoc"),
        arrow(
            app(cst("NonEmpty"), app(cst("C"), bvar(0))),
            app(cst("NoRace"), bvar(1)),
        ),
    )
}
/// `TSan_Sound : ThreadSanitizer reports all races`
pub fn tsan_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("HasRace"), bvar(0)),
            app(cst("TSanReports"), bvar(1)),
        ),
    )
}
/// `DataRaceFreedom : Program → Prop` — No data races in the program.
pub fn data_race_freedom_ty() -> Expr {
    arrow(cst("Program"), prop())
}
/// `DRF_Sequential : ∀ prog, DRF prog → sequential_consistent prog`
pub fn drf_sequential_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("DataRaceFreedom"), bvar(0)),
            app(cst("SeqConsistent"), bvar(1)),
        ),
    )
}
/// `TaintSource : Type` — A source of tainted data (user input, env vars, etc.).
pub fn taint_source_ty() -> Expr {
    type0()
}
/// `TaintSink : Type` — A sink that must not receive tainted data (SQL query, shell cmd).
pub fn taint_sink_ty() -> Expr {
    type0()
}
/// `Sanitizer : Type` — A function that removes taint (e.g., HTML-escape).
pub fn sanitizer_ty() -> Expr {
    type0()
}
/// `TaintLabel : Var → Bool` — Is a variable tainted?
pub fn taint_label_ty() -> Expr {
    arrow(cst("Var"), bool_ty())
}
/// `TaintPropagation : Program → TaintLabel → TaintLabel`
/// Propagate taint through the program.
pub fn taint_propagation_ty() -> Expr {
    arrow(cst("Program"), arrow(taint_label_ty(), taint_label_ty()))
}
/// `TaintViolation : Program → TaintLabel → Set (Var × TaintSink) → Prop`
/// A taint violation: tainted variable reaches a sink without sanitization.
pub fn taint_violation_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(
            taint_label_ty(),
            arrow(set_ty(pair_ty(cst("Var"), taint_sink_ty())), prop()),
        ),
    )
}
/// `Taint_Sound : ∀ prog, taint_propagation over-approximates actual taint flow`
pub fn taint_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(cst("Sound"), app(cst("TaintPropagation"), bvar(0))),
    )
}
/// `Taint_NoFalseNegatives : all real taint violations are reported`
pub fn taint_no_false_neg_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("RealViolation"), bvar(0)),
            app(cst("Reported"), bvar(1)),
        ),
    )
}
/// `SepLogicHeap : Type` — A heap in separation logic (finite partial map Addr → Val).
pub fn sep_logic_heap_ty() -> Expr {
    arrow(cst("Addr"), option_ty(cst("Val")))
}
/// `SepConj : SepPred → SepPred → SepPred` — Separating conjunction P * Q.
pub fn sep_conj_ty() -> Expr {
    arrow(
        arrow(sep_logic_heap_ty(), prop()),
        arrow(
            arrow(sep_logic_heap_ty(), prop()),
            arrow(sep_logic_heap_ty(), prop()),
        ),
    )
}
/// `SepImp : SepPred → SepPred → SepPred` — Magic wand P −∗ Q.
pub fn sep_imp_ty() -> Expr {
    arrow(
        arrow(sep_logic_heap_ty(), prop()),
        arrow(
            arrow(sep_logic_heap_ty(), prop()),
            arrow(sep_logic_heap_ty(), prop()),
        ),
    )
}
/// `PointsToCell : Addr → Val → SepPred` — Singleton heap cell l ↦ v.
pub fn points_to_cell_ty() -> Expr {
    arrow(
        cst("Addr"),
        arrow(cst("Val"), arrow(sep_logic_heap_ty(), prop())),
    )
}
/// `FrameRule : ∀ prog P Q R, {P} prog {Q} → {P * R} prog {Q * R}` — Frame rule.
pub fn frame_rule_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "P",
        arrow(sep_logic_heap_ty(), prop()),
        pi(
            BinderInfo::Default,
            "Q",
            arrow(sep_logic_heap_ty(), prop()),
            pi(
                BinderInfo::Default,
                "R",
                arrow(sep_logic_heap_ty(), prop()),
                arrow(
                    app3(cst("HoareTriple"), bvar(2), cst("prog"), bvar(1)),
                    app3(
                        cst("HoareTriple"),
                        app2(cst("SepConj"), bvar(2), bvar(0)),
                        cst("prog"),
                        app2(cst("SepConj"), bvar(1), bvar(0)),
                    ),
                ),
            ),
        ),
    )
}
/// `HeapShape_TreePred : HeapNode → SepPred` — Predicate for an acyclic linked list.
pub fn heap_shape_tree_pred_ty() -> Expr {
    arrow(heap_node_ty(), arrow(sep_logic_heap_ty(), prop()))
}
/// `MemorySafety : Program → SepPred → Prop` — No out-of-bounds or dangling access.
pub fn memory_safety_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(arrow(sep_logic_heap_ty(), prop()), prop()),
    )
}
/// `OwnershipTransfer : SepPred → SepPred → Prop`
/// Ownership transfer from pre to post (move semantics).
pub fn ownership_transfer_ty() -> Expr {
    arrow(
        arrow(sep_logic_heap_ty(), prop()),
        arrow(arrow(sep_logic_heap_ty(), prop()), prop()),
    )
}
/// `Typestate : Type` — A typestate: a type annotated with a protocol state.
pub fn typestate_ty() -> Expr {
    type0()
}
/// `TypestateProtocol : Type` — A resource usage protocol (e.g. Opened/Closed file).
pub fn typestate_protocol_ty() -> Expr {
    arrow(typestate_ty(), set_ty(typestate_ty()))
}
/// `TypestateTransition : Typestate → Op → Typestate → Prop`
/// Specifies valid state transitions under operations.
pub fn typestate_transition_ty() -> Expr {
    arrow(
        typestate_ty(),
        arrow(cst("Op"), arrow(typestate_ty(), prop())),
    )
}
/// `TypestateCheck : Program → TypestateProtocol → Prop`
/// Program respects the resource usage protocol.
pub fn typestate_check_ty() -> Expr {
    arrow(cst("Program"), arrow(typestate_protocol_ty(), prop()))
}
/// `MustUseResource : Typestate → Prop` — Resource in this state must be consumed.
pub fn must_use_resource_ty() -> Expr {
    arrow(typestate_ty(), prop())
}
/// `TypestateSound : typestate analysis is a sound approximation of runtime states`
pub fn typestate_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("TypestateCheck"), bvar(0)),
            app(cst("NoProtocolViolation"), bvar(1)),
        ),
    )
}
/// `Region : Type` — A memory region (stack frame, heap generation, etc.).
pub fn region_ty() -> Expr {
    nat_ty()
}
/// `RegionAnnotation : Expr → Region` — Maps an expression to its allocation region.
pub fn region_annotation_ty() -> Expr {
    arrow(cst("Expr"), region_ty())
}
/// `EscapeAnalysis : Program → Var → Bool`
/// Returns true if a variable's value may escape its defining scope.
pub fn escape_analysis_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), bool_ty()))
}
/// `RegionInference : Program → RegionAnnotation`
/// Infer allocation regions to enable stack allocation of non-escaping values.
pub fn region_inference_ty() -> Expr {
    arrow(cst("Program"), region_annotation_ty())
}
/// `Escape_Sound : ∀ prog v, ¬escape prog v → stack_allocated prog v`
pub fn escape_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        pi(
            BinderInfo::Default,
            "v",
            cst("Var"),
            arrow(
                app(
                    app(cst("Not"), app2(cst("EscapeAnalysis"), bvar(1), bvar(0))),
                    nat_ty(),
                ),
                app2(cst("StackAllocated"), bvar(1), bvar(0)),
            ),
        ),
    )
}
/// `RegionSubtyping : Region → Region → Prop` — Lifetime/region containment.
pub fn region_subtyping_ty() -> Expr {
    arrow(region_ty(), arrow(region_ty(), prop()))
}
/// `MonadicEffect : Type → EffectSet → Type`
/// A computation of type T with effects E (monadic encoding).
pub fn monadic_effect_ty() -> Expr {
    arrow(type0(), arrow(effect_set_ty(), type0()))
}
/// `GradedMonad : (EffectSet → Type → Type) → Prop`
/// A graded monad indexed by effect sets.
pub fn graded_monad_ty() -> Expr {
    arrow(arrow(effect_set_ty(), arrow(type0(), type0())), prop())
}
/// `CapabilitySet : Type` — A set of capabilities (permissions) held at a program point.
pub fn capability_set_ty() -> Expr {
    set_ty(cst("Capability"))
}
/// `CapabilityJudgment : Context → Expr → EffectType → Prop`
/// Typing judgment: in context Γ with capabilities C, expression e has effect type T.
pub fn capability_judgment_ty() -> Expr {
    arrow(
        cst("Context"),
        arrow(cst("Expr"), arrow(effect_type_ty(), prop())),
    )
}
/// `EffectPolymorphism : ∀ e f, e : T!{f} → e : T!{f ∪ g}` — Effect weakening.
pub fn effect_polymorphism_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "f",
        effect_set_ty(),
        pi(
            BinderInfo::Default,
            "g",
            effect_set_ty(),
            pi(
                BinderInfo::Default,
                "T",
                type0(),
                arrow(
                    app2(cst("HasEffectType"), bvar(0), bvar(2)),
                    app2(
                        cst("HasEffectType"),
                        bvar(0),
                        app2(cst("EffectUnion"), bvar(2), bvar(1)),
                    ),
                ),
            ),
        ),
    )
}
/// `AlgebraicEffectHandler : EffectSet → Type → Type`
/// Handler type that handles a set of algebraic effects.
pub fn algebraic_effect_handler_ty() -> Expr {
    arrow(effect_set_ty(), arrow(type0(), type0()))
}
/// `GradualType : Type` — A gradual type (may contain the unknown type ?).
pub fn gradual_type_ty() -> Expr {
    type0()
}
/// `UnknownType : GradualType` — The dynamic unknown type ?.
pub fn unknown_type_ty() -> Expr {
    gradual_type_ty()
}
/// `ConsistencyRel : GradualType → GradualType → Prop` — Type consistency (~).
pub fn consistency_rel_ty() -> Expr {
    arrow(gradual_type_ty(), arrow(gradual_type_ty(), prop()))
}
/// `CastInsertion : GradualExpr → StaticExpr` — Elaborates gradual to casted static code.
pub fn cast_insertion_ty() -> Expr {
    arrow(cst("GradualExpr"), cst("StaticExpr"))
}
/// `CastCorrectness : ∀ e, eval (cast_insert e) = gradual_eval e`
/// Cast insertion preserves semantics.
pub fn cast_correctness_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "e",
        cst("GradualExpr"),
        app(
            app(
                cst("Eq"),
                app(cst("eval"), app(cst("CastInsertion"), bvar(0))),
            ),
            app(cst("gradual_eval"), bvar(0)),
        ),
    )
}
/// `Blame_Theorem : dynamic cast failures are attributed to correct source location`
pub fn blame_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "e",
        cst("GradualExpr"),
        arrow(
            app(cst("CastFails"), bvar(0)),
            app(cst("BlameCorrect"), bvar(1)),
        ),
    )
}
/// `LiquidType : BaseType → Qualifier → RefinementType`
/// A liquid type `{v : B | Q(v)}` with a qualifier drawn from a template set.
pub fn liquid_type_ty() -> Expr {
    arrow(
        cst("BaseType"),
        arrow(cst("Qualifier"), cst("RefinementType")),
    )
}
/// `QualifierInstantiation : Template → Substitution → Qualifier`
/// A qualifier instantiated from a Liquid Haskell template.
pub fn qualifier_instantiation_ty() -> Expr {
    arrow(
        cst("Template"),
        arrow(cst("Substitution"), cst("Qualifier")),
    )
}
/// `SubtypingRefinement : RefinementType → RefinementType → Prop`
/// `{v : B | P} <: {v : B | Q}` iff P ⊢ Q.
pub fn subtyping_refinement_ty() -> Expr {
    arrow(cst("RefinementType"), arrow(cst("RefinementType"), prop()))
}
/// `RefinementInference : Program → Var → RefinementType`
/// Automatically infer strongest safe refinement types.
pub fn refinement_inference_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), cst("RefinementType")))
}
/// `LiquidType_Complete : liquid type inference is complete for the qualifier set`
pub fn liquid_type_complete_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("QualifierSetFinite"), bvar(0)),
            app(cst("RefinementInferenceComplete"), bvar(1)),
        ),
    )
}
/// `SecurityLabel : Type` — A security lattice element (e.g. Low, High, Secret).
pub fn security_label_ty() -> Expr {
    type0()
}
/// `SecrecyLattice : SecurityLabel → SecurityLabel → Prop` — Label ordering ⊑.
pub fn secrecy_lattice_ty() -> Expr {
    arrow(security_label_ty(), arrow(security_label_ty(), prop()))
}
/// `LabelEnv : Var → SecurityLabel` — Security label environment.
pub fn label_env_ty() -> Expr {
    arrow(cst("Var"), security_label_ty())
}
/// `NonInterference : Program → LabelEnv → Prop`
/// Low-equivalent inputs produce low-equivalent outputs.
pub fn non_interference_ty() -> Expr {
    arrow(cst("Program"), arrow(label_env_ty(), prop()))
}
/// `Declassification : Expr → SecurityLabel → SecurityLabel → Prop`
/// Explicit declassification from high to low label.
pub fn declassification_ty() -> Expr {
    arrow(
        cst("Expr"),
        arrow(security_label_ty(), arrow(security_label_ty(), prop())),
    )
}
/// `IFCTypeSystem : Context → Expr → LabeledType → Prop`
/// Information flow control typing judgment.
pub fn ifc_type_system_ty() -> Expr {
    arrow(
        cst("Context"),
        arrow(cst("Expr"), arrow(cst("LabeledType"), prop())),
    )
}
/// `NI_Theorem : ∀ prog env, IFC_typed prog env → NonInterference prog env`
pub fn ni_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        pi(
            BinderInfo::Default,
            "env",
            label_env_ty(),
            arrow(
                app2(cst("IFC_typed"), bvar(1), bvar(0)),
                app2(cst("NonInterference"), bvar(2), bvar(1)),
            ),
        ),
    )
}
/// `ConstantFolding : Expr → Expr` — Evaluate constant sub-expressions at compile time.
pub fn constant_folding_ty() -> Expr {
    arrow(cst("Expr"), cst("Expr"))
}
/// `ConstantPropagation : Program → Var → Option Val`
/// Statically determine the value of a variable if it is constant.
pub fn constant_propagation_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), option_ty(cst("Val"))))
}
/// `ConstFold_Correct : ∀ e, eval (const_fold e) = eval e`
pub fn const_fold_correct_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "e",
        cst("Expr"),
        app(
            app(
                cst("Eq"),
                app(cst("eval"), app(cst("ConstantFolding"), bvar(0))),
            ),
            app(cst("eval"), bvar(0)),
        ),
    )
}
/// `IntervalDomain : Type` — Abstract domain for value range analysis (intervals).
pub fn interval_domain_ty() -> Expr {
    type0()
}
/// `BitfieldDomain : Type` — Abstract domain tracking known/unknown bits.
pub fn bitfield_domain_ty() -> Expr {
    type0()
}
/// `ValueRangeAnalysis : Program → Var → IntervalDomain`
/// Compute abstract value ranges for all variables.
pub fn value_range_analysis_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), interval_domain_ty()))
}
/// `VRA_Sound : ∀ prog, value_range_analysis over-approximates concrete values`
pub fn vra_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(cst("Sound"), app(cst("ValueRangeAnalysis"), bvar(0))),
    )
}
/// `NullabilityAnnotation : Type → Bool → Type`
/// Type annotated with nullability: T? vs T!.
pub fn nullability_annotation_ty() -> Expr {
    arrow(type0(), arrow(bool_ty(), type0()))
}
/// `NullPointerAnalysis : Program → Var → ThreeValued`
/// Three-valued result: definitely null / definitely non-null / maybe null.
pub fn null_pointer_analysis_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), three_valued_ty()))
}
/// `DefiniteAssignment : Program → Var → Prop`
/// Every use of a variable is preceded by a definition.
pub fn definite_assignment_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Var"), prop()))
}
/// `NullSafety : Program → Prop` — No null dereferences occur.
pub fn null_safety_ty() -> Expr {
    arrow(cst("Program"), prop())
}
/// `NullAnalysis_Sound : ∀ prog, null_pointer_analysis is sound`
pub fn null_analysis_sound_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        app(cst("Sound"), app(cst("NullPointerAnalysis"), bvar(0))),
    )
}
/// `LockOrder : Lock → Lock → Prop` — A consistent lock acquisition order.
pub fn lock_order_ty() -> Expr {
    arrow(cst("Lock"), arrow(cst("Lock"), prop()))
}
/// `DeadlockFreedom : Program → Prop` — No circular lock dependencies.
pub fn deadlock_freedom_ty() -> Expr {
    arrow(cst("Program"), prop())
}
/// `LockOrder_Acyclic : ∀ prog, acyclic_lock_order prog → DeadlockFreedom prog`
pub fn lock_order_acyclic_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("AcyclicLockOrder"), bvar(0)),
            app(cst("DeadlockFreedom"), bvar(1)),
        ),
    )
}
/// `AtomicBlock : Program → Stmt → Prop`
/// A statement executes atomically with respect to all other threads.
pub fn atomic_block_ty() -> Expr {
    arrow(cst("Program"), arrow(cst("Stmt"), prop()))
}
/// `Atomicity_Serializability : ∀ prog s, Atomic prog s → serializable_execution prog s`
pub fn atomicity_serializability_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        pi(
            BinderInfo::Default,
            "s",
            cst("Stmt"),
            arrow(
                app2(cst("AtomicBlock"), bvar(1), bvar(0)),
                app2(cst("SerializableExec"), bvar(2), bvar(1)),
            ),
        ),
    )
}
/// `LockSetAnalysis : Program → Thread → MemLoc → LockSet`
/// Compute the set of locks held by thread t when accessing loc.
pub fn lock_set_analysis_ty() -> Expr {
    arrow(
        cst("Program"),
        arrow(thread_ty(), arrow(cst("MemLoc"), lock_set_ty())),
    )
}
/// `OwnershipType : Type` — A type carrying ownership (unique, shared, borrowed).
pub fn ownership_type_ty() -> Expr {
    type0()
}
/// `BorrowKind : Type` — Borrow flavor: immutable (&) or mutable (&mut).
pub fn borrow_kind_ty() -> Expr {
    type0()
}
/// `Lifetime : Type` — A lifetime region for borrow validity.
pub fn lifetime_ty() -> Expr {
    nat_ty()
}
/// `BorrowCheck : Program → Prop` — Rust-like borrow checker soundness.
pub fn borrow_check_ty() -> Expr {
    arrow(cst("Program"), prop())
}
/// `OwnershipUnique : OwnershipType → Prop` — At most one owner at any time.
pub fn ownership_unique_ty() -> Expr {
    arrow(ownership_type_ty(), prop())
}
/// `BorrowCheck_MemSafe : ∀ prog, borrow_check prog → memory_safe prog`
pub fn borrow_check_mem_safe_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        arrow(
            app(cst("BorrowCheck"), bvar(0)),
            app(cst("MemorySafe"), bvar(1)),
        ),
    )
}
/// `LifetimeSubtyping : Lifetime → Lifetime → Prop` — 'a: 'b (a outlives b).
pub fn lifetime_subtyping_ty() -> Expr {
    arrow(lifetime_ty(), arrow(lifetime_ty(), prop()))
}
/// `NonLexicalLifetime : Program → LifetimeAnnotation`
/// Non-lexical lifetime inference for precise scope analysis.
pub fn non_lexical_lifetime_ty() -> Expr {
    arrow(cst("Program"), cst("LifetimeAnnotation"))
}
/// `DataDependence : Stmt → Stmt → Prop` — def-use data dependence edge.
pub fn data_dependence_ty() -> Expr {
    arrow(cst("Stmt"), arrow(cst("Stmt"), prop()))
}
/// `ControlDependence : Stmt → Stmt → Prop` — Control dependence edge.
pub fn control_dependence_ty() -> Expr {
    arrow(cst("Stmt"), arrow(cst("Stmt"), prop()))
}
/// `ProgramDependenceGraph : Program → PDG`
/// Build the program dependence graph combining data and control edges.
pub fn program_dependence_graph_ty() -> Expr {
    arrow(cst("Program"), cst("PDG"))
}
/// `BackwardSlice : PDG → SliceCriterion → Set Stmt`
/// Backward slice: all statements that can affect the criterion.
pub fn backward_slice_ty() -> Expr {
    arrow(
        cst("PDG"),
        arrow(cst("SliceCriterion"), set_ty(cst("Stmt"))),
    )
}
/// `ForwardSlice : PDG → SliceCriterion → Set Stmt`
/// Forward slice: all statements that the criterion can affect.
pub fn forward_slice_ty() -> Expr {
    arrow(
        cst("PDG"),
        arrow(cst("SliceCriterion"), set_ty(cst("Stmt"))),
    )
}
/// `Slice_Correct : ∀ prog c, backward_slice preserves criterion semantics`
pub fn slice_correct_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "prog",
        cst("Program"),
        pi(
            BinderInfo::Default,
            "c",
            cst("SliceCriterion"),
            app(
                cst("PreservesSemantics"),
                app2(
                    cst("BackwardSlice"),
                    app(cst("ProgramDependenceGraph"), bvar(1)),
                    bvar(0),
                ),
            ),
        ),
    )
}
/// Populate an OxiLean kernel `Environment` with all static-analysis axioms.
pub fn build_static_analysis_env() -> Environment {
    let mut env = Environment::new();
    let axioms: &[(&str, Expr)] = &[
        ("Lattice", lattice_ty()),
        ("LatticeBottom", lattice_bottom_ty()),
        ("LatticeTop", lattice_top_ty()),
        ("LatticeJoin", lattice_join_ty()),
        ("LatticeMeet", lattice_meet_ty()),
        ("LatticeLeq", lattice_leq_ty()),
        ("MooreFamily", moore_family_ty()),
        ("CompleteLattice_GaloisConn", complete_lattice_galois_ty()),
        ("ConcreteSemantics", concrete_semantics_ty()),
        ("AbstractSemantics", abstract_semantics_ty()),
        ("GaloisConnection", galois_connection_ty()),
        ("Abstraction", abstraction_ty()),
        ("Concretization", concretization_ty()),
        ("GaloisInsertion", galois_insertion_ty()),
        ("Widening", widening_ty()),
        ("Narrowing", narrowing_ty()),
        ("Widening_Terminates", widening_terminates_ty()),
        ("AbstractInterp_Sound", abstract_interp_sound_ty()),
        ("Narrowing_RefinesPost", narrowing_refines_post_ty()),
        ("HeapGraph", heap_graph_ty()),
        ("HeapNode", heap_node_ty()),
        ("SharingPred", sharing_pred_ty()),
        ("CyclicPred", cyclic_pred_ty()),
        ("ShapeDescriptor", shape_descriptor_ty()),
        ("shape_join", shape_join_ty()),
        ("shape_transfer", shape_transfer_ty()),
        ("ShapeSound", shape_sound_ty()),
        ("ThreeValued", three_valued_ty()),
        ("MustAlias", must_alias_ty()),
        ("AllocSite", alloc_site_ty()),
        ("PointsTo", points_to_ty()),
        ("AndersenAnalysis", andersen_analysis_ty()),
        ("SteensgaardAnalysis", steensgaard_analysis_ty()),
        ("Andersen_Sound", andersen_sound_ty()),
        ("Steensgaard_SubAndersen", steensgaard_sub_andersen_ty()),
        ("Andersen_Cubic", andersen_cubic_ty()),
        ("Steensgaard_AlmostLinear", steensgaard_almost_linear_ty()),
        ("AliasResult", alias_result_ty()),
        ("MayAlias", may_alias_ty()),
        ("MustAliasPair", must_alias_pair_ty()),
        ("TypeBasedAlias", type_based_alias_ty()),
        ("NoAlias", no_alias_ty()),
        ("Alias_Undecidable", alias_undecidable_ty()),
        ("SoftType", soft_type_ty()),
        ("SoftTypeCheck", soft_type_check_ty()),
        ("RefinementType", refinement_type_ty()),
        ("EffectType", effect_type_ty()),
        ("EffectSubtype", effect_subtype_ty()),
        ("Liquid_Haskell_Sound", liquid_haskell_sound_ty()),
        ("CallSite", call_site_ty()),
        ("AbstractClosure", abstract_closure_ty()),
        ("ZeroCFA", zero_cfa_ty()),
        ("KCFA", k_cfa_ty()),
        ("CFA_Overapprox", cfa_overapprox_ty()),
        ("CFA_Monotone_in_k", cfa_monotone_k_ty()),
        ("KCFA_Complexity", k_cfa_complexity_ty()),
        ("Effect", effect_ty()),
        ("EffectSet", effect_set_ty()),
        ("ReadEffect", read_effect_ty()),
        ("WriteEffect", write_effect_ty()),
        ("ExnEffect", exn_effect_ty()),
        ("infer_effects", infer_effects_ty()),
        ("EffectSound", effect_sound_ty()),
        ("PureFunction", pure_function_ty()),
        ("ResourceType", resource_type_ty()),
        ("UsageAnnotation", usage_annotation_ty()),
        ("LinearType", linear_type_ty()),
        ("AffineType", affine_type_ty()),
        ("ResourceUsageAnalysis", resource_usage_analysis_ty()),
        ("LeakFreedom", leak_freedom_ty()),
        ("LinearType_LeakFree", linear_type_leak_free_ty()),
        ("UsageCount_Sound", usage_count_sound_ty()),
        ("Thread", thread_ty()),
        ("LockSet", lock_set_ty()),
        ("HappensBefore", happens_before_ty()),
        ("DataRace", data_race_ty()),
        ("EraserLockSet", eraser_lock_set_ty()),
        ("Eraser_Invariant", eraser_invariant_ty()),
        ("TSan_Sound", tsan_sound_ty()),
        ("DataRaceFreedom", data_race_freedom_ty()),
        ("DRF_Sequential", drf_sequential_ty()),
        ("TaintSource", taint_source_ty()),
        ("TaintSink", taint_sink_ty()),
        ("Sanitizer", sanitizer_ty()),
        ("TaintLabel", taint_label_ty()),
        ("TaintPropagation", taint_propagation_ty()),
        ("TaintViolation", taint_violation_ty()),
        ("Taint_Sound", taint_sound_ty()),
        ("Taint_NoFalseNegatives", taint_no_false_neg_ty()),
        ("SepLogicHeap", sep_logic_heap_ty()),
        ("SepConj", sep_conj_ty()),
        ("SepImp", sep_imp_ty()),
        ("PointsToCell", points_to_cell_ty()),
        ("FrameRule", frame_rule_ty()),
        ("HeapShape_TreePred", heap_shape_tree_pred_ty()),
        ("MemorySafety", memory_safety_ty()),
        ("OwnershipTransfer", ownership_transfer_ty()),
        ("Typestate", typestate_ty()),
        ("TypestateProtocol", typestate_protocol_ty()),
        ("TypestateTransition", typestate_transition_ty()),
        ("TypestateCheck", typestate_check_ty()),
        ("MustUseResource", must_use_resource_ty()),
        ("TypestateSound", typestate_sound_ty()),
        ("Region", region_ty()),
        ("RegionAnnotation", region_annotation_ty()),
        ("EscapeAnalysis", escape_analysis_ty()),
        ("RegionInference", region_inference_ty()),
        ("Escape_Sound", escape_sound_ty()),
        ("RegionSubtyping", region_subtyping_ty()),
        ("MonadicEffect", monadic_effect_ty()),
        ("GradedMonad", graded_monad_ty()),
        ("CapabilitySet", capability_set_ty()),
        ("CapabilityJudgment", capability_judgment_ty()),
        ("EffectPolymorphism", effect_polymorphism_ty()),
        ("AlgebraicEffectHandler", algebraic_effect_handler_ty()),
        ("GradualType", gradual_type_ty()),
        ("UnknownType", unknown_type_ty()),
        ("ConsistencyRel", consistency_rel_ty()),
        ("CastInsertion", cast_insertion_ty()),
        ("CastCorrectness", cast_correctness_ty()),
        ("Blame_Theorem", blame_theorem_ty()),
        ("LiquidType", liquid_type_ty()),
        ("QualifierInstantiation", qualifier_instantiation_ty()),
        ("SubtypingRefinement", subtyping_refinement_ty()),
        ("RefinementInference", refinement_inference_ty()),
        ("LiquidType_Complete", liquid_type_complete_ty()),
        ("SecurityLabel", security_label_ty()),
        ("SecrecyLattice", secrecy_lattice_ty()),
        ("LabelEnv", label_env_ty()),
        ("NonInterference", non_interference_ty()),
        ("Declassification", declassification_ty()),
        ("IFCTypeSystem", ifc_type_system_ty()),
        ("NI_Theorem", ni_theorem_ty()),
        ("ConstantFolding", constant_folding_ty()),
        ("ConstantPropagation", constant_propagation_ty()),
        ("ConstFold_Correct", const_fold_correct_ty()),
        ("IntervalDomain", interval_domain_ty()),
        ("BitfieldDomain", bitfield_domain_ty()),
        ("ValueRangeAnalysis", value_range_analysis_ty()),
        ("VRA_Sound", vra_sound_ty()),
        ("NullabilityAnnotation", nullability_annotation_ty()),
        ("NullPointerAnalysis", null_pointer_analysis_ty()),
        ("DefiniteAssignment", definite_assignment_ty()),
        ("NullSafety", null_safety_ty()),
        ("NullAnalysis_Sound", null_analysis_sound_ty()),
        ("LockOrder", lock_order_ty()),
        ("DeadlockFreedom", deadlock_freedom_ty()),
        ("LockOrder_Acyclic", lock_order_acyclic_ty()),
        ("AtomicBlock", atomic_block_ty()),
        ("Atomicity_Serializability", atomicity_serializability_ty()),
        ("LockSetAnalysis", lock_set_analysis_ty()),
        ("OwnershipType", ownership_type_ty()),
        ("BorrowKind", borrow_kind_ty()),
        ("Lifetime", lifetime_ty()),
        ("BorrowCheck", borrow_check_ty()),
        ("OwnershipUnique", ownership_unique_ty()),
        ("BorrowCheck_MemSafe", borrow_check_mem_safe_ty()),
        ("LifetimeSubtyping", lifetime_subtyping_ty()),
        ("NonLexicalLifetime", non_lexical_lifetime_ty()),
        ("DataDependence", data_dependence_ty()),
        ("ControlDependence", control_dependence_ty()),
        ("ProgramDependenceGraph", program_dependence_graph_ty()),
        ("BackwardSlice", backward_slice_ty()),
        ("ForwardSlice", forward_slice_ty()),
        ("Slice_Correct", slice_correct_ty()),
    ];
    for (name, ty) in axioms {
        env.add(Declaration::Axiom {
            name: Name::str(*name),
            univ_params: vec![],
            ty: ty.clone(),
        })
        .ok();
    }
    env
}
#[cfg(test)]
mod tests {
    use super::*;
    /// Smoke test: build env produces expected axioms.
    #[test]
    fn test_build_env_nonempty() {
        let env = build_static_analysis_env();
        let names = [
            "Lattice",
            "GaloisConnection",
            "Widening",
            "Narrowing",
            "AndersenAnalysis",
            "HappensBefore",
            "TaintPropagation",
            "ShapeDescriptor",
            "KCFA",
            "DataRaceFreedom",
        ];
        let count = names
            .iter()
            .filter(|&&n| env.get(&Name::str(n)).is_some())
            .count();
        assert_eq!(count, 10);
    }
    /// Interval lattice: join, meet, order.
    #[test]
    fn test_interval_lattice() {
        let a = Interval::Range(1, 5);
        let b = Interval::Range(3, 8);
        assert_eq!(a.join(&b), Interval::Range(1, 8));
        assert_eq!(a.meet(&b), Interval::Range(3, 5));
        assert!(Interval::Bottom.leq(&a));
        assert!(a.leq(&Interval::top()));
        assert!(!b.leq(&a));
    }
    /// Interval widening drives to ⊤.
    #[test]
    fn test_interval_widening() {
        let mut x = Interval::Range(0, 0);
        for _ in 0..5 {
            let next = x.add(&Interval::single(1));
            x = x.widen(&next);
        }
        assert_eq!(x, Interval::Range(0, i64::MAX));
    }
    /// Sign domain: join and add.
    #[test]
    fn test_sign_domain() {
        assert_eq!(Sign::of(3), Sign::Pos);
        assert_eq!(Sign::of(-2), Sign::Neg);
        assert_eq!(Sign::of(0), Sign::Zero);
        assert_eq!(Sign::Pos.join(&Sign::Neg), Sign::Top);
        assert_eq!(Sign::Pos.add(&Sign::Zero), Sign::Pos);
        assert_eq!(Sign::Neg.neg(), Sign::Pos);
    }
    /// Andersen PTA: simple copy chain.
    #[test]
    fn test_andersen_copy_chain() {
        let mut pta = AndersenPTA::new(3);
        pta.add_alloc(0, 0);
        pta.add_copy(0, 1);
        pta.add_copy(1, 2);
        pta.solve();
        assert!(pta.pts[0].contains(&0));
        assert!(pta.pts[1].contains(&0));
        assert!(pta.pts[2].contains(&0));
        assert!(pta.may_alias(0, 1));
        assert!(pta.may_alias(1, 2));
    }
    /// Taint propagation: source → propagation → sink.
    #[test]
    fn test_taint_propagation() {
        let mut ts = TaintState::new();
        ts.add_source("user_input");
        ts.propagate("x", &["user_input"]);
        ts.propagate("y", &["x", "const"]);
        assert!(ts.violates("x"));
        assert!(ts.violates("y"));
        ts.sanitize("x");
        assert!(!ts.violates("x"));
        assert!(ts.violates("y"));
    }
    /// Eraser race detection: two threads, no common lock → race.
    #[test]
    fn test_eraser_race_detected() {
        let mut state = EraserState::new();
        let locks_t1: BTreeSet<usize> = vec![1].into_iter().collect();
        let locks_t2: BTreeSet<usize> = vec![2].into_iter().collect();
        state.observe_access(0, &locks_t1, true);
        state.observe_access(1, &locks_t2, true);
        assert!(state.has_race());
    }
    /// Eraser: same lock on both accesses → no race.
    #[test]
    fn test_eraser_no_race() {
        let mut state = EraserState::new();
        let locks: BTreeSet<usize> = vec![42].into_iter().collect();
        state.observe_access(0, &locks, true);
        state.observe_access(1, &locks, false);
        assert!(!state.has_race());
    }
    /// Fixpoint solver: reachability over a 3-node chain.
    #[test]
    fn test_fixpoint_reachability() {
        let edges = vec![vec![1], vec![2], vec![]];
        let mut solver = FixpointSolver::new(
            3,
            edges,
            false,
            |a: &bool, b: &bool| *a || *b,
            |n, v| if n == 0 { true } else { *v },
        );
        solver.values[0] = true;
        solver.solve();
        assert!(solver.values[1]);
        assert!(solver.values[2]);
    }
    /// New axioms are registered in the environment.
    #[test]
    fn test_new_axioms_registered() {
        let env = build_static_analysis_env();
        let names = [
            "SepConj",
            "FrameRule",
            "TypestateSound",
            "EscapeAnalysis",
            "GradedMonad",
            "CastCorrectness",
            "LiquidType",
            "NonInterference",
            "ConstantFolding",
            "NullSafety",
            "DeadlockFreedom",
            "BorrowCheck",
            "BackwardSlice",
        ];
        let count = names
            .iter()
            .filter(|&&n| env.get(&Name::str(n)).is_some())
            .count();
        assert_eq!(count, names.len());
    }
    /// TypestateAutomaton: file open/close protocol.
    #[test]
    fn test_typestate_automaton_file() {
        let mut aut = TypestateAutomaton::new(2, 0);
        aut.add_transition(0, "open", 1);
        aut.add_transition(1, "read", 1);
        aut.add_transition(1, "close", 0);
        aut.set_accepting(0);
        assert!(aut.accepts(&["open", "read", "close"]));
        assert!(!aut.accepts(&["open", "read"]));
        assert!(aut.violates(&["open", "open"]));
    }
    /// IFCTracker: high-labeled data must not flow to low sink.
    #[test]
    fn test_ifc_tracker_violation() {
        let mut tracker = IFCTracker::new();
        tracker.assign("password", SecurityLevel::High);
        tracker.assign("user_id", SecurityLevel::Low);
        tracker.propagate("derived", &["password", "user_id"]);
        assert_eq!(tracker.label_of("derived"), SecurityLevel::High);
        tracker.check_flow("derived", &SecurityLevel::Low);
        assert!(tracker.has_violation());
    }
    /// IFCTracker: low-labeled data can flow to high sink.
    #[test]
    fn test_ifc_tracker_ok() {
        let mut tracker = IFCTracker::new();
        tracker.assign("public_id", SecurityLevel::Low);
        tracker.check_flow("public_id", &SecurityLevel::High);
        assert!(!tracker.has_violation());
    }
    /// ConstPropState: basic folding and join.
    #[test]
    fn test_const_prop_state() {
        let mut s1 = ConstPropState::new();
        s1.set_const("x", 10);
        s1.set_const("y", 5);
        assert_eq!(s1.fold_add("x", "y"), Some(15));
        let mut s2 = ConstPropState::new();
        s2.set_const("x", 10);
        s2.set_top("y");
        let joined = s1.join(&s2);
        assert_eq!(joined.get("x"), Some(10));
        assert_eq!(joined.get("y"), None);
    }
    /// PDGraph: backward and forward slicing.
    #[test]
    fn test_pd_graph_slicing() {
        let mut pdg = PDGraph::new(4);
        pdg.add_data_edge(0, 1);
        pdg.add_data_edge(1, 3);
        let bwd = pdg.backward_slice(3);
        assert!(bwd.contains(&3));
        assert!(bwd.contains(&1));
        assert!(bwd.contains(&0));
        assert!(!bwd.contains(&2));
        let fwd = pdg.forward_slice(0);
        assert!(fwd.contains(&0));
        assert!(fwd.contains(&1));
        assert!(fwd.contains(&3));
    }
    /// NullTracker: alarm on dereference of maybe-null variable.
    #[test]
    fn test_null_tracker_alarm() {
        let mut tracker = NullTracker::new();
        tracker.declare_maybe_null("ptr");
        tracker.dereference("ptr");
        assert!(tracker.has_alarm());
    }
    /// NullTracker: no alarm on definitely non-null variable.
    #[test]
    fn test_null_tracker_no_alarm() {
        let mut tracker = NullTracker::new();
        tracker.declare_non_null("safe_ptr");
        tracker.dereference("safe_ptr");
        assert!(!tracker.has_alarm());
    }
    /// NullTracker: join merges states correctly.
    #[test]
    fn test_null_tracker_join() {
        let mut t1 = NullTracker::new();
        t1.declare_non_null("p");
        let mut t2 = NullTracker::new();
        t2.declare_null("p");
        let merged = t1.join(&t2);
        assert_eq!(merged.get("p"), &Nullability::MaybeNull);
    }
}