aboutsummaryrefslogtreecommitdiffstats
path: root/theories/nix/tests.v
diff options
context:
space:
mode:
authorRutger Broekhoff2025-07-07 21:52:08 +0200
committerRutger Broekhoff2025-07-07 21:52:08 +0200
commitba61dfd69504ec6263a9dee9931d93adeb6f3142 (patch)
treed6c9b78e50eeab24e0c1c09ab45909a6ae3fd5db /theories/nix/tests.v
downloadverified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.tar.gz
verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.zip
Initialize repository
Diffstat (limited to 'theories/nix/tests.v')
-rw-r--r--theories/nix/tests.v185
1 files changed, 185 insertions, 0 deletions
diff --git a/theories/nix/tests.v b/theories/nix/tests.v
new file mode 100644
index 0000000..cbce874
--- /dev/null
+++ b/theories/nix/tests.v
@@ -0,0 +1,185 @@
1From mininix Require Export nix.interp nix.notations.
2From stdpp Require Import options.
3Open Scope Z_scope.
4
5(** Compare base vals without comparing the proofs. Since we do not have
6definitional proof irrelevance, comparing the proofs would fail (and in practice
7make Coq loop). *)
8Definition res_eq (rv : res val) (bl2 : base_lit) :=
9 match rv with
10 | Res (Some (VLit bl1 _)) => bl1 = bl2
11 | _ => False
12 end.
13Infix "=?" := res_eq.
14
15Definition float_1 :=
16 ceil: (Float.of_Z 20 /: 3).
17Goal interp 100 ∅ float_1 =? 7.
18Proof. by vm_compute. Qed.
19
20Definition float_2 :=
21 Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *:
22 Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *:
23 Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *:
24 Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *:
25 Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000.
26Goal interp 100 ∅ float_2 =? NFloat (Binary.B754_infinity false).
27Proof. by vm_compute. Qed.
28
29Definition float_3 := float_2 /: float_2.
30Goal interp 100 ∅ float_3 =? NFloat (`Float.indef_nan).
31Proof. by vm_compute. Qed.
32
33Definition let_let :=
34 let: "x" := 1 in let: "x" := 2 in "x".
35Goal interp 100 ∅ let_let =? 2.
36Proof. by vm_compute. Qed.
37
38Definition with_let :=
39 with: EAttr {[ "x" := AttrN 1 ]} in let: "x" := 2 in "x".
40Goal interp 100 ∅ with_let =? 2.
41Proof. by vm_compute. Qed.
42
43Definition let_with :=
44 let: "x" := 1 in with: EAttr {[ "x" := AttrN 2 ]} in "x".
45Goal interp 100 ∅ let_with =? 1.
46Proof. by vm_compute. Qed.
47
48Definition with_with :=
49 with: EAttr {[ "x" := AttrN 1 ]} in with: EAttr {[ "x" := AttrN 2 ]} in "x".
50Goal interp 100 ∅ with_with =? 2.
51Proof. by vm_compute. Qed.
52
53Definition with_with_inherit :=
54 with: EAttr {[ "x" := AttrN 1 ]} in with: EAttr {[ "x" := AttrN "x" ]} in "x".
55Goal interp 100 ∅ with_with_inherit =? 1.
56Proof. by vm_compute. Qed.
57
58Definition with_loop :=
59 with: EAttr {[ "x" := AttrR "x" ]} in "x".
60Goal interp 100 ∅ with_loop = NoFuel.
61Proof. by vm_compute. Qed.
62
63Definition rec_attr_shadow_1 :=
64 let: "foo" := EAttr {[ "bar" := AttrN 10 ]} in
65 EAttr {[
66 "bar" := AttrR ("foo" .: "bar");
67 "foo" := AttrR (EAttr {[ "bar" := AttrN 20 ]})
68 ]} .: "bar".
69Goal interp 100 ∅ rec_attr_shadow_1 =? 20.
70Proof. by vm_compute. Qed.
71
72Definition rec_attr_shadow_2 :=
73 EAttr {[
74 "y" := AttrR (EAttr {[ "y" := AttrN "z" ]} .: "y");
75 "z" := AttrR 20
76 ]} .: "y".
77Goal interp 100 ∅ rec_attr_shadow_2 =? 20.
78Proof. by vm_compute. Qed.
79
80Definition nested_functor_1 :=
81 EAttr {[ "__functor" := AttrN $ λ: "self",
82 EAttr {[ "__functor" := AttrN $ λ: "self" "x", 10 ]} ]} 10.
83Goal interp 100 ∅ nested_functor_1 =? 10.
84Proof. by vm_compute. Qed.
85
86Definition nested_functor_2 :=
87 EAttr {[ "__functor" := AttrN $
88 EAttr {[ "__functor" := AttrN $ λ: "self" "self" "x", 10 ]} ]} 10.
89Goal interp 100 ∅ nested_functor_2 =? 10.
90Proof. by vm_compute. Qed.
91
92Definition functor_loop_1 :=
93 EAttr {[ "__functor" := AttrN $
94 λ: "self", "self" "self"
95 ]} 10.
96Goal interp 1000 ∅ functor_loop_1 = NoFuel.
97Proof. by vm_compute. Qed.
98
99Definition functor_loop_2 :=
100 EAttr {[ "__functor" := AttrN $
101 λ: "self" "f", "f" ("self" "f")
102 ]} (λ: "go" "x", "go" "x") 10.
103Goal interp 1000 ∅ functor_loop_2 = NoFuel.
104Proof. by vm_compute. Qed.
105
106Fixpoint many_lets (i : nat) (e : expr) : expr :=
107 match i with
108 | O => e
109 | S i => let: "x" +:+ pretty i := 0 in many_lets i e
110 end.
111
112Fixpoint many_adds (i : nat) : expr :=
113 match i with
114 | O => 0
115 | S i => ("x" +:+ pretty i) +: many_adds i
116 end.
117
118Definition big_prog (i : nat) : expr := many_lets i $ many_adds i.
119
120Definition big := big_prog 1000.
121
122Goal interp 5000 ∅ big =? 0.
123Proof. by vm_compute. Qed.
124
125Definition matching_1 :=
126 (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y")
127 (EAttr {[ "x" := AttrN 10; "y" := AttrN 11 ]}).
128Goal interp 1000 ∅ matching_1 =? 21.
129Proof. by vm_compute. Qed.
130
131Definition matching_2 :=
132 (λattr: {[ "x" := None; "y" := Some (EId' "x") ]}, "x" +: "y")
133 (EAttr {[ "x" := AttrN 10 ]}).
134Goal interp 1000 ∅ matching_2 =? 20.
135Proof. by vm_compute. Qed.
136
137Definition matching_3 :=
138 (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y")
139 (EAttr {[ "x" := AttrN 10 ]}).
140Goal interp 1000 ∅ matching_3 = mfail.
141Proof. by vm_compute. Qed.
142
143Definition matching_4 :=
144 (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y")
145 (EAttr {[ "x" := AttrN 10; "y" := AttrN 11; "z" := AttrN 12 ]}).
146Goal interp 1000 ∅ matching_4 = mfail.
147Proof. by vm_compute. Qed.
148
149Definition matching_5 :=
150 (λattr: {[ "x" := None; "y" := None ]} .., "x" +: "y")
151 (EAttr {[ "x" := AttrN 10; "y" := AttrN 11; "z" := AttrN 12 ]}).
152Goal interp 1000 ∅ matching_5 =? 21.
153Proof. by vm_compute. Qed.
154
155Definition matching_6 :=
156 (λattr: {[ "y" := Some (EId' "y") ]}, "y")
157 (EAttr {[ "y" := AttrN 10 ]}).
158Goal interp 1000 ∅ matching_6 =? 10.
159Proof. by vm_compute. Qed.
160
161Definition matching_7 :=
162 (λattr: {[ "y" := Some (EId' "y") ]}, "y") (EAttr ∅).
163Goal interp 1000 ∅ matching_7 = NoFuel.
164Proof. by vm_compute. Qed.
165
166Definition matching_8 :=
167 (λattr: {[ "y" := Some (EId' "y") ]}.., "y")
168 (EAttr {[ "x" := AttrN 10 ]}).
169Goal interp 1000 ∅ matching_8 = NoFuel.
170Proof. by vm_compute. Qed.
171
172Definition list_lt_1 :=
173 EList [ELit 2; ELit 3] <: EList [ELit 3].
174Goal interp 1000 ∅ list_lt_1 =? true.
175Proof. by vm_compute. Qed.
176
177Definition list_lt_2 :=
178 EList [ELit 2; ELit 3] <: EList [ELit 2].
179Goal interp 1000 ∅ list_lt_2 =? false.
180Proof. by vm_compute. Qed.
181
182Definition list_lt_3 :=
183 EList [ELit 2] <: EList [ELit 2; ELit 3].
184Goal interp 1000 ∅ list_lt_3 =? true.
185Proof. by vm_compute. Qed.