| 1 |
From Corelib Require Import PrimInt63 PrimArray. |
| 2 |
|
| 3 |
Open Scope array_scope. |
| 4 |
|
| 5 |
(* Test reduction of primitives on array with kernel conversion, vm_compute, |
| 6 |
native_compute, cbv, cbn *) |
| 7 |
|
| 8 |
(* Immediate values *) |
| 9 |
Definition t : array nat := [| 1; 3; 2 | 4 |]. |
| 10 |
Definition foo1 := (eq_refl : t.[0] = 1). |
| 11 |
Definition foo2 := (eq_refl 1 <: t.[0] = 1). |
| 12 |
Definition foo3 := (eq_refl 1 <<: t.[0] = 1). |
| 13 |
Definition x1 := Eval compute in t.[0]. |
| 14 |
Definition foo4 := (eq_refl : x1 = 1). |
| 15 |
Definition x2 := Eval cbn in t.[0]. |
| 16 |
Definition foo5 := (eq_refl : x2 = 1). |
| 17 |
|
| 18 |
Definition foo6 := (eq_refl : t.[2] = 2). |
| 19 |
Definition foo7 := (eq_refl 2 <: t.[2] = 2). |
| 20 |
Definition foo8 := (eq_refl 2 <<: t.[2] = 2). |
| 21 |
Definition x3 := Eval compute in t.[2]. |
| 22 |
Definition foo9 := (eq_refl : x3 = 2). |
| 23 |
Definition x4 := Eval cbn in t.[2]. |
| 24 |
Definition foo10 := (eq_refl : x4 = 2). |
| 25 |
|
| 26 |
Definition foo11 := (eq_refl : t.[99] = 4). |
| 27 |
Definition foo12 := (eq_refl 4 <: t.[99] = 4). |
| 28 |
Definition foo13 := (eq_refl 4 <<: t.[99] = 4). |
| 29 |
Definition x5 := Eval compute in t.[4]. |
| 30 |
Definition foo14 := (eq_refl : x5 = 4). |
| 31 |
Definition x6 := Eval cbn in t.[4]. |
| 32 |
Definition foo15 := (eq_refl : x6 = 4). |
| 33 |
|
| 34 |
(* Computations inside the array *) |
| 35 |
Definition t2 : array nat := [| 1 + 3 | 5 |]. |
| 36 |
Definition foo16 := (eq_refl : t2.[0] = 4). |
| 37 |
Definition foo17 := (eq_refl 4 <: t2.[0] = 4). |
| 38 |
Definition foo18 := (eq_refl 4 <<: t2.[0] = 4). |
| 39 |
Definition x7 := Eval compute in t2.[0]. |
| 40 |
Definition foo19 := (eq_refl : x7 = 4). |
| 41 |
Definition x8 := Eval cbn in t2.[0]. |
| 42 |
Definition foo20 := (eq_refl : x8 = 4). |
| 43 |
|
| 44 |
(* Functions inside the array *) |
| 45 |
Definition t3 : array (nat -> nat) := [| fun x => x | fun x => O |]. |
| 46 |
Definition foo21 := (eq_refl : t3.[0] 2 = 2). |
| 47 |
Definition foo22 := (eq_refl 2 <: t3.[0] 2 = 2). |
| 48 |
Definition foo23 := (eq_refl 2 <<: t3.[0] 2 = 2). |
| 49 |
Definition x9 := Eval compute in t3.[0] 2. |
| 50 |
Definition foo24 := (eq_refl : x9 = 2). |
| 51 |
Definition x10 := Eval cbn in t3.[0] 2. |
| 52 |
Definition foo25 := (eq_refl : x10 = 2). |
| 53 |
|
| 54 |
Ltac check_const_eq name constr := |
| 55 |
let v := (eval cbv delta [name] in name) in |
| 56 |
tryif constr_eq v constr |
| 57 |
then idtac |
| 58 |
else fail 0 "Not syntactically equal:" name ":=" v "<>" constr. |
| 59 |
|
| 60 |
Notation check_const_eq name constr := (ltac:(check_const_eq name constr; exact constr)) (only parsing). |
| 61 |
|
| 62 |
(* Stuck primitive *) |
| 63 |
Definition lazy_stuck_get := Eval lazy in (fun A (t : array A) => t.[0]). |
| 64 |
Definition vm_stuck_get := Eval vm_compute in (fun A (t : array A) => t.[0]). |
| 65 |
Definition native_stuck_get := Eval native_compute in (fun A (t : array A) => t.[0]). |
| 66 |
Definition compute_stuck_get := Eval compute in (fun A (t : array A) => t.[0]). |
| 67 |
Definition cbn_stuck_get := Eval cbn in (fun A (t : array A) => t.[0]). |
| 68 |
|
| 69 |
Check check_const_eq lazy_stuck_get (fun A (t : array A) => t.[0]). |
| 70 |
Check check_const_eq vm_stuck_get (fun A (t : array A) => t.[0]). |
| 71 |
Check check_const_eq native_stuck_get (fun A (t : array A) => t.[0]). |
| 72 |
Check check_const_eq compute_stuck_get (fun A (t : array A) => t.[0]). |
| 73 |
Check check_const_eq cbn_stuck_get (fun A (t : array A) => t.[0]). |
| 74 |
|
| 75 |
(* Under-application *) |
| 76 |
Definition lazy_get := Eval lazy in @PrimArray.get. |
| 77 |
Definition vm_get := Eval vm_compute in @PrimArray.get. |
| 78 |
Definition native_get := Eval native_compute in @PrimArray.get. |
| 79 |
Definition compute_get := Eval compute in @PrimArray.get. |
| 80 |
Definition cbn_get := Eval cbn in @PrimArray.get. |
| 81 |
|
| 82 |
Check check_const_eq lazy_get (@PrimArray.get). |
| 83 |
Check check_const_eq vm_get (fun A (t : array A) i => t.[i]). |
| 84 |
Check check_const_eq native_get (fun A (t : array A) i => t.[i]). |
| 85 |
Check check_const_eq compute_get (@PrimArray.get). |
| 86 |
Check check_const_eq cbn_get (@PrimArray.get). |