-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_glass.py
More file actions
3482 lines (3340 loc) · 197 KB
/
Copy pathtest_glass.py
File metadata and controls
3482 lines (3340 loc) · 197 KB
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
"""Regression suite for Glass.
Runs every example and every expected-failure case, prints a summary.
"""
from __future__ import annotations
import subprocess
import sys
import os
# Glass requires Python >= 3.10 (pyproject.toml). On an older interpreter the suite "runs" but
# every quartz (compile) gate dies on a `dict | None` annotation TypeError — 176 cryptic FAILs
# instead of one clear message. Fail fast and loudly instead (macOS /usr/bin/python3 is 3.9).
if sys.version_info < (3, 10):
sys.exit(f"tests/test_glass.py: Python >= 3.10 required (running {sys.version.split()[0]}); "
"try python3.12")
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
GLASS = os.path.join(ROOT, "glass.py")
EX = os.path.join(ROOT, "examples")
def run(src: str) -> tuple[int, str, str]:
p = subprocess.run(
[sys.executable, GLASS, "/dev/stdin"],
input=src, capture_output=True, text=True,
)
return p.returncode, p.stdout, p.stderr
def run_file(path: str) -> tuple[int, str, str]:
p = subprocess.run(
[sys.executable, GLASS, path], capture_output=True, text=True,
)
return p.returncode, p.stdout, p.stderr
# A heavy native `glass prove` gate occasionally HANGS in a resource-starved env — the documented
# under-load native-compile flake (a native subprocess deadlocks at 0% CPU). Without a timeout, the
# suite's subprocess.run would block FOREVER on that one gate, so the whole suite never completes.
# `_prove_run` bounds every prove gate: a hang past PROVE_TIMEOUT becomes a synthetic signal-like
# result (rc=137), which `_heavy_skipped` treats as an env-limited SKIP (CI green) — exactly as it
# already does for a signal-KILLED heavy prove. A genuine regression still returns a verdict in time
# and is evaluated normally; only a true hang is skipped (and logged — no silent cap). Legit heavy
# proves finish in well under a minute, so a multi-minute timeout fires only on a real stall.
PROVE_TIMEOUT = 600
def _prove_run(args, **kw):
kw.setdefault("capture_output", True)
kw.setdefault("text", True)
kw.setdefault("cwd", ROOT)
try:
return subprocess.run(args, timeout=PROVE_TIMEOUT, **kw)
except subprocess.TimeoutExpired:
return subprocess.CompletedProcess(args, 137, stdout="", stderr=f"TIMEOUT >{PROVE_TIMEOUT}s (native prove hung — env-limited)")
# Examples that must succeed.
POSITIVE = [
os.path.join(EX, "basic", "hello.glass"),
os.path.join(EX, "basic", "fib.glass"),
os.path.join(EX, "basic", "list_ops.glass"),
os.path.join(EX, "basic", "option_result.glass"),
os.path.join(EX, "basic", "records.glass"),
os.path.join(EX, "features", "generics.glass"),
os.path.join(EX, "features", "crypto.glass"),
os.path.join(EX, "features", "effects.glass"),
os.path.join(EX, "features", "queries.glass"),
os.path.join(EX, "features", "ai.glass"),
os.path.join(EX, "features", "infer.glass"),
os.path.join(EX, "selfhost", "parser.glass"),
os.path.join(EX, "selfhost", "bootstrap.glass"),
os.path.join(EX, "selfhost", "prism.glass"),
os.path.join(EX, "selfhost", "typecheck.glass"),
os.path.join(EX, "selfhost", "mini.glass"),
os.path.join(EX, "showcase", "derive.glass"),
os.path.join(EX, "showcase", "prover.glass"),
os.path.join(EX, "showcase", "nash.glass"),
os.path.join(EX, "showcase", "quantum.glass"),
os.path.join(EX, "showcase", "golden.glass"),
os.path.join(EX, "showcase", "harmonic.glass"),
os.path.join(EX, "showcase", "geometry.glass"),
os.path.join(EX, "showcase", "fractal.glass"),
os.path.join(EX, "showcase", "spiral.glass"),
os.path.join(EX, "showcase", "symmetry.glass"),
os.path.join(EX, "showcase", "epistemic.glass"),
os.path.join(EX, "showcase", "entanglement.glass"),
os.path.join(EX, "showcase", "amplitude.glass"),
os.path.join(EX, "showcase", "strategy.glass"),
os.path.join(EX, "showcase", "worlds.glass"),
os.path.join(EX, "showcase", "rational.glass"),
os.path.join(EX, "showcase", "probability.glass"),
os.path.join(EX, "showcase", "causal.glass"),
os.path.join(EX, "showcase", "counterfactual.glass"),
os.path.join(EX, "showcase", "identity.glass"),
os.path.join(EX, "showcase", "observer.glass"),
os.path.join(EX, "showcase", "simulation.glass"),
os.path.join(EX, "showcase", "infoflow.glass"),
os.path.join(EX, "showcase", "units.glass"),
os.path.join(EX, "showcase", "conservation.glass"),
os.path.join(EX, "showcase", "linear.glass"),
os.path.join(EX, "features", "linear_ok.glass"),
os.path.join(EX, "showcase", "refined_data.glass"),
os.path.join(EX, "features", "imports.glass"),
os.path.join(EX, "showcase", "refine.glass"),
os.path.join(EX, "showcase", "compose.glass"),
os.path.join(EX, "showcase", "imply.glass"),
os.path.join(EX, "showcase", "regex.glass"),
os.path.join(EX, "showcase", "json.glass"),
os.path.join(EX, "showcase", "config.glass"),
os.path.join(EX, "showcase", "markdown.glass"),
os.path.join(EX, "features", "letstar.glass"),
os.path.join(EX, "features", "letqmark.glass"),
os.path.join(EX, "features", "letpat.glass"),
os.path.join(EX, "features", "generic_fn.glass"),
os.path.join(EX, "features", "generic_rec.glass"),
os.path.join(EX, "features", "refine.glass"),
os.path.join(EX, "features", "alpha_refine.glass"),
os.path.join(EX, "features", "imply_refine.glass"),
os.path.join(EX, "features", "runtime_refine.glass"),
os.path.join(EX, "features", "curried_refine.glass"),
os.path.join(EX, "features", "return_refine.glass"),
os.path.join(EX, "features", "safe_div.glass"),
os.path.join(EX, "features", "parens_after_let.glass"),
os.path.join(EX, "features", "lambda_refine.glass"),
os.path.join(EX, "features", "lambda_multi.glass"),
os.path.join(EX, "features", "lambda_multi_refine.glass"),
os.path.join(EX, "features", "and_or.glass"),
os.path.join(EX, "features", "mod_refine.glass"),
os.path.join(EX, "features", "not_refine.glass"),
os.path.join(EX, "features", "xparam_refine.glass"),
os.path.join(EX, "selfhost", "prism_lexer.glass"),
os.path.join(EX, "selfhost", "quartz_min.glass"),
os.path.join(EX, "selfhost", "build_pipeline.glass"),
os.path.join(EX, "selfhost", "quartz_parser.glass"),
os.path.join(EX, "selfhost", "selfcompile.glass"),
os.path.join(EX, "stage3", "tinylang.glass"),
os.path.join(EX, "stage3", "tinycalc.glass"),
os.path.join(EX, "stage3", "midlang.glass"),
os.path.join(EX, "stage3", "safecalc.glass"),
]
# (label, source, expected substring in stderr) — must fail with the right reason.
NEGATIVE = [
# ---- v0.0.1 cases ----
# ---- Tzimtzum: a concealed value can never escape to an observable position ----
("conceal cannot be revealed by arithmetic",
'conceal(5) + 1',
"Concealed"),
("conceal is opaque — no constructor, cannot be pattern-matched open",
'match conceal(5) { Conceal(x) => x }',
"unknown constructor"),
("fn return mismatch",
'fn f(n: Int) : Int = "no"',
"declared return Int, body is String"),
("heterogeneous list",
'let xs : List<Int> = [1, 2, "three"]',
"list elements differ"),
("bare spread outside list points to ++",
'let x : Int = 1\n'
'let y : List<Int> = ...x',
"use '++'"),
("if branches differ",
'let x : Int = if true then 1 else "x"',
"if branches differ"),
("polymorphic builtin mismatch",
'let xs : List<String> = ["a"]\n'
'fn d(n: Int) : Int = n\n'
'let bad : List<Int> = map(xs, d)',
"arg type mismatch"),
("unbound identifier",
'let x : Int = nope',
"unbound identifier"),
("arity mismatch",
'fn f(a: Int, b: Int) : Int = a + b\n'
'let r : Int = f(1)',
"arity mismatch"),
# ---- v0.1 sum-type cases ----
("non-exhaustive match on Option",
'fn f(o: Option<Int>) : Int = match o { Some(x) => x }',
"non-exhaustive match on Option"),
("non-exhaustive match on Bool",
'fn f(b: Bool) : Int = match b { true => 1 }',
"non-exhaustive match"),
("non-exhaustive match on List",
'fn f(xs: List<Int>) : Int = match xs { [] => 0 }',
"non-exhaustive match on list"),
# Nested-pattern exhaustiveness: a refutable SUB-pattern leaves cases
# uncovered even when the outer shape looks total. These used to type-check
# and then crash at runtime ("non-exhaustive match" RuntimeError).
("non-exhaustive: refutable list head",
'fn f(xs: List<Int>) : Int = match xs { [] => 0; [1, ...t] => 9 }',
"non-exhaustive match on list"),
("non-exhaustive: fixed-length list misses longer",
'fn f(xs: List<Int>) : Int = match xs { [] => 0; [a, b] => a + b }',
"non-exhaustive match on list"),
("non-exhaustive: refutable tuple component",
'fn f(p: (Int, Int)) : Int = match p { (1, b) => b }',
"non-exhaustive match on tuple"),
("non-exhaustive: refutable constructor argument",
'type Box = Empty | Hold(Int)\n'
'fn f(b: Box) : Int = match b { Empty => 0; Hold(1) => 9 }',
"non-exhaustive match on Box"),
("ctor from wrong type",
'fn f(o: Option<Int>) : Int = match o { Ok(x) => x ; None => 0 }',
"Ok is from Result, but scrutinee is Option"),
("type-arity mismatch on annotation",
'let bad : Option<Int, String> = None',
"expects 1 arg"),
("unknown type in annotation",
'let bad : Frobnicate<Int> = None',
"unknown type"),
("ctor expects more fields",
'let bad : Option<Int> = Some',
# Some has no args here — it's the bare ctor as a value, which has fn type;
# the annotation expects Option<Int>, not (Int) -> Option<Int>.
"declared Option<Int>"),
# ---- v0.2 cases ----
("head returns Option, not raw",
'let xs : List<Int> = [1, 2, 3]\n'
'let bad : Int = head(xs)',
"declared Int, inferred Option<Int>"),
("Pair from prelude — type-arity check",
'let bad : Pair<Int> = Pair(1, 2)',
"expects 2 arg"),
("can't mix env types in Pair list",
'let bad : List<Pair<String, Int>> = [Pair("a", 1), Pair("b", "wrong")]',
"list elements differ"),
# ---- v0.3 polymorphism soundness cases ----
("can't treat type param as Int inside body",
'fn bad<A>(x: A) : A = let y : A = 42 in y',
"let-in y: declared A, inferred Int"),
("can't return Int as type param A",
'fn bad<A>(x: A) : A = 42',
"declared return A, body is Int"),
("calling polymorphic fn with mismatched types",
'fn id<T>(x: T) : T = x\n'
'fn use_it(s: String) : Int = id(s)',
"declared return Int"),
("type-arity on user-defined polymorphic fn",
'fn id<T>(x: T) : T = x\n'
'let bad : Int = id(1, 2)',
"arity mismatch"),
# ---- v0.4 refinement-type cases ----
# v1.2: refinements with constant args are discharged statically.
("refinement violated at compile time (literal arg)",
'fn d(a: Int, b: Int where (b != 0)) : Int = a / b\n'
'let r : Int = d(10, 0)',
"refinement violated at compile time"),
# Runtime check still applies for non-constant arguments.
("refinement violated at runtime (dynamic arg)",
'fn d(a: Int, b: Int where (b != 0)) : Int = a / b\n'
'fn ident(n: Int) : Int = n\n'
'let zero = ident(0)\n'
'let r : Int = d(10, zero)',
"refinement violated: b = 0"),
# v4.24: curried multi-param case where the refinement is on the
# SECOND param and the arg is a let-bound variable (not a literal).
# Pinned down as a host-parity spec — prism's port mirrors this
# error shape via its v4.24 VRefinedClos wrapper.
("refinement violated on second param at runtime (v4.24 host parity)",
"fn safe_add(a: Int, b: Int where (b != 0)) : Int = a + b\n"
"let zero : Int = 0\n"
"let r : Int = safe_add(10, zero)",
"refinement violated: b = 0"),
# v4.25: return-type refinement violation. Host check has been in
# place since v1.3; prism's port mirrors this shape — the
# VRefinedClos wrapper carries the return type forward across
# curried applies and checks against the final value on the last
# apply.
("return refinement violated (multi-param, v4.25 host parity)",
"fn diff(a: Int, b: Int) : Int where (result >= 0) = a - b\n"
"let smaller : Int = 3\n"
"let bigger : Int = 7\n"
"let r : Int = diff(smaller, bigger)",
"refinement violated: result = -4"),
# Static discharge through arithmetic constant-folding.
("static discharge via subtraction fold",
'fn f(n: Int where (n > 0)) : Int = n\n'
'let r : Int = f(5 - 7)',
"refinement violated at compile time"),
# Static discharge through if-then-else folding.
("static discharge via if-fold",
'fn f(n: Int where (n > 0)) : Int = n\n'
'let r : Int = f(if true then 0 else 10)',
"refinement violated at compile time"),
# Return-type refinement violation at runtime (v1.3).
("return refinement violated at runtime",
'fn negate(n: Int) : Int where (result >= 0) = 0 - n\n'
'let r : Int = negate(5)',
"refinement violated: result = -5 fails predicate"),
# v1.4: implication discharges (result >= 5) does NOT imply (n > 5),
# so the runtime check fires when at_least_five returns exactly 5.
("implication unsound: >= 5 should not imply > 5",
'fn at_least_five(n: Int) : Int where (result >= 5) =\n'
' if n >= 5 then n else 5\n'
'fn needs_above_five(n: Int where (n > 5)) : Int = n\n'
'let r : Int = needs_above_five(at_least_five(0))',
"refinement violated: n = 5 fails predicate (n > 5)"),
("refinement predicate must be Bool",
'fn d(b: Int where (b + 1)) : Int = b',
"must return Bool"),
("refinement predicate references unbound name",
'fn d(b: Int where (q > 0)) : Int = b',
"unbound identifier"),
("let refinement violated",
'let x : Int where (x > 100) = 5',
"refinement violated: x = 5"),
# ---- v0.5 effect-tracking cases ----
("pure fn performing IO without declaring",
'fn loud() : Int = let _ : String = print("oops") in 42',
"fn loud performs effect(s) ['IO']"),
("fn declaring only IO but doing Random",
'fn r() : Int !{IO} = random_int(0, 10)',
"performs effect(s) ['Random']"),
("fn declaring only Random but doing IO",
'fn s() : Int !{Random} = let _ : String = print("hi") in 0',
"performs effect(s) ['IO']"),
# ---- v0.7 effect polymorphism + Inference ----
("pure fn can't use map with effectful callback (caller must declare effects)",
'fn loud(n: Int) : Int !{IO} =\n'
' let _ : String = print("x") in n\n'
'fn pure_run() : List<Int> = map([1, 2], loud)',
"performs effect(s) ['IO']"),
("undeclared !{Inference} is caught",
'fn sneaky(s: String) : String = model_call("x: " ++ s)',
"performs effect(s) ['Inference']"),
("fn declaring IO but body also does Inference is caught",
'fn mixed(s: String) : String !{IO} =\n'
' let _ : String = print("doing it") in\n'
' model_call(s)',
"performs effect(s) ['Inference']"),
# A body that propagates TWO distinct abstract effect rows but declares
# only one used to be accepted (extend_effects dropped the 2nd row var),
# which let a fn that performs the 2nd effect be certified without it —
# a soundness hole. The dropped row must now surface as undeclared.
("fn propagating a 2nd abstract effect row can't hide it under a 1-var decl",
'fn twice<E, F>(p: () -> Int !{E}, q: () -> Int !{F}) : Int !{E} = p() + q()',
"not declared in {E}"),
# ---- v0.6 tuple cases ----
("tuple-arity mismatch in pattern",
'let p : (Int, String) = (1, "x")\n'
'fn f(p: (Int, String)) : Int = match p { (a, b, c) => a }',
"tuple pattern arity mismatch"),
("tuple type-arity mismatch",
'let p : (Int, String) = (1, 2)',
"declared (Int, String), inferred (Int, Int)"),
("non-tuple destructured with tuple pattern",
'fn f(n: Int) : Int = match n { (a, b) => a }',
"tuple pattern against Int"),
# Mutual recursion success: this would have failed before v0.6.
# Tested via examples/queries.glass (bump <-> count_by_country) and
# by being able to declare fns in source-independent order.
# ---- v0.7 effect polymorphism + Inference ----
("pure fn can't use polymorphic map with Inference callback",
'fn pure_batch(xs: List<String>) : List<String> =\n'
' map(xs, fn(s: String) -> model_call(s))',
"performs effect(s) ['Inference']"),
("fn declaring only IO can't call a model",
'fn io_only(s: String) : String !{IO} = model_call(s)',
"performs effect(s) ['Inference']"),
("refinement violation on model output",
'fn must_be_long(s: String) : String !{Inference} =\n'
' let r : String where (string_length(r) >= 1000) = model_call(s) in r\n'
'let _ : String = must_be_long("hi")',
"refinement violated"),
# ---- v0.8 record cases ----
("record missing field",
'type U = { id: Int, name: String }\n'
'let u : U = U { id: 1 }',
"missing field"),
("record extra field",
'type U = { id: Int }\n'
'let u : U = U { id: 1, extra: 5 }',
"has no field"),
("record wrong field type",
'type U = { id: Int, name: String }\n'
'let u : U = U { id: "wrong", name: "Alice" }',
"expected Int"),
("field access on non-record",
'let n : Int = 5\n'
'let x : Int = n.foo',
"field access on non-record"),
("field access on unknown field",
'type U = { id: Int }\n'
'let u : U = U { id: 1 }\n'
'let x : Int = u.bogus',
"no field 'bogus'"),
("sum type used as record literal",
'type Maybe = | Nope | Yep(Int)\n'
'let m : Maybe = Maybe { Nope: 1 }',
"use Maybe(...) for constructor call"),
# ---- v0.8.1 string-ops cases ----
("substring with negative index",
'let s : String = substring("hello", -1, 3)',
"negative index"),
("substring with start > end",
'let s : String = substring("hello", 4, 2)',
"start > end"),
# ---- v4.47: refined-param lambda rejection ----
# The lambda's `where (x > 0)` runs at apply time. `let n = 0 - 3`
# produces a non-literal so static discharge defers; the runtime
# check then fires on n = -3 and the predicate fails.
("refined-param lambda rejects bad arg (v4.47)",
"let n : Int = 0 - 3\n"
"let r : Int = (fn(x: Int where (x > 0)) -> x * 2)(n)\n"
"r\n",
"refinement violated"),
# ---- v4.48: refined SECOND param of a multi-arg lambda ----
# First arg satisfies its refinement; the second fails. Pins
# down that the per-param TyRefine check runs at each position,
# not just the first.
("multi-arg refined lambda rejects 2nd arg (v4.48)",
"let n : Int = 0\n"
"let r : Int = (fn(a: Int where (a > 0), b: Int where (b > 0))"
" -> a * b)(3, n)\n"
"r\n",
"b = 0 fails predicate"),
# ---- v4.51: && / || type-checked as Bool, Bool → Bool ----
# Non-Bool operands must be rejected with a clear shape error.
("&& rejects non-Bool operands (v4.51)",
"let r : Bool = 1 && true\n",
"expected Bool, Bool"),
# ---- v4.53: % type-checked as Int, Int → Int ----
("% rejects non-Int operands (v4.53)",
"let r : Int = true % 2\n",
"expected Int, Int"),
# ---- v4.54: ! requires a Bool operand ----
("! rejects non-Bool operand (v4.54)",
"let r : Bool = !5\n",
"expected Bool"),
# ---- v4.56: cross-parameter refinement rejects bad input ----
# hi=3, lo=10 → hi > lo is false. The check sees lo (earlier
# param) and fires.
("cross-param refinement rejects bad input (v4.56)",
"fn clamp(lo: Int, hi: Int where (hi > lo)) : Int = hi - lo\n"
"let bad : Int = clamp(10, 3)\n"
"bad\n",
"refinement violated"),
# ---- v4.66: conservation-law refinement rejects minting ----
# The gate `after == before` (cross-param) fails when a transition
# creates value (175 → 200), so non-conservative transitions are
# rejected at the boundary.
("conservation refinement rejects minting (v4.66)",
"fn checked(before: Int, after: Int where (after == before)) : Int"
" = after\n"
"let bad : Int = checked(175, 200)\n"
"bad\n",
"refinement violated"),
# ---- v4.67: linear types — no cloning, no dropping ----
# Using a linear resource twice is forbidden (no cloning).
("linear resource rejects cloning (v4.67)",
"fn f() : Int = let lin x = 5 in x + x\n"
"f()\n",
"no cloning"),
# Dropping a linear resource (never using it) is forbidden.
("linear resource rejects dropping (v4.67)",
"fn f() : Int = let lin x = 5 in 99\n"
"f()\n",
"no dropping"),
# Capturing a linear value in a closure can't guarantee single use.
("linear resource rejects lambda capture (v4.67)",
"fn f() : Int = let lin x = 5 in (fn(y: Int) -> x + y)(3)\n"
"f()\n",
"captured in a lambda"),
# ---- v4.69: field-level refinements rejected at construction ----
# A negative value can't be packed into a Pos.
("refined ADT field rejects bad value (v4.69)",
"type Pos = | Pos(n: Int where (n > 0))\n"
"let bad = Pos(0 - 3)\n"
"bad\n",
"n = -3 fails predicate"),
# Cross-field: hi must exceed lo; Range(10, 3) is rejected.
("cross-field refinement rejects bad range (v4.69)",
"type Range = | Range(lo: Int, hi: Int where (hi > lo))\n"
"let bad = Range(10, 3)\n"
"bad\n",
"hi = 3 fails predicate"),
]
def main() -> int:
failures = 0
print("== positive cases ==")
for path in POSITIVE:
rc, out, err = run_file(path)
ok = (rc == 0)
print(f" {'OK ' if ok else 'FAIL'} {os.path.basename(path)}")
if not ok:
print(f" stderr: {err.strip()}")
failures += 1
print("== negative cases (must reject) ==")
for label, src, needle in NEGATIVE:
rc, out, err = run(src)
ok = (rc != 0) and (needle in err)
print(f" {'OK ' if ok else 'FAIL'} {label}")
if not ok:
print(f" rc={rc}, expected substring {needle!r}")
print(f" stderr: {err.strip()}")
failures += 1
print("== inline regression cases ==")
# (label, source, expected substring in stdout). Short programs that
# pin down specific past bugs. Add a case when fixing a real bug.
inline_positive = [
# Tzimtzum: conceal a value, compute within concealment (cmap), prove a property
# about it (concealed_in_range -> a PUBLIC Bool) — all without ever revealing it.
("Concealed<T>: provable-about, computable-within, never revealed",
"fn add5(x: Int) : Int = x + 5\n"
"let c : Concealed<Int> = cmap(conceal(20), add5)\n"
"let ok : Bool = concealed_in_range(c, 24, 26)\n"
"ok\n",
"ok : Bool = true"),
# Exhaustiveness must recognise coverage spread ACROSS arms via nested
# patterns: the two Ok(...) arms together cover all of Box, so this is
# total and must NOT be rejected (guards the recursive checker against
# the over-strict per-arm version).
("nested cross-arm exhaustiveness accepted",
"type Box = Empty | Hold(Int)\n"
"fn f(r: Result<Box, String>) : Int =\n"
" match r { Ok(Hold(x)) => x; Ok(Empty) => 0; Err(m) => 0 - 1 }\n"
"let out : Int = f(Ok(Hold(7)))\n"
"out\n",
"out : Int = 7"),
# Interpreter integer arithmetic matches the compiled int64/C backend
# (see eval_binop): / and % truncate toward zero (not Python floor),
# + - * wrap at 64 bits, and a shift count is masked to 6 bits. Pins
# the host side of the host<->compiled agreement on the exact inputs
# where they used to diverge.
("neg division truncates toward zero", "let r : Int = (0 - 7) / 2\nr\n", "r : Int = -3"),
("neg modulo has dividend sign", "let r : Int = (0 - 7) % 2\nr\n", "r : Int = -1"),
("int64 overflow wraps (+)", "let r : Int = 9223372036854775807 + 1\nr\n", "r : Int = -9223372036854775808"),
("shift count masked to 6 bits", "let r : Int = bit_shl(1, 64)\nr\n", "r : Int = 1"),
# v4.21: parser used to greedily eat an LPAREN-starting next line as
# call-continuation. `let s = id("hello")\n(n, s)` mis-parsed to
# `id("hello")(n, s)` and crashed with "not a function: String".
# The column-1 + new-line rule in parse_postfix stops it.
("parens-after-let split (v4.21)",
'fn id<A>(x: A) : A = x\n'
'let n = id(42)\n'
'let s = id("hello")\n'
'let p = (n, s)\n'
'p\n',
"(42, hello)"),
# v4.28: deep tail recursion. Without the trampoline-based TCE
# added in v4.28, count_down(15000) blows Python's recursion
# limit even with sys.setrecursionlimit(20000). The test verifies
# both correctness and unbounded-depth tolerance. We use 25000 to
# exceed any reasonable Python limit so the test FAILS if TCE is
# ever accidentally removed.
("deep tail recursion via TCE (v4.28)",
"fn count_down(n: Int) : Int =\n"
" if n == 0 then 0 else count_down(n - 1)\n"
"let result : Int = count_down(25000)\n"
"result\n",
"result : Int = 0"),
# v4.28: tail-recursive sum_to with explicit accumulator. The
# arithmetic check pins down the *value* — confirms that env
# bindings (acc) flow correctly through the trampoline.
("tail-recursive accumulator via TCE (v4.28)",
"fn sum_to(n: Int, acc: Int) : Int =\n"
" if n == 0 then acc else sum_to(n - 1, acc + n)\n"
"let result : Int = sum_to(50000, 0)\n"
"result\n",
"result : Int = 1250025000"),
# v4.23: prism runtime refinement check fires when static discharge
# defers. The host already enforces runtime checks (since v0.4); this
# test runs the same program through host to pin down the shape of the
# error message that prism's port mirrors. The prism-side check is
# exercised end-to-end when prism.glass runs in the POSITIVE list —
# its demo chain reads runtime_refine_bad.glass and prints the same
# message, which surfaces in prism's stdout (not its exit code).
("runtime refinement check (v4.23 host parity)",
"fn positive_double(n: Int where (n > 0)) : Int = n * 2\n"
"let x : Int = 21\n"
"let r : Int = positive_double(x)\n"
"r\n",
"r : Int = 42"),
# v4.21 drift catch: AGENT.md §5 claimed sequential top-level lets
# using the same generic fn at different types fail to type-check.
# They don't — the symptom in §5's repro was the parens-after-let
# parser bug above. Pin both invariants down with a test.
("sequential generic-fn instantiation (v4.21)",
'fn id<A>(x: A) : A = x\n'
'let n = id(42)\n'
'let s = id("hello")\n'
'let b = id(true)\n'
'b\n',
": Bool = true"),
# v4.47: refined-param lambdas. Before v4.47 the host's
# parse_lambda called parse_params without accept_refinement,
# so `fn(x: Int where (x > 0)) -> ...` failed at the `where`
# token. Now the parser accepts the refinement and the
# existing apply_fn TyRefine path checks the predicate at
# call time. Positive case: 5 > 0 holds, body returns 10.
("refined-param lambda accepts (v4.47)",
"let r : Int = (fn(x: Int where (x > 0)) -> x * 2)(5)\n"
"r\n",
"r : Int = 10"),
# v4.47 capture-aware variant: the lambda closes over `k`
# AND has a refined param. Confirms ELamR (prism) / refined
# Lambda (host) interoperates with closures, not just bare
# arithmetic — refinement check runs before capture lookup.
("refined-param lambda with capture (v4.47)",
"let k : Int = 100\n"
"let r : Int = (fn(x: Int where (x > 0)) -> x + k)(7)\n"
"r\n",
"r : Int = 107"),
# v4.48: multi-param lambdas. Three-arg variant pins down
# that the right-fold builds the chain correctly across more
# than two params (a common edge of "did I get the
# recursion-base-case right?").
("three-arg lambda applied inline (v4.48)",
"let r : Int = (fn(a: Int, b: Int, c: Int) -> a + b + c)(1, 2, 3)\n"
"r\n",
"r : Int = 6"),
# v4.51: `&&` and `||` lex, parse, typecheck, evaluate. The
# bigger language win for v4.51 is that boolean combinators
# become legal in refinement predicates — pinning down basic
# eval here means the predicate machinery has solid ground.
("&& and || basic truth tables (v4.51)",
"let a : Bool = true && false\n"
"let b : Bool = true || false\n"
"let c : Bool = (3 > 0) && (3 < 100)\n"
"let r : Bool = (a == false) && b && c\n"
"r\n",
"r : Bool = true"),
# v4.51 precedence pin-down: `&&` binds tighter than `||`.
# `false || true && false` must parse as
# `false || (true && false)` = `false || false` = false.
# If precedence were inverted it would be
# `(false || true) && false` = `true && false` = false (same
# answer by luck) — so we need a discriminating case:
# `true && false || true` parses as `(true && false) || true`
# = `false || true` = true. Flipped would be
# `true && (false || true)` = `true && true` = true (same).
# The actually discriminating shape:
("&& binds tighter than || (v4.51)",
"let r : Bool = false || true && false\n"
"r\n",
"r : Bool = false"),
# v4.51 range refinement at runtime. `n > 0 && n < 100` is
# the canonical interval refinement; before this release a
# single-comparison was the only valid shape.
("range refinement via && (v4.51)",
"fn middling(n: Int where (n > 0 && n < 100)) : Int = n + 1\n"
"let r : Int = middling(50)\n"
"r\n",
"r : Int = 51"),
# v4.51 short-circuit semantics: the rhs of `&&` is NOT
# evaluated when lhs is false. We probe this by putting an
# expression that WOULD raise (refinement violation) on the
# rhs, then verify the program completes successfully.
("&& short-circuits on false lhs (v4.51)",
"fn pos(n: Int where (n > 0)) : Int = n\n"
"let n : Int = 0\n"
"let r : Bool = (n > 0) && (pos(n) > 0)\n"
"r\n",
"r : Bool = false"),
# v4.53: modulo as a basic arithmetic operator. Same precedence
# as `*` and `/`, so `1 + 17 % 5` parses as `1 + (17 % 5) = 3`.
("basic modulo + precedence (v4.53)",
"let r : Int = 1 + 17 % 5\n"
"r\n",
"r : Int = 3"),
# v4.53: parity refinement. The canonical use of `%` in
# predicate position — `n % 2 == 0` enforces evenness.
("parity refinement holds (v4.53)",
"fn even_only(n: Int where (n % 2 == 0)) : Int = n + 1\n"
"let r : Int = even_only(10)\n"
"r\n",
"r : Int = 11"),
# v4.54: unary NOT. Basic truth + double-negation + applied to
# a comparison. `!(3 > 5)` is true.
("unary NOT basics (v4.54)",
"let a : Bool = !true\n"
"let b : Bool = !!false\n"
"let r : Bool = (a == false) && (b == false) && !(3 > 5)\n"
"r\n",
"r : Bool = true"),
# v4.54: NOT in a refinement predicate. `!(n == 0)` is the
# "anything but zero" guard; 5 satisfies it so 100/5 = 20.
("NOT refinement holds (v4.54)",
"fn nonzero(n: Int where (!(n == 0))) : Int = 100 / n\n"
"let r : Int = nonzero(5)\n"
"r\n",
"r : Int = 20"),
# v4.55: arithmetic inside a refinement predicate. The host
# always handled this (full eval); v4.55 brings Quartz to
# parity. Pinned here so host + Quartz agree on the shape.
("arithmetic in refinement predicate (v4.55)",
"fn f(n: Int where (n * n >= 1 && n + 1 > 0)) : Int = n\n"
"let r : Int = f(7)\n"
"r\n",
"r : Int = 7"),
# v4.56: cross-parameter refinement in the host. `hi > lo`
# references the earlier param; host binds-and-checks in order
# so `lo` is bound when `hi`'s check runs. clamp(3,10) = 7.
("cross-parameter refinement holds (v4.56)",
"fn clamp(lo: Int, hi: Int where (hi > lo)) : Int = hi - lo\n"
"let r : Int = clamp(3, 10)\n"
"r\n",
"r : Int = 7"),
# v4.48 composes with v4.47: two-arg lambda where BOTH params
# are refined. The host's apply_fn checks each TyRefine at
# call time; prism's port mirrors via two stacked VRefinedClos
# wrappers. 3 > 0 and 4 > 0 hold, body returns 12.
("two-arg refined lambda (v4.48)",
"let r : Int = (fn(a: Int where (a > 0), b: Int where (b > 0))"
" -> a * b)(3, 4)\n"
"r\n",
"r : Int = 12"),
# v4.57: quantum-inspired measurement (showcase/quantum.glass).
# Weighted collapse via cumulative buckets + `seed % total`.
# Over seeds 0..99 a 9:1 superposition collapses to |0> exactly
# 90 times — measurement frequency tracks the weights, and the
# whole thing is pure (seed threaded explicitly).
("quantum measurement tracks weights (v4.57)",
"type Amp = | Amp(String, Int)\n"
"fn tw(xs: List<Amp>) : Int =\n"
" fold(xs, 0, fn(a: Int, x: Amp) -> match x { Amp(_, w) => a + w })\n"
"fn pick(xs: List<Amp>, r: Int) : String =\n"
" match xs { [] => \"_\";"
" [Amp(l, w), ...rest] => if r < w then l else pick(rest, r - w) }\n"
"fn measure(xs: List<Amp>, seed: Int where (seed >= 0)) : String =\n"
" pick(xs, seed % tw(xs))\n"
"let bias = [Amp(\"|0>\", 9), Amp(\"|1>\", 1)]\n"
"let hits : Int =\n"
" fold(range(0, 100), 0, fn(a: Int, s: Int) ->\n"
" if measure(bias, s) == \"|0>\" then a + 1 else a)\n"
"hits\n",
"hits : Int = 90"),
# v4.58 (Proportion & Form bundle): the golden fingerprint.
# |a² − a·b − b²| = 1 holds EXACTLY for consecutive Fibonacci
# pairs — here (34, 21) gives residue +1, the φ convergent test.
("golden-ratio residue is +1 for Fibonacci pair (v4.58)",
"fn residue(a: Int, b: Int) : Int = a * a - a * b - b * b\n"
"let r : Int = residue(34, 21)\n"
"r\n",
"r : Int = 1"),
# v4.58: Euler's formula as the polyhedron refinement. The
# cross-param gate accepts the dodecahedron (20−30+12 = 2) and
# the body returns V+E+F.
("Euler polyhedron gate accepts dodecahedron (v4.58)",
"fn make_poly(v: Int, e: Int, f: Int where (v - e + f == 2)) : Int"
" = v + e + f\n"
"let r : Int = make_poly(20, 30, 12)\n"
"r\n",
"r : Int = 62"),
# v4.58: harmonic consonance via gcd-reduction. 6:4 reduces to
# 3:2 (perfect fifth) — reduced denominator 2 <= 4, consonant.
("harmonic ratio reduces to perfect fifth (v4.58)",
"fn gcd(a: Int, b: Int) : Int = if b == 0 then a else gcd(b, a % b)\n"
"let rd : Int = 4 / gcd(6, 4)\n"
"rd\n",
"rd : Int = 2"),
# v4.59 (Self-Similarity & Spirals): the fractal self-similarity
# gate. Sierpinski triples each depth, so 27 is a valid successor
# of 9 under branch 3 (cross-param refinement next == prev * 3).
("fractal self-similarity gate (v4.59)",
"fn next_level(prev: Int, branch: Int,"
" next: Int where (next == prev * branch)) : Int = next\n"
"let r : Int = next_level(9, 3, 27)\n"
"r\n",
"r : Int = 27"),
# v4.59: the golden-spiral peel is exact in Int —
# F(n+1) − F(n) = F(n-1). For F(6)=8, F(5)=5: 8 − 5 = 3 = F(4).
# The Σ-Fibonacci identity F(1)+…+F(n) = F(n+2) − 1 gives 20 at
# n=6, pinned via the closed form.
("golden spiral Fibonacci-sum identity (v4.59)",
"fn fib(n: Int) : Int = if n < 2 then n else fib(n - 1) + fib(n - 2)\n"
"let r : Int = fib(8) - 1\n" # F(8)-1 = 21-1 = 20 = sum F(1..6)
"r\n",
"r : Int = 20"),
# v4.60 (Epistemic-games + symmetry): D₄ is non-abelian — the
# dihedral group law makes r1·s0 ≠ s0·r1. Composing a quarter
# turn with a reflection in each order gives different elements
# (s3 vs s1 in our encoding), so their rotation indices differ.
("D4 group is non-abelian (v4.60)",
"fn mod4(n: Int) : Int = ((n % 4) + 4) % 4\n"
"fn compose_k(k1: Int, f1: Bool, k2: Int, f2: Bool) : Int =\n"
" mod4((if f2 then 0 - k1 else k1) + k2)\n"
"let rs : Int = compose_k(1, false, 0, true)\n" # r1 then s0
"let sr : Int = compose_k(0, true, 1, false)\n" # s0 then r1
"let r : Bool = rs != sr\n"
"r\n",
"r : Bool = true"),
# v4.60: epistemic knowledge — a child KNOWS their own state iff
# all indistinguishable live worlds agree on it. In the muddy
# world (M,M) with only {(M,M)} live, the single world fixes the
# value, so the child knows (returns the mud value 1).
("epistemic: knowledge from a singleton world set (v4.60)",
"type World = | W(Int, Int)\n"
"fn mud(c: Int, w: World) : Int ="
" match w { W(a, b) => if c == 1 then a else b }\n"
"fn knows(c: Int, w: World, live: List<World>) : Bool =\n"
" fold(live, true, fn(acc: Bool, x: World) ->"
" acc && mud(c, x) == mud(c, w))\n"
"let r : Bool = knows(1, W(1, 1), [W(1, 1)])\n"
"r\n",
"r : Bool = true"),
# v4.61 (Quantum II): destructive interference. Two paths with
# opposite-phase amplitudes (+1 and −1) sum to amplitude 0, so
# the quantum probability |Σ aₖ|² = 0 — the outcome is
# impossible despite each path being individually possible. The
# classical sum Σ|aₖ|² would be 2. This is the dark fringe.
("destructive interference cancels (v4.61)",
"type Cx = | Cx(Int, Int)\n"
"fn cadd(a: Cx, b: Cx) : Cx ="
" match a { Cx(ar, ai) => match b { Cx(br, bi) =>"
" Cx(ar + br, ai + bi) } }\n"
"fn norm2(z: Cx) : Int = match z { Cx(re, im) => re * re + im * im }\n"
"fn qprob(ps: List<Cx>) : Int ="
" norm2(fold(ps, Cx(0, 0), fn(a: Cx, p: Cx) -> cadd(a, p)))\n"
"let r : Int = qprob([Cx(1, 0), Cx(0 - 1, 0)])\n"
"r\n",
"r : Int = 0"),
# v4.61: entanglement — in the Bell state |00>+|11> (weights
# 1,0,0,1), measuring q1=0 leaves only the 00 branch, so q2 is
# determined to 0 (the conditional weight for q2=1 is zero).
("entanglement pins the partner qubit (v4.61)",
"type Joint = | Joint(Int, Int, Int, Int)\n"
"fn cond01(j: Joint) : Int =" # q2=1 weight given q1=0
" match j { Joint(w00, w01, w10, w11) => w01 }\n"
"let bell = Joint(1, 0, 0, 1)\n"
"let r : Int = cond01(bell)\n" # 0 ⇒ q2=1 impossible ⇒ q2 pinned to 0
"r\n",
"r : Int = 0"),
# v4.62 (Strategy & Worlds): the Prisoner's Dilemma tragedy —
# (Cooperate,Cooperate)=(3,3) Pareto-dominates the forced
# equilibrium (Defect,Defect)=(1,1): both better off, yet
# dominance forces the worse outcome.
("Prisoner's Dilemma: equilibrium is Pareto-dominated (v4.62)",
"fn pareto_dom(a1: Int, a2: Int, b1: Int, b2: Int) : Bool =\n"
" a1 >= b1 && a2 >= b2 && (a1 > b1 || a2 > b2)\n"
"let r : Bool = pareto_dom(3, 3, 1, 1)\n"
"r\n",
"r : Bool = true"),
# v4.62: multi-world branching. Three coin flips multiply into
# 2³ = 8 worlds (the list-monad bind unions every branch); the
# head-counts form the binomial row 1,3,3,1.
("multi-world branching: 3 flips = 8 worlds (v4.62)",
"type World = | World(List<Int>)\n"
"fn wof(w: World) : List<Int> = match w { World(xs) => xs }\n"
"fn pure(x: Int) : World = World([x])\n"
"fn wbind(w: World, f: (Int) -> World) : World =\n"
" World(fold(wof(w), [], fn(acc: List<Int>, x: Int) ->"
" acc ++ wof(f(x))))\n"
"let flip = World([0, 1])\n"
"let three = wbind(flip, fn(a: Int) ->"
" wbind(flip, fn(b: Int) -> wbind(flip, fn(c: Int) ->"
" pure(a + b + c))))\n"
"let r : Int = len(wof(three))\n"
"r\n",
"r : Int = 8"),
# v4.63 (Rationals & Probability): exact fraction arithmetic.
# 1/3 + 1/6 reduces to exactly 1/2 — no rounding. The result is
# gcd-normalized, so num=1, den=2; we pin the numerator.
("exact rational 1/3 + 1/6 = 1/2 (v4.63)",
"type Rat = | Rat(Int, Int)\n"
"fn gcd(a: Int, b: Int) : Int = if b == 0 then a else gcd(b, a % b)\n"
"fn rat(n: Int, d: Int) : Int = n / gcd(n, d)\n" # numerator of reduced n/d
"let total : Int = 1 * 6 + 1 * 3\n" # 1/3 + 1/6 = (6+3)/18 = 9/18
"let r : Int = rat(total, 18)\n" # 9/18 → numerator 1
"r\n",
"r : Int = 1"),
# v4.63: Gini/collision uncertainty is exact and rational. For a
# fair coin [1/2,1/2]: 1 − (1/4 + 1/4) = 1/2. We compute it over
# a common denominator (4): numerator of 1 − 2/4 = 2, over 4.
("Gini uncertainty of fair coin = 1/2 (v4.63)",
"let sum_sq_num : Int = 1 + 1\n" # (1/2)²+(1/2)² = 1/4+1/4 = 2/4
"let u_num : Int = 4 - sum_sq_num\n" # 1 − 2/4 = (4-2)/4 = 2/4 = 1/2
"u_num\n",
"u_num : Int = 2"),
# v4.64 (Time & Causality): the do-operator. Intervening
# do(rain := false) recomputes wet = rain ∨ sprinkler from the
# structural equation — with sprinkler off, the grass is dry.
# This is intervention, not observation: the equation re-runs.
("counterfactual intervention dries the grass (v4.64)",
"fn wet(rain: Bool, sprinkler: Bool) : Bool = rain || sprinkler\n"
"let actual : Bool = wet(true, false)\n" # actually wet
"let cf : Bool = wet(false, false)\n" # do(rain:=false)
"let r : Bool = actual && !cf\n" # was wet, would be dry
"r\n",
"r : Bool = true"),
# v4.64: Ship of Theseus. After replacing all 4 planks, the
# original [1,2,3,4] and final [5,6,7,8] differ in every
# position — diff_count = 4, so strictly NOT the same (yet each
# step changed only one plank: continuous).
("Ship of Theseus shares no original part (v4.64)",
"fn diff(a: List<Int>, b: List<Int>) : Int =\n"
" match a { [] => 0; [x, ...xs] => match b { [] => 0;"
" [y, ...ys] => (if x == y then 0 else 1) + diff(xs, ys) } }\n"
"let r : Int = diff([1, 2, 3, 4], [5, 6, 7, 8])\n"
"r\n",
"r : Int = 4"),
# v4.65 (Information & Observation): nested simulation depth.
# Sim(Sim(Add(3, Sim(4)))) is three realities deep, while the
# value (7) is level-independent.
("nested simulation depth (v4.65)",
"type Expr = | Lit(Int) | Add(Expr, Expr) | Sim(Expr)\n"
"fn depth(e: Expr) : Int =\n"
" match e { Lit(_) => 0;"
" Add(a, b) => let da = depth(a) in let db = depth(b) in"
" (if da > db then da else db);"
" Sim(inner) => 1 + depth(inner) }\n"
"let r : Int = depth(Sim(Sim(Add(Lit(3), Sim(Lit(4))))))\n"
"r\n",
"r : Int = 3"),
# v4.65: information-flow taint. Joining a public value with a
# secret one yields secret (Secret dominates the lattice), so
# the result is NOT publishable — non-interference by the join.
("info-flow taint blocks publish (v4.65)",
"type Label = | Public | Secret\n"
"fn join(a: Label, b: Label) : Bool =\n" # returns is_public of join
" match a { Secret => false;"
" Public => match b { Public => true; Secret => false } }\n"
"let publishable : Bool = join(Public, Secret)\n"
"publishable\n",
"publishable : Bool = false"),
# v4.66 (Physical types): dimensional analysis. distance/time
# subtracts dimension vectors, so (1,0,0) ÷ (0,1,0) = (1,−1,0),
# a velocity. We pin the time exponent of the result = −1.
("dimensional division yields velocity (v4.66)",
"type Dim = | Dim(Int, Int, Int)\n"
"fn dsub(a: Dim, b: Dim) : Dim =\n"
" match a { Dim(l1, t1, m1) => match b { Dim(l2, t2, m2) =>"
" Dim(l1 - l2, t1 - t2, m1 - m2) } }\n"
"fn time_exp(d: Dim) : Int = match d { Dim(_, t, _) => t }\n"
"let v : Dim = dsub(Dim(1, 0, 0), Dim(0, 1, 0))\n"
"let r : Int = time_exp(v)\n"
"r\n",
"r : Int = -1"),
# v4.67 (Tier-3): linear types. A `let lin` resource consumed
# exactly once type-checks and runs. Path-aware: using it once