Debian Codegraph @

test-suite/bugs/bug_14011.v

raw
1 (** Test that Ltac2 Array.init doesn't compute the first argument twice, and has the correct asymptotics when nested *)
2 Require Import Ltac2.Ltac2.
3
4 (** Non-performance-based test *)
5 Ltac2 foo () :=
6 let x := { contents := 0 } in
7 let _ := Array.init 1 (fun _ => x.(contents) := Int.add 1 (x.(contents))) in
8 Control.assert_true (Int.equal 1 (x.(contents))).
9
10 Ltac2 Eval foo ().
11
12 Ltac2 Type rec singleton := [ Single (int) | Arr (singleton array) ].
13 Ltac2 rec init_rec (n : int) :=
14 match Int.equal n 0 with
15 | true => Single 0
16 | false => Arr (Array.init 1 (fun _ => init_rec (Int.sub n 1)))
17 end.
18 Ltac2 rec timing (n : int) :=
19 (match Int.equal n 0 with
20 | true => ()
21 | false => timing (Int.sub n 1)
22 end;
23 Message.print (Message.concat (Message.of_int n) (Message.of_string ": "));
24 let _ := Control.time None (fun _ => init_rec n) in
25 ()).
26 (** Should take less than 0.1 seconds if the asymptotics are correct.
27 Previous behavior was to take an expected 1 million times the age of
28 the universe. Capping the time at 100 seconds seems like a reasonable
29 middle ground between these times, as I expect that compilation of Coq
30 itself will not finish in reasonable time if the computer is running
31 1000x slower than modern machines. *)
32 Timeout 100 Ltac2 Eval timing 100.