Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Implicit Type for identonly binders in notations #19003

Closed
wants to merge 1 commit into from

Conversation

SkySkimmer
Copy link
Contributor

Fix #9764

@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label May 6, 2024
@SkySkimmer SkySkimmer requested a review from a team as a code owner May 6, 2024 12:40
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label May 6, 2024
Copy link
Member

@herbelin herbelin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Contributor

coqbot-app bot commented May 6, 2024

🔴 CI failures at commit e7bb878 without any failure in the test-suite

✔️ Corresponding jobs for the base commit 00ef3a2 succeeded

❔ Ask me to try to extract minimal test cases that can be added to the test-suite

🏃 @coqbot ci minimize will minimize the following targets: ci-iris, ci-mathcomp, ci-mathcomp_1, ci-metacoq, ci-perennial, ci-sf
  • You can also pass me a specific list of targets to minimize as arguments.

@SkySkimmer
Copy link
Contributor Author

@coqbot ci minimize

Copy link
Contributor

coqbot-app bot commented May 6, 2024

I have initiated minimization at commit e7bb878 for the suggested targets ci-iris, ci-mathcomp, ci-mathcomp_1, ci-metacoq, ci-perennial, ci-sf as requested.

Copy link
Contributor

coqbot-app bot commented May 6, 2024

Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/sf/slf-current/LibSepReference.v (from ci-sf) (full log on GitHub Actions - verbose log)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

🌟 Minimized Coq File (consider adding this file to the test-suite)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-implicit-core-hint-db,-ambiguous-paths" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current" "SLF" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "SLF.LibSepReference") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 4306 lines to 103 lines, then from 116 lines to 600 lines, then from 604 lines to 106 lines, then from 119 lines to 176 lines, then from 181 lines to 107 lines, then from 120 lines to 489 lines, then from 493 lines to 117 lines, then from 130 lines to 4151 lines, then from 4153 lines to 128 lines, then from 141 lines to 1101 lines, then from 1104 lines to 129 lines, then from 134 lines to 131 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.09.0
   coqtop version runner-t7b1znuaq-project-4504-concurrent-4:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 0.244 sec *)

Require Coq.ZArith.ZArith.

Export Coq.ZArith.ZArith.
Notation "'int'" := Z : Int_scope.

Declare Scope liblist_scope.
Open Scope liblist_scope.

Infix "::" := cons (at level 60, right associativity) : liblist_scope.

Fixpoint nat_seq (start:nat) (nb:nat) :=
  match nb with
  | O => nil
  | S nb' => start :: nat_seq (S start) nb'
  end.

Module Export LibListExec.

Set Implicit Arguments.

Module Import RewListExec.

End RewListExec.
Definition length : forall A, list A -> nat.
Admitted.
Definition map : forall A B, (A->B) -> list A -> list B.
Admitted.
Open Scope Int_scope.
Definition var : Type.
Admitted.

Inductive prim : Type :=
  | val_ref : prim
  | val_get : prim
  | val_set : prim
  | val_free : prim
  | val_neg : prim
  | val_opp : prim
  | val_eq : prim
  | val_add : prim
  | val_neq : prim
  | val_sub : prim
  | val_mul : prim
  | val_div : prim
  | val_mod : prim
  | val_rand : prim
  | val_le : prim
  | val_lt : prim
  | val_ge : prim
  | val_gt : prim
  | val_ptr_add : prim.
Definition loc : Type.
Admitted.

Inductive val : Type :=
  | val_unit : val
  | val_bool : bool -> val
  | val_int : int -> val
  | val_loc : loc -> val
  | val_prim : prim -> val
  | val_fun : var -> trm -> val
  | val_fix : var -> var -> trm -> val
  | val_uninit : val
  | val_error : val

with trm : Type :=
  | trm_val : val -> trm
  | trm_var : var -> trm
  | trm_fun : var -> trm -> trm
  | trm_fix : var -> var -> trm -> trm
  | trm_app : trm -> trm -> trm
  | trm_seq : trm -> trm -> trm
  | trm_let : var -> trm -> trm -> trm
  | trm_if : trm -> trm -> trm -> trm.
Definition heap : Type.
Admitted.
Implicit Types p : loc.

Declare Scope hprop_scope.
Open Scope hprop_scope.

Definition hprop := heap -> Prop.
Definition hempty : hprop.
Admitted.
Definition hstar (H1 H2 : hprop) : hprop.
Admitted.
Definition hexists A (J:A->hprop) : hprop.
Admitted.

Notation "\[]" := (hempty)
  (at level 0) : hprop_scope.

Notation "H1 '\*' H2" := (hstar H1 H2)
  (at level 41, right associativity) : hprop_scope.

Notation "'\exists' x1 .. xn , H" :=
  (hexists (fun x1 => .. (hexists (fun xn => H)) ..))
  (at level 39, x1 binder, H at level 50, right associativity,
   format "'[' '\exists' '/ '  x1  ..  xn , '/ '  H ']'") : hprop_scope.
Definition hpure (P:Prop) : hprop.
Admitted.

Notation "\[ P ]" := (hpure P)
  (at level 0, format "\[ P ]") : hprop_scope.
Definition triple (t:trm) (H:hprop) (Q:val->hprop) : Prop.
Admitted.

Notation "'funloc' p '=>' H" :=
  (fun (r:val) => \exists p, \[r = val_loc p] \* H)
  (at level 200, p name, format "'funloc'  p  '=>'  H") : hprop_scope.
Definition field : Type.
exact (nat).
Defined.

Definition hrecord_field : Type := (field * val).
Definition hrecord_fields : Type.
exact (list hrecord_field).
Defined.

Parameter hrecord : forall (kvs:hrecord_fields) (p:loc), hprop.

Parameter val_alloc_hrecord : forall (ks:list field), trm.

Parameter triple_alloc_hrecord : forall ks,
  ks = nat_seq 0 (LibListExec.length ks) ->
  triple (val_alloc_hrecord ks)
    \[]
    (funloc p => hrecord (LibListExec.map (fun k => (k,val_uninit)) ks) p).
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 3.1MiB file on GitHub Actions Artifacts under build.log)
ild_ci/sf/lf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.JeXmb3VV18
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/lf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.kKhmtXUFO0
MINIMIZER_DEBUG: files: 
make[2]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/lf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.QYz2pBD4Le
MINIMIZER_DEBUG: files: 
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/lf-current'
+ cd plf-current
+ make
+ '[' -z x ']'
+ command make
+ make
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.K0zAiJUnCJ
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.7yqOTVRcWB
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.xxBFynEgrV
MINIMIZER_DEBUG: files: 
make[2]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.MeGPoJidcl
MINIMIZER_DEBUG: files: 
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/plf-current'
+ cd vfa-current
+ make
+ '[' -z x ']'
+ command make
+ make
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.4nNBkJklbZ
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.4beUzm6JF0
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.jhkyvt8eMM
MINIMIZER_DEBUG: files: 
make[2]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.lVLKJSqpq7
MINIMIZER_DEBUG: files: 
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/vfa-current'
+ cd slf-current
+ make
+ '[' -z x ']'
+ command make
+ make
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.rlXx1BLdBf
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.qMczCh2jkz
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.8yLDr2ndra
MINIMIZER_DEBUG: files: 
COQC LibSepReference.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -implicit-core-hint-db\,-ambiguous-paths -w -deprecated-native-compiler-option -native-compiler ondemand -Q /github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current SLF LibSepReference.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.zN2K9SkkiK
MINIMIZER_DEBUG: files:  LibSepReference.v
File "./LibSepReference.v", line 3956, characters 0-203:
Error:
Unexpected type constraint in notation already providing a type constraint.

Command exited with non-zero status 1
LibSepReference.vo (real: 7.25, user: 7.08, sys: 0.16, mem: 611680 ko)
make[2]: *** [Makefile.coq:803: LibSepReference.vo] Error 1
make[1]: *** [Makefile.coq:417: all] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/sf/slf-current'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real sf.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m07.25s | 611680 ko | Total Time / Peak Mem
--------------------------------------------
0m07.25s | 611680 ko | LibSepReference.vo   
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-sf] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 167KiB file on GitHub Actions Artifacts under bug.log)

�[92m
Admitting Qed Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qed Obligations unsuccessful.
No successful changes.

I will now attempt to replace Qeds with Admitteds
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to replace Qeds with admit. Defined.
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  The alternate coqc (/github/workspace/builds/coq/coq-passing/_install_ci/bin/coqc.orig) was supposed to pass, but instead emitted an error.  
The new error was:
File "/tmp/tmpavvxjcar/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmpavvxjcar/LibSepReference.v", line 132, characters 28-30:
Error:
In environment
ks : list nat
The term "ks" has type "list nat" while it is expected to have type
 "list field".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmp2_ve1bxn/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp2_ve1bxn/SLF/LibSepReference.v", line 121, characters 0-8:
Error:  (in proof field): Attempt to save an incomplete proof
(the proof term is not complete because of given up (admitted) goals).
If this is really what you want to do, use Admitted in place of Qed.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 12, characters 0-34:
Warning: Declaring a scope implicitly is deprecated; use in advance an
explicit "Declare Scope Int_scope.".
[undeclared-scope,deprecated-since-8.10,deprecated,default]
File "/tmp/tmp9aq3whus/SLF/LibSepReference.v", line 61, characters 10-13:
Error: The reference val was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...
�[92m
Succeeded in stripping newlines and spaces.�[0m

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 6, 2024

Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp/ssreflect/seq.v (from ci-mathcomp_1) (full log on GitHub Actions - verbose log)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

🌟 Minimized Coq File (consider adding this file to the test-suite)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-projection-no-head-constant" "-w" "-redundant-canonical-projection" "-w" "-notation-overridden" "-w" "+duplicate-clear" "-w" "-ambiguous-paths" "-w" "+non-primitive-record" "-w" "+undeclared-scope" "-w" "+deprecated-hint-without-locality" "-w" "+deprecated-hint-rewrite-without-locality" "-w" "-opaque-let" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp" "mathcomp" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-I" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp" "-top" "mathcomp.ssreflect.seq") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 4741 lines to 61 lines, then from 74 lines to 2244 lines, then from 2249 lines to 77 lines, then from 90 lines to 1126 lines, then from 1131 lines to 89 lines, then from 102 lines to 324 lines, then from 329 lines to 90 lines, then from 103 lines to 161 lines, then from 166 lines to 90 lines, then from 95 lines to 92 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.14.1
   coqtop version runner-t7b1znuaq-project-4504-concurrent-1:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4c) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 0.120 sec *)

Require Coq.ssr.ssrbool.

Axiom proof_admitted : False.
Tactic Notation "admit" := abstract case proof_admitted.

Export Coq.ssr.ssreflect.
Export Coq.ssr.ssrbool.

Set Implicit Arguments.

Module Export Equality.

Definition axiom T (e : rel T) := forall x y, reflect (x = y) (e x y).

Structure mixin_of T := Mixin {op : rel T; _ : axiom op}.
Notation class_of := mixin_of (only parsing).

Structure type := Pack {sort; _ : class_of sort}.
Coercion sort : type >-> Sortclass.
Notation eqType := type.
Notation EqMixin := Mixin.
Notation EqType T m := (@Pack T m).

Notation succn := Datatypes.S.

Notation "n .+1" := (succn n) (at level 2, left associativity,
  format "n .+1") : nat_scope.

Fixpoint eqn m n {struct m} :=
  match m, n with
  | 0, 0 => true
  | m'.+1, n'.+1 => eqn m' n'
  | _, _ => false
  end.

Lemma eqnP : Equality.axiom eqn.
Admitted.

Canonical nat_eqMixin := EqMixin eqnP.
Canonical nat_eqType := Eval hnf in EqType nat nat_eqMixin.
Unset Strict Implicit.

Declare Scope seq_scope.
Open Scope seq_scope.

Notation seq := list.

Infix "::" := cons : seq_scope.

Notation "[ :: ]" := nil (at level 0, format "[ :: ]") : seq_scope.

Section EqSeq.

Variables (n0 : nat) (T : eqType) (x0 : T).

Definition seq_eqclass := seq T.
Coercion pred_of_seq (s : seq_eqclass) : {pred T}.
admit.
Defined.

Canonical seq_predType := PredType (pred_of_seq : seq T -> pred T).

Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true.

End EqSeq.

Section Map.

Variables (n0 : nat) (T1 : Type) (x1 : T1).
Variables (T2 : Type) (x2 : T2) (f : T1 -> T2).

Fixpoint map s := if s is x :: s' then f x :: map s' else [::].

End Map.

Section Zip.

Variables (S T : Type) (r : S -> T -> bool).

Definition unzip1 := map (@fst S T).
Definition unzip2 := map (@snd S T).

End Zip.

Variable T : eqType.
Implicit Types (x : T) (s t : seq T) (bs : seq (T * nat)) (acc : seq (seq T)).

Definition wf_tally :=
  [qualify a bs : seq (T * nat) | uniq (unzip1 bs) && (0 \notin unzip2 bs)].
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 3.2MiB file on GitHub Actions Artifacts under build.log)
.orig
-rwxr-xr-x 1 root root     2134 May  6 20:05 coqpp
-rwxr-xr-x 1 root root  3492824 May  6 15:37 coqpp.orig
-rwxr-xr-x 1 root root     2144 May  6 20:05 coqtimelog2html
-rwxr-xr-x 1 root root  4590512 May  6 15:37 coqtimelog2html.orig
-rwxr-xr-x 1 root root     2135 May  6 20:05 coqtop
-rwxr-xr-x 1 root root     2140 May  6 20:05 coqtop.byte
-rwxr-xr-x 1 root root 65219387 May  6 15:37 coqtop.byte.orig
-rwxr-xr-x 1 root root 71564400 May  6 15:37 coqtop.orig
-rwxr-xr-x 1 root root     2134 May  6 20:05 coqwc
-rwxr-xr-x 1 root root  2325600 May  6 15:37 coqwc.orig
-rwxr-xr-x 1 root root     2142 May  6 20:05 coqworker.opt
-rwxr-xr-x 1 root root 71413456 May  6 15:37 coqworker.opt.orig
-rwxr-xr-x 1 root root     2139 May  6 20:05 coqworkmgr
-rwxr-xr-x 1 root root  3401152 May  6 15:37 coqworkmgr.orig
-rwxr-xr-x 1 root root     2137 May  6 20:05 csdpcert
-rwxr-xr-x 1 root root  5992488 May  6 15:37 csdpcert.orig
-rwxr-xr-x 1 root root     2140 May  6 20:05 ocamllibdep
-rwxr-xr-x 1 root root  3489704 May  6 15:37 ocamllibdep.orig
-rwxr-xr-x 1 root root     2135 May  6 20:05 votour
-rwxr-xr-x 1 root root  4509200 May  6 15:37 votour.orig
++ CI_BUILD_DIR=/github/workspace/builds/coq/coq-failing/_build_ci
++ ls -l /github/workspace/builds/coq/coq-failing/_build_ci
total 4
drwxr-xr-x 6 root root 4096 May  6 16:10 mathcomp_1
++ declare -A overlays
++ set +x
+ git_download mathcomp_1
+ local project=mathcomp_1
+ local dest=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1
+ local giturl_var=mathcomp_1_CI_GITURL
+ local giturl=https://github.com/math-comp/math-comp
+ local ref_var=mathcomp_1_CI_REF
+ local ref=a526d8dc7956ce1c1bc88051d0656d35b76608a3
+ local parent_project_var=mathcomp_1_CI_PARENT_PROJECT
+ local parent_project=
+ local submodule_folder_var=mathcomp_1_CI_SUBMODULE_FOLDER
+ local submodule_folder=
+ local ov_url=
+ local ov_ref=
++ dirname /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1
+ local dest_prefix=/github/workspace/builds/coq/coq-failing/_build_ci/
+ '[' '' = '' ']'
+ local parent_project_dest=/github/workspace/builds/coq/coq-failing/_build_ci/
+ local parent_project_relative_dest=
+ '[' -d /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1 ']'
+ echo 'Warning: download and unpacking of mathcomp_1 skipped because /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1 already exists.'
Warning: download and unpacking of mathcomp_1 skipped because /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1 already exists.
+ '[' '' ']'
+ cd /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
+ make
+ '[' -z x ']'
+ command make
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop.orig -v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.JiUnMdtCw0
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.zk8BbolquB
MINIMIZER_DEBUG: files: 
/github/workspace/builds/coq/coq-failing/_install_ci/bin/coq_makefile  -f Make -o Makefile.coq
make -f Makefile.coq --no-print-directory
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.FuivyxA2yH
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.kxBmHYODfA
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.Sgh9D4e8Dh
MINIMIZER_DEBUG: files: 
COQC ssreflect/seq.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -projection-no-head-constant -w -redundant-canonical-projection -w -notation-overridden -w +duplicate-clear -w -ambiguous-paths -w +non-primitive-record -w +undeclared-scope -w +deprecated-hint-without-locality -w +deprecated-hint-rewrite-without-locality -w -opaque-let -w -deprecated-native-compiler-option -native-compiler ondemand -I /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp -R /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp mathcomp ssreflect/seq.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.PCRq38dKFO
MINIMIZER_DEBUG: files:  ssreflect/seq.v
File "./ssreflect/seq.v", line 3, characters 0-68:
Warning: Overwriting previous delimiting key nat in scope nat_scope
[overwriting-delimiting-key,parsing,default]
File "./ssreflect/seq.v", line 215, characters 0-41:
Warning: The '%' scope delimiter in 'Arguments' commands is deprecated, use
'%_' instead (available since 8.19). The '%' syntax will be reused in a
future version with the same semantics as in terms, that is adding scope to
the stack for all subterms. Code can be adapted with a script like: for f in
$(find . -name '*.v'); do sed '/Arguments/ s/%/%_/g' -i $f ; done
[argument-scope-delimiter,deprecated-since-8.19,deprecated,default]
File "./ssreflect/seq.v", line 216, characters 0-32:
Warning: The '%' scope delimiter in 'Arguments' commands is deprecated, use
'%_' instead (available since 8.19). The '%' syntax will be reused in a
future version with the same semantics as in terms, that is adding scope to
the stack for all subterms. Code can be adapted with a script like: for f in
$(find . -name '*.v'); do sed '/Arguments/ s/%/%_/g' -i $f ; done
[argument-scope-delimiter,deprecated-since-8.19,deprecated,default]
File "./ssreflect/seq.v", line 4454, characters 0-99:
Error:
Unexpected type constraint in notation already providing a type constraint.

Command exited with non-zero status 1
ssreflect/seq.vo (real: 4.06, user: 3.94, sys: 0.11, mem: 517320 ko)
make[3]: *** [Makefile.coq:818: ssreflect/seq.vo] Error 1
make[3]: *** [ssreflect/seq.vo] Deleting file 'ssreflect/seq.glob'
make[2]: *** [Makefile.coq:417: all] Error 2
make[1]: *** [Makefile.common:99: this-build] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp_1/mathcomp'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real mathcomp_1.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m04.06s | 517320 ko | Total Time / Peak Mem
--------------------------------------------
0m04.06s | 517320 ko | ssreflect/seq.vo     
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-mathcomp_1] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 176KiB file on GitHub Actions Artifacts under bug.log)
ttempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Qed Obligation with Admit Obligations
�[92m
Admitting Qed Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qed Obligations unsuccessful.
No successful changes.

I will now attempt to replace Qeds with Admitteds
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to replace Qeds with admit. Defined.
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  The alternate coqc (/github/workspace/builds/coq/coq-passing/_install_ci/bin/coqc.orig) was supposed to pass, but instead emitted an error.  
The new error was:
File "/tmp/tmpisdb99el/seq.v", line 92, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
File "/tmp/tmpisdb99el/seq.v", line 96, characters 40-49:
Error:
In environment
bs : seq (T * nat)
The term "unzip1 bs" has type "seq T" while it is expected to have type
 "nat".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpt1hjo1s6/mathcomp/ssreflect/seq.v", line 68, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
Error: The module Equality needs to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...
�[92m
Succeeded in stripping newlines and spaces.�[0m

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 6, 2024

Partially Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp/ssreflect/seq.v (from ci-mathcomp) (full log on GitHub Actions - verbose log)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

⭐ 🏗️ Partially Minimized Coq File (could not inline HB.structures)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-projection-no-head-constant" "-w" "-redundant-canonical-projection" "-w" "-notation-overridden" "-w" "+duplicate-clear" "-w" "-ambiguous-paths" "-w" "+non-primitive-record" "-w" "+undeclared-scope" "-w" "+deprecated-hint-without-locality" "-w" "+deprecated-hint-rewrite-without-locality" "-w" "-elpi.add-const-for-axiom-or-sectionvar" "-w" "-opaque-let" "-w" "-argument-scope-delimiter" "-w" "-overwriting-delimiting-key" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp" "mathcomp" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/HB" "HB" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/elpi" "elpi" "-I" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp" "-top" "mathcomp.ssreflect.seq") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 4743 lines to 61 lines, then from 74 lines to 2258 lines, then from 2263 lines to 78 lines, then from 91 lines to 1146 lines, then from 1151 lines to 85 lines, then from 98 lines to 225 lines, then from 231 lines to 86 lines, then from 100 lines to 160 lines, then from 166 lines to 86 lines, then from 92 lines to 88 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.14.1
   coqtop version runner-t7b1znuaq-project-4504-concurrent-1:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4c) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Modules that could not be inlined: HB.structures
   Expected coqc runtime on this file: 0.362 sec *)

Require Coq.ssr.ssrbool.
Require HB.structures.

Axiom proof_admitted : False.
Tactic Notation "admit" := abstract case proof_admitted.

Export Coq.ssr.ssreflect.
Export Coq.ssr.ssrbool.

Import HB.structures.

Set Implicit Arguments.

Definition eq_axiom T (e : rel T) := forall x y, reflect (x = y) (e x y).

HB.mixin Record hasDecEq T := { eq_op : rel T; eqP : eq_axiom eq_op }.

#[mathcomp(axiom="eq_axiom"), short(type="eqType")]
HB.structure Definition Equality := { T of hasDecEq T }.

Notation succn := Datatypes.S.

Notation "n .+1" := (succn n) (at level 2, left associativity,
  format "n .+1") : nat_scope.

Fixpoint eqn m n {struct m} :=
  match m, n with
  | 0, 0 => true
  | m'.+1, n'.+1 => eqn m' n'
  | _, _ => false
  end.

Lemma eqnP : Equality.axiom eqn.
Admitted.

HB.instance Definition _ := hasDecEq.Build nat eqnP.
Unset Strict Implicit.

Declare Scope seq_scope.
Open Scope seq_scope.

Notation seq := list.

Infix "::" := cons : seq_scope.

Notation "[ :: ]" := nil (at level 0, format "[ :: ]") : seq_scope.

Section EqSeq.

Variables (n0 : nat) (T : eqType) (x0 : T).

Definition seq_eqclass := seq T.
Coercion pred_of_seq (s : seq_eqclass) : {pred T}.
admit.
Defined.

Canonical seq_predType := PredType (pred_of_seq : seq T -> pred T).

Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true.

End EqSeq.

Section Map.

Variables (n0 : nat) (T1 : Type) (x1 : T1).
Variables (T2 : Type) (x2 : T2) (f : T1 -> T2).

Fixpoint map s := if s is x :: s' then f x :: map s' else [::].

End Map.

Section Zip.

Variables (S T : Type) (r : S -> T -> bool).

Definition unzip1 := map (@fst S T).
Definition unzip2 := map (@snd S T).

End Zip.

Variable T : eqType.
Implicit Types (x : T) (s t : seq T) (bs : seq (T * nat)) (acc : seq (seq T)).

Definition wf_tally :=
  [qualify a bs : seq (T * nat) | uniq (unzip1 bs) && (0 \notin unzip2 bs)].
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted) (truncated to 6.0KiB; full 50KiB file on GitHub Actions Artifacts under tmp.v)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-projection-no-head-constant" "-w" "-redundant-canonical-projection" "-w" "-notation-overridden" "-w" "+duplicate-clear" "-w" "-ambiguous-paths" "-w" "+non-primitive-record" "-w" "+undeclared-scope" "-w" "+deprecated-hint-without-locality" "-w" "+deprecated-hint-rewrite-without-locality" "-w" "-elpi.add-const-for-axiom-or-sectionvar" "-w" "-opaque-let" "-w" "-argument-scope-delimiter" "-w" "-overwriting-delimiting-key" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp" "mathcomp" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/HB" "HB" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/elpi" "elpi" "-I" "/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp" "-top" "mathcomp.ssreflect.seq") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 4743 lines to 61 lines, then from 74 lines to 2258 lines, then from 2263 lines to 78 lines, then from 91 lines to 1146 lines, then from 1151 lines to 85 lines, then from 98 lines to 1328 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.14.1
   coqtop version runner-t7b1znuaq-project-4504-concurrent-1:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4c) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 0.000 sec *)
Require Coq.Init.Ltac.
Module Export AdmitTactic.
Module Import LocalFalse.
Inductive False : Prop := .
End LocalFalse.
Axiom proof_admitted : False.
Import Coq.Init.Ltac.
Tactic Notation "admit" := abstract case proof_admitted.
End AdmitTactic.
Require mathcomp.ssreflect.ssrbool.
Require Coq.Bool.Bool.
Require Coq.Floats.PrimFloat.
Require Coq.Init.Ltac.
Require Coq.Numbers.Cyclic.Int63.PrimInt63.
Require Coq.Strings.String.
Require Coq.ssr.ssreflect.
Require Coq.ssr.ssrfun.
Require elpi.elpi.
Require elpi.apps.locker.

Module HB_DOT_structures_WRAPPED.
Module structures.
(* Support constants, to be kept in sync with shim/structures.v *)
Import Coq.Strings.String Coq.ssr.ssreflect Coq.ssr.ssrfun.
Export String.StringSyntax.

Variant error_msg := NoMsg | IsNotCanonicallyA (x : Type).
Definition unify T1 T2 (t1 : T1) (t2 : T2) (s : error_msg) :=
  phantom T1 t1 -> phantom T2 t2.
Definition id_phant {T} {t : T} (x : phantom T t) := x.
Definition id_phant_disabled {T T'} {t : T} {t' : T'} (x : phantom T t) := Phantom T' t'.
Definition nomsg : error_msg := NoMsg.
Definition is_not_canonically_a x := IsNotCanonicallyA x.
Definition new {T} (x : T) := x.
Definition eta {T} (x : T) := x.
Definition ignore {T} (x: T) := x.
Definition ignore_disabled {T T'} (x : T) (x' : T') := x'.

(* ********************* structures ****************************** *)
Import elpi.elpi.

Register unify as hb.unify.
Register id_phant as hb.id.
Register id_phant_disabled as hb.id_disabled.
Register ignore as hb.ignore.
Register ignore_disabled as hb.ignore_disabled.
Register Coq.Init.Datatypes.None as hb.none.
Register nomsg as hb.nomsg.
Register is_not_canonically_a as hb.not_a_msg.
Register Coq.Init.Datatypes.Some as hb.some.
Register Coq.Init.Datatypes.pair as hb.pair.
Register Coq.Init.Datatypes.prod as hb.prod.
Register Coq.Init.Specif.sigT as hb.sigT.
Register Coq.ssr.ssreflect.phant as hb.phant.
Register Coq.ssr.ssreflect.Phant as hb.Phant.
Register Coq.ssr.ssreflect.phantom as hb.phantom.
Register Coq.ssr.ssreflect.Phantom as hb.Phantom.
Register Coq.Init.Logic.eq as hb.eq.
Register Coq.Init.Logic.eq_refl as hb.erefl.
Register new as hb.new.
Register eta as hb.eta.

#[deprecated(since="HB 1.0.1", note="use #[key=...] instead")]
Notation indexed T := T (only parsing).

Declare Scope HB_scope.
Notation "{  A  'of'  P  &  ..  &  Q  }" :=
  (sigT (fun A => (prod P .. (prod Q True) ..)%type))
  (at level 0, A at level 99) : HB_scope.
Notation "{  A  'of'  P  &  ..  &  Q  &  }" :=
  (sigT (fun A => (prod P .. (prod Q False) ..)%type))
  (at level 0, A at level 99) : HB_scope.
Global Open Scope HB_scope.

(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)

(** This data represents the hierarchy and some other piece of state to
    implement the commands of this file *)

#[interp] Elpi Db hb.db lp:{{

typeabbrev mixinname   gref.
typeabbrev classname   gref.
typeabbrev factoryname gref.
typeabbrev structure   gref.

typeabbrev (w-args A) (triple A (list term) term).

kind w-params type -> type -> type.
type w-params.cons id -> term -> (term -> w-params A) -> w-params A.
type w-params.nil id -> term -> (term -> A) -> w-params A.

typeabbrev (list-w-params A) (w-params (list (w-args A))).
typeabbrev (one-w-params A) (w-params (w-args A)).
typeabbrev mixins (list-w-params mixinname).
typeabbrev factories (list-w-params mixinname).
typeabbrev (w-mixins A) (pair mixins (w-params A)).

%%%%% Classes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% (class C S ML) represents a class C packed in S containing mixins ML.
% Example:
%
%  HB.mixin Record IsZmodule V := { ... }
%  HB.mixin Record Zmodule_IsLmodule (R : ringType) V of Zmodule V := { ... }
%  HB.structure Definition Lmodule R := {M of Zmodule M & Zmodule_IsLmodule R M}
%
% The class description for Lmodule would be:
%
%  class (indt «Lmodule.axioms»)                   /* The record with all mixins     */
%        (indt «Lmodule.type»)                     /* The record with sort and class */
%        (w-params.cons "R" {{ Ring.type }} P \    /* The first parameter, named "R" */
%          w-params.nil "M" {{ Type }} T \         /* The key of the structure       */
%           [...,                                  /* deps of IsZmodule.mixin        */
%            triple (indt «IsZmodule.mixin») [] T, /* a mixins with its params       */
%  
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
File "/tmp/tmpg8skrf8z/mathcomp/ssreflect/seq.v", line 315, characters 0-44:
Error: The syntax 'Elpi Accumulate File "path"' is deprecated, use 'Elpi
Accumulate File "path" From logpath'
[elpi.accumulate-syntax,elpi.deprecated,deprecated,elpi,default]
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 3.7MiB file on GitHub Actions Artifacts under build.log)

-rwxr-xr-x 1 root root  2741424 May  6 15:37 coq-tex.orig
-rwxr-xr-x 1 root root  6437128 May  6 15:37 coq_makefile
-rwxr-xr-x 1 root root     2133 May  6 20:06 coqc
-rwxr-xr-x 1 root root     2138 May  6 20:06 coqc.byte
-rwxr-xr-x 1 root root 43282407 May  6 15:37 coqc.byte.orig
-rwxr-xr-x 1 root root 71412032 May  6 15:37 coqc.orig
-rwxr-xr-x 1 root root 21417448 May  6 15:37 coqchk
-rwxr-xr-x 1 root root  7057464 May  6 15:37 coqdep
-rwxr-xr-x 1 root root     2135 May  6 20:06 coqdoc
-rwxr-xr-x 1 root root  6517552 May  6 15:37 coqdoc.orig
-rwxr-xr-x 1 root root     2135 May  6 20:06 coqide
-rwxr-xr-x 1 root root 19394904 May  6 15:37 coqide.orig
-rwxr-xr-x 1 root root     2143 May  6 20:06 coqidetop.byte
-rwxr-xr-x 1 root root 43846066 May  6 15:37 coqidetop.byte.orig
-rwxr-xr-x 1 root root     2142 May  6 20:06 coqidetop.opt
-rwxr-xr-x 1 root root 72245480 May  6 15:37 coqidetop.opt.orig
-rwxr-xr-x 1 root root     2138 May  6 20:06 coqnative
-rwxr-xr-x 1 root root 21609216 May  6 15:37 coqnative.orig
-rwxr-xr-x 1 root root     2134 May  6 20:06 coqpp
-rwxr-xr-x 1 root root  3492824 May  6 15:37 coqpp.orig
-rwxr-xr-x 1 root root     2144 May  6 20:06 coqtimelog2html
-rwxr-xr-x 1 root root  4590512 May  6 15:37 coqtimelog2html.orig
-rwxr-xr-x 1 root root     2135 May  6 20:06 coqtop
-rwxr-xr-x 1 root root     2140 May  6 20:06 coqtop.byte
-rwxr-xr-x 1 root root 65219387 May  6 15:37 coqtop.byte.orig
-rwxr-xr-x 1 root root 71564400 May  6 15:37 coqtop.orig
-rwxr-xr-x 1 root root     2134 May  6 20:06 coqwc
-rwxr-xr-x 1 root root  2325600 May  6 15:37 coqwc.orig
-rwxr-xr-x 1 root root     2142 May  6 20:06 coqworker.opt
-rwxr-xr-x 1 root root 71413456 May  6 15:37 coqworker.opt.orig
-rwxr-xr-x 1 root root     2139 May  6 20:06 coqworkmgr
-rwxr-xr-x 1 root root  3401152 May  6 15:37 coqworkmgr.orig
-rwxr-xr-x 1 root root     2137 May  6 20:06 csdpcert
-rwxr-xr-x 1 root root  5992488 May  6 15:37 csdpcert.orig
-rwxr-xr-x 1 root root     2140 May  6 20:06 ocamllibdep
-rwxr-xr-x 1 root root  3489704 May  6 15:37 ocamllibdep.orig
-rwxr-xr-x 1 root root     2135 May  6 20:06 votour
-rwxr-xr-x 1 root root  4509200 May  6 15:37 votour.orig
++ CI_BUILD_DIR=/github/workspace/builds/coq/coq-failing/_build_ci
++ ls -l /github/workspace/builds/coq/coq-failing/_build_ci
total 12
drwxr-xr-x 12 root root 4096 May  6 20:07 elpi
drwxr-xr-x 11 root root 4096 May  6 20:07 hierarchy_builder
drwxr-xr-x  7 root root 4096 May  6 16:21 mathcomp
++ declare -A overlays
++ set +x
+ git_download mathcomp
+ local project=mathcomp
+ local dest=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp
+ local giturl_var=mathcomp_CI_GITURL
+ local giturl=https://github.com/math-comp/math-comp
+ local ref_var=mathcomp_CI_REF
+ local ref=master
+ local parent_project_var=mathcomp_CI_PARENT_PROJECT
+ local parent_project=
+ local submodule_folder_var=mathcomp_CI_SUBMODULE_FOLDER
+ local submodule_folder=
+ local ov_url=
+ local ov_ref=
++ dirname /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp
+ local dest_prefix=/github/workspace/builds/coq/coq-failing/_build_ci/
+ '[' '' = '' ']'
+ local parent_project_dest=/github/workspace/builds/coq/coq-failing/_build_ci/
+ local parent_project_relative_dest=
+ '[' -d /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp ']'
+ echo 'Warning: download and unpacking of mathcomp skipped because /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp already exists.'
Warning: download and unpacking of mathcomp skipped because /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp already exists.
+ '[' '' ']'
+ cd /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
+ make
+ '[' -z x ']'
+ command make
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop.orig -v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.hNcovHjZLY
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqtop.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.MvYTDejZge
MINIMIZER_DEBUG: files: 
/github/workspace/builds/coq/coq-failing/_install_ci/bin/coq_makefile  -f Make -o Makefile.coq
make -f Makefile.coq --no-print-directory
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.AjoKreRNix
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.PQg1JqgGVs
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.SenC2tukbB
MINIMIZER_DEBUG: files: 
COQC ssreflect/seq.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -projection-no-head-constant -w -redundant-canonical-projection -w -notation-overridden -w +duplicate-clear -w -ambiguous-paths -w +non-primitive-record -w +undeclared-scope -w +deprecated-hint-without-locality -w +deprecated-hint-rewrite-without-locality -w -elpi.add-const-for-axiom-or-sectionvar -w -opaque-let -w -argument-scope-delimiter -w -overwriting-delimiting-key -w -deprecated-native-compiler-option -native-compiler ondemand -I /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp -R /github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp mathcomp ssreflect/seq.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.yXcQPp4hrx
MINIMIZER_DEBUG: files:  ssreflect/seq.v
File "./ssreflect/seq.v", line 4456, characters 0-99:
Error:
Unexpected type constraint in notation already providing a type constraint.

Command exited with non-zero status 1
ssreflect/seq.vo (real: 3.91, user: 3.78, sys: 0.12, mem: 541804 ko)
make[3]: *** [Makefile.coq:818: ssreflect/seq.vo] Error 1
make[3]: *** [ssreflect/seq.vo] Deleting file 'ssreflect/seq.glob'
make[2]: *** [Makefile.coq:417: all] Error 2
make[1]: *** [Makefile.common:99: this-build] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/mathcomp/mathcomp'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real mathcomp.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m03.91s | 541804 ko | Total Time / Peak Mem
--------------------------------------------
0m03.91s | 541804 ko | ssreflect/seq.vo     
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-mathcomp] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 405KiB file on GitHub Actions Artifacts under bug.log)
sful.�[0m

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Qed Obligation with Admit Obligations
�[92m
Admitting Qed Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qed Obligations unsuccessful.
No successful changes.

I will now attempt to replace Qeds with Admitteds
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to replace Qeds with admit. Defined.
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  The alternate coqc (/github/workspace/builds/coq/coq-passing/_install_ci/bin/coqc.orig) was supposed to pass, but instead emitted an error.  
The new error was:
File "/tmp/tmpxtqvmqm8/seq.v", line 26, characters 0-108:
Warning: Notation mixin_of is deprecated since mathcomp 2.0.0.
use the factory instead
[deprecated-syntactic-definition-since-mathcomp-2.0.0,deprecated-since-mathcomp-2.0.0,deprecated-syntactic-definition,deprecated,default]
File "/tmp/tmpxtqvmqm8/seq.v", line 26, characters 0-108:
Warning: Notation Mixin is deprecated since mathcomp 2.0.0.
use the F.Build instead
[deprecated-syntactic-definition-since-mathcomp-2.0.0,deprecated-since-mathcomp-2.0.0,deprecated-syntactic-definition,deprecated,default]
File "/tmp/tmpxtqvmqm8/seq.v", line 26, characters 0-108:
Warning: Notation mcpack is deprecated since mathcomp 2.0.0.
use native HB Structure.pack instead
[deprecated-syntactic-definition-since-mathcomp-2.0.0,deprecated-since-mathcomp-2.0.0,deprecated-syntactic-definition,deprecated,default]
File "/tmp/tmpxtqvmqm8/seq.v", line 88, characters 0-20:
Warning: Interpreting this declaration as if a global declaration prefixed by
"Local", i.e. as a global declaration which shall not be available without
qualification when imported. [local-declaration,vernacular,default]
File "/tmp/tmpxtqvmqm8/seq.v", line 92, characters 40-49:
Error:
In environment
bs : seq (T * nat)
The term "unzip1 bs" has type "seq T" while it is expected to have type
 "nat".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpkvtl1coa/mathcomp/ssreflect/seq.v", line 43, characters 26-32:
Error: The reference eqType was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...
�[92m
Succeeded in stripping newlines and spaces.�[0m

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

cc @JasonGross

Copy link
Contributor

coqbot-app bot commented May 6, 2024

Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris/algebra/view.v (from ci-perennial) (full log on GitHub Actions - verbose log)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

🌟 Minimized Coq File (consider adding this file to the test-suite)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-w" "-ssr-search-moved" "-w" "+deprecated-instance-without-locality" "-w" "-future-coercion-class-field" "-w" "+deprecated-hint-rewrite-without-locality" "-w" "-deprecated-field-instance-without-locality" "-w" "+deprecated-tactic-notation" "-w" "-deprecated-since-8.19" "-w" "-deprecated-since-8.20" "-w" "-notation-overridden,-redundant-canonical-projection,-deprecated-typeclasses-transparency-without-locality" "-w" "-deprecated-native-compiler-option,-native-compiler-disabled" "-native-compiler" "ondemand" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/src" "Perennial" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp" "stdpp" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_unstable" "stdpp.unstable" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_bitvector" "stdpp.bitvector" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris" "iris" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_deprecated" "iris.deprecated" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_unstable" "iris.unstable" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_heap_lang" "iris.heap_lang" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coqutil/src/coqutil" "coqutil" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/Goose" "Goose" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/record-update/src" "RecordUpdate" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coq-tactical/src" "Tactical" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris-named-props/src" "iris_named_props" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "iris.algebra.view") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 702 lines to 65 lines, then from 78 lines to 1129 lines, then from 1133 lines to 74 lines, then from 87 lines to 490 lines, then from 495 lines to 77 lines, then from 90 lines to 385 lines, then from 390 lines to 81 lines, then from 94 lines to 2144 lines, then from 2149 lines to 196 lines, then from 209 lines to 323 lines, then from 328 lines to 204 lines, then from 217 lines to 2215 lines, then from 2217 lines to 232 lines, then from 245 lines to 307 lines, then from 312 lines to 232 lines, then from 245 lines to 311 lines, then from 316 lines to 232 lines, then from 245 lines to 310 lines, then from 315 lines to 232 lines, then from 245 lines to 635 lines, then from 640 lines to 232 lines, then from 245 lines to 660 lines, then from 665 lines to 232 lines, then from 245 lines to 5699 lines, then from 5704 lines to 240 lines, then from 253 lines to 1931 lines, then from 1935 lines to 244 lines, then from 257 lines to 796 lines, then from 801 lines to 250 lines, then from 263 lines to 1197 lines, then from 1200 lines to 249 lines, then from 262 lines to 552 lines, then from 557 lines to 266 lines, then from 279 lines to 348 lines, then from 353 lines to 277 lines, then from 290 lines to 1931 lines, then from 1931 lines to 327 lines, then from 332 lines to 328 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.14.1
   coqtop version runner-t7b1znuaq-project-4504-concurrent-1:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4c) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 0.281 sec *)

Require Coq.QArith.Qcanon.
Require Coq.Unicode.Utf8.

Module Export stdpp_DOT_base_WRAPPED.
Module Export base.
Export Coq.Classes.Morphisms.
Export Coq.Lists.List.
Export Coq.Setoids.Setoid.
Export Coq.Init.Peano.
Export Coq.Unicode.Utf8.
Export ListNotations.
Export Coq.Program.Basics.

Global Generalizable All Variables.

Declare Scope stdpp_scope.
Global Open Scope stdpp_scope.

Notation "(=)" := eq (only parsing) : stdpp_scope.
Notation "(=@{ A } )" := (@eq A) (only parsing) : stdpp_scope.

Class Equiv A := equiv: relation A.

Infix "≡" := equiv (at level 70, no associativity) : stdpp_scope.
Infix "≡@{ A }" := (@equiv A _)
  (at level 70, only parsing, no associativity) : stdpp_scope.

Notation "(≡)" := equiv (only parsing) : stdpp_scope.

Notation "(≡@{ A } )" := (@equiv A _) (only parsing) : stdpp_scope.

Class Decision (P : Prop) := decide : {P} + {¬P}.
Global Arguments decide _ {_} : simpl never, assert.

Class RelDecision {A B} (R : A → B → Prop) :=
  decide_rel x y :: Decision (R x y).
Notation EqDecision A := (RelDecision (=@{A})).

Class Inj {A B} (R : relation A) (S : relation B) (f : A → B) : Prop :=
  inj x y : S (f x) (f y) → R x y.
Class Comm {A B} (R : relation A) (f : B → B → A) : Prop :=
  comm x y : R (f x y) (f y x).
Class LeftId {A} (R : relation A) (i : A) (f : A → A → A) : Prop :=
  left_id x : R (f i x) x.
Class Assoc {A} (R : relation A) (f : A → A → A) : Prop :=
  assoc x y z : R (f x (f y z)) (f (f x y) z).

End base.
Module Export stdpp.
Module Export base.
Include stdpp_DOT_base_WRAPPED.base.
End base.

Module Export stdpp_DOT_proof_irrel_WRAPPED.
Module Export proof_irrel.

Export stdpp.base.

End proof_irrel.
Module Export stdpp.
Module Export proof_irrel.
Include stdpp_DOT_proof_irrel_WRAPPED.proof_irrel.
End proof_irrel.

Module Export stdpp_DOT_decidable_WRAPPED.
Module Export decidable.

Export stdpp.proof_irrel.
Notation cast_if S := (if S then left _ else right _).

Program Definition inj_eq_dec `{EqDecision A} {B} (f : B → A)
  `{!Inj (=) (=) f} : EqDecision B := λ x y, cast_if (decide (f x = f y)).
Solve Obligations with firstorder congruence.
Definition bool_decide (P : Prop) {dec : Decision P} : bool.
Admitted.

End decidable.
Module Export stdpp.
Module Export decidable.
Include stdpp_DOT_decidable_WRAPPED.decidable.
End decidable.

Global Instance option_equiv `{Equiv A} : Equiv (option A).
Admitted.

Import Coq.QArith.Qcanon.
Export stdpp.decidable.

Record Qp := mk_Qp { Qp_to_Qc : Qc ; Qp_prf : (0 < Qp_to_Qc)%Qc }.

Section general_properties.
Context {A : Type}.
Implicit Types l k : list A.
Global Instance list_eq_nil_dec l : Decision (l = []).
Admitted.

End general_properties.

Class Dist A := dist : nat → relation A.
Notation "x ≡{ n }≡ y" := (dist n x y)
  (at level 70, n at next level, format "x  ≡{ n }≡  y").
Notation NonExpansive f := (∀ n, Proper (dist n ==> dist n) f).
Notation NonExpansive2 f := (∀ n, Proper (dist n ==> dist n ==> dist n) f).

Record OfeMixin A `{Equiv A, Dist A} := {
  mixin_equiv_dist (x y : A) : x ≡ y ↔ ∀ n, x ≡{n}≡ y;
  mixin_dist_equivalence n : Equivalence (@dist A _ n);
  mixin_dist_lt n m (x y : A) : x ≡{n}≡ y → m < n → x ≡{m}≡ y;
}.

Structure ofe := Ofe {
  ofe_car :> Type;
  ofe_equiv : Equiv ofe_car;
  ofe_dist : Dist ofe_car;
  ofe_mixin : OfeMixin ofe_car
}.
Global Arguments Ofe _ {_ _} _.

Global Hint Extern 0 (Equiv _) => refine (ofe_equiv _); shelve : typeclass_instances.
Global Hint Extern 0 (Dist _) => refine (ofe_dist _); shelve : typeclass_instances.
Definition ofe_mixin_of' A {Ac : ofe} (f : Ac → A) : OfeMixin Ac.
exact (ofe_mixin Ac).
Defined.
Notation ofe_mixin_of A :=
  ltac:(let H := eval hnf in (ofe_mixin_of' A id) in exact H) (only parsing).

Class Monoid {M : ofe} (o : M → M → M) := {
  monoid_unit : M;
  monoid_ne : NonExpansive2 o;
  monoid_assoc : Assoc (≡) o;
  monoid_comm : Comm (≡) o;
  monoid_left_id : LeftId (≡) monoid_unit o;
}.

Class PCore (A : Type) := pcore : A → option A.

Class Op (A : Type) := op : A → A → A.
Infix "⋅" := op (at level 50, left associativity) : stdpp_scope.
Notation "(⋅)" := op (only parsing) : stdpp_scope.

Definition included {A} `{!Equiv A, !Op A} (x y : A) := ∃ z, y ≡ x ⋅ z.
Infix "≼" := included (at level 70) : stdpp_scope.

Class ValidN (A : Type) := validN : nat → A → Prop.
Notation "✓{ n } x" := (validN n x)
  (at level 20, n at next level, format "✓{ n }  x").

Class Valid (A : Type) := valid : A → Prop.
Notation "✓ x" := (valid x) (at level 20) : stdpp_scope.

Definition includedN `{!Dist A, !Op A} (n : nat) (x y : A) := ∃ z, y ≡{n}≡ x ⋅ z.
Notation "x ≼{ n } y" := (includedN n x y)
  (at level 70, n at next level, format "x  ≼{ n }  y") : stdpp_scope.

Section mixin.
  Record CmraMixin A `{!Dist A, !Equiv A, !PCore A, !Op A, !Valid A, !ValidN A} := {

    mixin_cmra_op_ne (x : A) : NonExpansive (op x);
    mixin_cmra_pcore_ne n (x y : A) cx :
      x ≡{n}≡ y → pcore x = Some cx → ∃ cy, pcore y = Some cy ∧ cx ≡{n}≡ cy;
    mixin_cmra_validN_ne n : Proper (dist (A := A) n ==> impl) (validN n);

    mixin_cmra_valid_validN (x : A) : ✓ x ↔ ∀ n, ✓{n} x;
    mixin_cmra_validN_S n (x : A) : ✓{S n} x → ✓{n} x;

    mixin_cmra_assoc : Assoc (≡@{A}) (⋅);
    mixin_cmra_comm : Comm (≡@{A}) (⋅);
    mixin_cmra_pcore_l (x : A) cx : pcore x = Some cx → cx ⋅ x ≡ x;
    mixin_cmra_pcore_idemp (x : A) cx : pcore x = Some cx → pcore cx ≡ Some cx;
    mixin_cmra_pcore_mono (x y : A) cx :
      x ≼ y → pcore x = Some cx → ∃ cy, pcore y = Some cy ∧ cx ≼ cy;
    mixin_cmra_validN_op_l n (x y : A) : ✓{n} (x ⋅ y) → ✓{n} x;
    mixin_cmra_extend n (x y1 y2 : A) :
      ✓{n} x → x ≡{n}≡ y1 ⋅ y2 →
      { z1 : A & { z2 | x ≡ z1 ⋅ z2 ∧ z1 ≡{n}≡ y1 ∧ z2 ≡{n}≡ y2 } }
  }.
End mixin.

#[projections(primitive=no)]
Structure cmra := Cmra' {
  cmra_car :> Type;
  cmra_equiv : Equiv cmra_car;
  cmra_dist : Dist cmra_car;
  cmra_pcore : PCore cmra_car;
  cmra_op : Op cmra_car;
  cmra_valid : Valid cmra_car;
  cmra_validN : ValidN cmra_car;
  cmra_ofe_mixin : OfeMixin cmra_car;
  cmra_mixin : CmraMixin cmra_car;
}.
Global Arguments Cmra' _ {_ _ _ _ _ _} _ _.

Notation Cmra A m := (Cmra' A (ofe_mixin_of A%type) m) (only parsing).

Global Hint Extern 0 (PCore _) => refine (cmra_pcore _); shelve : typeclass_instances.
Global Hint Extern 0 (Op _) => refine (cmra_op _); shelve : typeclass_instances.
Global Hint Extern 0 (Valid _) => refine (cmra_valid _); shelve : typeclass_instances.
Global Hint Extern 0 (ValidN _) => refine (cmra_validN _); shelve : typeclass_instances.
Coercion cmra_ofeO (A : cmra) : ofe.
exact (Ofe A (cmra_ofe_mixin A)).
Defined.
Canonical Structure cmra_ofeO.
Definition cmra_mixin_of' A {Ac : cmra} (f : Ac → A) : CmraMixin Ac.
Admitted.
Notation cmra_mixin_of A :=
  ltac:(let H := eval hnf in (cmra_mixin_of' A id) in exact H) (only parsing).

Class Unit (A : Type) := ε : A.

Record UcmraMixin A `{!Dist A, !Equiv A, !PCore A, !Op A, !Valid A, !Unit A} := {
  mixin_ucmra_unit_valid : ✓ (ε : A);
  mixin_ucmra_unit_left_id : LeftId (≡@{A}) ε (⋅);
  mixin_ucmra_pcore_unit : pcore ε ≡@{option A} Some ε
}.

#[projections(primitive=no)]
Structure ucmra := Ucmra' {
  ucmra_car :> Type;
  ucmra_equiv : Equiv ucmra_car;
  ucmra_dist : Dist ucmra_car;
  ucmra_pcore : PCore ucmra_car;
  ucmra_op : Op ucmra_car;
  ucmra_valid : Valid ucmra_car;
  ucmra_validN : ValidN ucmra_car;
  ucmra_unit : Unit ucmra_car;
  ucmra_ofe_mixin : OfeMixin ucmra_car;
  ucmra_cmra_mixin : CmraMixin ucmra_car;
  ucmra_mixin : UcmraMixin ucmra_car;
}.
Global Arguments Ucmra' _ {_ _ _ _ _ _ _} _ _ _.
Notation Ucmra A m :=
  (Ucmra' A (ofe_mixin_of A%type) (cmra_mixin_of A%type) m) (only parsing).

Global Hint Extern 0 (Unit _) => refine (ucmra_unit _); shelve : typeclass_instances.
Coercion ucmra_ofeO (A : ucmra) : ofe.
exact (Ofe A (ucmra_ofe_mixin A)).
Defined.
Canonical Structure ucmra_ofeO.
Coercion ucmra_cmraR (A : ucmra) : cmra.
exact (Cmra' A (ucmra_ofe_mixin A) (ucmra_cmra_mixin A)).
Defined.
Canonical Structure ucmra_cmraR.

Section ucmra.
  Context {A : ucmra}.
Global Instance cmra_monoid : Monoid (@op A _).
Admitted.
End ucmra.

Inductive dfrac :=
  | DfracOwn : Qp → dfrac
  | DfracDiscarded : dfrac
  | DfracBoth : Qp → dfrac.

Record agree (A : Type) : Type := {
  agree_car : list A;
  agree_not_nil : bool_decide (agree_car = []) = false
}.

Fixpoint big_opL {M : ofe} {o : M → M → M} `{!Monoid o} {A} (f : nat → A → M) (xs : list A) : M :=
  match xs with
  | [] => monoid_unit
  | x :: xs => o (f 0 x) (big_opL (λ n, f (S n)) xs)
  end.
Global Arguments big_opL {M} o {_ A} _ !_ /.
Notation "'[^' o 'list]' k ↦ x ∈ l , P" := (big_opL o (λ k x, P) l)
  (at level 200, o at level 1, l at level 10, k, x at level 1, right associativity,
   format "[^ o  list]  k ↦ x  ∈  l ,  P") : stdpp_scope.

Structure view_rel (A : ofe) (B : ucmra) := ViewRel {
  view_rel_holds :> nat → A → B → Prop;
  view_rel_mono n1 n2 a1 a2 b1 b2 :
    view_rel_holds n1 a1 b1 →
    a1 ≡{n2}≡ a2 →
    b2 ≼{n2} b1 →
    n2 ≤ n1 →
    view_rel_holds n2 a2 b2;
  view_rel_validN n a b :
    view_rel_holds n a b → ✓{n} b;
  view_rel_unit n :
    ∃ a, view_rel_holds n a ε
}.

Record view {A B} (rel : nat → A → B → Prop) :=
  View { view_auth_proj : option (dfrac * agree A) ; view_frag_proj : B }.
Definition view_frag {A B} {rel : view_rel A B} (b : B) : view rel.
Admitted.
Notation "◯V a" := (view_frag a) (at level 20).

Section ofe.
  Context {A B : ofe} (rel : nat → A → B → Prop).
Local Instance view_equiv : Equiv (view rel).
Admitted.
Local Instance view_dist : Dist (view rel).
Admitted.

  Definition view_ofe_mixin : OfeMixin (view rel).
Admitted.
  Canonical Structure viewO := Ofe (view rel) view_ofe_mixin.
End ofe.

Section cmra.
  Context {A B} (rel : view_rel A B).
  Implicit Types x y : view rel.
Local Instance view_valid_instance : Valid (view rel).
Admitted.
Local Instance view_validN_instance : ValidN (view rel).
Admitted.
Local Instance view_pcore_instance : PCore (view rel).
Admitted.
Local Instance view_op_instance : Op (view rel).
Admitted.

  Lemma view_cmra_mixin : CmraMixin (view rel).
Admitted.
  Canonical Structure viewR := Cmra (view rel) view_cmra_mixin.
Local Instance view_empty_instance : Unit (view rel).
Admitted.
  Lemma view_ucmra_mixin : UcmraMixin (view rel).
Admitted.
  Canonical Structure viewUR := Ucmra (view rel) view_ucmra_mixin.

  Lemma big_opL_view_frag {C} (g : nat → C → B) (l : list C) :
    (◯V [^op list] k↦x ∈ l, g k x) ≡ [^op list] k↦x ∈ l, ◯V (g k x).
Admitted.
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 3.7MiB file on GitHub Actions Artifacts under build.log)
d_ci/perennial/external/record-update/src RecordUpdate -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coq-tactical/src Tactical -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris-named-props/src iris_named_props -o /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris/proofmode/class_instances_make.vo external/iris/iris/proofmode/class_instances_make.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.3xW1Bvc8CK
MINIMIZER_DEBUG: files:  external/iris/iris/proofmode/class_instances_make.v
COQC external/iris/iris/proofmode/proofmode.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/perennial
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/src Perennial -w -ssr-search-moved -w +deprecated-instance-without-locality -w -future-coercion-class-field -w +deprecated-hint-rewrite-without-locality -w -deprecated-field-instance-without-locality -w +deprecated-tactic-notation -w -deprecated-since-8.19 -w -deprecated-since-8.20 -w -notation-overridden\,-redundant-canonical-projection\,-deprecated-typeclasses-transparency-without-locality -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp stdpp -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_unstable stdpp.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_bitvector stdpp.bitvector -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris iris -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_deprecated iris.deprecated -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coqutil/src/coqutil coqutil -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/Goose Goose -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/record-update/src RecordUpdate -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coq-tactical/src Tactical -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris-named-props/src iris_named_props -o /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris/proofmode/proofmode.vo external/iris/iris/proofmode/proofmode.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.QrkVMT6ARH
MINIMIZER_DEBUG: files:  external/iris/iris/proofmode/proofmode.v
COQC external/iris/iris/proofmode/tactics.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/perennial
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/src Perennial -w -ssr-search-moved -w +deprecated-instance-without-locality -w -future-coercion-class-field -w +deprecated-hint-rewrite-without-locality -w -deprecated-field-instance-without-locality -w +deprecated-tactic-notation -w -deprecated-since-8.19 -w -deprecated-since-8.20 -w -notation-overridden\,-redundant-canonical-projection\,-deprecated-typeclasses-transparency-without-locality -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp stdpp -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_unstable stdpp.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_bitvector stdpp.bitvector -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris iris -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_deprecated iris.deprecated -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coqutil/src/coqutil coqutil -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/Goose Goose -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/record-update/src RecordUpdate -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coq-tactical/src Tactical -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris-named-props/src iris_named_props -o /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris/proofmode/tactics.vo external/iris/iris/proofmode/tactics.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.1bfpdXA4G5
MINIMIZER_DEBUG: files:  external/iris/iris/proofmode/tactics.v
COQC external/iris/iris/algebra/view.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/perennial
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/src Perennial -w -ssr-search-moved -w +deprecated-instance-without-locality -w -future-coercion-class-field -w +deprecated-hint-rewrite-without-locality -w -deprecated-field-instance-without-locality -w +deprecated-tactic-notation -w -deprecated-since-8.19 -w -deprecated-since-8.20 -w -notation-overridden\,-redundant-canonical-projection\,-deprecated-typeclasses-transparency-without-locality -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp stdpp -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_unstable stdpp.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/stdpp/stdpp_bitvector stdpp.bitvector -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris iris -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_deprecated iris.deprecated -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coqutil/src/coqutil coqutil -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/Goose Goose -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/record-update/src RecordUpdate -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/coq-tactical/src Tactical -Q /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris-named-props/src iris_named_props -o /github/workspace/builds/coq/coq-failing/_build_ci/perennial/external/iris/iris/algebra/view.vo external/iris/iris/algebra/view.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.dnCyF4fhjH
MINIMIZER_DEBUG: files:  external/iris/iris/algebra/view.v
File "./external/iris/iris/algebra/view.v", line 315, characters 38-39:
Error:
In environment
A : ofe
B : ucmra
rel : view_rel A B
C : Type
g : nat → C → B
l : list C
k : nat
x : view rel
The term "x" has type "view rel" while it is expected to have type "C".

make[1]: *** [Makefile:59: external/iris/iris/algebra/view.vo] Error 1
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/perennial'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real perennial.log
No timing data
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-perennial] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 582KiB file on GitHub Actions Artifacts under bug.log)
cessful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpy793e6ci/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpy793e6ci/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpa1edf_e9/iris/algebra/view.v", line 207, characters 0-9:
Warning:
New coercion path [cmra_ofeO; ofe_car] : cmra >-> Sortclass is ambiguous with existing 
[cmra_car] : cmra >-> Sortclass (reversible).
[ambiguous-paths,coercions,default]
File "/tmp/tmpa1edf_e9/iris/algebra/view.v", line 208, characters 0-30:
Error: Could not declare a canonical structure cmra_ofeO.
Could not find its value in the global environment.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpqg8v_s3g/iris/algebra/view.v", line 131, characters 0-8:
Error:  (in proof ofe_mixin_of'): Attempt to save an incomplete proof
(the proof term is not complete because of given up (admitted) goals).
If this is really what you want to do, use Admitted in place of Qed.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpy793e6ci/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...
�[92m
Succeeded in stripping newlines and spaces.�[0m

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 6, 2024

Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/iris/iris/algebra/view.v (from ci-iris) (full log on GitHub Actions - verbose log)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

🌟 Minimized Coq File (consider adding this file to the test-suite)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-notation-overridden" "-w" "-redundant-canonical-projection" "-w" "-unknown-warning" "-w" "-argument-scope-delimiter" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/prelude" "iris.prelude" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/algebra" "iris.algebra" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/si_logic" "iris.si_logic" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/bi" "iris.bi" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/proofmode" "iris.proofmode" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/base_logic" "iris.base_logic" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/program_logic" "iris.program_logic" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_heap_lang" "iris.heap_lang" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_unstable" "iris.unstable" "-Q" "/github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_deprecated" "iris.deprecated" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Autosubst" "Autosubst" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/stdpp" "stdpp" "-top" "iris.algebra.view") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 702 lines to 65 lines, then from 78 lines to 1129 lines, then from 1133 lines to 74 lines, then from 87 lines to 490 lines, then from 495 lines to 77 lines, then from 90 lines to 385 lines, then from 390 lines to 81 lines, then from 94 lines to 2144 lines, then from 2149 lines to 196 lines, then from 209 lines to 323 lines, then from 328 lines to 204 lines, then from 217 lines to 2215 lines, then from 2217 lines to 232 lines, then from 245 lines to 307 lines, then from 312 lines to 232 lines, then from 245 lines to 311 lines, then from 316 lines to 232 lines, then from 245 lines to 310 lines, then from 315 lines to 232 lines, then from 245 lines to 635 lines, then from 640 lines to 232 lines, then from 245 lines to 660 lines, then from 665 lines to 232 lines, then from 245 lines to 5699 lines, then from 5704 lines to 240 lines, then from 253 lines to 1931 lines, then from 1935 lines to 244 lines, then from 257 lines to 796 lines, then from 801 lines to 250 lines, then from 263 lines to 1197 lines, then from 1200 lines to 249 lines, then from 262 lines to 552 lines, then from 557 lines to 266 lines, then from 279 lines to 348 lines, then from 353 lines to 277 lines, then from 290 lines to 1931 lines, then from 1931 lines to 327 lines, then from 332 lines to 328 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.14.1
   coqtop version runner-t7b1znuaq-project-4504-concurrent-1:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4c) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 0.313 sec *)

Require Coq.QArith.Qcanon.
Require Coq.Unicode.Utf8.

Module Export stdpp_DOT_base_WRAPPED.
Module Export base.
Export Coq.Classes.Morphisms.
Export Coq.Lists.List.
Export Coq.Setoids.Setoid.
Export Coq.Init.Peano.
Export Coq.Unicode.Utf8.
Export ListNotations.
Export Coq.Program.Basics.

Global Generalizable All Variables.

Declare Scope stdpp_scope.
Global Open Scope stdpp_scope.

Notation "(=)" := eq (only parsing) : stdpp_scope.
Notation "(=@{ A } )" := (@eq A) (only parsing) : stdpp_scope.

Class Equiv A := equiv: relation A.

Infix "≡" := equiv (at level 70, no associativity) : stdpp_scope.
Infix "≡@{ A }" := (@equiv A _)
  (at level 70, only parsing, no associativity) : stdpp_scope.

Notation "(≡)" := equiv (only parsing) : stdpp_scope.

Notation "(≡@{ A } )" := (@equiv A _) (only parsing) : stdpp_scope.

Class Decision (P : Prop) := decide : {P} + {¬P}.
Global Arguments decide _ {_} : simpl never, assert.

Class RelDecision {A B} (R : A → B → Prop) :=
  decide_rel x y :: Decision (R x y).
Notation EqDecision A := (RelDecision (=@{A})).

Class Inj {A B} (R : relation A) (S : relation B) (f : A → B) : Prop :=
  inj x y : S (f x) (f y) → R x y.
Class Comm {A B} (R : relation A) (f : B → B → A) : Prop :=
  comm x y : R (f x y) (f y x).
Class LeftId {A} (R : relation A) (i : A) (f : A → A → A) : Prop :=
  left_id x : R (f i x) x.
Class Assoc {A} (R : relation A) (f : A → A → A) : Prop :=
  assoc x y z : R (f x (f y z)) (f (f x y) z).

End base.
Module Export stdpp.
Module Export base.
Include stdpp_DOT_base_WRAPPED.base.
End base.

Module Export stdpp_DOT_proof_irrel_WRAPPED.
Module Export proof_irrel.

Export stdpp.base.

End proof_irrel.
Module Export stdpp.
Module Export proof_irrel.
Include stdpp_DOT_proof_irrel_WRAPPED.proof_irrel.
End proof_irrel.

Module Export stdpp_DOT_decidable_WRAPPED.
Module Export decidable.

Export stdpp.proof_irrel.
Notation cast_if S := (if S then left _ else right _).

Program Definition inj_eq_dec `{EqDecision A} {B} (f : B → A)
  `{!Inj (=) (=) f} : EqDecision B := λ x y, cast_if (decide (f x = f y)).
Solve Obligations with firstorder congruence.
Definition bool_decide (P : Prop) {dec : Decision P} : bool.
Admitted.

End decidable.
Module Export stdpp.
Module Export decidable.
Include stdpp_DOT_decidable_WRAPPED.decidable.
End decidable.

Global Instance option_equiv `{Equiv A} : Equiv (option A).
Admitted.

Import Coq.QArith.Qcanon.
Export stdpp.decidable.

Record Qp := mk_Qp { Qp_to_Qc : Qc ; Qp_prf : (0 < Qp_to_Qc)%Qc }.

Section general_properties.
Context {A : Type}.
Implicit Types l k : list A.
Global Instance list_eq_nil_dec l : Decision (l = []).
Admitted.

End general_properties.

Class Dist A := dist : nat → relation A.
Notation "x ≡{ n }≡ y" := (dist n x y)
  (at level 70, n at next level, format "x  ≡{ n }≡  y").
Notation NonExpansive f := (∀ n, Proper (dist n ==> dist n) f).
Notation NonExpansive2 f := (∀ n, Proper (dist n ==> dist n ==> dist n) f).

Record OfeMixin A `{Equiv A, Dist A} := {
  mixin_equiv_dist (x y : A) : x ≡ y ↔ ∀ n, x ≡{n}≡ y;
  mixin_dist_equivalence n : Equivalence (@dist A _ n);
  mixin_dist_lt n m (x y : A) : x ≡{n}≡ y → m < n → x ≡{m}≡ y;
}.

Structure ofe := Ofe {
  ofe_car :> Type;
  ofe_equiv : Equiv ofe_car;
  ofe_dist : Dist ofe_car;
  ofe_mixin : OfeMixin ofe_car
}.
Global Arguments Ofe _ {_ _} _.

Global Hint Extern 0 (Equiv _) => refine (ofe_equiv _); shelve : typeclass_instances.
Global Hint Extern 0 (Dist _) => refine (ofe_dist _); shelve : typeclass_instances.
Definition ofe_mixin_of' A {Ac : ofe} (f : Ac → A) : OfeMixin Ac.
exact (ofe_mixin Ac).
Defined.
Notation ofe_mixin_of A :=
  ltac:(let H := eval hnf in (ofe_mixin_of' A id) in exact H) (only parsing).

Class Monoid {M : ofe} (o : M → M → M) := {
  monoid_unit : M;
  monoid_ne : NonExpansive2 o;
  monoid_assoc : Assoc (≡) o;
  monoid_comm : Comm (≡) o;
  monoid_left_id : LeftId (≡) monoid_unit o;
}.

Class PCore (A : Type) := pcore : A → option A.

Class Op (A : Type) := op : A → A → A.
Infix "⋅" := op (at level 50, left associativity) : stdpp_scope.
Notation "(⋅)" := op (only parsing) : stdpp_scope.

Definition included {A} `{!Equiv A, !Op A} (x y : A) := ∃ z, y ≡ x ⋅ z.
Infix "≼" := included (at level 70) : stdpp_scope.

Class ValidN (A : Type) := validN : nat → A → Prop.
Notation "✓{ n } x" := (validN n x)
  (at level 20, n at next level, format "✓{ n }  x").

Class Valid (A : Type) := valid : A → Prop.
Notation "✓ x" := (valid x) (at level 20) : stdpp_scope.

Definition includedN `{!Dist A, !Op A} (n : nat) (x y : A) := ∃ z, y ≡{n}≡ x ⋅ z.
Notation "x ≼{ n } y" := (includedN n x y)
  (at level 70, n at next level, format "x  ≼{ n }  y") : stdpp_scope.

Section mixin.
  Record CmraMixin A `{!Dist A, !Equiv A, !PCore A, !Op A, !Valid A, !ValidN A} := {

    mixin_cmra_op_ne (x : A) : NonExpansive (op x);
    mixin_cmra_pcore_ne n (x y : A) cx :
      x ≡{n}≡ y → pcore x = Some cx → ∃ cy, pcore y = Some cy ∧ cx ≡{n}≡ cy;
    mixin_cmra_validN_ne n : Proper (dist (A := A) n ==> impl) (validN n);

    mixin_cmra_valid_validN (x : A) : ✓ x ↔ ∀ n, ✓{n} x;
    mixin_cmra_validN_S n (x : A) : ✓{S n} x → ✓{n} x;

    mixin_cmra_assoc : Assoc (≡@{A}) (⋅);
    mixin_cmra_comm : Comm (≡@{A}) (⋅);
    mixin_cmra_pcore_l (x : A) cx : pcore x = Some cx → cx ⋅ x ≡ x;
    mixin_cmra_pcore_idemp (x : A) cx : pcore x = Some cx → pcore cx ≡ Some cx;
    mixin_cmra_pcore_mono (x y : A) cx :
      x ≼ y → pcore x = Some cx → ∃ cy, pcore y = Some cy ∧ cx ≼ cy;
    mixin_cmra_validN_op_l n (x y : A) : ✓{n} (x ⋅ y) → ✓{n} x;
    mixin_cmra_extend n (x y1 y2 : A) :
      ✓{n} x → x ≡{n}≡ y1 ⋅ y2 →
      { z1 : A & { z2 | x ≡ z1 ⋅ z2 ∧ z1 ≡{n}≡ y1 ∧ z2 ≡{n}≡ y2 } }
  }.
End mixin.

#[projections(primitive=no)]
Structure cmra := Cmra' {
  cmra_car :> Type;
  cmra_equiv : Equiv cmra_car;
  cmra_dist : Dist cmra_car;
  cmra_pcore : PCore cmra_car;
  cmra_op : Op cmra_car;
  cmra_valid : Valid cmra_car;
  cmra_validN : ValidN cmra_car;
  cmra_ofe_mixin : OfeMixin cmra_car;
  cmra_mixin : CmraMixin cmra_car;
}.
Global Arguments Cmra' _ {_ _ _ _ _ _} _ _.

Notation Cmra A m := (Cmra' A (ofe_mixin_of A%type) m) (only parsing).

Global Hint Extern 0 (PCore _) => refine (cmra_pcore _); shelve : typeclass_instances.
Global Hint Extern 0 (Op _) => refine (cmra_op _); shelve : typeclass_instances.
Global Hint Extern 0 (Valid _) => refine (cmra_valid _); shelve : typeclass_instances.
Global Hint Extern 0 (ValidN _) => refine (cmra_validN _); shelve : typeclass_instances.
Coercion cmra_ofeO (A : cmra) : ofe.
exact (Ofe A (cmra_ofe_mixin A)).
Defined.
Canonical Structure cmra_ofeO.
Definition cmra_mixin_of' A {Ac : cmra} (f : Ac → A) : CmraMixin Ac.
Admitted.
Notation cmra_mixin_of A :=
  ltac:(let H := eval hnf in (cmra_mixin_of' A id) in exact H) (only parsing).

Class Unit (A : Type) := ε : A.

Record UcmraMixin A `{!Dist A, !Equiv A, !PCore A, !Op A, !Valid A, !Unit A} := {
  mixin_ucmra_unit_valid : ✓ (ε : A);
  mixin_ucmra_unit_left_id : LeftId (≡@{A}) ε (⋅);
  mixin_ucmra_pcore_unit : pcore ε ≡@{option A} Some ε
}.

#[projections(primitive=no)]
Structure ucmra := Ucmra' {
  ucmra_car :> Type;
  ucmra_equiv : Equiv ucmra_car;
  ucmra_dist : Dist ucmra_car;
  ucmra_pcore : PCore ucmra_car;
  ucmra_op : Op ucmra_car;
  ucmra_valid : Valid ucmra_car;
  ucmra_validN : ValidN ucmra_car;
  ucmra_unit : Unit ucmra_car;
  ucmra_ofe_mixin : OfeMixin ucmra_car;
  ucmra_cmra_mixin : CmraMixin ucmra_car;
  ucmra_mixin : UcmraMixin ucmra_car;
}.
Global Arguments Ucmra' _ {_ _ _ _ _ _ _} _ _ _.
Notation Ucmra A m :=
  (Ucmra' A (ofe_mixin_of A%type) (cmra_mixin_of A%type) m) (only parsing).

Global Hint Extern 0 (Unit _) => refine (ucmra_unit _); shelve : typeclass_instances.
Coercion ucmra_ofeO (A : ucmra) : ofe.
exact (Ofe A (ucmra_ofe_mixin A)).
Defined.
Canonical Structure ucmra_ofeO.
Coercion ucmra_cmraR (A : ucmra) : cmra.
exact (Cmra' A (ucmra_ofe_mixin A) (ucmra_cmra_mixin A)).
Defined.
Canonical Structure ucmra_cmraR.

Section ucmra.
  Context {A : ucmra}.
Global Instance cmra_monoid : Monoid (@op A _).
Admitted.
End ucmra.

Inductive dfrac :=
  | DfracOwn : Qp → dfrac
  | DfracDiscarded : dfrac
  | DfracBoth : Qp → dfrac.

Record agree (A : Type) : Type := {
  agree_car : list A;
  agree_not_nil : bool_decide (agree_car = []) = false
}.

Fixpoint big_opL {M : ofe} {o : M → M → M} `{!Monoid o} {A} (f : nat → A → M) (xs : list A) : M :=
  match xs with
  | [] => monoid_unit
  | x :: xs => o (f 0 x) (big_opL (λ n, f (S n)) xs)
  end.
Global Arguments big_opL {M} o {_ A} _ !_ /.
Notation "'[^' o 'list]' k ↦ x ∈ l , P" := (big_opL o (λ k x, P) l)
  (at level 200, o at level 1, l at level 10, k, x at level 1, right associativity,
   format "[^ o  list]  k ↦ x  ∈  l ,  P") : stdpp_scope.

Structure view_rel (A : ofe) (B : ucmra) := ViewRel {
  view_rel_holds :> nat → A → B → Prop;
  view_rel_mono n1 n2 a1 a2 b1 b2 :
    view_rel_holds n1 a1 b1 →
    a1 ≡{n2}≡ a2 →
    b2 ≼{n2} b1 →
    n2 ≤ n1 →
    view_rel_holds n2 a2 b2;
  view_rel_validN n a b :
    view_rel_holds n a b → ✓{n} b;
  view_rel_unit n :
    ∃ a, view_rel_holds n a ε
}.

Record view {A B} (rel : nat → A → B → Prop) :=
  View { view_auth_proj : option (dfrac * agree A) ; view_frag_proj : B }.
Definition view_frag {A B} {rel : view_rel A B} (b : B) : view rel.
Admitted.
Notation "◯V a" := (view_frag a) (at level 20).

Section ofe.
  Context {A B : ofe} (rel : nat → A → B → Prop).
Local Instance view_equiv : Equiv (view rel).
Admitted.
Local Instance view_dist : Dist (view rel).
Admitted.

  Definition view_ofe_mixin : OfeMixin (view rel).
Admitted.
  Canonical Structure viewO := Ofe (view rel) view_ofe_mixin.
End ofe.

Section cmra.
  Context {A B} (rel : view_rel A B).
  Implicit Types x y : view rel.
Local Instance view_valid_instance : Valid (view rel).
Admitted.
Local Instance view_validN_instance : ValidN (view rel).
Admitted.
Local Instance view_pcore_instance : PCore (view rel).
Admitted.
Local Instance view_op_instance : Op (view rel).
Admitted.

  Lemma view_cmra_mixin : CmraMixin (view rel).
Admitted.
  Canonical Structure viewR := Cmra (view rel) view_cmra_mixin.
Local Instance view_empty_instance : Unit (view rel).
Admitted.
  Lemma view_ucmra_mixin : UcmraMixin (view rel).
Admitted.
  Canonical Structure viewUR := Ucmra (view rel) view_ucmra_mixin.

  Lemma big_opL_view_frag {C} (g : nat → C → B) (l : list C) :
    (◯V [^op list] k↦x ∈ l, g k x) ≡ [^op list] k↦x ∈ l, ◯V (g k x).
Admitted.
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 3.9MiB file on GitHub Actions Artifacts under build.log)
ub/workspace/builds/coq/coq-failing/_build_ci/iris/iris/si_logic iris.si_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/bi iris.bi -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/proofmode iris.proofmode -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/base_logic iris.base_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/program_logic iris.program_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_deprecated iris.deprecated iris/proofmode/classes.vo 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.K4H6Cm14BG
MINIMIZER_DEBUG: files: 
iris/proofmode/classes.vo.native (real: 0.58, user: 0.46, sys: 0.11, mem: 156484 ko)
COQC iris/base_logic/proofmode.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/iris
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -notation-overridden -w -redundant-canonical-projection -w -unknown-warning -w -argument-scope-delimiter -w -deprecated-native-compiler-option -native-compiler ondemand -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/prelude iris.prelude -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/algebra iris.algebra -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/si_logic iris.si_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/bi iris.bi -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/proofmode iris.proofmode -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/base_logic iris.base_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/program_logic iris.program_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_deprecated iris.deprecated iris/base_logic/proofmode.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.uR88ZdZfrK
MINIMIZER_DEBUG: files:  iris/base_logic/proofmode.v
iris/base_logic/proofmode.vo (real: 0.94, user: 0.81, sys: 0.12, mem: 555980 ko)
COQNATIVE iris/base_logic/proofmode.vo
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqnative
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/iris
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqnative.orig -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/prelude iris.prelude -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/algebra iris.algebra -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/si_logic iris.si_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/bi iris.bi -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/proofmode iris.proofmode -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/base_logic iris.base_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/program_logic iris.program_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_deprecated iris.deprecated iris/base_logic/proofmode.vo 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.SXqteCXbyr
MINIMIZER_DEBUG: files: 
iris/base_logic/proofmode.vo.native (real: 0.46, user: 0.39, sys: 0.06, mem: 160936 ko)
COQC iris/algebra/view.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/iris
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -notation-overridden -w -redundant-canonical-projection -w -unknown-warning -w -argument-scope-delimiter -w -deprecated-native-compiler-option -native-compiler ondemand -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/prelude iris.prelude -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/algebra iris.algebra -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/si_logic iris.si_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/bi iris.bi -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/proofmode iris.proofmode -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/base_logic iris.base_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris/program_logic iris.program_logic -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_heap_lang iris.heap_lang -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_unstable iris.unstable -Q /github/workspace/builds/coq/coq-failing/_build_ci/iris/iris_deprecated iris.deprecated iris/algebra/view.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.GknjFj21aQ
MINIMIZER_DEBUG: files:  iris/algebra/view.v
File "./iris/algebra/view.v", line 315, characters 38-39:
Error:
In environment
A : ofe
B : ucmra
rel : view_rel A B
C : Type
g : nat → C → B
l : list C
k : nat
x : view rel
The term "x" has type "view rel" while it is expected to have type "C".

Command exited with non-zero status 1
iris/algebra/view.vo (real: 1.62, user: 1.48, sys: 0.13, mem: 551516 ko)
make[3]: *** [Makefile.coq:818: iris/algebra/view.vo] Error 1
make[3]: *** [iris/algebra/view.vo] Deleting file 'iris/algebra/view.glob'
make[2]: *** [Makefile.coq:417: all] Error 2
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/iris'
make[1]: *** [Makefile:3: all] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/iris'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real iris.log
    Time |  Peak Mem | File Name                          
----------------------------------------------------------
0m39.61s | 711664 ko | Total Time / Peak Mem              
----------------------------------------------------------
0m12.13s | 711664 ko | iris/bi/big_op.vo                  
0m03.78s | 564264 ko | iris/algebra/gmap.vo               
0m03.36s | 563084 ko | iris/bi/plainly.vo                 
0m02.63s | 556136 ko | iris/bi/updates.vo                 
0m02.24s | 546412 ko | iris/bi/internal_eq.vo             
0m01.95s | 553472 ko | iris/bi/embedding.vo               
0m01.62s | 551516 ko | iris/algebra/view.vo               
0m01.18s | 562632 ko | iris/proofmode/classes.vo          
0m01.12s | 548884 ko | iris/base_logic/derived.vo         
0m00.94s | 555980 ko | iris/base_logic/proofmode.vo       
0m00.90s | 540812 ko | iris/proofmode/modalities.vo       
0m00.70s | 147444 ko | iris/bi/big_op.vo.native           
0m00.67s | 542020 ko | iris/base_logic/bi.vo              
0m00.63s | 152164 ko | iris/bi/updates.vo.native          
0m00.59s | 144440 ko | iris/algebra/gmap.vo.native        
0m00.58s | 536284 ko | iris/bi/bi.vo                      
0m00.58s | 156484 ko | iris/proofmode/classes.vo.native   
0m00.56s | 154160 ko | iris/proofmode/modalities.vo.native
0m00.55s | 149384 ko | iris/bi/plainly.vo.native          
0m00.54s | 147492 ko | iris/bi/embedding.vo.native        
0m00.51s | 156420 ko | iris/base_logic/derived.vo.native  
0m00.49s | 146408 ko | iris/base_logic/bi.vo.native       
0m00.47s | 145824 ko | iris/bi/internal_eq.vo.native      
0m00.46s | 160936 ko | iris/base_logic/proofmode.vo.native
0m00.43s | 150092 ko | iris/bi/bi.vo.native               
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-iris] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 584KiB file on GitHub Actions Artifacts under bug.log)
cessful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpa597inaa/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpa597inaa/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmppcn2s1zw/iris/algebra/view.v", line 207, characters 0-9:
Warning:
New coercion path [cmra_ofeO; ofe_car] : cmra >-> Sortclass is ambiguous with existing 
[cmra_car] : cmra >-> Sortclass (reversible).
[ambiguous-paths,coercions,default]
File "/tmp/tmppcn2s1zw/iris/algebra/view.v", line 208, characters 0-30:
Error: Could not declare a canonical structure cmra_ofeO.
Could not find its value in the global environment.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpn52posfp/iris/algebra/view.v", line 131, characters 0-8:
Error:  (in proof ofe_mixin_of'): Attempt to save an incomplete proof
(the proof term is not complete because of given up (admitted) goals).
If this is really what you want to do, use Admitted in place of Qed.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpa597inaa/iris/algebra/view.v", line 168, characters 62-82:
Error: 
Could not find an instance for "Equiv (option A)" in
environment:
CmraMixin :
  ∀ A : Type, Dist A → Equiv A → PCore A → Op A → Valid A → ValidN A → Type
A : Type
Dist0 : Dist A
Equiv0 : Equiv A
PCore0 : PCore A
Op0 : Op A
Valid0 : Valid A
ValidN0 : ValidN A
mixin_cmra_op_ne : ∀ (x : A) (n : nat), Proper (dist n ==> dist n) (op x)
mixin_cmra_pcore_ne :
  ∀ (n : nat) (x y cx : A),
    x ≡{n}≡ y → pcore x = Some cx → ∃ cy : A, pcore y = Some cy ∧ cx ≡{n}≡ cy
mixin_cmra_validN_ne : ∀ n : nat, Proper (dist n ==> impl) (validN n)
mixin_cmra_valid_validN : ∀ x : A, ✓ x ↔ ∀ n : nat, ✓{n} x
mixin_cmra_validN_S : ∀ (n : nat) (x : A), ✓{S n} x → ✓{n} x
mixin_cmra_assoc : Assoc equiv op
mixin_cmra_comm : Comm equiv op
mixin_cmra_pcore_l : ∀ x cx : A, pcore x = Some cx → cx ⋅ x ≡ x
x, cx : A



�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
Error: The section cmra, module stdpp, module stdpp_DOT_decidable_WRAPPED,
module stdpp, module stdpp_DOT_proof_irrel_WRAPPED, module stdpp and module
stdpp_DOT_base_WRAPPED need to be closed.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...
�[92m
Succeeded in stripping newlines and spaces.�[0m

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 7, 2024

Minimization interrupted by timeout, being automatically continued. Partially Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories/PCUICSafeChecker.v (from ci-metacoq) (interrupted by timeout, being automatically continued) (full log on GitHub Actions - verbose log)
⭐ ⏱️ Partially Minimized Coq File (timeout)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-deprecated-native-compiler-option" "-native-compiler" "no" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories" "MetaCoq.Utils" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories" "MetaCoq.Common" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories" "MetaCoq.PCUIC" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories" "MetaCoq.SafeChecker" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Equations" "Equations" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "MetaCoq.SafeChecker.PCUICSafeChecker") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 2560 lines to 33 lines, then from 46 lines to 622 lines, then from 625 lines to 113 lines, then from 126 lines to 1493 lines, then from 1494 lines to 115 lines, then from 128 lines to 821 lines, then from 825 lines to 280 lines, then from 293 lines to 710 lines, then from 715 lines to 282 lines, then from 295 lines to 1746 lines, then from 1751 lines to 545 lines, then from 558 lines to 1457 lines, then from 1461 lines to 711 lines, then from 724 lines to 2544 lines, then from 2543 lines to 722 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.09.0
   coqtop version runner-t7b1znuaq-project-4504-concurrent-4:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 2.158 sec *)
Require MetaCoq.PCUIC.PCUICEquality.
Import Coq.ssr.ssrbool.
Import MetaCoq.Utils.utils.
Import MetaCoq.PCUIC.PCUICAst.

Definition shiftnP k p i :=
  (i <? k) || p (i - k).
Fixpoint on_free_vars (p : nat -> bool) (t : term) : bool.
Admitted.

Definition on_free_vars_decl P d :=
  test_decl (on_free_vars P) d.

Definition on_free_vars_ctx P ctx :=
  alli (fun k => (on_free_vars_decl (shiftnP k P))) 0 (List.rev ctx).

Notation is_open_term Γ := (on_free_vars (shiftnP #|Γ| xpred0)).
Notation is_closed_context := (on_free_vars_ctx xpred0).
Module Export PCUICCumulativitySpec.
Import MetaCoq.Common.config.
Import MetaCoq.PCUIC.PCUICEquality.
Import MetaCoq.PCUIC.Syntax.PCUICCases.

Implicit Types (cf : checker_flags).

Definition cumul_predicate (cumul : context -> term -> term -> Type) cumul_universe Γ p p' :=
  All2 (cumul Γ) p.(pparams) p'.(pparams) ×
  cmp_universe_instance cumul_universe p.(puinst) p'.(puinst) ×
  eq_context_upto_names p.(pcontext) p'.(pcontext) ×
  cumul (Γ ,,, inst_case_predicate_context p) p.(preturn) p'.(preturn).

Definition cumul_branch (cumul_term : context -> term -> term -> Type) Γ p br br' :=
  eq_context_upto_names br.(bcontext) br'.(bcontext) ×
  cumul_term (Γ ,,, inst_case_branch_context p br) br.(bbody) br'.(bbody).

Definition cumul_branches cumul_term Γ p brs brs' := All2 (cumul_branch cumul_term Γ p) brs brs'.

Definition cumul_mfixpoint (cumul_term : context -> term -> term -> Type) Γ mfix mfix' :=
  All2 (fun d d' =>
    cumul_term Γ d.(dtype) d'.(dtype) ×
    cumul_term (Γ ,,, fix_context mfix) d.(dbody) d'.(dbody) ×
    d.(rarg) = d'.(rarg) ×
    eq_binder_annot d.(dname) d'.(dname)
  ) mfix mfix'.

Reserved Notation " Σ ;;; Γ ⊢ t ≤s[ pb ] u" (at level 50, Γ, t, u at next level,
  format "Σ  ;;;  Γ  ⊢  t  ≤s[ pb ]  u").

Definition cumul_Ind_univ {cf} (Σ : global_env_ext) pb i napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (IndRef i) napp.

Definition cumul_Construct_univ {cf} (Σ : global_env_ext) pb  i k napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (ConstructRef i k) napp.
Inductive cumulSpec0 {cf : checker_flags} (Σ : global_env_ext) Γ (pb : conv_pb) : term -> term -> Type :=

| cumul_Trans : forall t u v,
    is_closed_context Γ -> is_open_term Γ u ->
    Σ ;;; Γ ⊢ t ≤s[pb] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] v ->
    Σ ;;; Γ ⊢ t ≤s[pb] v

| cumul_Sym : forall t u,
    Σ ;;; Γ ⊢ t ≤s[Conv] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] t

| cumul_Refl : forall t,
    Σ ;;; Γ ⊢ t ≤s[pb] t

| cumul_Ind : forall i u u' args args',
    cumul_Ind_univ Σ pb i #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tInd i u) args ≤s[pb] mkApps (tInd i u') args'

| cumul_Construct : forall i k u u' args args',
    cumul_Construct_univ Σ pb i k #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tConstruct i k u) args ≤s[pb] mkApps (tConstruct i k u') args'

| cumul_Sort : forall s s',
    compare_sort Σ pb s s' ->
    Σ ;;; Γ ⊢ tSort s ≤s[pb] tSort s'

| cumul_Const : forall c u u',
    cmp_universe_instance (compare_universe Σ Conv) u u' ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] tConst c u'

| cumul_Evar : forall e args args',
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ tEvar e args ≤s[pb] tEvar e args'

| cumul_App : forall t t' u u',
    Σ ;;; Γ ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ u ≤s[Conv] u' ->
    Σ ;;; Γ ⊢ tApp t u ≤s[pb] tApp t' u'

| cumul_Lambda : forall na na' ty ty' t t',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vass na ty ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ tLambda na ty t ≤s[pb] tLambda na' ty' t'

| cumul_Prod : forall na na' a a' b b',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ a ≤s[Conv] a' ->
    Σ ;;; Γ ,, vass na a ⊢ b ≤s[pb] b' ->
    Σ ;;; Γ ⊢ tProd na a b ≤s[pb] tProd na' a' b'

| cumul_LetIn : forall na na' t t' ty ty' u u',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ t ≤s[Conv] t' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vdef na t ty ⊢ u ≤s[pb] u' ->
    Σ ;;; Γ ⊢ tLetIn na t ty u ≤s[pb] tLetIn na' t' ty' u'

| cumul_Case indn : forall p p' c c' brs brs',
    cumul_predicate (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) (compare_universe Σ Conv) Γ p p' ->
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    cumul_branches (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ p brs brs' ->
    Σ ;;; Γ ⊢ tCase indn p c brs ≤s[pb] tCase indn p' c' brs'

| cumul_Proj : forall p c c',
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    Σ ;;; Γ ⊢ tProj p c ≤s[pb] tProj p c'

| cumul_Fix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tFix mfix idx ≤s[pb] tFix mfix' idx

| cumul_CoFix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tCoFix mfix idx ≤s[pb] tCoFix mfix' idx

| cumul_Prim p p' :
  onPrims (fun x y => Σ ;;; Γ ⊢ x ≤s[Conv] y) (compare_universe Σ Conv) p p' ->
  Σ ;;; Γ ⊢ tPrim p ≤s[pb] tPrim p'

| cumul_beta : forall na t b a,
    Σ ;;; Γ ⊢ tApp (tLambda na t b) a ≤s[pb] b {0 := a}

| cumul_zeta : forall na b t b',
    Σ ;;; Γ ⊢ tLetIn na b t b' ≤s[pb] b' {0 := b}

| cumul_rel i body :
    option_map decl_body (nth_error Γ i) = Some (Some body) ->
    Σ ;;; Γ ⊢ tRel i ≤s[pb] lift0 (S i) body

| cumul_iota : forall ci c u args p brs br,
    nth_error brs c = Some br ->
    #|args| = (ci.(ci_npar) + context_assumptions br.(bcontext))%nat ->
    Σ ;;; Γ ⊢ tCase ci p (mkApps (tConstruct ci.(ci_ind) c u) args) brs  ≤s[pb] iota_red ci.(ci_npar) p args br

| cumul_fix : forall mfix idx args narg fn,
    unfold_fix mfix idx = Some (narg, fn) ->
    is_constructor narg args = true ->
    Σ ;;; Γ ⊢ mkApps (tFix mfix idx) args ≤s[pb] mkApps fn args

| cumul_cofix_case : forall ip p mfix idx args narg fn brs,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tCase ip p (mkApps (tCoFix mfix idx) args) brs ≤s[pb] tCase ip p (mkApps fn args) brs

| cumul_cofix_proj : forall p mfix idx args narg fn,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tCoFix mfix idx) args) ≤s[pb] tProj p (mkApps fn args)

| cumul_delta : forall c decl body (isdecl : declared_constant Σ c decl) u,
    decl.(cst_body) = Some body ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] body@[u]

| cumul_proj : forall p args u arg,
    nth_error args (p.(proj_npars) + p.(proj_arg)) = Some arg ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tConstruct p.(proj_ind) 0 u) args) ≤s[pb] arg

where " Σ ;;; Γ ⊢ t ≤s[ pb ] u " := (@cumulSpec0 _ Σ Γ pb t u) : type_scope.
Definition cumulSpec `{checker_flags} (Σ : global_env_ext) Γ := cumulSpec0 Σ Γ Cumul.

Notation " Σ ;;; Γ |- t <=s u " := (@cumulSpec _ Σ Γ t u) (at level 50, Γ, t, u at next level).

Module PCUICConversionParSpec <: EnvironmentTyping.ConversionParSig PCUICTerm PCUICEnvironment PCUICTermUtils PCUICEnvTyping.
  Definition cumul_gen := @cumulSpec0.
End PCUICConversionParSpec.

End PCUICCumulativitySpec.
Import MetaCoq.Common.config.
Import MetaCoq.PCUIC.utils.PCUICAstUtils.
Import MetaCoq.PCUIC.utils.PCUICPrimitive.
Import MetaCoq.PCUIC.PCUICEquality.
Export MetaCoq.PCUIC.Syntax.PCUICCases.

Implicit Types (cf : checker_flags) (Σ : global_env_ext).

Definition type_of_constructor mdecl (cdecl : constructor_body) (c : inductive * nat) (u : list Level.t) :=
  let mind := inductive_mind (fst c) in
  subst0 (inds mind u mdecl.(ind_bodies)) (subst_instance u (cstr_type cdecl)).

Include PCUICEnvTyping.

Inductive FixCoFix : Type := Fix | CoFix.

Class GuardChecker :=
{
  guard : FixCoFix -> global_env_ext -> context -> mfixpoint term -> Prop ;
}.

Axiom guard_checking : GuardChecker.
#[global]
Existing Instance guard_checking.

Definition fix_guard := guard Fix.
Definition cofix_guard := guard CoFix.

Definition destInd (t : term) :=
  match t with
  | tInd ind u => Some (ind, u)
  | _ => None
  end.

Definition isCoFinite (r : recursivity_kind) :=
  match r with
  | CoFinite => true
  | _ => false
  end.

Definition check_recursivity_kind
  (lookup: kername -> option global_decl) ind r :=
  match lookup ind with
  | Some (InductiveDecl mib) => ReflectEq.eqb mib.(ind_finite) r
  | _ => false
  end.

Definition check_one_fix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  match nth_error (List.rev (smash_context [] ctx)) arg with
  | Some argd =>
    let (hd, args) := decompose_app argd.(decl_type) in
    match destInd hd with
    | Some (mkInd mind _, u) => Some mind
    | None => None
    end
  | None => None
  end.

Definition wf_fixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  forallb (isLambda ∘ dbody) mfix &&
  let checks := map check_one_fix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind Finite
  | _ => false
  end.

Definition wf_fixpoint (Σ : global_env) := wf_fixpoint_gen (lookup_env Σ).

Definition check_one_cofix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  let (hd, args) := decompose_app ty in
  match destInd hd with
  | Some (mkInd ind _, u) => Some ind
  | None => None
  end.

Definition wf_cofixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  let checks := map check_one_cofix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind CoFinite
  | _ => false
  end.

Definition wf_cofixpoint (Σ : global_env) := wf_cofixpoint_gen (lookup_env Σ).

Reserved Notation "'wf_local' Σ Γ " (at level 9, Σ, Γ at next level).

Reserved Notation " Σ ;;; Γ |- t : T " (at level 50, Γ, t, T at next level).

Variant case_side_conditions `{checker_flags} wf_local_fun typing Σ Γ ci p ps mdecl idecl indices predctx :=
| case_side_info
    (eq_npars : mdecl.(ind_npars) = ci.(ci_npar))
    (wf_pred : wf_predicate mdecl idecl p)
    (cons : consistent_instance_ext Σ (ind_universes mdecl) p.(puinst))
    (wf_pctx : wf_local_fun Σ (Γ ,,, predctx))

    (conv_pctx : eq_context_upto_names p.(pcontext) (ind_predicate_context ci.(ci_ind) mdecl idecl))
    (allowed_elim : is_allowed_elimination Σ idecl.(ind_kelim) ps)
    (ind_inst : ctx_inst (typing Σ) Γ (p.(pparams) ++ indices)
                         (List.rev (subst_instance p.(puinst)
                                                   (ind_params mdecl ,,, ind_indices idecl : context))))
    (not_cofinite : isCoFinite mdecl.(ind_finite) = false).

Variant case_branch_typing `{checker_flags} wf_local_fun typing Σ Γ (ci:case_info) p ps mdecl idecl ptm  brs :=
| case_branch_info
    (wf_brs : wf_branches idecl brs)
    (brs_ty :
       All2i (fun i cdecl br =>

                eq_context_upto_names br.(bcontext) (cstr_branch_context ci mdecl cdecl) ×
                let brctxty := case_branch_type ci.(ci_ind) mdecl idecl p br ptm i cdecl in
                (wf_local_fun Σ (Γ ,,, brctxty.1) ×
                ((typing Σ (Γ ,,, brctxty.1) br.(bbody) (brctxty.2)) ×
                (typing Σ (Γ ,,, brctxty.1) brctxty.2 (tSort ps)))))
             0 idecl.(ind_ctors) brs).

Variant primitive_typing_hyps `{checker_flags}
  (typing : forall (Σ : global_env_ext) (Γ : context), term -> term -> Type)
  Σ Γ : prim_val term -> Type :=
| prim_int_hyps i : primitive_typing_hyps typing Σ Γ (primInt; primIntModel i)
| prim_float_hyps f : primitive_typing_hyps typing Σ Γ (primFloat; primFloatModel f)
| prim_array_hyps a
  (wfl : wf_universe Σ (Universe.make' a.(array_level)))
  (hty : typing Σ Γ a.(array_type) (tSort (sType (Universe.make' a.(array_level)))))
  (hdef : typing Σ Γ a.(array_default) a.(array_type))
  (hvalue : All (fun x => typing Σ Γ x a.(array_type)) a.(array_value)) :
  primitive_typing_hyps typing Σ Γ (primArray; primArrayModel a).

Equations prim_type (p : prim_val term) (cst : kername) : term :=
prim_type (primInt; _) cst := tConst cst [];
prim_type (primFloat; _) cst := tConst cst [];
prim_type (primArray; primArrayModel a) cst := tApp (tConst cst [a.(array_level)]) a.(array_type).

Inductive typing `{checker_flags} (Σ : global_env_ext) (Γ : context) : term -> term -> Type :=
| type_Rel : forall n decl,
    wf_local Σ Γ ->
    nth_error Γ n = Some decl ->
    Σ ;;; Γ |- tRel n : lift0 (S n) decl.(decl_type)

| type_Sort : forall s,
    wf_local Σ Γ ->
    wf_sort Σ s ->
    Σ ;;; Γ |- tSort s : tSort (Sort.super s)

| type_Prod : forall na A B s1 s2,
    lift_typing typing Σ Γ (j_vass_s na A s1) ->
    Σ ;;; Γ ,, vass na A |- B : tSort s2 ->
    Σ ;;; Γ |- tProd na A B : tSort (Sort.sort_of_product s1 s2)

| type_Lambda : forall na A t B,
    lift_typing typing Σ Γ (j_vass na A) ->
    Σ ;;; Γ ,, vass na A |- t : B ->
    Σ ;;; Γ |- tLambda na A t : tProd na A B

| type_LetIn : forall na b B t A,
    lift_typing typing Σ Γ (j_vdef na b B) ->
    Σ ;;; Γ ,, vdef na b B |- t : A ->
    Σ ;;; Γ |- tLetIn na b B t : tLetIn na b B A

| type_App : forall t na A B s u,

    Σ ;;; Γ |- tProd na A B : tSort s ->
    Σ ;;; Γ |- t : tProd na A B ->
    Σ ;;; Γ |- u : A ->
    Σ ;;; Γ |- tApp t u : B{0 := u}

| type_Const : forall cst u decl,
    wf_local Σ Γ ->
    declared_constant Σ cst decl ->
    consistent_instance_ext Σ decl.(cst_universes) u ->
    Σ ;;; Γ |- tConst cst u : decl.(cst_type)@[u]

| type_Ind : forall ind u mdecl idecl,
    wf_local Σ Γ ->
    declared_inductive Σ ind mdecl idecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tInd ind u : idecl.(ind_type)@[u]

| type_Construct : forall ind i u mdecl idecl cdecl,
    wf_local Σ Γ ->
    declared_constructor Σ (ind, i) mdecl idecl cdecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tConstruct ind i u : type_of_constructor mdecl cdecl (ind, i) u

| type_Case : forall ci p c brs indices ps mdecl idecl,
    let predctx := case_predicate_context ci.(ci_ind) mdecl idecl p in
    let ptm := it_mkLambda_or_LetIn predctx p.(preturn) in
    declared_inductive Σ ci.(ci_ind) mdecl idecl ->
    Σ ;;; Γ ,,, predctx |- p.(preturn) : tSort ps ->
    Σ ;;; Γ |- c : mkApps (tInd ci.(ci_ind) p.(puinst)) (p.(pparams) ++ indices) ->
    case_side_conditions (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                         mdecl idecl indices predctx  ->
    case_branch_typing (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                        mdecl idecl ptm brs ->
    Σ ;;; Γ |- tCase ci p c brs : mkApps ptm (indices ++ [c])

| type_Proj : forall p c u mdecl idecl cdecl pdecl args,
    declared_projection Σ p mdecl idecl cdecl pdecl ->
    Σ ;;; Γ |- c : mkApps (tInd p.(proj_ind) u) args ->
    #|args| = ind_npars mdecl ->
    Σ ;;; Γ |- tProj p c : subst0 (c :: List.rev args) pdecl.(proj_type)@[u]

| type_Fix : forall mfix n decl,
    wf_local Σ Γ ->
    fix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_fixpoint Σ mfix ->
    Σ ;;; Γ |- tFix mfix n : decl.(dtype)

| type_CoFix : forall mfix n decl,
    wf_local Σ Γ ->
    cofix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_cofixpoint Σ mfix ->
    Σ ;;; Γ |- tCoFix mfix n : decl.(dtype)

| type_Prim p prim_ty cdecl :
    wf_local Σ Γ ->
    primitive_constant Σ (prim_val_tag p) = Some prim_ty ->
    declared_constant Σ prim_ty cdecl ->
    primitive_invariants (prim_val_tag p) cdecl ->
    primitive_typing_hyps typing Σ Γ p ->
    Σ ;;; Γ |- tPrim p : prim_type p prim_ty

| type_Cumul : forall t A B s,
    Σ ;;; Γ |- t : A ->
    Σ ;;; Γ |- B : tSort s ->
    Σ ;;; Γ |- A <=s B ->
    Σ ;;; Γ |- t : B

where " Σ ;;; Γ |- t : T " := (typing Σ Γ t T)
and "'wf_local' Σ Γ " := (All_local_env (lift_typing1 (typing Σ)) Γ).

Module PCUICTypingDef <: EnvironmentTyping.Typing PCUICTerm PCUICEnvironment PCUICTermUtils PCUICEnvTyping PCUICConversion PCUICConversionParSpec.

  Definition typing := @typing.

End PCUICTypingDef.

Definition wf `{checker_flags} := on_global_env cumulSpec0 (lift_typing typing).

Definition wf_ext `{checker_flags} := on_global_env_ext cumulSpec0 (lift_typing typing).

Record normalizing_flags {cf : checker_flags} : Prop :=
  { nor_check_univs :> check_univs }.
Import MetaCoq.PCUIC.PCUICAst.

Inductive ConversionError :=
| NotFoundConstants (c1 c2 : kername)

| NotFoundConstant (c : kername)

| LambdaNotConvertibleTypes
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)
    (e : ConversionError)

| LambdaNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)

| ProdNotConvertibleDomains
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)
    (e : ConversionError)

| ProdNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)

| ContextNotConvertibleAnn
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleType
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleBody
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleLength

| CaseOnDifferentInd
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredParamsUnequalLength
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredUnequalUniverseInstances
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| DistinctStuckProj
    (Γ : context) (p : projection) (c : term)
    (Γ' : context) (p' : projection) (c' : term)

| CannotUnfoldFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| FixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| FixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctCoFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| CoFixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| CoFixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctPrimTags
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| DistinctPrimValues
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| ArrayNotConvertibleLevels
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayValuesNotSameLength
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayNotConvertibleValues
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleDefault
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleTypes
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| StackHeadError
    (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackTailError (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackMismatch
    (Γ1 : context) (t1 : term) (args1 l1 : list term)
    (Γ2 : context) (t2 : term) (l2 : list term)

| HeadMismatch
    (leq : conv_pb)
    (Γ1 : context) (t1 : term)
    (Γ2 : context) (t2 : term).

Inductive type_error :=
| UnboundRel (n : nat)
| UnboundVar (id : string)
| UnboundEvar (ev : nat)
| UndeclaredConstant (c : kername)
| UndeclaredInductive (c : inductive)
| UndeclaredConstructor (c : inductive) (i : nat)
| NotCumulSmaller {abstract_structure} (le : bool)
  (G : abstract_structure) (Γ : context) (t u t' u' : term) (e : ConversionError)
| NotConvertible {abstract_structure}
  (G : abstract_structure)
  (Γ : context) (t u : term)
| NotASort (t : term)
| NotAProduct (t t' : term)
| NotAnInductive (t : term)
| NotAnArity (t : term)
| IllFormedFix (m : mfixpoint term) (i : nat)
| UnsatisfiedConstraints (c : ConstraintSet.t)
| Msg (s : string).

Inductive env_error :=
| IllFormedDecl (e : string) (e : type_error)
| AlreadyDeclared (id : string).

Section EnvCheck.

  Context (abstract_structure : Type).

Inductive EnvCheck (A : Type) :=
| CorrectDecl (a : A)
| EnvError (Σ : abstract_structure) (e : env_error).
Global Instance envcheck_monad : Monad EnvCheck.
Admitted.

End EnvCheck.
Import MetaCoq.Common.uGraph.

Lemma wf_ext_gc_of_uctx {cf:checker_flags} {Σ : global_env_ext} (HΣ : ∥ wf_ext Σ ∥)
: ∑ uctx', gc_of_uctx (global_ext_uctx Σ) = Some uctx'.
Admitted.

Definition on_global_decls {cf:checker_flags} Σ :=
  on_global_decls_data cumulSpec0 (lift_typing typing) (cf:=cf) Σ.(universes) Σ.(retroknowledge) Σ.(declarations).

Class abstract_env_struct {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl : Type) := {

  abstract_env_rel : abstract_env_impl -> global_env -> Prop;
  abstract_env_ext_rel : abstract_env_ext_impl -> global_env_ext -> Prop;

  abstract_env_init (cs:ContextSet.t) (retro : Retroknowledge.t) : on_global_univs cs -> abstract_env_impl;
  abstract_env_add_decl X (kn:kername) (d:global_decl) :
   (forall Σ, abstract_env_rel X Σ -> ∥ on_global_decls Σ kn d ∥)
   -> abstract_env_impl;
  abstract_env_add_udecl X udecl :
    (forall Σ, abstract_env_rel X Σ -> ∥ on_udecl Σ.(universes) udecl ∥) ->
    abstract_env_ext_impl ;
  abstract_pop_decls : abstract_env_impl -> abstract_env_impl ;

  abstract_env_lookup : abstract_env_ext_impl -> kername -> option global_decl;
  abstract_primitive_constant : abstract_env_ext_impl -> Primitive.prim_tag -> option kername;

  abstract_env_level_mem : abstract_env_ext_impl -> Level.t -> bool;
  abstract_env_leqb_level_n : abstract_env_ext_impl -> Z -> Level.t -> Level.t -> bool;
  abstract_env_guard : abstract_env_ext_impl -> FixCoFix -> context -> mfixpoint term -> bool;
  abstract_env_is_consistent : abstract_env_impl -> LevelSet.t * GoodConstraintSet.t -> bool ;

}.

Class abstract_env_prop {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl: Type)
  `{!abstract_env_struct abstract_env_impl abstract_env_ext_impl} : Prop := {

  abstract_env_ext_exists X : ∥ ∑ Σ , abstract_env_ext_rel X Σ ∥;
  abstract_env_ext_wf X {Σ} : abstract_env_ext_rel X Σ -> ∥ wf_ext Σ ∥ ;
  abstract_env_ext_irr X {Σ Σ'} :
      abstract_env_ext_rel X Σ -> abstract_env_ext_rel X Σ' ->  Σ = Σ';

  abstract_env_exists X : ∥ ∑ Σ , abstract_env_rel X Σ ∥;
  abstract_env_wf X {Σ} : abstract_env_rel X Σ -> ∥ wf Σ ∥;
  abstract_env_irr X {Σ Σ'} :
    abstract_env_rel X Σ -> abstract_env_rel X Σ' ->  Σ = Σ';

  abstract_env_init_correct univs retro cuniv :
    abstract_env_rel (abstract_env_init univs retro cuniv)
    {| universes := univs; declarations := []; retroknowledge := retro |} ;
  abstract_env_add_decl_correct X Σ kn d H : abstract_env_rel X Σ ->
    abstract_env_rel (abstract_env_add_decl X kn d H) (add_global_decl Σ (kn,d));
  abstract_env_add_udecl_rel X {Σ} udecl H :
    (abstract_env_rel X Σ.1 /\ Σ.2 = udecl) <->
    abstract_env_ext_rel (abstract_env_add_udecl X udecl H) Σ;
  abstract_pop_decls_correct X decls (prf : forall Σ : global_env, abstract_env_rel X Σ ->
            exists d, Σ.(declarations) = d :: decls) :
    let X' := abstract_pop_decls X in
    forall Σ Σ', abstract_env_rel X Σ -> abstract_env_rel X' Σ' ->
                      Σ'.(declarations) = decls /\ Σ.(universes) = Σ'.(universes) /\
                      Σ.(retroknowledge) = Σ'.(retroknowledge);

  abstract_env_lookup_correct X {Σ} kn decl : abstract_env_ext_rel X Σ ->
      In (kn, decl) (declarations Σ) <-> abstract_env_lookup X kn = Some decl ;

  abstract_env_leqb_level_n_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ):
    let uctx := (wf_ext_gc_of_uctx (abstract_env_ext_wf X wfΣ)).π1 in
    leqb_level_n_spec_gen uctx (abstract_env_leqb_level_n X);
  abstract_env_level_mem_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) l:
    LevelSet.In l (global_ext_levels Σ) <-> abstract_env_level_mem X l;
  abstract_env_is_consistent_correct X Σ uctx udecl :
    abstract_env_rel X Σ ->
    ConstraintSet.For_all (declared_cstr_levels (LevelSet.union udecl.1 (global_levels Σ))) udecl.2 ->
    gc_of_uctx udecl = Some uctx ->
    consistent_extension_on (global_uctx Σ) udecl.2 <-> abstract_env_is_consistent X uctx ;

  abstract_env_guard_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) fix_cofix Γ mfix :
      guard fix_cofix Σ Γ mfix <-> abstract_env_guard X fix_cofix Γ mfix;
  abstract_primitive_constant_correct X tag Σ :
    abstract_env_ext_rel X Σ -> abstract_primitive_constant X tag = PCUICEnvironment.primitive_constant Σ tag
  }.

Definition abstract_env_impl {cf:checker_flags} := ∑ X Y Z, @abstract_env_prop _ X Y Z.

Import MCMonadNotation.

Section CheckEnv.
  Context {cf:checker_flags} {nor : normalizing_flags}.

  Context (X_impl : abstract_env_impl).

  Definition X_env_type := X_impl.π1.

  Implicit Type X : X_env_type.
    Context {AA : Type} {BB : AA -> Type} {T : Type -> Type} {M : Monad T} {A} {P : forall (aa:AA), BB aa -> A -> Type} {Q : forall (aa:AA), BB aa -> A -> Type}
    (f : forall x, (forall aa bb, ∥ Q aa bb x ∥) -> T (forall aa bb, ∥ P aa bb x ∥)).
    Program Fixpoint monad_All_All l :
      (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) ->
      T (forall (aa:AA) (bb:BB aa), ∥ All (P aa bb) l ∥) :=
      match l return (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) -> T (forall (aa:AA) (bb:BB aa) , ∥ All (P aa bb) l ∥) with
        | [] => fun _ => ret (fun aa bb  => sq All_nil)
        | a :: l => fun allq =>
        X <- f a _ ;;
        Y <- monad_All_All l _ ;;
        ret (fun aa bb  => _)
        end.
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 4.2MiB file on GitHub Actions Artifacts under build.log)
space/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.zvKVcsKEH6
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.4RCE23UpgM
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.2ASNGMuRR8
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make -C pcuic
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -f Makefile.coq
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.KfgjVhINeP
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.xXnqic20ns
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.9hrL37j7Z6
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.qPA2joDTGq
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -C safechecker
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make -f Makefile.safechecker
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.7VUbd3wgss
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.JZPbhR3wn9
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.1N6fl4AIlf
MINIMIZER_DEBUG: files: 
COQC theories/PCUICSafeChecker.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -deprecated-native-compiler-option -native-compiler no -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories MetaCoq.Utils -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories MetaCoq.Common -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories MetaCoq.PCUIC -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories MetaCoq.SafeChecker theories/PCUICSafeChecker.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.usn9xhQkcn
MINIMIZER_DEBUG: files:  theories/PCUICSafeChecker.v
File "./theories/PCUICSafeChecker.v", line 1739, characters 8-85:
Error:
In environment
cf : checker_flags
nor : normalizing_flags
X_impl : abstract_env_impl
AA : Type
BB : AA -> Type
T : Type -> Type
M : Monad T
A : Type
P : forall aa : AA, BB aa -> A -> Type
Q : forall aa : AA, BB aa -> A -> Type
f :
  forall x : A,
  (forall (aa : AA) (bb : BB aa), ∥ Q aa bb x ∥) ->
  T (forall (aa : AA) (bb : BB aa), ∥ P aa bb x ∥)
monad_All_All :
  Tactics.fix_proto
    (forall l : list A,
     (forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) l ∥) ->
     T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) l ∥))
l : list A
a : A
l0 : list A
allq : forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) (a :: l0) ∥
Unable to unify
 "EnvCheck ?abstract_structure0@{l0:=l; l:=l0}
    (forall (aa : ?T@{l0:=l; l:=l0}) (bb : ?T0@{l0:=l; l:=l0}),
     ?T1@{l0:=l; l:=l0})" with
 "T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) (a :: l0) ∥)".

Command exited with non-zero status 1
theories/PCUICSafeChecker.vo (real: 13.37, user: 13.18, sys: 0.18, mem: 990560 ko)
make[4]: *** [Makefile.safechecker:803: theories/PCUICSafeChecker.vo] Error 1
make[3]: *** [Makefile.safechecker:417: all] Error 2
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[2]: *** [Makefile:11: theory] Error 2
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[1]: *** [Makefile:151: safechecker] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real metacoq.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m13.37s | 990560 ko | Total Time / Peak Mem
--------------------------------------------
0m13.37s | 990560 ko | PCUICSafeChecker.vo  
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-metacoq] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 300KiB file on GitHub Actions Artifacts under bug.log)
 at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal successful

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpateqgs7i/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpo54vm57f/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpateqgs7i/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpo54vm57f/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Qed Obligation with Admit Obligations
�[92m
Admitting Qed Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qed Obligations unsuccessful.
No successful changes.

I will now attempt to replace Qeds with Admitteds
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to replace Qeds with admit. Defined.
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpateqgs7i/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpo54vm57f/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpateqgs7i/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpo54vm57f/MetaCoq/SafeChecker/PCUICSafeChecker.v", line 179, characters 0-27:
Error:
The field cumul_gen is missing in MetaCoq.SafeChecker.PCUICSafeChecker.PCUICCumulativitySpec.PCUICConversionParSpec.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables
�[92m
Variable removal successful.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined
�[92m
Admitting definitions successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 7, 2024

Minimization interrupted by timeout, being automatically continued. Partially Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories/PCUICSafeChecker.v (from ci-metacoq) (interrupted by timeout, being automatically continued) (full log on GitHub Actions - verbose log)
⭐ ⏱️ Partially Minimized Coq File (timeout) (truncated to first and last 32KiB; full 114KiB file on GitHub Actions Artifacts under bug.v)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-deprecated-native-compiler-option" "-native-compiler" "no" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories" "MetaCoq.Utils" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories" "MetaCoq.Common" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories" "MetaCoq.PCUIC" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories" "MetaCoq.SafeChecker" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Equations" "Equations" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "Top.bug_01") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 2560 lines to 33 lines, then from 46 lines to 622 lines, then from 625 lines to 113 lines, then from 126 lines to 1493 lines, then from 1494 lines to 115 lines, then from 128 lines to 821 lines, then from 825 lines to 280 lines, then from 293 lines to 710 lines, then from 715 lines to 282 lines, then from 295 lines to 1746 lines, then from 1751 lines to 545 lines, then from 558 lines to 1457 lines, then from 1461 lines to 711 lines, then from 724 lines to 2544 lines, then from 2543 lines to 722 lines, then from 740 lines to 722 lines, then from 735 lines to 2955 lines, then from 2955 lines to 780 lines, then from 793 lines to 1386 lines, then from 1389 lines to 903 lines, then from 916 lines to 2194 lines, then from 2193 lines to 920 lines, then from 933 lines to 2554 lines, then from 2555 lines to 1195 lines, then from 1208 lines to 1598 lines, then from 1602 lines to 1261 lines, then from 1274 lines to 3763 lines, then from 3760 lines to 3089 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.09.0
   coqtop version runner-t7b1znuaq-project-4504-concurrent-4:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 7.630 sec *)











Require Coq.Init.Ltac.
Require Coq.ssr.ssreflect.
Require Coq.ssr.ssrbool.
Require Coq.Structures.OrderedTypeAlt.
Require Coq.MSets.MSetAVL.
Require Coq.MSets.MSetFacts.
Require Coq.MSets.MSetProperties.
Require Coq.MSets.MSetDecide.
Require Coq.Classes.Morphisms.
Require Coq.Bool.Bool.
Require Coq.ZArith.ZArith.
Require Coq.Arith.Arith.
Require Coq.micromega.Lia.
Require Coq.Lists.List.
Require Coq.Init.Nat.
Require Coq.Strings.Ascii.
Require Coq.Strings.String.
Require Coq.extraction.Extraction.
Require Coq.Unicode.Utf8_core.
Require Equations.Init.
Require Equations.Signature.
Require Equations.CoreTactics.
Require Coq.Relations.Relation_Definitions.
Require Equations.Prop.Logic.
Require Equations.Prop.Classes.
Require Coq.Program.Tactics.
Require Equations.Prop.EqDec.
Require Equations.Prop.DepElim.
Require Coq.Relations.Relations.
Require Equations.Prop.Constants.
Require Coq.Bool.Bvector.
Require Coq.Arith.Wf_nat.
Require Coq.Wellfounded.Wellfounded.
Require Coq.Relations.Relation_Operators.
Require Coq.Wellfounded.Lexicographic_Product.
Require Coq.Program.Wf.
Require Coq.Logic.FunctionalExtensionality.
Require Equations.Prop.Subterm.
Require Equations.Prop.FunctionalInduction.
Require Equations.Prop.Tactics.
Require Equations.Prop.NoConfusion.
Require Equations.Prop.EqDecInstances.
Require Equations.Prop.Loader.
Require Equations.Prop.Telescopes.
Require Equations.Prop.Equations.
Require Coq.btauto.Algebra.
Require MetaCoq.Utils.MCPrelude.
Require MetaCoq.Utils.MCReflect.
Require Coq.Unicode.Utf8.
Require Coq.Lists.SetoidList.
Require Coq.Classes.CRelationClasses.
Require Equations.Type.Logic.
Require Equations.Type.Relation.
Require Equations.Type.Relation_Properties.
Require Coq.Classes.RelationClasses.
Require MetaCoq.Utils.MCRelations.
Require MetaCoq.Utils.ReflectEq.
Require MetaCoq.Utils.MCList.
Require MetaCoq.Utils.MCProd.
Require MetaCoq.Utils.MCOption.
Require MetaCoq.Utils.MCSquash.
Require MetaCoq.Utils.All_Forall.
Require Coq.Classes.Morphisms_Prop.
Require MetaCoq.Utils.MCArith.
Require Coq.Structures.OrderedType.
Require Coq.Structures.Orders.
Require MetaCoq.Utils.MCCompare.
Require MetaCoq.Utils.MCEquality.
Require Coq.Init.Decimal.
Require Coq.Numbers.DecimalString.
Require Coq.NArith.NArith.
Require Coq.Strings.Byte.
Require Coq.NArith.BinNat.
Require MetaCoq.Utils.ByteCompare.
Require Coq.Logic.Eqdep_dec.
Require MetaCoq.Utils.ByteCompareSpec.
Require Coq.Structures.OrdersAlt.
Require MetaCoq.Utils.bytestring.
Require MetaCoq.Utils.MCString.
Require MetaCoq.Utils.MCTactics.SpecializeBy.
Require MetaCoq.Utils.MCTactics.Zeta1.
Require MetaCoq.Utils.MCTactics.GeneralizeOverHoles.
Require MetaCoq.Utils.MCTactics.FindHyp.
Require MetaCoq.Utils.MCTactics.UniquePose.
Require MetaCoq.Utils.MCTactics.InHypUnderBindersDo.
Require MetaCoq.Utils.MCTactics.SpecializeUnderBindersBy.
Require MetaCoq.Utils.MCTactics.Head.
Require MetaCoq.Utils.MCTactics.DestructHyps.
Require MetaCoq.Utils.MCTactics.DestructHead.
Require MetaCoq.Utils.MCTactics.SpecializeAllWays.
Require MetaCoq.Utils.MCTactics.SplitInContext.
Require Ltac2.Init.
Require Ltac2.Message.
Require Ltac2.Control.
Require Ltac2.Std.
Require Ltac2.Ltac1.
Require MetaCoq.Utils.MCUtils.
Require MetaCoq.Utils.monad_utils.
Require MetaCoq.Utils.utils.
Require Coq.ZArith.Zcompare.
Require Coq.MSets.MSetInterface.
Require MetaCoq.Utils.wGraph.
Require Coq.btauto.Btauto.
Require MetaCoq.Common.config.
Require Coq.MSets.MSetList.
Require Coq.FSets.FMapAVL.
Require MetaCoq.Utils.MCMSets.
Require Coq.Structures.Equalities.
Require Coq.FSets.FMapInterface.
Require Coq.FSets.FMapList.
Require Coq.FSets.FMapFullAVL.
Require Coq.FSets.FMapFacts.
Require MetaCoq.Utils.MCFSets.
Require Coq.Setoids.Setoid.
Require Coq.Structures.OrderedTypeEx.
Require MetaCoq.Common.Kernames.
Require Coq.Floats.SpecFloat.
Require MetaCoq.Common.BasicAst.
Require MetaCoq.Common.Universes.
Require Coq.Classes.SetoidTactics.
Require MetaCoq.Common.uGraph.
Require Coq.Numbers.Cyclic.Int63.Uint63.
Require Coq.Floats.PrimFloat.
Require Coq.Floats.FloatAxioms.
Require MetaCoq.Common.Reflect.
Require Coq.Classes.CMorphisms.
Require Coq.Floats.FloatOps.
Require Coq.Numbers.HexadecimalString.
Require Coq.ssr.ssrfun.
Require MetaCoq.Common.Primitive.
Require MetaCoq.Common.Environment.

Module Export AdmitTactic.
Module Import LocalFalse.
Inductive False : Prop := .
End LocalFalse.
Axiom proof_admitted : False.
Import Coq.Init.Ltac.
Tactic Notation "admit" := abstract case proof_admitted.
End AdmitTactic.

Module Export MetaCoq_DOT_Common_DOT_EnvironmentTyping_WRAPPED.
Module Export EnvironmentTyping.
Import Coq.ssr.ssreflect.
Import Coq.ssr.ssrbool.
Import MetaCoq.Utils.utils.
Import MetaCoq.Common.config.
Import MetaCoq.Common.BasicAst.
Import MetaCoq.Common.Universes.
Import MetaCoq.Common.Environment.
Import MetaCoq.Common.Primitive.
Import Equations.Prop.Equations.

Module Lookup (T : Term) (E : EnvironmentSig T).
Import T.
Import E.

  

  Definition declared_constant_gen (lookup : kername -> option global_decl) (id : kername) decl : Prop :=
    lookup id = Some (ConstantDecl decl).

  Definition declared_constant (Σ : global_env) id decl := In (id,ConstantDecl decl) (declarations Σ).

  Definition declared_minductive_gen (lookup : kername -> option global_decl) mind decl :=
    lookup mind = Some (InductiveDecl decl).

  Definition declared_minductive Σ mind decl := In (mind,InductiveDecl decl) (declarations Σ).

  Definition declared_inductive_gen lookup ind mdecl decl :=
    declared_minductive_gen lookup (inductive_mind ind) mdecl /\
    List.nth_error mdecl.(ind_bodies) (inductive_ind ind) = Some decl.

  Definition declared_inductive Σ ind mdecl decl :=
    declared_minductive Σ (inductive_mind ind) mdecl /\
    List.nth_error mdecl.(ind_bodies) (inductive_ind ind) = Some decl.

  Definition declared_constructor_gen lookup cstr mdecl idecl cdecl : Prop :=
    declared_inductive_gen lookup (fst cstr) mdecl idecl /\
    List.nth_error idecl.(ind_ctors) (snd cstr) = Some cdecl.

  Definition declared_constructor Σ cstr mdecl idecl cdecl :=
    declared_inductive Σ (fst cstr) mdecl idecl /\
    List.nth_error idecl.(ind_ctors) (snd cstr) = Some cdecl.

  Definition declared_projection_gen lookup (proj : projection) mdecl idecl cdecl pdecl
  : Prop :=
    declared_constructor_gen lookup (proj.(proj_ind), 0) mdecl idecl cdecl /\
    List.nth_error idecl.(ind_projs) proj.(proj_arg) = Some pdecl /\
    mdecl.(ind_npars) = proj.(proj_npars).

  Definition declared_projection Σ (proj : projection) mdecl idecl cdecl pdecl
  : Prop :=
    declared_constructor Σ (proj.(proj_ind), 0) mdecl idecl cdecl /\
    List.nth_error idecl.(ind_projs) proj.(proj_arg) = Some pdecl /\
    mdecl.(ind_npars) = proj.(proj_npars).

  Definition lookup_constant_gen (lookup : kername -> option global_decl) kn :=
    match lookup kn with
    | Some (ConstantDecl d) => Some d
    | _ => None
    end.

  Definition lookup_constant Σ := lookup_constant_gen (lookup_env Σ).

  Definition lookup_minductive_gen (lookup : kername -> option global_decl) mind :=
    match lookup mind with
    | Some (InductiveDecl decl) => Some decl
    | _ => None
    end.

  Definition lookup_minductive Σ := lookup_minductive_gen (lookup_env Σ).

  Definition lookup_inductive_gen lookup ind :=
    match lookup_minductive_gen lookup (inductive_mind ind) with
    | Some mdecl =>
      match nth_error mdecl.(ind_bodies) (inductive_ind ind) with
      | Some idecl => Some (mdecl, idecl)
      | None => None
      end
    | None => None
    end.

  Definition lookup_inductive Σ := lookup_inductive_gen (lookup_env Σ).

  Definition lookup_constructor_gen lookup ind k :=
    match lookup_inductive_gen lookup ind with
    | Some (mdecl, idecl) =>
      match nth_error idecl.(ind_ctors) k with
      | Some cdecl => Some (mdecl, idecl, cdecl)
      | None => None
      end
    | _ => None
    end.

  Definition lookup_constructor Σ := lookup_constructor_gen (lookup_env Σ).

  Definition lookup_projection_gen lookup p :=
    match lookup_constructor_gen lookup p.(proj_ind) 0 with
    | Some (mdecl, idecl, cdecl) =>
      match nth_error idecl.(ind_projs) p.(proj_arg) with
      | Some pdecl => Some (mdecl, idecl, cdecl, pdecl)
      | None => None
      end
    | _ => None
    end.

  Definition lookup_projection Σ := lookup_projection_gen (lookup_env Σ).

  Lemma declared_constant_lookup_gen {lookup kn cdecl} :
    declared_constant_gen lookup kn cdecl ->
    lookup_constant_gen lookup kn = Some cdecl.
Admitted.

  Lemma lookup_constant_declared_gen {lookup kn cdecl} :
    lookup_constant_gen lookup kn = Some cdecl ->
    declared_constant_gen lookup kn cdecl.
Admitted.

  Lemma declared_minductive_lookup_gen {lookup ind mdecl} :
    declared_minductive_gen lookup ind mdecl ->
    lookup_minductive_gen lookup ind = Some mdecl.
Admitted.

  Lemma lookup_minductive_declared_gen {lookup ind mdecl} :
    lookup_minductive_gen lookup ind = Some mdecl ->
    declared_minductive_gen lookup ind mdecl.
Admitted.

  Lemma declared_inductive_lookup_gen {lookup ind mdecl idecl} :
    declared_inductive_gen lookup ind mdecl idecl ->
    lookup_inductive_gen lookup ind = Some (mdecl, idecl).
Admitted.

  Lemma lookup_inductive_declared_gen {lookup ind mdecl idecl} :
    lookup_inductive_gen lookup ind = Some (mdecl, idecl) ->
    declared_inductive_gen lookup ind mdecl idecl.
Admitted.

  Lemma declared_constructor_lookup_gen {lookup id mdecl idecl cdecl} :
    declared_constructor_gen lookup id mdecl idecl cdecl ->
    lookup_constructor_gen lookup id.1 id.2 = Some (mdecl, idecl, cdecl).
Admitted.

  Lemma lookup_constructor_declared_gen {lookup id mdecl idecl cdecl} :
    lookup_constructor_gen lookup id.1 id.2 = Some (mdecl, idecl, cdecl) ->
    declared_constructor_gen lookup id mdecl idecl cdecl.
Admitted.

  Lemma declared_projection_lookup_gen {lookup p mdecl idecl cdecl pdecl} :
    declared_projection_gen lookup p mdecl idecl cdecl pdecl ->
    lookup_projection_gen lookup p = Some (mdecl, idecl, cdecl, pdecl).
Admitted.

  Lemma lookup_projection_declared_gen {lookup p mdecl idecl cdecl pdecl} :
    ind_npars mdecl = p.(proj_npars) ->
    lookup_projection_gen lookup p = Some (mdecl, idecl, cdecl, pdecl) ->
    declared_projection_gen lookup p mdecl idecl cdecl pdecl.
Admitted.

  Definition on_udecl_decl {A} (F : universes_decl -> A) d : A :=
  match d with
  | ConstantDecl cb => F cb.(cst_universes)
  | InductiveDecl mb => F mb.(ind_universes)
  end.

  Definition universes_decl_of_decl := on_udecl_decl (fun x => x).

  

  Definition global_levels (univs : ContextSet.t) : LevelSet.t :=
    LevelSet.union (ContextSet.levels univs) (LevelSet.singleton (Level.lzero)).

  Lemma global_levels_InSet Σ :
    LevelSet.In Level.lzero (global_levels Σ).
Admitted.

  Lemma global_levels_memSet univs :
    LevelSet.mem Level.lzero (global_levels univs) = true.
Admitted.

  

  Definition global_constraints (Σ : global_env) : ConstraintSet.t :=
    snd Σ.(universes).

  Definition global_uctx (Σ : global_env) : ContextSet.t :=
    (global_levels Σ.(universes), global_constraints Σ).

  Definition global_ext_levels (Σ : global_env_ext) : LevelSet.t :=
    LevelSet.union (levels_of_udecl (snd Σ)) (global_levels Σ.1.(universes)).

  Definition global_ext_constraints (Σ : global_env_ext) : ConstraintSet.t :=
    ConstraintSet.union
      (constraints_of_udecl (snd Σ))
      (global_constraints Σ.1).

  Coercion global_ext_constraints : global_env_ext >-> ConstraintSet.t.

  Definition global_ext_uctx (Σ : global_env_ext) : ContextSet.t :=
    (global_ext_levels Σ, global_ext_constraints Σ).

  Lemma global_ext_levels_InSet Σ :
    LevelSet.In Level.lzero (global_ext_levels Σ).
Admitted.

  

  Definition consistent_instance `{checker_flags} (lvs : LevelSet.t) (φ : ConstraintSet.t) uctx (u : Instance.t) :=
    match uctx with
    | Monomorphic_ctx => List.length u = 0
    | Polymorphic_ctx c =>
      
      forallb (fun l => LevelSet.mem l lvs) u /\
      List.length u = List.length c.1 /\
      valid_constraints φ (subst_instance_cstrs u c.2)
    end.

  Definition consistent_instance_ext `{checker_flags} Σ :=
    consistent_instance (global_ext_levels Σ) (global_ext_constraints Σ).

  Lemma consistent_instance_length {cf : checker_flags} {Σ : global_env_ext} {univs u} :
    consistent_instance_ext Σ univs u ->
    #|u| = #|abstract_instance univs|.
Admitted.

  Definition wf_universe Σ (u : Universe.t) : Prop :=
    forall l, LevelExprSet.In l u -> LevelSet.In (LevelExpr.get_level l) (global_ext_levels Σ).

  Definition wf_sort Σ (s : sort) : Prop :=
    Sort.on_sort (wf_universe Σ) True s.

  Definition wf_universe_dec Σ u : {wf_universe Σ u} + {~wf_universe Σ u}.
Admitted.

  Definition wf_sort_dec Σ s : {@wf_sort Σ s} + {~@wf_sort Σ s}.
Admitted.

  Lemma declared_ind_declared_constructors `{cf : checker_flags} {Σ ind mib oib} :
    declared_inductive Σ ind mib oib ->
    Alli (fun i => declared_constructor Σ (ind, i) mib oib) 0 (ind_ctors oib).
Admitted.

End Lookup.

Module Type LookupSig (T : Term) (E : EnvironmentSig T).
  Include Lookup T E.
End LookupSig.

Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
Import T.
Import E.
Import TU.

  

  Notation on_local_decl P Γ d :=
    (P Γ (j_decl d)).

  Definition on_def_type (P : context -> judgment -> Type) Γ d :=
    P Γ (Typ d.(dtype)).

  Definition on_def_body (P : context -> judgment -> Type) types Γ d :=
    P (Γ ,,, types) (TermTyp d.(dbody) (lift0 #|types| d.(dtype))).

  

  Definition lift_wf_term wf_term (j : judgment) := option_default wf_term (j_term j) (unit : Type) × wf_term (j_typ j).
  Notation lift_wf_term1 wf_term := (fun (Γ : context) => lift_wf_term (wf_term Γ)).

  Definition lift_wfu_term wf_term wf_univ (j : judgment) := option_default wf_term (j_term j) unit × wf_term (j_typ j) × option_default wf_univ (j_univ j) unit.

  Definition lift_wfb_term wfb_term (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j).
  Notation lift_wfb_term1 wfb_term := (fun (Γ : context) => lift_wfb_term (wfb_term Γ)).

  Definition lift_wfbu_term wfb_term wfb_univ (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j) && option_default wfb_univ (j_univ j) true.

  Definition lift_sorting checking sorting : judgment -> Type :=
    fun j => option_default (fun tm => checking tm (j_typ j)) (j_term j) (unit : Type) ×
                                ∑ s, sorting (j_typ j) s × option_default (fun u => (u = s : Type)) (j_univ j) unit.

  Notation lift_sorting1 checking sorting := (fun Γ => lift_sorting (checking Γ) (sorting Γ)).
  Notation lift_sorting2 checking sorting := (fun Σ Γ => lift_sorting (checking Σ Γ) (sorting Σ Γ)).

  Notation typing_sort typing := (fun T s => typing T (tSort s)).
  Notation typing_sort1 typing := (fun Γ T s => typing Γ T (tSort s)).
  Notation typing_sort2 typing := (fun Σ Γ T s => typing Σ Γ T (tSort s)).

  Definition lift_typing0 typing := lift_sorting typing (typing_sort typing).
  Notation lift_typing1 typing := (fun Γ => lift_typing0 (typing Γ)).
  Notation lift_typing typing := (fun Σ Γ => lift_typing0 (typing Σ Γ)).

  Notation Prop_local_conj P Q := (fun Γ t T => P Γ t T × Q Γ t T).
  Notation Prop_conj P Q := (fun Σ Γ t T => P Σ Γ t T × Q Σ Γ t T).

  Definition lift_typing_conj (P Q : context -> _) := lift_typing1 (Prop_local_conj P Q).

  Lemma lift_wf_term_it_impl {P Q} {tm tm' : option term} {t t' : term} {u u'} :
    forall tu: lift_wf_term P (Judge tm t u),
    match tm', tm with None, _ => unit | Some tm', Some tm => P tm -> Q tm' | _, _ => False end ->
    (P t -> Q t') ->
    lift_wf_term Q (Judge tm' t' u').
Admitted.

  Lemma lift_wf_term_f_impl P Q tm t u u' :
    forall f,
    lift_wf_term P (Judge tm t u) ->
    (forall t, P t -> Q (f t)) ->
    lift_wf_term Q (Judge (option_map f tm) (f t) u').
Admitted.

  Lemma lift_wf_term_impl P Q j :
    lift_wf_term P j ->
    (forall t, P t -> Q t) ->
    lift_wf_term Q j.
Admitted.

  Lemma lift_wfbu_term_f_impl (P Q : term -> bool) tm t u :
    forall f fu,
    lift_wfbu_term P (P ∘ tSort) (Judge tm t u) ->
    (forall u, f (tSort u) = tSort (fu u)) ->
    (forall t, P t -> Q (f t)) ->
    lift_wfbu_term Q (Q ∘ tSort) (Judge (option_map f tm) (f t) (option_map fu u)).
Admitted.

  Lemma unlift_TermTyp {Pc Ps tm ty u} :
    lift_sorting Pc Ps (Judge (Some tm) ty u) ->
    Pc tm ty.
Admitted.

  Definition unlift_TypUniv {Pc Ps tm ty u} :
    lift_sorting Pc Ps (Judge tm ty (Some u)) ->
    Ps ty u
    := fun H => eq_rect_r _ H.2.π2.1 H.2.π2.2.

  Definition lift_sorting_extract {c s tm ty u} (w : lift_sorting c s (Judge tm ty u)) :
    lift_sorting c s (Judge tm ty (Some w.2.π1)) :=
    (w.1, existT _ w.2.π1 (w.2.π2.1, eq_refl)).

  Lemma lift_sorting_forget_univ {Pc Ps tm ty u} :
    lift_sorting Pc Ps (Judge tm ty u) ->
    lift_sorting Pc Ps (TermoptTyp tm ty).
Admitted.

  Lemma lift_sorting_forget_body {Pc Ps tm ty u} :
    lift_sorting Pc Ps (Judge tm ty u) ->
    lift_sorting Pc Ps (Judge None ty u).
Admitted.

  Lemma lift_sorting_ex_it_impl_gen {Pc Qc Ps Qs} {tm tm' : option term} {t t' : term} :
    forall tu: lift_sorting Pc Ps (TermoptTyp tm t),
    let s := tu.2.π1 in
    match tm', tm with None, _ => unit | Some tm', Some tm => Pc tm t -> Qc tm' t' | _, _ => False end ->
    (Ps t s -> ∑ s', Qs t' s') ->
    lift_sorting Qc Qs (TermoptTyp tm' t').
Admitted.

  Lemma lift_sorting_it_impl_gen {Pc Qc Ps Qs} {tm tm' : option term} {t t' : term} {u} :
    forall tu: lift_sorting Pc Ps (Judge tm t u),
    let s := tu.2.π1 in
    match tm', tm with None, _ => unit | Some tm', Some tm => Pc tm t -> Qc tm' t' | _, _ => False end ->
    (Ps t s -> Qs t' s) ->
    lift_sorting Qc Qs (Judge tm' t' u).
Admitted.

  Lemma lift_sorting_fu_it_impl {Pc Qc Ps Qs} {tm : option term} {t : term} {u} :
    forall f fu, forall tu: lift_sorting Pc Ps (Judge tm t u),
    let s := tu.2.π1 in
    option_default (fun tm => Pc tm t -> Qc (f tm) (f t)) tm unit ->
    (Ps t s -> Qs (f t) (fu s)) ->
    lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u)).
Admitted.

  Lemma lift_sorting_f_it_impl {Pc Qc Ps Qs} {j : judgment} :
    forall f, forall tu: lift_sorting Pc Ps j,
    let s := tu.2.π1 in
    option_default (fun tm => Pc tm (j_typ j) -> Qc (f tm) (f (j_typ j))) (j_term j) unit ->
    (Ps (j_typ j) s -> Qs (f (j_typ j)) s) ->
    lift_sorting Qc Qs (judgment_map f j).
Admitted.

  Lemma lift_sorting_it_impl {Pc Qc Ps Qs} {j} :
    forall tu: lift_sorting Pc Ps j,
    let s := tu.2.π1 in
    option_default (fun tm => Pc tm (j_typ j) -> Qc tm (j_typ j)) (j_term j) unit ->
    (Ps (j_typ j) s -> Qs (j_typ j) s) ->
    lift_sorting Qc Qs j.
Admitted.

  Lemma lift_sorting_fu_impl {Pc Qc Ps Qs tm t u} :
    forall f fu,
    lift_sorting Pc Ps (Judge tm t u) ->
    (forall t T, Pc t T -> Qc (f t) (f T)) ->
    (forall t u, Ps t u -> Qs (f t) (fu u)) ->
    lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u)).
Admitted.

  Lemma lift_typing_fu_impl {P Q tm t u} :
    forall f fu,
    lift_typing0 P (Judge tm t u) ->
    (forall t T, P t T -> Q (f t) (f T)) ->
    (forall u, f (tSort u) = tSort (fu u)) ->
    lift_typing0 Q (Judge (option_map f tm) (f t) (option_map fu u)).
Admitted.

  Lemma lift_sorting_f_impl {Pc Qc Ps Qs j} :
    forall f,
    lift_sorting Pc Ps j ->
    (forall t T, Pc t T -> Qc (f t) (f T)) ->
    (forall t u, Ps t u -> Qs (f t) u) ->
    lift_sorting Qc Qs (judgment_map f j).
Admitted.

  Lemma lift_typing_f_impl {P Q j} :
    forall f,
    lift_typing0 P j ->
    (forall t T, P t T -> Q (f t) (f T)) ->
    (forall u, f (tSort u) = tSort u) ->
    lift_typing0 Q (judgment_map f j).
Admitted.

  Lemma lift_typing_map {P} f j :
    lift_typing0 (fun t T => P (f t) (f T)) j ->
    (forall u, f (tSort u) = tSort u) ->
    lift_typing0 P (judgment_map f j).
Admitted.

  Lemma lift_typing_mapu {P} f fu {tm ty u} :
    lift_typing0 (fun t T => P (f t) (f T)) (Judge tm ty u) ->
    (forall u, f (tSort u) = tSort (fu u)) ->
    lift_typing0 P (Judge (option_map f tm) (f ty) (option_map fu u)).
Admitted.

  Lemma lift_sorting_impl {Pc Qc Ps Qs j} :
    lift_sorting Pc Ps j ->
    (forall t T, Pc t T -> Qc t T) ->
    (forall t u, Ps t u -> Qs t u) ->
    lift_sorting Qc Qs j.
Admitted.

  Lemma lift_typing_impl {P Q j} :
    lift_typing0 P j ->
    (forall t T, P t T -> Q t T) ->
    lift_typing0 Q j.
Admitted.

  Section TypeLocal.
    Context (typing : forall (Γ : context), judgment -> Type).

    Inductive All_local_env : context -> Type :=
    | localenv_nil :
        All_local_env []

    | localenv_cons_abs Γ na t :
        All_local_env Γ ->
        typing Γ (j_vass na t) ->
        All_local_env (Γ ,, vass na t)

    | localenv_cons_def Γ na b t :
        All_local_env Γ ->
        typing Γ (j_vdef na b t) ->
        All_local_env (Γ ,, vdef na b t).

  Derive Signature NoConfusion for All_local_env.
  End TypeLocal.

  Arguments localenv_nil {_}.
  Arguments localenv_cons_def {_ _ _ _ _} _ _.
  Arguments localenv_cons_abs {_ _ _ _} _ _.

  Definition localenv_cons {typing Γ na bo t} :
    All_local_env typing Γ -> typing Γ (TermoptTyp bo t) -> All_local_env typing (Γ ,, mkdecl na bo t)
    := match bo with None => localenv_cons_abs | Some b => localenv_cons_def end.

  Definition All_local_env_snoc {P Γ decl} : All_local_env P Γ -> on_local_decl P Γ decl -> All_local_env P (Γ ,, decl) :=
    match decl with mkdecl na bo t => localenv_cons end.

  Lemma All_local_env_tip {typing Γ decl} : All_local_env typing (Γ ,, decl) -> All_local_env typing Γ × on_local_decl typing Γ decl.
Admitted.

  Lemma All_local_env_ind1 typing P :
    P [] ->
    (forall Γ decl, P Γ -> on_local_decl typing Γ decl -> P (Γ ,, decl)) ->
    forall Γ, All_local_env typing Γ -> P Γ.
Admitted.

  Lemma All_local_env_map (P : context -> judgment -> Type) f Γ :
    All_local_env (fun Γ j => P (map (map_decl f) Γ) (judgment_map f j)) Γ ->
    All_local_env P (map (map_decl f) Γ).
Admitted.

  Lemma All_local_env_fold P f Γ :
    All_local_env (fun Γ j => P (fold_context_k f Γ) (judgment_map (f #|Γ|) j)) Γ <~>
    All_local_env P (fold_context_k f Γ).
Admitted.

  Lemma All_local_env_impl_gen (P Q : context -> judgment -> Type) l :
    All_local_env P l ->
    (forall Γ decl, P Γ (j_decl decl) -> Q Γ (j_decl decl)) ->
    All_local_env Q l.
Admitted.

  Lemma All_local_env_impl (P Q : context -> judgment -> Type) l :
    All_local_env P l ->
    (forall Γ j, P Γ j -> Q Γ j) ->
    All_local_env Q l.
Admitted.

  Lemma All_local_env_impl_ind {P Q : context -> judgment -> Type} {l} :
    All_local_env P l ->
    (forall Γ j, All_local_env Q Γ -> P Γ j -> Q Γ j) ->
    All_local_env Q l.
Admitted.

  Lemma All_local_env_skipn {P Γ} n : All_local_env P Γ -> All_local_env P (skipn n Γ).
Admitted.
  #[global]
  Hint Resolve All_local_env_skipn : wf.

  Lemma All_local_env_app_skipn {P Γ Δ} n : All_local_env P (Γ ,,, Δ) ->
    All_local_env P (Γ ,,, skipn n Δ).
Admitted.

  Lemma All_local_env_nth_error {P Γ n decl} : All_local_env P Γ -> nth_error Γ n = Some decl -> on_local_decl P (skipn (S n) Γ) decl.
Admitted.

  Lemma All_local_env_cst {P Γ} : All_local_env (fun _ => P) Γ <~> All (fun d => P (j_decl d)) Γ.
Admitted.

  Section All_local_env_rel.

    Definition All_local_rel P Γ Γ'
      := (All_local_env (fun Δ j => P (Γ ,,, Δ) j) Γ').

    Definition All_local_rel_nil {P Γ} : All_local_rel P Γ []
      := localenv_nil.

    Definition All_local_rel_snoc {P Γ Γ' decl} :
      All_local_rel P Γ Γ' -> on_local_decl P (Γ ,,, Γ') decl ->
      All_local_rel P Γ (Γ' ,, decl)
      := All_local_env_snoc.

    Definition All_local_rel_abs {P Γ Γ' A na} :
      All_local_rel P Γ Γ' -> P (Γ ,,, Γ') (j_vass na A)
      -> All_local_rel P Γ (Γ',, vass na A)
      := localenv_cons.

    Definition All_local_rel_def {P Γ Γ' t A na} :
      All_local_rel P Γ Γ' ->
      P (Γ ,,, Γ') (j_vdef na t A) ->
      All_local_rel P Γ (Γ',, vdef na t A)
      := localenv_cons.

    Definition All_local_rel_tip {P Γ Γ' decl} :
      All_local_rel P Γ (Γ' ,, decl) -> All_local_rel P Γ Γ' × on_local_decl P (Γ ,,, Γ') decl
      := All_local_env_tip.

    Definition All_local_rel_ind1 typing Γ P :
      P [] ->
      (forall Δ decl, P Δ -> on_local_decl typing (Γ ,,, Δ) decl -> P (Δ ,, decl)) ->
      forall Δ, All_local_rel typing Γ Δ -> P Δ
      := All_local_env_ind1 _ P.

    Lemma All_local_rel_local :
      forall P Γ,
        All_local_env P Γ ->
        All_local_rel P [] Γ.
Admitted.

    Lemma All_local_local_rel P Γ :
      All_local_rel P [] Γ -> All_local_env P Γ.
Admitted.

    Lemma All_local_app_rel {P Γ Γ'} :
      All_local_env P (Γ ,,, Γ') -> All_local_env P Γ × All_local_rel P Γ Γ'.
Admitted.

    Definition All_local_env_app_inv {P Γ Γ'} := @All_local_app_rel P Γ Γ'.

    Lemma All_local_rel_app_inv {P Γ Γ' Γ''} :
      All_local_rel P Γ (Γ' ,,, Γ'') -> All_local_rel P Γ Γ' × All_local_rel P (Γ ,,, Γ') Γ''.
Admitted.

    Lemma All_local_env_app {P Γ Γ'} :
      All_local_env P Γ -> All_local_rel P Γ Γ' -> All_local_env P (Γ ,,, Γ').
Admitted.

    Lemma All_local_rel_app {P Γ Γ' Γ''} :
      All_local_rel P Γ Γ' -> All_local_rel P (Γ ,,, Γ') Γ'' -> All_local_rel P Γ (Γ' ,,, Γ'').
Admitted.

    Lemma All_local_env_prod_inv :
      forall P Q Γ,
        All_local_env (fun Δ j => P Δ j × Q Δ j) Γ ->
        All_local_env P Γ × All_local_env Q Γ.
Admitted.

    Lemma All_local_env_lift_prod_inv :
      forall P Q Δ,
        All_local_env (lift_typing1 (Prop_local_conj P Q)) Δ ->
        All_local_env (lift_typing1 P) Δ × All_local_env (lift_typing1 Q) Δ.
Admitted.

  End All_local_env_rel.

  Section TypeLocalOver.
    Context (checking : context -> term -> term -> Type).
    Context (sorting : context -> term -> sort -> Type).
    Context (cproperty : forall (Γ : context),
                All_local_env (lift_sorting1 checking sorting) Γ ->
                forall (t T : term), checking Γ t T -> Type).
    Context (sproperty : forall (Γ : context),
                All_local_env (lift_sorting1 checking sorting) Γ ->
                forall (t : term) (u : sort), sorting Γ t u -> Type).

    Inductive All_local_env_over_sorting :
        forall (Γ : context), All_local_env (lift_sorting1 checking sorting) Γ -> Type :=
    | localenv_over_nil :
        All_local_env_over_sorting [] localenv_nil

    | localenv_over_cons_abs Γ na t
        (all : All_local_env (lift_sorting1 checking sorting) Γ) :
        All_local_env_over_sorting Γ all ->
        forall (tu : lift_sorting1 checking sorting Γ (j_vass na t))
          (Hs: sproperty Γ all _ _ tu.2.π2.1),
          All_local_env_over_sorting (Γ ,, vass na t)
                              (localenv_cons_abs all tu)

    | localenv_over_cons_def Γ na b t
        (all : All_local_env (lift_sorting1 checking sorting) Γ) :
        All_local_env_over_sorting Γ all ->
        forall (tu : lift_sorting1 checking sorting Γ (j_vdef na b t))
          (Hc: cproperty Γ all _ _ tu.1)
          (Hs: sproperty Γ all _ _ tu.2.π2.1),
          All_local_env_over_sorting (Γ ,, vdef na b t)
                              (localenv_cons_def all tu).

  End TypeLocalOver.
  Derive Signature for All_local_env_over_sorting.

  Definition All_local_env_over typing property :=
    (All_local_env_over_sorting typing (typing_sort1 typing) property (fun Γ H t u tu => property _ H _ _ tu)).

  Lemma All_local_env_over_sorting_2 c s Pc Ps Γ (H : All_local_env (lift_sorting1 c s) Γ) :
    All_local_env_over_sorting _ _ (fun Γ _ t T _ => Pc Γ t T) (fun Γ _ t s _ => Ps Γ t s) _ H ->
    All_local_env (lift_sorting1 (Prop_local_conj c Pc) (Prop_local_conj s Ps)) Γ.
Admitted.

  Definition on_wf_local_decl {typing Γ}
    (P : forall Γ (wfΓ : All_local_env (lift_typing1 typing) Γ) t T, typing Γ t T -> Type)
    (wfΓ : All_local_env (lift_typing1 typing) Γ) {d}
    (H : on_local_decl (lift_typing1 typing) Γ d) :=
  match d return (on_local_decl (lift_typing1 typing) Γ d) -> Type with
  | {| decl_name := na; decl_body := Some b; decl_type := ty |}
  => fun H => P Γ wfΓ b ty H.1 × P Γ wfΓ ty _ H.2.π2.1
  | {| decl_name := na; decl_body := None; decl_type := ty |}
  => fun H => P Γ wfΓ ty _ H.2.π2.1
  end H.

  Lemma nth_error_All_local_env_over {typing} {P Γ n decl} (eq : nth_error Γ n = Some decl) {wfΓ : All_local_env (lift_typing1 typing) Γ} :
    All_local_env_over typing P Γ wfΓ ->
    let Γ' := skipn (S n) Γ in
    let wfΓ' := All_local_env_skipn _ wfΓ in
    let p := All_local_env_nth_error wfΓ eq in
    (All_local_env_over typing P Γ' wfΓ' * on_wf_local_decl P wfΓ' p)%type.
Admitted.

  Lemma All_local_env_over_2 typing P Γ (H : All_local_env (lift_typing1 typing) Γ) :
    All_local_env_over _ (fun Γ _ t T _ => P Γ t T) _ H ->
    All_local_env (lift_typing_conj typing P) Γ.
Admitted.

  Section TypeCtxInst.
    Context (typing : forall (Γ : context), term -> term -> Type).

    
    Inductive ctx_inst (Γ : context) : list term -> context -> Type :=
    | ctx_inst_nil : ctx_inst Γ [] []
    | ctx_inst_ass na t i inst Δ :
        typing Γ i t ->
        ctx_inst Γ inst (subst_telescope [i] 0 Δ) ->
        ctx_inst Γ (i :: inst) (vass na t :: Δ)
    | ctx_inst_def na b t inst Δ :
        ctx_inst Γ inst (subst_telescope [b] 0 Δ) ->
        ctx_inst Γ inst (vdef na b t :: Δ).
    Derive Signature NoConfusion for ctx_inst.
  End TypeCtxInst.

  Lemma ctx_inst_impl_gen Γ inst Δ args P :
    { P' & ctx_inst P' Γ inst Δ } ->
    (forall t T,
        All (fun P' => P' Γ t T) args ->
        P Γ t T) ->
    All (fun P' => ctx_inst P' Γ inst Δ) args ->
    ctx_inst P Γ inst Δ.
Admitted.

  Lemma ctx_inst_impl P Q Γ inst Δ :
    ctx_inst P Γ inst Δ ->
    (forall t T, P Γ t T -> Q Γ t T) ->
    ctx_inst Q Γ inst Δ.
Admitted.

  Definition option_default_size {A f} (fsize : forall (a : A), f a -> size) o (w : option_default f o (unit : Type)) : size :=
    match o as tm return option_default _ tm (unit : Type) -> size with
    | Some tm => fun w => fsize _ w
    | None => fun w => 0
    end w.

  Section lift_sorting_size_gen.
    Context {checking : term -> term -> Type}.
    Context {sorting : term -> sort -> Ty

[...]

l.(ind_universes))
       mdecl.(ind_bodies)) #|mdecl.(ind_params)|
      cdecl.(cstr_args)).

Definition pre_case_branch_context_gen ind mdecl cdecl params puinst : context :=
  inst_case_context params puinst (cstr_branch_context ind mdecl cdecl).

Definition case_branch_context_gen ind mdecl params puinst pctx cdecl :=
  map2 set_binder_name pctx (pre_case_branch_context_gen ind mdecl cdecl params puinst).

Definition case_branch_type_gen ind mdecl (idecl : one_inductive_body) params puinst bctx ptm i cdecl : context * term :=
  let cstr := tConstruct ind i puinst in
  let args := to_extended_list cdecl.(cstr_args) in
  let cstrapp := mkApps cstr (map (lift0 #|cdecl.(cstr_args)|) params ++ args) in
  let brctx := case_branch_context_gen ind mdecl params puinst bctx cdecl in
  let upars := subst_instance puinst mdecl.(ind_params) in
  let indices :=
    (map (subst (List.rev params) #|cdecl.(cstr_args)|)
      (map (expand_lets_k upars #|cdecl.(cstr_args)|)
        (map (subst (inds (inductive_mind ind) puinst mdecl.(ind_bodies))
                    (#|mdecl.(ind_params)| + #|cdecl.(cstr_args)|))
          (map (subst_instance puinst) cdecl.(cstr_indices))))) in
  let ty := mkApps (lift0 #|cdecl.(cstr_args)| ptm) (indices ++ [cstrapp]) in
  (brctx, ty).

Definition case_branch_type ind mdecl idecl p (b : branch term) ptm i cdecl : context * term :=
  case_branch_type_gen ind mdecl idecl p.(pparams) p.(puinst) (forget_types b.(bcontext)) ptm i cdecl.

Definition idecl_binder idecl :=
  {| decl_name :=
    {| binder_name := nNamed idecl.(ind_name);
        binder_relevance := idecl.(ind_relevance) |};
     decl_body := None;
     decl_type := idecl.(ind_type) |}.

Definition wf_predicate_gen mdecl idecl (pparams : list term) (pcontext : list aname) : Prop :=
  let decl := idecl_binder idecl in
  (#|pparams| = mdecl.(ind_npars)) /\
  (Forall2 (fun na decl => eq_binder_annot na decl.(decl_name))
    pcontext (decl :: idecl.(ind_indices))).

Definition wf_predicate mdecl idecl (p : predicate term) : Prop :=
  wf_predicate_gen mdecl idecl p.(pparams) (forget_types p.(pcontext)).

Definition wf_branch_gen cdecl (bctx : list aname) : Prop :=
  (Forall2 (fun na decl => eq_binder_annot na decl.(decl_name))
    bctx cdecl.(cstr_args)).

Definition wf_branch cdecl (b : branch term) : Prop :=
  wf_branch_gen cdecl (forget_types b.(bcontext)).

Definition wf_branches idecl (brs : list (branch term)) : Prop :=
  Forall2 wf_branch idecl.(ind_ctors) brs.

Definition fix_subst (l : mfixpoint term) :=
  let fix aux n :=
      match n with
      | 0 => []
      | S n => tFix l n :: aux n
      end
  in aux (List.length l).

Definition unfold_fix (mfix : mfixpoint term) (idx : nat) :=
  match List.nth_error mfix idx with
  | Some d => Some (d.(rarg), subst0 (fix_subst mfix) d.(dbody))
  | None => None
  end.

Definition cofix_subst (l : mfixpoint term) :=
  let fix aux n :=
      match n with
      | 0 => []
      | S n => tCoFix l n :: aux n
      end
  in aux (List.length l).

Definition unfold_cofix (mfix : mfixpoint term) (idx : nat) :=
  match List.nth_error mfix idx with
  | Some d => Some (d.(rarg), subst0 (cofix_subst mfix) d.(dbody))
  | None => None
  end.

Definition is_constructor n ts :=
  match List.nth_error ts n with
  | Some a => isConstruct_app a
  | None => false
  end.
Definition cmp_universe_instance (cmp_univ : Universe.t -> Universe.t -> Prop) : Instance.t -> Instance.t -> Prop.
Admitted.

Definition cmp_universe_variance (cmp_univ : conv_pb -> Universe.t -> Universe.t -> Prop) pb v u u' :=
  match v with
  | Variance.Irrelevant => True
  | Variance.Covariant => on_rel (cmp_univ pb) Universe.make' u u'
  | Variance.Invariant => on_rel (cmp_univ Conv) Universe.make' u u'
  end.

Definition cmp_universe_instance_variance cmp_univ pb v u u' :=
  Forall3 (cmp_universe_variance cmp_univ pb) v u u'.

Definition global_variance_gen lookup gr napp :=
  match gr with
  | IndRef ind =>
    match lookup_inductive_gen lookup ind with
    | Some (mdecl, idecl) =>
      match destArity [] idecl.(ind_type) with
      | Some (ctx, _) => if (context_assumptions ctx) <=? napp then
          match mdecl.(ind_variance) with
          | Some var => Variance var
          | None => AllEqual
          end
        else AllEqual
      | None => AllEqual
      end
    | None => AllEqual
    end
  | ConstructRef ind k =>
    match lookup_constructor_gen lookup ind k with
    | Some (mdecl, idecl, cdecl) =>
      if (cdecl.(cstr_arity) + mdecl.(ind_npars))%nat <=? napp then

        AllIrrelevant
      else AllEqual
    | _ => AllEqual
    end
  | _ => AllEqual
  end.

Definition cmp_opt_variance cmp_univ pb v :=
  match v with
  | AllEqual => cmp_universe_instance (cmp_univ Conv)
  | AllIrrelevant => fun l l' => #|l| = #|l'|
  | Variance v => fun u u' => cmp_universe_instance (cmp_univ Conv) u u' \/ cmp_universe_instance_variance cmp_univ pb v u u'
  end.

Definition cmp_global_instance_gen Σ cmp_universe pb gr napp :=
  cmp_opt_variance cmp_universe pb (global_variance_gen Σ gr napp).

Notation cmp_global_instance Σ := (cmp_global_instance_gen (lookup_env Σ)).

Inductive eq_decl_upto_names : context_decl -> context_decl -> Type :=
  | compare_vass {na na' T} :
    eq_binder_annot na na' -> eq_decl_upto_names (vass na T) (vass na' T)
  | compare_vdef {na na' b T} :
    eq_binder_annot na na' -> eq_decl_upto_names (vdef na b T) (vdef na' b T).

Notation eq_context_upto_names := (All2 eq_decl_upto_names).
Import Coq.ssr.ssrbool.

Definition shiftnP k p i :=
  (i <? k) || p (i - k).
Fixpoint on_free_vars (p : nat -> bool) (t : term) : bool.
Admitted.

Definition on_free_vars_decl P d :=
  test_decl (on_free_vars P) d.

Definition on_free_vars_ctx P ctx :=
  alli (fun k => (on_free_vars_decl (shiftnP k P))) 0 (List.rev ctx).

Notation is_open_term Γ := (on_free_vars (shiftnP #|Γ| xpred0)).
Notation is_closed_context := (on_free_vars_ctx xpred0).
Module Export PCUICCumulativitySpec.
Import MetaCoq.Common.config.

Implicit Types (cf : checker_flags).

Definition cumul_predicate (cumul : context -> term -> term -> Type) cumul_universe Γ p p' :=
  All2 (cumul Γ) p.(pparams) p'.(pparams) ×
  cmp_universe_instance cumul_universe p.(puinst) p'.(puinst) ×
  eq_context_upto_names p.(pcontext) p'.(pcontext) ×
  cumul (Γ ,,, inst_case_predicate_context p) p.(preturn) p'.(preturn).

Definition cumul_branch (cumul_term : context -> term -> term -> Type) Γ p br br' :=
  eq_context_upto_names br.(bcontext) br'.(bcontext) ×
  cumul_term (Γ ,,, inst_case_branch_context p br) br.(bbody) br'.(bbody).

Definition cumul_branches cumul_term Γ p brs brs' := All2 (cumul_branch cumul_term Γ p) brs brs'.

Definition cumul_mfixpoint (cumul_term : context -> term -> term -> Type) Γ mfix mfix' :=
  All2 (fun d d' =>
    cumul_term Γ d.(dtype) d'.(dtype) ×
    cumul_term (Γ ,,, fix_context mfix) d.(dbody) d'.(dbody) ×
    d.(rarg) = d'.(rarg) ×
    eq_binder_annot d.(dname) d'.(dname)
  ) mfix mfix'.

Reserved Notation " Σ ;;; Γ ⊢ t ≤s[ pb ] u" (at level 50, Γ, t, u at next level,
  format "Σ  ;;;  Γ  ⊢  t  ≤s[ pb ]  u").

Definition cumul_Ind_univ {cf} (Σ : global_env_ext) pb i napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (IndRef i) napp.

Definition cumul_Construct_univ {cf} (Σ : global_env_ext) pb  i k napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (ConstructRef i k) napp.
Inductive cumulSpec0 {cf : checker_flags} (Σ : global_env_ext) Γ (pb : conv_pb) : term -> term -> Type :=

| cumul_Trans : forall t u v,
    is_closed_context Γ -> is_open_term Γ u ->
    Σ ;;; Γ ⊢ t ≤s[pb] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] v ->
    Σ ;;; Γ ⊢ t ≤s[pb] v

| cumul_Sym : forall t u,
    Σ ;;; Γ ⊢ t ≤s[Conv] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] t

| cumul_Refl : forall t,
    Σ ;;; Γ ⊢ t ≤s[pb] t

| cumul_Ind : forall i u u' args args',
    cumul_Ind_univ Σ pb i #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tInd i u) args ≤s[pb] mkApps (tInd i u') args'

| cumul_Construct : forall i k u u' args args',
    cumul_Construct_univ Σ pb i k #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tConstruct i k u) args ≤s[pb] mkApps (tConstruct i k u') args'

| cumul_Sort : forall s s',
    compare_sort Σ pb s s' ->
    Σ ;;; Γ ⊢ tSort s ≤s[pb] tSort s'

| cumul_Const : forall c u u',
    cmp_universe_instance (compare_universe Σ Conv) u u' ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] tConst c u'

| cumul_Evar : forall e args args',
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ tEvar e args ≤s[pb] tEvar e args'

| cumul_App : forall t t' u u',
    Σ ;;; Γ ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ u ≤s[Conv] u' ->
    Σ ;;; Γ ⊢ tApp t u ≤s[pb] tApp t' u'

| cumul_Lambda : forall na na' ty ty' t t',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vass na ty ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ tLambda na ty t ≤s[pb] tLambda na' ty' t'

| cumul_Prod : forall na na' a a' b b',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ a ≤s[Conv] a' ->
    Σ ;;; Γ ,, vass na a ⊢ b ≤s[pb] b' ->
    Σ ;;; Γ ⊢ tProd na a b ≤s[pb] tProd na' a' b'

| cumul_LetIn : forall na na' t t' ty ty' u u',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ t ≤s[Conv] t' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vdef na t ty ⊢ u ≤s[pb] u' ->
    Σ ;;; Γ ⊢ tLetIn na t ty u ≤s[pb] tLetIn na' t' ty' u'

| cumul_Case indn : forall p p' c c' brs brs',
    cumul_predicate (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) (compare_universe Σ Conv) Γ p p' ->
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    cumul_branches (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ p brs brs' ->
    Σ ;;; Γ ⊢ tCase indn p c brs ≤s[pb] tCase indn p' c' brs'

| cumul_Proj : forall p c c',
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    Σ ;;; Γ ⊢ tProj p c ≤s[pb] tProj p c'

| cumul_Fix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tFix mfix idx ≤s[pb] tFix mfix' idx

| cumul_CoFix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tCoFix mfix idx ≤s[pb] tCoFix mfix' idx

| cumul_Prim p p' :
  onPrims (fun x y => Σ ;;; Γ ⊢ x ≤s[Conv] y) (compare_universe Σ Conv) p p' ->
  Σ ;;; Γ ⊢ tPrim p ≤s[pb] tPrim p'

| cumul_beta : forall na t b a,
    Σ ;;; Γ ⊢ tApp (tLambda na t b) a ≤s[pb] b {0 := a}

| cumul_zeta : forall na b t b',
    Σ ;;; Γ ⊢ tLetIn na b t b' ≤s[pb] b' {0 := b}

| cumul_rel i body :
    option_map decl_body (nth_error Γ i) = Some (Some body) ->
    Σ ;;; Γ ⊢ tRel i ≤s[pb] lift0 (S i) body

| cumul_iota : forall ci c u args p brs br,
    nth_error brs c = Some br ->
    #|args| = (ci.(ci_npar) + context_assumptions br.(bcontext))%nat ->
    Σ ;;; Γ ⊢ tCase ci p (mkApps (tConstruct ci.(ci_ind) c u) args) brs  ≤s[pb] iota_red ci.(ci_npar) p args br

| cumul_fix : forall mfix idx args narg fn,
    unfold_fix mfix idx = Some (narg, fn) ->
    is_constructor narg args = true ->
    Σ ;;; Γ ⊢ mkApps (tFix mfix idx) args ≤s[pb] mkApps fn args

| cumul_cofix_case : forall ip p mfix idx args narg fn brs,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tCase ip p (mkApps (tCoFix mfix idx) args) brs ≤s[pb] tCase ip p (mkApps fn args) brs

| cumul_cofix_proj : forall p mfix idx args narg fn,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tCoFix mfix idx) args) ≤s[pb] tProj p (mkApps fn args)

| cumul_delta : forall c decl body (isdecl : declared_constant Σ c decl) u,
    decl.(cst_body) = Some body ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] body@[u]

| cumul_proj : forall p args u arg,
    nth_error args (p.(proj_npars) + p.(proj_arg)) = Some arg ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tConstruct p.(proj_ind) 0 u) args) ≤s[pb] arg

where " Σ ;;; Γ ⊢ t ≤s[ pb ] u " := (@cumulSpec0 _ Σ Γ pb t u) : type_scope.
Definition cumulSpec `{checker_flags} (Σ : global_env_ext) Γ := cumulSpec0 Σ Γ Cumul.

Notation " Σ ;;; Γ |- t <=s u " := (@cumulSpec _ Σ Γ t u) (at level 50, Γ, t, u at next level).

Module PCUICConversionParSpec <: EnvironmentTyping.ConversionParSig PCUICTerm PCUICEnvironment PCUICTermUtils PCUICEnvTyping.
  Definition cumul_gen := @cumulSpec0.
End PCUICConversionParSpec.

End PCUICCumulativitySpec.
Import MetaCoq.Common.config.
Import MetaCoq.PCUIC.utils.PCUICPrimitive.

Implicit Types (cf : checker_flags) (Σ : global_env_ext).

Definition type_of_constructor mdecl (cdecl : constructor_body) (c : inductive * nat) (u : list Level.t) :=
  let mind := inductive_mind (fst c) in
  subst0 (inds mind u mdecl.(ind_bodies)) (subst_instance u (cstr_type cdecl)).

Include PCUICEnvTyping.

Inductive FixCoFix : Type := Fix | CoFix.

Class GuardChecker :=
{
  guard : FixCoFix -> global_env_ext -> context -> mfixpoint term -> Prop ;
}.

Axiom guard_checking : GuardChecker.
#[global]
Existing Instance guard_checking.

Definition fix_guard := guard Fix.
Definition cofix_guard := guard CoFix.

Definition destInd (t : term) :=
  match t with
  | tInd ind u => Some (ind, u)
  | _ => None
  end.

Definition isCoFinite (r : recursivity_kind) :=
  match r with
  | CoFinite => true
  | _ => false
  end.

Definition check_recursivity_kind
  (lookup: kername -> option global_decl) ind r :=
  match lookup ind with
  | Some (InductiveDecl mib) => ReflectEq.eqb mib.(ind_finite) r
  | _ => false
  end.

Definition check_one_fix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  match nth_error (List.rev (smash_context [] ctx)) arg with
  | Some argd =>
    let (hd, args) := decompose_app argd.(decl_type) in
    match destInd hd with
    | Some (mkInd mind _, u) => Some mind
    | None => None
    end
  | None => None
  end.

Definition wf_fixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  forallb (isLambda ∘ dbody) mfix &&
  let checks := map check_one_fix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind Finite
  | _ => false
  end.

Definition wf_fixpoint (Σ : global_env) := wf_fixpoint_gen (lookup_env Σ).

Definition check_one_cofix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  let (hd, args) := decompose_app ty in
  match destInd hd with
  | Some (mkInd ind _, u) => Some ind
  | None => None
  end.

Definition wf_cofixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  let checks := map check_one_cofix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind CoFinite
  | _ => false
  end.

Definition wf_cofixpoint (Σ : global_env) := wf_cofixpoint_gen (lookup_env Σ).

Reserved Notation "'wf_local' Σ Γ " (at level 9, Σ, Γ at next level).

Reserved Notation " Σ ;;; Γ |- t : T " (at level 50, Γ, t, T at next level).

Variant case_side_conditions `{checker_flags} wf_local_fun typing Σ Γ ci p ps mdecl idecl indices predctx :=
| case_side_info
    (eq_npars : mdecl.(ind_npars) = ci.(ci_npar))
    (wf_pred : wf_predicate mdecl idecl p)
    (cons : consistent_instance_ext Σ (ind_universes mdecl) p.(puinst))
    (wf_pctx : wf_local_fun Σ (Γ ,,, predctx))

    (conv_pctx : eq_context_upto_names p.(pcontext) (ind_predicate_context ci.(ci_ind) mdecl idecl))
    (allowed_elim : is_allowed_elimination Σ idecl.(ind_kelim) ps)
    (ind_inst : ctx_inst (typing Σ) Γ (p.(pparams) ++ indices)
                         (List.rev (subst_instance p.(puinst)
                                                   (ind_params mdecl ,,, ind_indices idecl : context))))
    (not_cofinite : isCoFinite mdecl.(ind_finite) = false).

Variant case_branch_typing `{checker_flags} wf_local_fun typing Σ Γ (ci:case_info) p ps mdecl idecl ptm  brs :=
| case_branch_info
    (wf_brs : wf_branches idecl brs)
    (brs_ty :
       All2i (fun i cdecl br =>

                eq_context_upto_names br.(bcontext) (cstr_branch_context ci mdecl cdecl) ×
                let brctxty := case_branch_type ci.(ci_ind) mdecl idecl p br ptm i cdecl in
                (wf_local_fun Σ (Γ ,,, brctxty.1) ×
                ((typing Σ (Γ ,,, brctxty.1) br.(bbody) (brctxty.2)) ×
                (typing Σ (Γ ,,, brctxty.1) brctxty.2 (tSort ps)))))
             0 idecl.(ind_ctors) brs).

Variant primitive_typing_hyps `{checker_flags}
  (typing : forall (Σ : global_env_ext) (Γ : context), term -> term -> Type)
  Σ Γ : prim_val term -> Type :=
| prim_int_hyps i : primitive_typing_hyps typing Σ Γ (primInt; primIntModel i)
| prim_float_hyps f : primitive_typing_hyps typing Σ Γ (primFloat; primFloatModel f)
| prim_array_hyps a
  (wfl : wf_universe Σ (Universe.make' a.(array_level)))
  (hty : typing Σ Γ a.(array_type) (tSort (sType (Universe.make' a.(array_level)))))
  (hdef : typing Σ Γ a.(array_default) a.(array_type))
  (hvalue : All (fun x => typing Σ Γ x a.(array_type)) a.(array_value)) :
  primitive_typing_hyps typing Σ Γ (primArray; primArrayModel a).

Equations prim_type (p : prim_val term) (cst : kername) : term :=
prim_type (primInt; _) cst := tConst cst [];
prim_type (primFloat; _) cst := tConst cst [];
prim_type (primArray; primArrayModel a) cst := tApp (tConst cst [a.(array_level)]) a.(array_type).

Inductive typing `{checker_flags} (Σ : global_env_ext) (Γ : context) : term -> term -> Type :=
| type_Rel : forall n decl,
    wf_local Σ Γ ->
    nth_error Γ n = Some decl ->
    Σ ;;; Γ |- tRel n : lift0 (S n) decl.(decl_type)

| type_Sort : forall s,
    wf_local Σ Γ ->
    wf_sort Σ s ->
    Σ ;;; Γ |- tSort s : tSort (Sort.super s)

| type_Prod : forall na A B s1 s2,
    lift_typing typing Σ Γ (j_vass_s na A s1) ->
    Σ ;;; Γ ,, vass na A |- B : tSort s2 ->
    Σ ;;; Γ |- tProd na A B : tSort (Sort.sort_of_product s1 s2)

| type_Lambda : forall na A t B,
    lift_typing typing Σ Γ (j_vass na A) ->
    Σ ;;; Γ ,, vass na A |- t : B ->
    Σ ;;; Γ |- tLambda na A t : tProd na A B

| type_LetIn : forall na b B t A,
    lift_typing typing Σ Γ (j_vdef na b B) ->
    Σ ;;; Γ ,, vdef na b B |- t : A ->
    Σ ;;; Γ |- tLetIn na b B t : tLetIn na b B A

| type_App : forall t na A B s u,

    Σ ;;; Γ |- tProd na A B : tSort s ->
    Σ ;;; Γ |- t : tProd na A B ->
    Σ ;;; Γ |- u : A ->
    Σ ;;; Γ |- tApp t u : B{0 := u}

| type_Const : forall cst u decl,
    wf_local Σ Γ ->
    declared_constant Σ cst decl ->
    consistent_instance_ext Σ decl.(cst_universes) u ->
    Σ ;;; Γ |- tConst cst u : decl.(cst_type)@[u]

| type_Ind : forall ind u mdecl idecl,
    wf_local Σ Γ ->
    declared_inductive Σ ind mdecl idecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tInd ind u : idecl.(ind_type)@[u]

| type_Construct : forall ind i u mdecl idecl cdecl,
    wf_local Σ Γ ->
    declared_constructor Σ (ind, i) mdecl idecl cdecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tConstruct ind i u : type_of_constructor mdecl cdecl (ind, i) u

| type_Case : forall ci p c brs indices ps mdecl idecl,
    let predctx := case_predicate_context ci.(ci_ind) mdecl idecl p in
    let ptm := it_mkLambda_or_LetIn predctx p.(preturn) in
    declared_inductive Σ ci.(ci_ind) mdecl idecl ->
    Σ ;;; Γ ,,, predctx |- p.(preturn) : tSort ps ->
    Σ ;;; Γ |- c : mkApps (tInd ci.(ci_ind) p.(puinst)) (p.(pparams) ++ indices) ->
    case_side_conditions (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                         mdecl idecl indices predctx  ->
    case_branch_typing (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                        mdecl idecl ptm brs ->
    Σ ;;; Γ |- tCase ci p c brs : mkApps ptm (indices ++ [c])

| type_Proj : forall p c u mdecl idecl cdecl pdecl args,
    declared_projection Σ p mdecl idecl cdecl pdecl ->
    Σ ;;; Γ |- c : mkApps (tInd p.(proj_ind) u) args ->
    #|args| = ind_npars mdecl ->
    Σ ;;; Γ |- tProj p c : subst0 (c :: List.rev args) pdecl.(proj_type)@[u]

| type_Fix : forall mfix n decl,
    wf_local Σ Γ ->
    fix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_fixpoint Σ mfix ->
    Σ ;;; Γ |- tFix mfix n : decl.(dtype)

| type_CoFix : forall mfix n decl,
    wf_local Σ Γ ->
    cofix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_cofixpoint Σ mfix ->
    Σ ;;; Γ |- tCoFix mfix n : decl.(dtype)

| type_Prim p prim_ty cdecl :
    wf_local Σ Γ ->
    primitive_constant Σ (prim_val_tag p) = Some prim_ty ->
    declared_constant Σ prim_ty cdecl ->
    primitive_invariants (prim_val_tag p) cdecl ->
    primitive_typing_hyps typing Σ Γ p ->
    Σ ;;; Γ |- tPrim p : prim_type p prim_ty

| type_Cumul : forall t A B s,
    Σ ;;; Γ |- t : A ->
    Σ ;;; Γ |- B : tSort s ->
    Σ ;;; Γ |- A <=s B ->
    Σ ;;; Γ |- t : B

where " Σ ;;; Γ |- t : T " := (typing Σ Γ t T)
and "'wf_local' Σ Γ " := (All_local_env (lift_typing1 (typing Σ)) Γ).

Module PCUICTypingDef <: EnvironmentTyping.Typing PCUICTerm PCUICEnvironment PCUICTermUtils PCUICEnvTyping PCUICConversion PCUICConversionParSpec.

  Definition typing := @typing.

End PCUICTypingDef.

Definition wf `{checker_flags} := on_global_env cumulSpec0 (lift_typing typing).

Definition wf_ext `{checker_flags} := on_global_env_ext cumulSpec0 (lift_typing typing).

Record normalizing_flags {cf : checker_flags} : Prop :=
  { nor_check_univs :> check_univs }.
Import MetaCoq.PCUIC.PCUICAst.

Inductive ConversionError :=
| NotFoundConstants (c1 c2 : kername)

| NotFoundConstant (c : kername)

| LambdaNotConvertibleTypes
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)
    (e : ConversionError)

| LambdaNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)

| ProdNotConvertibleDomains
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)
    (e : ConversionError)

| ProdNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)

| ContextNotConvertibleAnn
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleType
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleBody
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleLength

| CaseOnDifferentInd
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredParamsUnequalLength
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredUnequalUniverseInstances
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| DistinctStuckProj
    (Γ : context) (p : projection) (c : term)
    (Γ' : context) (p' : projection) (c' : term)

| CannotUnfoldFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| FixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| FixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctCoFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| CoFixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| CoFixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctPrimTags
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| DistinctPrimValues
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| ArrayNotConvertibleLevels
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayValuesNotSameLength
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayNotConvertibleValues
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleDefault
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleTypes
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| StackHeadError
    (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackTailError (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackMismatch
    (Γ1 : context) (t1 : term) (args1 l1 : list term)
    (Γ2 : context) (t2 : term) (l2 : list term)

| HeadMismatch
    (leq : conv_pb)
    (Γ1 : context) (t1 : term)
    (Γ2 : context) (t2 : term).

Inductive type_error :=
| UnboundRel (n : nat)
| UnboundVar (id : string)
| UnboundEvar (ev : nat)
| UndeclaredConstant (c : kername)
| UndeclaredInductive (c : inductive)
| UndeclaredConstructor (c : inductive) (i : nat)
| NotCumulSmaller {abstract_structure} (le : bool)
  (G : abstract_structure) (Γ : context) (t u t' u' : term) (e : ConversionError)
| NotConvertible {abstract_structure}
  (G : abstract_structure)
  (Γ : context) (t u : term)
| NotASort (t : term)
| NotAProduct (t t' : term)
| NotAnInductive (t : term)
| NotAnArity (t : term)
| IllFormedFix (m : mfixpoint term) (i : nat)
| UnsatisfiedConstraints (c : ConstraintSet.t)
| Msg (s : string).

Inductive env_error :=
| IllFormedDecl (e : string) (e : type_error)
| AlreadyDeclared (id : string).

Section EnvCheck.

  Context (abstract_structure : Type).

Inductive EnvCheck (A : Type) :=
| CorrectDecl (a : A)
| EnvError (Σ : abstract_structure) (e : env_error).
Global Instance envcheck_monad : Monad EnvCheck.
Admitted.

End EnvCheck.
Import MetaCoq.Common.uGraph.

Lemma wf_ext_gc_of_uctx {cf:checker_flags} {Σ : global_env_ext} (HΣ : ∥ wf_ext Σ ∥)
: ∑ uctx', gc_of_uctx (global_ext_uctx Σ) = Some uctx'.
Admitted.

Definition on_global_decls {cf:checker_flags} Σ :=
  on_global_decls_data cumulSpec0 (lift_typing typing) (cf:=cf) Σ.(universes) Σ.(retroknowledge) Σ.(declarations).

Class abstract_env_struct {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl : Type) := {

  abstract_env_rel : abstract_env_impl -> global_env -> Prop;
  abstract_env_ext_rel : abstract_env_ext_impl -> global_env_ext -> Prop;

  abstract_env_init (cs:ContextSet.t) (retro : Retroknowledge.t) : on_global_univs cs -> abstract_env_impl;
  abstract_env_add_decl X (kn:kername) (d:global_decl) :
   (forall Σ, abstract_env_rel X Σ -> ∥ on_global_decls Σ kn d ∥)
   -> abstract_env_impl;
  abstract_env_add_udecl X udecl :
    (forall Σ, abstract_env_rel X Σ -> ∥ on_udecl Σ.(universes) udecl ∥) ->
    abstract_env_ext_impl ;
  abstract_pop_decls : abstract_env_impl -> abstract_env_impl ;

  abstract_env_lookup : abstract_env_ext_impl -> kername -> option global_decl;
  abstract_primitive_constant : abstract_env_ext_impl -> Primitive.prim_tag -> option kername;

  abstract_env_level_mem : abstract_env_ext_impl -> Level.t -> bool;
  abstract_env_leqb_level_n : abstract_env_ext_impl -> Z -> Level.t -> Level.t -> bool;
  abstract_env_guard : abstract_env_ext_impl -> FixCoFix -> context -> mfixpoint term -> bool;
  abstract_env_is_consistent : abstract_env_impl -> LevelSet.t * GoodConstraintSet.t -> bool ;

}.

Class abstract_env_prop {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl: Type)
  `{!abstract_env_struct abstract_env_impl abstract_env_ext_impl} : Prop := {

  abstract_env_ext_exists X : ∥ ∑ Σ , abstract_env_ext_rel X Σ ∥;
  abstract_env_ext_wf X {Σ} : abstract_env_ext_rel X Σ -> ∥ wf_ext Σ ∥ ;
  abstract_env_ext_irr X {Σ Σ'} :
      abstract_env_ext_rel X Σ -> abstract_env_ext_rel X Σ' ->  Σ = Σ';

  abstract_env_exists X : ∥ ∑ Σ , abstract_env_rel X Σ ∥;
  abstract_env_wf X {Σ} : abstract_env_rel X Σ -> ∥ wf Σ ∥;
  abstract_env_irr X {Σ Σ'} :
    abstract_env_rel X Σ -> abstract_env_rel X Σ' ->  Σ = Σ';

  abstract_env_init_correct univs retro cuniv :
    abstract_env_rel (abstract_env_init univs retro cuniv)
    {| universes := univs; declarations := []; retroknowledge := retro |} ;
  abstract_env_add_decl_correct X Σ kn d H : abstract_env_rel X Σ ->
    abstract_env_rel (abstract_env_add_decl X kn d H) (add_global_decl Σ (kn,d));
  abstract_env_add_udecl_rel X {Σ} udecl H :
    (abstract_env_rel X Σ.1 /\ Σ.2 = udecl) <->
    abstract_env_ext_rel (abstract_env_add_udecl X udecl H) Σ;
  abstract_pop_decls_correct X decls (prf : forall Σ : global_env, abstract_env_rel X Σ ->
            exists d, Σ.(declarations) = d :: decls) :
    let X' := abstract_pop_decls X in
    forall Σ Σ', abstract_env_rel X Σ -> abstract_env_rel X' Σ' ->
                      Σ'.(declarations) = decls /\ Σ.(universes) = Σ'.(universes) /\
                      Σ.(retroknowledge) = Σ'.(retroknowledge);

  abstract_env_lookup_correct X {Σ} kn decl : abstract_env_ext_rel X Σ ->
      In (kn, decl) (declarations Σ) <-> abstract_env_lookup X kn = Some decl ;

  abstract_env_leqb_level_n_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ):
    let uctx := (wf_ext_gc_of_uctx (abstract_env_ext_wf X wfΣ)).π1 in
    leqb_level_n_spec_gen uctx (abstract_env_leqb_level_n X);
  abstract_env_level_mem_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) l:
    LevelSet.In l (global_ext_levels Σ) <-> abstract_env_level_mem X l;
  abstract_env_is_consistent_correct X Σ uctx udecl :
    abstract_env_rel X Σ ->
    ConstraintSet.For_all (declared_cstr_levels (LevelSet.union udecl.1 (global_levels Σ))) udecl.2 ->
    gc_of_uctx udecl = Some uctx ->
    consistent_extension_on (global_uctx Σ) udecl.2 <-> abstract_env_is_consistent X uctx ;

  abstract_env_guard_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) fix_cofix Γ mfix :
      guard fix_cofix Σ Γ mfix <-> abstract_env_guard X fix_cofix Γ mfix;
  abstract_primitive_constant_correct X tag Σ :
    abstract_env_ext_rel X Σ -> abstract_primitive_constant X tag = PCUICEnvironment.primitive_constant Σ tag
  }.

Definition abstract_env_impl {cf:checker_flags} := ∑ X Y Z, @abstract_env_prop _ X Y Z.

Import MCMonadNotation.

Section CheckEnv.
  Context {cf:checker_flags} {nor : normalizing_flags}.

  Context (X_impl : abstract_env_impl).

  Definition X_env_type := X_impl.π1.

  Implicit Type X : X_env_type.
    Context {AA : Type} {BB : AA -> Type} {T : Type -> Type} {M : Monad T} {A} {P : forall (aa:AA), BB aa -> A -> Type} {Q : forall (aa:AA), BB aa -> A -> Type}
    (f : forall x, (forall aa bb, ∥ Q aa bb x ∥) -> T (forall aa bb, ∥ P aa bb x ∥)).
    Program Fixpoint monad_All_All l :
      (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) ->
      T (forall (aa:AA) (bb:BB aa), ∥ All (P aa bb) l ∥) :=
      match l return (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) -> T (forall (aa:AA) (bb:BB aa) , ∥ All (P aa bb) l ∥) with
        | [] => fun _ => ret (fun aa bb  => sq All_nil)
        | a :: l => fun allq =>
        X <- f a _ ;;
        Y <- monad_All_All l _ ;;
        ret (fun aa bb  => _)
        end.
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 4.2MiB file on GitHub Actions Artifacts under build.log)
space/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.0Ve6ibjJNz
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.Q36mplDNud
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.9CEFLsEysm
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make -C pcuic
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -f Makefile.coq
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.AQhYWTFhkj
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.fg4Zbi81kz
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.fc6reMvOhg
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.vxHpuB6Nnv
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -C safechecker
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make -f Makefile.safechecker
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.wyUdofDKIp
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.fvE30dpxCZ
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.aFyMk1oztE
MINIMIZER_DEBUG: files: 
COQC theories/PCUICSafeChecker.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -deprecated-native-compiler-option -native-compiler no -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories MetaCoq.Utils -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories MetaCoq.Common -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories MetaCoq.PCUIC -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories MetaCoq.SafeChecker theories/PCUICSafeChecker.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.b0kIWBvrC5
MINIMIZER_DEBUG: files:  theories/PCUICSafeChecker.v
File "./theories/PCUICSafeChecker.v", line 1739, characters 8-85:
Error:
In environment
cf : checker_flags
nor : normalizing_flags
X_impl : abstract_env_impl
AA : Type
BB : AA -> Type
T : Type -> Type
M : Monad T
A : Type
P : forall aa : AA, BB aa -> A -> Type
Q : forall aa : AA, BB aa -> A -> Type
f :
  forall x : A,
  (forall (aa : AA) (bb : BB aa), ∥ Q aa bb x ∥) ->
  T (forall (aa : AA) (bb : BB aa), ∥ P aa bb x ∥)
monad_All_All :
  Tactics.fix_proto
    (forall l : list A,
     (forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) l ∥) ->
     T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) l ∥))
l : list A
a : A
l0 : list A
allq : forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) (a :: l0) ∥
Unable to unify
 "EnvCheck ?abstract_structure0@{l0:=l; l:=l0}
    (forall (aa : ?T@{l0:=l; l:=l0}) (bb : ?T0@{l0:=l; l:=l0}),
     ?T1@{l0:=l; l:=l0})" with
 "T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) (a :: l0) ∥)".

Command exited with non-zero status 1
theories/PCUICSafeChecker.vo (real: 13.08, user: 12.92, sys: 0.15, mem: 994348 ko)
make[4]: *** [Makefile.safechecker:803: theories/PCUICSafeChecker.vo] Error 1
make[3]: *** [Makefile.safechecker:417: all] Error 2
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[2]: *** [Makefile:11: theory] Error 2
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[1]: *** [Makefile:151: safechecker] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real metacoq.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m13.08s | 994348 ko | Total Time / Peak Mem
--------------------------------------------
0m13.08s | 994348 ko | PCUICSafeChecker.vo  
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-metacoq] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 273KiB file on GitHub Actions Artifacts under bug.log)
.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Qed Obligation with Admit Obligations
�[92m
Admitting Qed Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qed Obligations unsuccessful.
No successful changes.

I will now attempt to replace Qeds with Admitteds
�[92m
Admitting Qeds successful.�[0m
Success!

I will now attempt to replace Qeds with admit. Defined.
�[92m
Admitting Qeds successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Qeds unsuccessful.
No successful changes.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpz2owv947/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpz2owv947/Top/bug_01.v", line 645, characters 4-30:
Warning:
Automatically inlined signature for type All_local_env. Use [Derive Signature for All_local_env.] to avoid this.
File "/tmp/tmpz2owv947/Top/bug_01.v", line 1172, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 645, characters 4-30:
Warning:
Automatically inlined signature for type All_local_env. Use [Derive Signature for All_local_env.] to avoid this.
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 1172, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables

Non-fatal error: Failed to remove variables and preserve the error.  
The new error was:
File "/tmp/tmp_gkv5e2q/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp_gkv5e2q/Top/bug_01.v", line 1830, characters 21-30:
Error: The reference cumul_gen was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpz2owv947/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpz2owv947/Top/bug_01.v", line 645, characters 4-30:
Warning:
Automatically inlined signature for type All_local_env. Use [Derive Signature for All_local_env.] to avoid this.
File "/tmp/tmpz2owv947/Top/bug_01.v", line 1172, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 645, characters 4-30:
Warning:
Automatically inlined signature for type All_local_env. Use [Derive Signature for All_local_env.] to avoid this.
File "/tmp/tmp1w04ffpu/Top/bug_01.v", line 1172, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables

Non-fatal error: Failed to remove variables and preserve the error.  
The new error was:
File "/tmp/tmp_gkv5e2q/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp_gkv5e2q/Top/bug_01.v", line 1830, characters 21-30:
Error: The reference cumul_gen was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Success!

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpljuj9tzb/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpljuj9tzb/Top/bug_01.v", line 1969, characters 0-960:
Error: Cannot guess decreasing argument of fix.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions successful
Success!

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined
�[92m
Admitting definitions successful.�[0m
Success!

I will now attempt to export modules
Module exportation successful

I will now attempt to split imports and exports
Import/Export splitting successful

I will now attempt to split := definitions

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

Copy link
Contributor

coqbot-app bot commented May 7, 2024

Minimization interrupted by timeout, being automatically continued. Partially Minimized File /home/runner/work/run-coq-bug-minimizer/run-coq-bug-minimizer/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories/PCUICSafeChecker.v (from ci-metacoq) (interrupted by timeout, being automatically continued) (full log on GitHub Actions - verbose log)
⭐ ⏱️ Partially Minimized Coq File (timeout) (truncated to first and last 32KiB; full 81KiB file on GitHub Actions Artifacts under bug.v)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "-deprecated-native-compiler-option" "-native-compiler" "no" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories" "MetaCoq.Utils" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories" "MetaCoq.Common" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories" "MetaCoq.PCUIC" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories" "MetaCoq.SafeChecker" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Equations" "Equations" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "Top.bug_01") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 2560 lines to 33 lines, then from 46 lines to 622 lines, then from 625 lines to 113 lines, then from 126 lines to 1493 lines, then from 1494 lines to 115 lines, then from 128 lines to 821 lines, then from 825 lines to 280 lines, then from 293 lines to 710 lines, then from 715 lines to 282 lines, then from 295 lines to 1746 lines, then from 1751 lines to 545 lines, then from 558 lines to 1457 lines, then from 1461 lines to 711 lines, then from 724 lines to 2544 lines, then from 2543 lines to 722 lines, then from 740 lines to 722 lines, then from 735 lines to 2955 lines, then from 2955 lines to 780 lines, then from 793 lines to 1386 lines, then from 1389 lines to 903 lines, then from 916 lines to 2194 lines, then from 2193 lines to 920 lines, then from 933 lines to 2554 lines, then from 2555 lines to 1195 lines, then from 1208 lines to 1598 lines, then from 1602 lines to 1261 lines, then from 1274 lines to 3763 lines, then from 3760 lines to 3089 lines, then from 3022 lines to 1822 lines, then from 1835 lines to 3217 lines, then from 3220 lines to 2053 lines, then from 2066 lines to 2157 lines, then from 2162 lines to 2240 lines *)
(* coqc version 8.20+alpha compiled with OCaml 4.09.0
   coqtop version runner-t7b1znuaq-project-4504-concurrent-4:/builds/coq/coq/_build/default,(HEAD detached at e220577dc5a4) (e220577dc5a4cfa9bbac925c2e3fb42236b36b54)
   Expected coqc runtime on this file: 2.447 sec *)











Require Coq.Init.Ltac.
Require Coq.ssr.ssreflect.
Require Coq.ssr.ssrbool.
Require Coq.Structures.OrderedTypeAlt.
Require Coq.MSets.MSetAVL.
Require Coq.MSets.MSetFacts.
Require Coq.MSets.MSetProperties.
Require Coq.MSets.MSetDecide.
Require Coq.Classes.Morphisms.
Require Coq.Bool.Bool.
Require Coq.ZArith.ZArith.
Require Coq.Arith.Arith.
Require Coq.micromega.Lia.
Require Coq.Lists.List.
Require Coq.Init.Nat.
Require Coq.Strings.Ascii.
Require Coq.Strings.String.
Require Coq.extraction.Extraction.
Require Coq.Unicode.Utf8_core.
Require Equations.Init.
Require Equations.Signature.
Require Equations.CoreTactics.
Require Coq.Relations.Relation_Definitions.
Require Equations.Prop.Logic.
Require Equations.Prop.Classes.
Require Coq.Program.Tactics.
Require Equations.Prop.EqDec.
Require Equations.Prop.DepElim.
Require Coq.Relations.Relations.
Require Equations.Prop.Constants.
Require Coq.Bool.Bvector.
Require Coq.Arith.Wf_nat.
Require Coq.Wellfounded.Wellfounded.
Require Coq.Relations.Relation_Operators.
Require Coq.Wellfounded.Lexicographic_Product.
Require Coq.Program.Wf.
Require Coq.Logic.FunctionalExtensionality.
Require Equations.Prop.Subterm.
Require Equations.Prop.FunctionalInduction.
Require Equations.Prop.Tactics.
Require Equations.Prop.NoConfusion.
Require Equations.Prop.EqDecInstances.
Require Equations.Prop.Loader.
Require Equations.Prop.Telescopes.
Require Equations.Prop.Equations.
Require Coq.btauto.Algebra.
Require MetaCoq.Utils.MCPrelude.
Require MetaCoq.Utils.MCReflect.
Require Coq.Unicode.Utf8.
Require Coq.Lists.SetoidList.
Require Coq.Classes.CRelationClasses.
Require Equations.Type.Logic.
Require Equations.Type.Relation.
Require Equations.Type.Relation_Properties.
Require Coq.Classes.RelationClasses.
Require MetaCoq.Utils.MCRelations.
Require MetaCoq.Utils.ReflectEq.
Require MetaCoq.Utils.MCList.
Require MetaCoq.Utils.MCProd.
Require MetaCoq.Utils.MCOption.
Require MetaCoq.Utils.MCSquash.
Require MetaCoq.Utils.All_Forall.
Require Coq.Classes.Morphisms_Prop.
Require MetaCoq.Utils.MCArith.
Require Coq.Structures.OrderedType.
Require Coq.Structures.Orders.
Require MetaCoq.Utils.MCCompare.
Require MetaCoq.Utils.MCEquality.
Require Coq.Init.Decimal.
Require Coq.Numbers.DecimalString.
Require Coq.NArith.NArith.
Require Coq.Strings.Byte.
Require Coq.NArith.BinNat.
Require MetaCoq.Utils.ByteCompare.
Require Coq.Logic.Eqdep_dec.
Require MetaCoq.Utils.ByteCompareSpec.
Require Coq.Structures.OrdersAlt.
Require MetaCoq.Utils.bytestring.
Require MetaCoq.Utils.MCString.
Require MetaCoq.Utils.MCTactics.SpecializeBy.
Require MetaCoq.Utils.MCTactics.Zeta1.
Require MetaCoq.Utils.MCTactics.GeneralizeOverHoles.
Require MetaCoq.Utils.MCTactics.FindHyp.
Require MetaCoq.Utils.MCTactics.UniquePose.
Require MetaCoq.Utils.MCTactics.InHypUnderBindersDo.
Require MetaCoq.Utils.MCTactics.SpecializeUnderBindersBy.
Require MetaCoq.Utils.MCTactics.Head.
Require MetaCoq.Utils.MCTactics.DestructHyps.
Require MetaCoq.Utils.MCTactics.DestructHead.
Require MetaCoq.Utils.MCTactics.SpecializeAllWays.
Require MetaCoq.Utils.MCTactics.SplitInContext.
Require Ltac2.Init.
Require Ltac2.Message.
Require Ltac2.Control.
Require Ltac2.Std.
Require Ltac2.Ltac1.
Require MetaCoq.Utils.MCUtils.
Require MetaCoq.Utils.monad_utils.
Require MetaCoq.Utils.utils.
Require Coq.ZArith.Zcompare.
Require Coq.MSets.MSetInterface.
Require MetaCoq.Utils.wGraph.
Require Coq.btauto.Btauto.
Require MetaCoq.Common.config.
Require Coq.MSets.MSetList.
Require Coq.FSets.FMapAVL.
Require MetaCoq.Utils.MCMSets.
Require Coq.Structures.Equalities.
Require Coq.FSets.FMapInterface.
Require Coq.FSets.FMapList.
Require Coq.FSets.FMapFullAVL.
Require Coq.FSets.FMapFacts.
Require MetaCoq.Utils.MCFSets.
Require Coq.Setoids.Setoid.
Require Coq.Structures.OrderedTypeEx.
Require MetaCoq.Common.Kernames.
Require Coq.Floats.SpecFloat.
Require MetaCoq.Common.BasicAst.
Require MetaCoq.Common.Universes.
Require Coq.Classes.SetoidTactics.
Require MetaCoq.Common.uGraph.
Require Coq.Numbers.Cyclic.Int63.Uint63.
Require Coq.Floats.PrimFloat.
Require Coq.Floats.FloatAxioms.
Require MetaCoq.Common.Reflect.
Require Coq.Floats.FloatOps.
Require Coq.Numbers.HexadecimalString.

Module Export AdmitTactic.
Module Import LocalFalse.
Inductive False : Prop := .
End LocalFalse.
Axiom proof_admitted : False.
Import Coq.Init.Ltac.
Tactic Notation "admit" := abstract case proof_admitted.
End AdmitTactic.

Module Export MetaCoq_DOT_Common_DOT_Primitive_WRAPPED.
Module Export Primitive.
Import Coq.Numbers.Cyclic.Int63.Uint63.
Import Coq.Floats.PrimFloat.
Import Coq.Floats.SpecFloat.
Import Coq.Floats.FloatOps.
Import Coq.ZArith.ZArith.
Import Coq.Numbers.HexadecimalString.
Import MetaCoq.Utils.bytestring.
Import MetaCoq.Utils.MCString.
Local Open Scope bs.

Variant prim_tag :=
  | primInt
  | primFloat
  | primArray.
Derive NoConfusion EqDec for prim_tag.
Definition string_of_prim_int (i:Uint63.int) : string. exact (string_of_Z (Uint63.to_Z i)). Defined.
Definition string_of_float (f : PrimFloat.float) : string. exact (match Prim2SF f with
  | S754_zero sign => if sign then "-0" else "0"
  | S754_infinity sign => if sign then "-INFINITY" else "INFINITY"
  | S754_nan => "NAN"
  | S754_finite sign p z =>
    let abs := "0x" ++ bytestring.String.of_string (Numbers.HexadecimalString.NilZero.string_of_uint (Pos.to_hex_uint p)) ++ "p" ++
      bytestring.String.of_string (Numbers.DecimalString.NilZero.string_of_int (Z.to_int z))
    in if sign then "-" ++ abs else abs
  end). Defined.
End Primitive.

End MetaCoq_DOT_Common_DOT_Primitive_WRAPPED.
Module Export MetaCoq_DOT_Common_DOT_Primitive.
Module Export MetaCoq.
Module Export Common.
Module Export Primitive.
Include MetaCoq_DOT_Common_DOT_Primitive_WRAPPED.Primitive.
End Primitive.

End Common.

End MetaCoq.

End MetaCoq_DOT_Common_DOT_Primitive.
Axiom proof_admitted : False.
Tactic Notation "admit" := abstract case proof_admitted.
Import Coq.ssr.ssrbool.
Import MetaCoq.Utils.utils.
Import MetaCoq.Common.BasicAst.
Import MetaCoq.Common.Primitive.
Import MetaCoq.Common.Universes.

Module Type Term.

  Parameter Inline term : Type.

  Parameter Inline tRel : nat -> term.
  Parameter Inline tSort : Sort.t -> term.
  Parameter Inline tProd : aname -> term -> term -> term.
  Parameter Inline tLambda : aname -> term -> term -> term.
  Parameter Inline tLetIn : aname -> term -> term -> term -> term.
  Parameter Inline tProj : projection -> term -> term.
  Parameter Inline mkApps : term -> list term -> term.

  Parameter Inline lift : nat -> nat -> term -> term.
  Parameter Inline subst : list term -> nat -> term -> term.
  Parameter Inline closedn : nat -> term -> bool.
  Parameter Inline subst_instance_constr : UnivSubst term.

  Notation lift0 n := (lift n 0).
End Term.

Module Type TermDecide (Import T : Term).
End TermDecide.

Module TermDecideReflectInstances (Import T : Term) (Import TDec : TermDecide T).
End TermDecideReflectInstances.

Module Export Retroknowledge.

  Record t := mk_retroknowledge {
    retro_int63 : option kername;
    retro_float64 : option kername;
    retro_array : option kername;
  }.

Module Environment (T : Term).

  Import T.
  #[global] Existing Instance subst_instance_constr.

  Definition judgment := judgment_ Sort.t term.

  Notation context_decl := (context_decl term).

  Definition vass x A : context_decl :=
    {| decl_name := x ; decl_body := None ; decl_type := A |}.

  Definition vdef x t A : context_decl :=
    {| decl_name := x ; decl_body := Some t ; decl_type := A |}.

  Definition context := list context_decl.

  Definition lift_context n k (Γ : context) : context :=
    fold_context_k (fun k' => lift n (k' + k)) Γ.

  Definition subst_context s k (Γ : context) : context :=
    fold_context_k (fun k' => subst s (k' + k)) Γ.

  Definition subst_telescope s k (Γ : context) : context :=
    mapi (fun k' decl => map_decl (subst s (k' + k)) decl) Γ.
Global Instance subst_instance_context : UnivSubst context.
Admitted.
Definition set_binder_name (na : aname) (x : context_decl) : context_decl.
Admitted.

  Fixpoint context_assumptions (Γ : context) :=
    match Γ with
    | [] => 0
    | d :: Γ =>
      match d.(decl_body) with
      | Some _ => context_assumptions Γ
      | None => S (context_assumptions Γ)
      end
    end.

  Fixpoint is_assumption_context (Γ : context) :=
    match Γ with
    | [] => true
    | d :: Γ =>
      match d.(decl_body) with
      | Some _ => false
      | None => is_assumption_context Γ
      end
    end.
Fixpoint smash_context (Γ Γ' : context) : context.
Admitted.

  Fixpoint extended_subst (Γ : context) (n : nat)
   :=
  match Γ with
  | nil => nil
  | cons d vs =>
    match decl_body d with
    | Some b =>

      let s := extended_subst vs n in

      let b' := lift (context_assumptions vs + n) #|s| b in

      let b' := subst s 0 b' in

      b' :: s
    | None => tRel n :: extended_subst vs (S n)
    end
  end.

  Definition expand_lets_k Γ k t :=
    (subst (extended_subst Γ 0) k (lift (context_assumptions Γ) (k + #|Γ|) t)).

  Definition expand_lets Γ t := expand_lets_k Γ 0 t.

  Definition expand_lets_k_ctx Γ k Δ :=
    (subst_context (extended_subst Γ 0) k (lift_context (context_assumptions Γ) (k + #|Γ|) Δ)).

  Definition expand_lets_ctx Γ Δ := expand_lets_k_ctx Γ 0 Δ.
Definition fix_context (m : mfixpoint term) : context.
Admitted.

  Record constructor_body := {
    cstr_name : ident;

    cstr_args : context;
    cstr_indices : list term;
    cstr_type : term;

    cstr_arity : nat;
  }.

  Record projection_body := {
    proj_name : ident;

    proj_relevance : relevance;
    proj_type : term;
  }.

  Record one_inductive_body := {
    ind_name : ident;
    ind_indices : context;
    ind_sort : Sort.t;
    ind_type : term;
    ind_kelim : allowed_eliminations;
    ind_ctors : list constructor_body;
    ind_projs : list projection_body;
    ind_relevance : relevance  }.

  Record mutual_inductive_body := {
    ind_finite : recursivity_kind;
    ind_npars : nat;
    ind_params : context;
    ind_bodies : list one_inductive_body ;
    ind_universes : universes_decl;
    ind_variance : option (list Universes.Variance.t) }.

  Record constant_body := {
    cst_type : term;
    cst_body : option term;
    cst_universes : universes_decl;
    cst_relevance : relevance }.

  Inductive global_decl :=
  | ConstantDecl : constant_body -> global_decl
  | InductiveDecl : mutual_inductive_body -> global_decl.

  Definition global_declarations := list (kername * global_decl).

  Record global_env := mk_global_env
    { universes : ContextSet.t;
      declarations : global_declarations;
      retroknowledge : Retroknowledge.t }.

  Coercion universes : global_env >-> ContextSet.t.

  Definition add_global_decl Σ decl :=
    {| universes := Σ.(universes);
       declarations := decl :: Σ.(declarations);
       retroknowledge := Σ.(retroknowledge) |}.
Fixpoint lookup_global (Σ : global_declarations) (kn : kername) : option global_decl.
Admitted.

  Definition lookup_env (Σ : global_env) (kn : kername) := lookup_global Σ.(declarations) kn.
Definition primitive_constant (Σ : global_env) (p : prim_tag) : option kername.
Admitted.
Definition tImpl (dom codom : term) : term.
Admitted.

  Definition array_uctx := ([nAnon], ConstraintSet.empty).

  Definition primitive_invariants (p : prim_tag) (cdecl : constant_body) :=
    match p with
    | primInt | primFloat =>
     [/\ cdecl.(cst_type) = tSort Sort.type0, cdecl.(cst_body) = None &
          cdecl.(cst_universes) = Monomorphic_ctx]
    | primArray =>
      let s := sType (Universe.make' (Level.lvar 0)) in
      [/\ cdecl.(cst_type) = tImpl (tSort s) (tSort s), cdecl.(cst_body) = None &
        cdecl.(cst_universes) = Polymorphic_ctx array_uctx]
    end.
Definition global_env_ext : Type.
exact (global_env * universes_decl).
Defined.
Definition fst_ctx : global_env_ext -> global_env.
Admitted.
  Coercion fst_ctx : global_env_ext >-> global_env.

  Definition mkLambda_or_LetIn d t :=
    match d.(decl_body) with
    | None => tLambda d.(decl_name) d.(decl_type) t
    | Some b => tLetIn d.(decl_name) b d.(decl_type) t
    end.

  Definition it_mkLambda_or_LetIn (l : context) (t : term) :=
    List.fold_left (fun acc d => mkLambda_or_LetIn d acc) l t.

  Definition mkProd_or_LetIn d t :=
    match d.(decl_body) with
    | None => tProd d.(decl_name) d.(decl_type) t
    | Some b => tLetIn d.(decl_name) b d.(decl_type) t
    end.

  Definition it_mkProd_or_LetIn (l : context) (t : term) :=
    List.fold_left (fun acc d => mkProd_or_LetIn d acc) l t.
Fixpoint reln (l : list term) (p : nat) (Γ0 : list context_decl) {struct Γ0} : list term.
Admitted.

  Definition to_extended_list_k Γ k := reln [] k Γ.
  Definition to_extended_list Γ := to_extended_list_k Γ 0.

  Definition arities_context (l : list one_inductive_body) :=
    rev_map (fun ind => vass (mkBindAnn (nNamed ind.(ind_name))
                            (ind.(ind_relevance))) ind.(ind_type)) l.

  Fixpoint projs ind npars k :=
    match k with
    | 0 => []
    | S k' => (tProj (mkProjection ind npars k') (tRel 0)) :: projs ind npars k'
    end.

End Environment.

Module Type EnvironmentSig (T : Term).
 Include Environment T.
End EnvironmentSig.

Module Type EnvironmentDecide (T : Term) (Import E : EnvironmentSig T).
End EnvironmentDecide.

Module EnvironmentDecideReflectInstances (T : Term) (Import E : EnvironmentSig T) (Import EDec : EnvironmentDecide T E).
End EnvironmentDecideReflectInstances.

Module Type TermUtils (T: Term) (E: EnvironmentSig T).
Import T.
Import E.

  Parameter Inline destArity : context -> term -> option (context × Sort.t).
  Parameter Inline inds : kername -> Instance.t -> list one_inductive_body -> list term.

End TermUtils.
Module Export EnvironmentTyping.
Import MetaCoq.Common.config.

Module Lookup (T : Term) (E : EnvironmentSig T).
Import E.

  Definition declared_constant (Σ : global_env) id decl := In (id,ConstantDecl decl) (declarations Σ).

  Definition declared_minductive Σ mind decl := In (mind,InductiveDecl decl) (declarations Σ).

  Definition declared_inductive Σ ind mdecl decl :=
    declared_minductive Σ (inductive_mind ind) mdecl /\
    List.nth_error mdecl.(ind_bodies) (inductive_ind ind) = Some decl.

  Definition declared_constructor Σ cstr mdecl idecl cdecl :=
    declared_inductive Σ (fst cstr) mdecl idecl /\
    List.nth_error idecl.(ind_ctors) (snd cstr) = Some cdecl.

  Definition declared_projection Σ (proj : projection) mdecl idecl cdecl pdecl
  : Prop :=
    declared_constructor Σ (proj.(proj_ind), 0) mdecl idecl cdecl /\
    List.nth_error idecl.(ind_projs) proj.(proj_arg) = Some pdecl /\
    mdecl.(ind_npars) = proj.(proj_npars).

  Definition lookup_minductive_gen (lookup : kername -> option global_decl) mind :=
    match lookup mind with
    | Some (InductiveDecl decl) => Some decl
    | _ => None
    end.

  Definition lookup_inductive_gen lookup ind :=
    match lookup_minductive_gen lookup (inductive_mind ind) with
    | Some mdecl =>
      match nth_error mdecl.(ind_bodies) (inductive_ind ind) with
      | Some idecl => Some (mdecl, idecl)
      | None => None
      end
    | None => None
    end.

  Definition lookup_constructor_gen lookup ind k :=
    match lookup_inductive_gen lookup ind with
    | Some (mdecl, idecl) =>
      match nth_error idecl.(ind_ctors) k with
      | Some cdecl => Some (mdecl, idecl, cdecl)
      | None => None
      end
    | _ => None
    end.

  Definition on_udecl_decl {A} (F : universes_decl -> A) d : A :=
  match d with
  | ConstantDecl cb => F cb.(cst_universes)
  | InductiveDecl mb => F mb.(ind_universes)
  end.

  Definition universes_decl_of_decl := on_udecl_decl (fun x => x).
Definition global_levels (univs : ContextSet.t) : LevelSet.t.
Admitted.
Definition global_uctx (Σ : global_env) : ContextSet.t.
Admitted.
Definition global_ext_levels (Σ : global_env_ext) : LevelSet.t.
Admitted.
Definition global_ext_constraints (Σ : global_env_ext) : ConstraintSet.t.
Admitted.

  Coercion global_ext_constraints : global_env_ext >-> ConstraintSet.t.
Definition global_ext_uctx (Σ : global_env_ext) : ContextSet.t.
Admitted.

  Definition consistent_instance `{checker_flags} (lvs : LevelSet.t) (φ : ConstraintSet.t) uctx (u : Instance.t) :=
    match uctx with
    | Monomorphic_ctx => List.length u = 0
    | Polymorphic_ctx c =>

      forallb (fun l => LevelSet.mem l lvs) u /\
      List.length u = List.length c.1 /\
      valid_constraints φ (subst_instance_cstrs u c.2)
    end.

  Definition consistent_instance_ext `{checker_flags} Σ :=
    consistent_instance (global_ext_levels Σ) (global_ext_constraints Σ).

  Definition wf_universe Σ (u : Universe.t) : Prop :=
    forall l, LevelExprSet.In l u -> LevelSet.In (LevelExpr.get_level l) (global_ext_levels Σ).

  Definition wf_sort Σ (s : sort) : Prop :=
    Sort.on_sort (wf_universe Σ) True s.

End Lookup.

Module Type LookupSig (T : Term) (E : EnvironmentSig T).
  Include Lookup T E.
End LookupSig.

Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
Import T.
Import E.

  Definition on_def_type (P : context -> judgment -> Type) Γ d :=
    P Γ (Typ d.(dtype)).

  Definition on_def_body (P : context -> judgment -> Type) types Γ d :=
    P (Γ ,,, types) (TermTyp d.(dbody) (lift0 #|types| d.(dtype))).

  Definition lift_sorting checking sorting : judgment -> Type :=
    fun j => option_default (fun tm => checking tm (j_typ j)) (j_term j) (unit : Type) ×
                                ∑ s, sorting (j_typ j) s × option_default (fun u => (u = s : Type)) (j_univ j) unit.

  Notation typing_sort typing := (fun T s => typing T (tSort s)).

  Definition lift_typing0 typing := lift_sorting typing (typing_sort typing).
  Notation lift_typing1 typing := (fun Γ => lift_typing0 (typing Γ)).
  Notation lift_typing typing := (fun Σ Γ => lift_typing0 (typing Σ Γ)).

  Section TypeLocal.
    Context (typing : forall (Γ : context), judgment -> Type).

    Inductive All_local_env : context -> Type :=
    | localenv_nil :
        All_local_env []

    | localenv_cons_abs Γ na t :
        All_local_env Γ ->
        typing Γ (j_vass na t) ->
        All_local_env (Γ ,, vass na t)

    | localenv_cons_def Γ na b t :
        All_local_env Γ ->
        typing Γ (j_vdef na b t) ->
        All_local_env (Γ ,, vdef na b t).
  End TypeLocal.

  Section TypeCtxInst.
    Context (typing : forall (Γ : context), term -> term -> Type).

    Inductive ctx_inst (Γ : context) : list term -> context -> Type :=
    | ctx_inst_nil : ctx_inst Γ [] []
    | ctx_inst_ass na t i inst Δ :
        typing Γ i t ->
        ctx_inst Γ inst (subst_telescope [i] 0 Δ) ->
        ctx_inst Γ (i :: inst) (vass na t :: Δ)
    | ctx_inst_def na b t inst Δ :
        ctx_inst Γ inst (subst_telescope [b] 0 Δ) ->
        ctx_inst Γ inst (vdef na b t :: Δ).
  End TypeCtxInst.

  End EnvTyping.

Module Type EnvTypingSig (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
  Include EnvTyping T E TU.
End EnvTypingSig.

Module Conversion (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E) (ET : EnvTypingSig T E TU).
Import T.
Import E.

  Section Conversion.
  Context (cumul_gen : global_env_ext -> context -> conv_pb -> term -> term -> Type).

  Inductive All_decls_alpha_pb {pb} {P : conv_pb -> term -> term -> Type} :
    context_decl -> context_decl -> Type :=
  | all_decls_alpha_vass {na na' : binder_annot name} {t t' : term}
    (eqna : eq_binder_annot na na')
    (eqt : P pb t t') :
    All_decls_alpha_pb (vass na t) (vass na' t')

  | all_decls_alpha_vdef {na na' : binder_annot name} {b t b' t' : term}
    (eqna : eq_binder_annot na na')
    (eqb : P Conv b b')
    (eqt : P pb t t') :
    All_decls_alpha_pb (vdef na b t) (vdef na' b' t').

  Arguments All_decls_alpha_pb pb P : clear implicits.

  Definition cumul_pb_decls pb (Σ : global_env_ext) (Γ Γ' : context) : forall (x y : context_decl), Type :=
    All_decls_alpha_pb pb (cumul_gen Σ Γ).

  Definition cumul_ctx_rel Σ Γ Δ Δ' :=
    All2_fold (fun Δ Δ' => cumul_pb_decls Cumul Σ (Γ ,,, Δ) (Γ ,,, Δ')) Δ Δ'.
  End Conversion.
End Conversion.

Module Type ConversionSig (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E) (ET : EnvTypingSig T E TU).
  Include Conversion T E TU ET.
End ConversionSig.

Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvTypingSig T E TU) (C: ConversionSig T E TU ET) (L: LookupSig T E).
Import T.
Import E.
Import TU.
Import ET.
Import C.
Import L.

  Section GlobalMaps.

    Context {cf: checker_flags}.
    Context (Pcmp: global_env_ext -> context -> conv_pb -> term -> term -> Type).
    Context (P : global_env_ext -> context -> judgment -> Type).
    Definition on_context Σ ctx :=
      All_local_env (P Σ) ctx.

    Fixpoint type_local_ctx Σ (Γ Δ : context) (u : sort) : Type :=
      match Δ with
      | [] => wf_sort Σ u
      | {| decl_name := na; decl_body := None; decl_type := t |} :: Δ =>
          type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (TypUniv t u )
      | {| decl_body := Some _; |} as d :: Δ =>
          type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (j_decl d)
      end.

    Fixpoint sorts_local_ctx Σ (Γ Δ : context) (us : list sort) : Type :=
      match Δ, us with
      | [], [] => unit
      | {| decl_name := na; decl_body := None;   decl_type := t |} :: Δ, u :: us =>
        sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (TypUniv t u )
      | {| decl_body := Some _ |} as d :: Δ, us =>
        sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (j_decl d)
      | _, _ => False
      end.

    Implicit Types (mdecl : mutual_inductive_body) (idecl : one_inductive_body) (cdecl : constructor_body).

    Definition on_type Σ Γ T := P Σ Γ (Typ T).

    Definition univs_ext_constraints univs φ :=
      ConstraintSet.union (constraints_of_udecl φ) univs.

    Definition satisfiable_udecl (univs : ContextSet.t) φ
      := consistent (univs_ext_constraints (ContextSet.constraints univs) φ).

    Definition valid_on_mono_udecl (univs : ContextSet.t) ϕ :=
      consistent_extension_on univs (constraints_of_udecl ϕ).

    Definition on_udecl (univs : ContextSet.t) (udecl : universes_decl)
      := let levels := levels_of_udecl udecl in
        let global_levels := global_levels univs in
        let all_levels := LevelSet.union levels global_levels in
        LevelSet.For_all (fun l => ~ LevelSet.In l global_levels) levels
        /\ ConstraintSet.For_all (declared_cstr_levels all_levels) (constraints_of_udecl udecl)
        /\ satisfiable_udecl univs udecl
        /\ valid_on_mono_udecl univs udecl.

    Definition ind_realargs (o : one_inductive_body) :=
      match destArity [] o.(ind_type) with
      | Some (ctx, _) => #|smash_context [] ctx|
      | _ => 0
      end.

    Definition mdecl_at_i mdecl i (Γ:context) k : Prop :=
      #|Γ| <= k /\ k < #|Γ| + #|mdecl.(ind_bodies)| /\
       nth_error (List.rev mdecl.(ind_bodies)) (k - #|Γ|) = Some i.

    Reserved Notation " mdecl ;;; Γ |arg+> t " (at level 50, Γ, t at next level).
    Notation "M { j := N }" := (subst [N] j M) (at level 10, right associativity).

    Inductive positive_cstr_arg mdecl Γ : term -> Type :=
    | pos_arg_closed ty :
      closedn #|Γ| ty ->
      mdecl ;;; Γ |arg+> ty

    | pos_arg_concl l k i :

      #|l| = ind_realargs i -> All (closedn #|Γ|) l ->
      mdecl_at_i mdecl i Γ k ->
      mdecl ;;; Γ |arg+> mkApps (tRel k) l

    | pos_arg_let na b ty ty' :
      mdecl ;;; Γ |arg+> ty' {0 := b} ->
      mdecl ;;; Γ |arg+> tLetIn na b ty ty'

    | pos_arg_ass na ty ty' :
      closedn #|Γ| ty ->
      mdecl ;;; vass na ty :: Γ |arg+> ty' ->
      mdecl ;;; Γ |arg+> tProd na ty ty'

  where " mdecl ;;; Γ |arg+> t " := (positive_cstr_arg mdecl Γ t) : type_scope.

    Reserved Notation " mdecl @ i ;;; Γ |+> t " (at level 50, i, Γ, t at next level).

    Inductive positive_cstr mdecl i Γ : term -> Type :=
    | pos_concl l (headrel := (#|mdecl.(ind_bodies)| - S i + #|Γ|)%nat) :
      All (closedn #|Γ|) l ->
      mdecl @ i ;;; Γ |+> mkApps (tRel headrel) l

    | pos_let na b ty ty' :
      mdecl @ i ;;; Γ |+> ty' {0 := b} ->
      mdecl @ i ;;; Γ |+> tLetIn na b ty ty'

    | pos_ass na ty ty' :
      mdecl ;;; Γ |arg+> ty ->
      mdecl @ i ;;; vass na ty :: Γ |+> ty' ->
      mdecl @ i ;;; Γ |+> tProd na ty ty'

    where " mdecl @ i ;;; Γ |+> t " := (positive_cstr mdecl i Γ t) : type_scope.

    Definition lift_level n l :=
      match l with
      | Level.lzero | Level.level _ => l
      | Level.lvar k => Level.lvar (n + k)
      end.

    Definition lift_instance n l :=
      map (lift_level n) l.

    Definition lift_constraint n (c : Level.t * ConstraintType.t * Level.t) :=
      let '((l, r), l') := c in
      ((lift_level n l, r), lift_level n l').

    Definition lift_constraints n cstrs :=
      ConstraintSet.fold (fun elt acc => ConstraintSet.add (lift_constraint n elt) acc)
        cstrs ConstraintSet.empty.

    Definition level_var_instance n (inst : list name) :=
      mapi_rec (fun i _ => Level.lvar i) inst n.

    Fixpoint variance_cstrs (v : list Variance.t) (u u' : Instance.t) :=
      match v, u, u' with
      | _, [], [] => ConstraintSet.empty
      | v :: vs, u :: us, u' :: us' =>
        match v with
        | Variance.Irrelevant => variance_cstrs vs us us'
        | Variance.Covariant => ConstraintSet.add (u, ConstraintType.Le 0, u') (variance_cstrs vs us us')
        | Variance.Invariant => ConstraintSet.add (u, ConstraintType.Eq, u') (variance_cstrs vs us us')
        end
      | _, _, _ =>  ConstraintSet.empty
      end.

    Definition variance_universes univs v :=
      match univs with
      | Monomorphic_ctx => None
      | Polymorphic_ctx auctx =>
        let (inst, cstrs) := auctx in
        let u' := level_var_instance 0 inst in
        let u := lift_instance #|inst| u' in
        let cstrs := ConstraintSet.union cstrs (lift_constraints #|inst| cstrs) in
        let cstrv := variance_cstrs v u u' in
        let auctx' := (inst ++ inst, ConstraintSet.union cstrs cstrv) in
        Some (Polymorphic_ctx auctx', u, u')
      end.

    Definition ind_arities mdecl := arities_context (ind_bodies mdecl).

    Definition ind_respects_variance Σ mdecl v indices :=
      let univs := ind_universes mdecl in
      match variance_universes univs v with
      | Some (univs, u, u') =>
        cumul_ctx_rel Pcmp (Σ, univs) (smash_context [] (ind_params mdecl))@[u]
          (expand_lets_ctx (ind_params mdecl) (smash_context [] indices))@[u]
          (expand_lets_ctx (ind_params mdecl) (smash_context [] indices))@[u']
      | None => False
      end.

    Definition cstr_respects_variance Σ mdecl v cs :=
      let univs := ind_universes mdecl in
      match variance_universes univs v with
      | Some (univs, u, u') =>
        cumul_ctx_rel Pcmp (Σ, univs) (ind_arities mdecl ,,, smash_context [] (ind_params mdecl))@[u]
          (expand_lets_ctx (ind_params mdecl) (smash_context [] (cstr_args cs)))@[u]
          (expand_lets_ctx (ind_params mdecl) (smash_context [] (cstr_args cs)))@[u'] *
        All2
          (Pcmp (Σ, univs) (ind_arities mdecl ,,, smash_context [] (ind_params mdecl ,,, cstr_args cs))@[u] Conv)
          (map (subst_instance u ∘ expand_lets (ind_params mdecl ,,, cstr_args cs)) (cstr_indices cs))
          (map (subst_instance u' ∘ expand_lets (ind_params mdecl ,,, cstr_args cs)) (cstr_indices cs))
      | None => False
      end.

    Definition cstr_concl_head mdecl i cdecl :=
      tRel (#|mdecl.(ind_bodies)| - S i + #|mdecl.(ind_params)| + #|cstr_args cdecl|).

    Definition cstr_concl mdecl i cdecl :=
      (mkApps (cstr_concl_head mdecl i cdecl)
        (to_extended_list_k mdecl.(ind_params) #|cstr_args cdecl|
          ++ cstr_indices cdecl)).

    Record on_constructor Σ mdecl i idecl ind_indices cdecl cunivs := {

      cstr_args_length : context_assumptions (cstr_args cdecl) = cstr_arity cdecl;

      cstr_eq : cstr_type cdecl =
       it_mkProd_or_LetIn mdecl.(ind_params)
        (it_mkProd_or_LetIn (cstr_args cdecl)
          (cstr_concl mdecl i cdecl));

      on_ctype : on_type Σ (arities_context mdecl.(ind_bodies)) (cstr_type cdecl);
      on_cargs :
        sorts_local_ctx Σ (arities_context mdecl.(ind_bodies) ,,, mdecl.(ind_params))
                      cdecl.(cstr_args) cunivs;
      on_cindices :
        ctx_inst (fun Γ t T => P Σ Γ (TermTyp t T)) (arities_context mdecl.(ind_bodies) ,,, mdecl.(ind_params) ,,, cdecl.(cstr_args))
                      cdecl.(cstr_indices)
                      (List.rev (lift_context #|cdecl.(cstr_args)| 0 ind_indices));

      on_ctype_positive :
        positive_cstr mdecl i [] (cstr_type cdecl);

      on_ctype_variance :
        forall v, ind_variance mdecl = Some v ->
        cstr_respects_variance Σ mdecl v cdecl;

      on_lets_in_type : if lets_in_constructor_types
                        then True else is_true (is_assumption_context (cstr_args cdecl))
    }.

    Definition on_constructors Σ mdecl i idecl ind_indices :=
      All2 (on_constructor Σ mdecl i idecl ind_indices).

    Record on_proj mdecl mind i k (p : projection_body) decl :=
      { on_proj_name :
          binder_name (decl_name decl) = nNamed p.(proj_name);
        on_proj_type :

          let u := abstract_instance mdecl.(ind_universes) in
          let ind := {| inductive_mind := mind; inductive_ind := i |} in
          p.(proj_type) = subst (inds mind u mdecl.(ind_bodies)) (S (ind_npars mdecl))
            (subst (projs ind mdecl.(ind_npars) k) 0
              (lift 1 k (decl_type decl)));
        on_proj_relevance : p.(proj_relevance) = decl.(decl_name).(binder_relevance) }.

    Definition on_projection mdecl mind i cdecl (k : nat) (p : projection_body) :=
      let Γ := smash_context [] (cdecl.(cstr_args) ++ mdecl.(ind_params)) in
      match nth_error Γ (context_assumptions cdecl.(cstr_args) - S k) with
      | None => False
      | Some decl => on_proj mdecl mind i k p decl
      end.

    Record on_projections mdecl mind i idecl (ind_indices : context) cdecl :=
      { on_projs_record : #|idecl.(ind_ctors)| = 1;

        on_projs_noidx : #|ind_indices| = 0;

        on_projs_elim : idecl.(ind_kelim) = IntoAny;

        on_projs_all : #|idecl.(ind_projs)| = context_assumptions (cstr_args cdecl);

        on_projs : Alli (on_pr

[...]

nition case_predicate_context ind mdecl idecl p : context :=
  case_predicate_context_gen ind mdecl idecl p.(pparams) p.(puinst) (forget_types p.(pcontext)).

Definition cstr_branch_context ind mdecl cdecl : context :=
  expand_lets_ctx mdecl.(ind_params)
    (subst_context (inds (inductive_mind ind) (abstract_instance mdecl.(ind_universes))
       mdecl.(ind_bodies)) #|mdecl.(ind_params)|
      cdecl.(cstr_args)).

Definition pre_case_branch_context_gen ind mdecl cdecl params puinst : context :=
  inst_case_context params puinst (cstr_branch_context ind mdecl cdecl).

Definition case_branch_context_gen ind mdecl params puinst pctx cdecl :=
  map2 set_binder_name pctx (pre_case_branch_context_gen ind mdecl cdecl params puinst).

Definition case_branch_type_gen ind mdecl (idecl : one_inductive_body) params puinst bctx ptm i cdecl : context * term :=
  let cstr := tConstruct ind i puinst in
  let args := to_extended_list cdecl.(cstr_args) in
  let cstrapp := mkApps cstr (map (lift0 #|cdecl.(cstr_args)|) params ++ args) in
  let brctx := case_branch_context_gen ind mdecl params puinst bctx cdecl in
  let upars := subst_instance puinst mdecl.(ind_params) in
  let indices :=
    (map (subst (List.rev params) #|cdecl.(cstr_args)|)
      (map (expand_lets_k upars #|cdecl.(cstr_args)|)
        (map (subst (inds (inductive_mind ind) puinst mdecl.(ind_bodies))
                    (#|mdecl.(ind_params)| + #|cdecl.(cstr_args)|))
          (map (subst_instance puinst) cdecl.(cstr_indices))))) in
  let ty := mkApps (lift0 #|cdecl.(cstr_args)| ptm) (indices ++ [cstrapp]) in
  (brctx, ty).

Definition case_branch_type ind mdecl idecl p (b : branch term) ptm i cdecl : context * term :=
  case_branch_type_gen ind mdecl idecl p.(pparams) p.(puinst) (forget_types b.(bcontext)) ptm i cdecl.

Definition idecl_binder idecl :=
  {| decl_name :=
    {| binder_name := nNamed idecl.(ind_name);
        binder_relevance := idecl.(ind_relevance) |};
     decl_body := None;
     decl_type := idecl.(ind_type) |}.

Definition wf_predicate_gen mdecl idecl (pparams : list term) (pcontext : list aname) : Prop :=
  let decl := idecl_binder idecl in
  (#|pparams| = mdecl.(ind_npars)) /\
  (Forall2 (fun na decl => eq_binder_annot na decl.(decl_name))
    pcontext (decl :: idecl.(ind_indices))).

Definition wf_predicate mdecl idecl (p : predicate term) : Prop :=
  wf_predicate_gen mdecl idecl p.(pparams) (forget_types p.(pcontext)).

Definition wf_branch_gen cdecl (bctx : list aname) : Prop :=
  (Forall2 (fun na decl => eq_binder_annot na decl.(decl_name))
    bctx cdecl.(cstr_args)).

Definition wf_branch cdecl (b : branch term) : Prop :=
  wf_branch_gen cdecl (forget_types b.(bcontext)).

Definition wf_branches idecl (brs : list (branch term)) : Prop :=
  Forall2 wf_branch idecl.(ind_ctors) brs.

Definition fix_subst (l : mfixpoint term) :=
  let fix aux n :=
      match n with
      | 0 => []
      | S n => tFix l n :: aux n
      end
  in aux (List.length l).

Definition unfold_fix (mfix : mfixpoint term) (idx : nat) :=
  match List.nth_error mfix idx with
  | Some d => Some (d.(rarg), subst0 (fix_subst mfix) d.(dbody))
  | None => None
  end.

Definition cofix_subst (l : mfixpoint term) :=
  let fix aux n :=
      match n with
      | 0 => []
      | S n => tCoFix l n :: aux n
      end
  in aux (List.length l).

Definition unfold_cofix (mfix : mfixpoint term) (idx : nat) :=
  match List.nth_error mfix idx with
  | Some d => Some (d.(rarg), subst0 (cofix_subst mfix) d.(dbody))
  | None => None
  end.

Definition is_constructor n ts :=
  match List.nth_error ts n with
  | Some a => isConstruct_app a
  | None => false
  end.
Definition cmp_universe_instance (cmp_univ : Universe.t -> Universe.t -> Prop) : Instance.t -> Instance.t -> Prop.
Admitted.

Definition cmp_universe_variance (cmp_univ : conv_pb -> Universe.t -> Universe.t -> Prop) pb v u u' :=
  match v with
  | Variance.Irrelevant => True
  | Variance.Covariant => on_rel (cmp_univ pb) Universe.make' u u'
  | Variance.Invariant => on_rel (cmp_univ Conv) Universe.make' u u'
  end.

Definition cmp_universe_instance_variance cmp_univ pb v u u' :=
  Forall3 (cmp_universe_variance cmp_univ pb) v u u'.

Definition global_variance_gen lookup gr napp :=
  match gr with
  | IndRef ind =>
    match lookup_inductive_gen lookup ind with
    | Some (mdecl, idecl) =>
      match destArity [] idecl.(ind_type) with
      | Some (ctx, _) => if (context_assumptions ctx) <=? napp then
          match mdecl.(ind_variance) with
          | Some var => Variance var
          | None => AllEqual
          end
        else AllEqual
      | None => AllEqual
      end
    | None => AllEqual
    end
  | ConstructRef ind k =>
    match lookup_constructor_gen lookup ind k with
    | Some (mdecl, idecl, cdecl) =>
      if (cdecl.(cstr_arity) + mdecl.(ind_npars))%nat <=? napp then

        AllIrrelevant
      else AllEqual
    | _ => AllEqual
    end
  | _ => AllEqual
  end.

Definition cmp_opt_variance cmp_univ pb v :=
  match v with
  | AllEqual => cmp_universe_instance (cmp_univ Conv)
  | AllIrrelevant => fun l l' => #|l| = #|l'|
  | Variance v => fun u u' => cmp_universe_instance (cmp_univ Conv) u u' \/ cmp_universe_instance_variance cmp_univ pb v u u'
  end.

Definition cmp_global_instance_gen Σ cmp_universe pb gr napp :=
  cmp_opt_variance cmp_universe pb (global_variance_gen Σ gr napp).

Notation cmp_global_instance Σ := (cmp_global_instance_gen (lookup_env Σ)).

Inductive eq_decl_upto_names : context_decl -> context_decl -> Type :=
  | compare_vass {na na' T} :
    eq_binder_annot na na' -> eq_decl_upto_names (vass na T) (vass na' T)
  | compare_vdef {na na' b T} :
    eq_binder_annot na na' -> eq_decl_upto_names (vdef na b T) (vdef na' b T).

Notation eq_context_upto_names := (All2 eq_decl_upto_names).

Definition shiftnP k p i :=
  (i <? k) || p (i - k).
Fixpoint on_free_vars (p : nat -> bool) (t : term) : bool.
Admitted.

Definition on_free_vars_decl P d :=
  test_decl (on_free_vars P) d.

Definition on_free_vars_ctx P ctx :=
  alli (fun k => (on_free_vars_decl (shiftnP k P))) 0 (List.rev ctx).

Notation is_open_term Γ := (on_free_vars (shiftnP #|Γ| xpred0)).
Notation is_closed_context := (on_free_vars_ctx xpred0).
Module Export PCUICCumulativitySpec.

Implicit Types (cf : checker_flags).

Definition cumul_predicate (cumul : context -> term -> term -> Type) cumul_universe Γ p p' :=
  All2 (cumul Γ) p.(pparams) p'.(pparams) ×
  cmp_universe_instance cumul_universe p.(puinst) p'.(puinst) ×
  eq_context_upto_names p.(pcontext) p'.(pcontext) ×
  cumul (Γ ,,, inst_case_predicate_context p) p.(preturn) p'.(preturn).

Definition cumul_branch (cumul_term : context -> term -> term -> Type) Γ p br br' :=
  eq_context_upto_names br.(bcontext) br'.(bcontext) ×
  cumul_term (Γ ,,, inst_case_branch_context p br) br.(bbody) br'.(bbody).

Definition cumul_branches cumul_term Γ p brs brs' := All2 (cumul_branch cumul_term Γ p) brs brs'.

Definition cumul_mfixpoint (cumul_term : context -> term -> term -> Type) Γ mfix mfix' :=
  All2 (fun d d' =>
    cumul_term Γ d.(dtype) d'.(dtype) ×
    cumul_term (Γ ,,, fix_context mfix) d.(dbody) d'.(dbody) ×
    d.(rarg) = d'.(rarg) ×
    eq_binder_annot d.(dname) d'.(dname)
  ) mfix mfix'.

Reserved Notation " Σ ;;; Γ ⊢ t ≤s[ pb ] u" (at level 50, Γ, t, u at next level,
  format "Σ  ;;;  Γ  ⊢  t  ≤s[ pb ]  u").

Definition cumul_Ind_univ {cf} (Σ : global_env_ext) pb i napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (IndRef i) napp.

Definition cumul_Construct_univ {cf} (Σ : global_env_ext) pb  i k napp :=
  cmp_global_instance Σ (compare_universe Σ) pb (ConstructRef i k) napp.
Inductive cumulSpec0 {cf : checker_flags} (Σ : global_env_ext) Γ (pb : conv_pb) : term -> term -> Type :=

| cumul_Trans : forall t u v,
    is_closed_context Γ -> is_open_term Γ u ->
    Σ ;;; Γ ⊢ t ≤s[pb] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] v ->
    Σ ;;; Γ ⊢ t ≤s[pb] v

| cumul_Sym : forall t u,
    Σ ;;; Γ ⊢ t ≤s[Conv] u ->
    Σ ;;; Γ ⊢ u ≤s[pb] t

| cumul_Refl : forall t,
    Σ ;;; Γ ⊢ t ≤s[pb] t

| cumul_Ind : forall i u u' args args',
    cumul_Ind_univ Σ pb i #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tInd i u) args ≤s[pb] mkApps (tInd i u') args'

| cumul_Construct : forall i k u u' args args',
    cumul_Construct_univ Σ pb i k #|args| u u' ->
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ mkApps (tConstruct i k u) args ≤s[pb] mkApps (tConstruct i k u') args'

| cumul_Sort : forall s s',
    compare_sort Σ pb s s' ->
    Σ ;;; Γ ⊢ tSort s ≤s[pb] tSort s'

| cumul_Const : forall c u u',
    cmp_universe_instance (compare_universe Σ Conv) u u' ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] tConst c u'

| cumul_Evar : forall e args args',
    All2 (fun t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) args args' ->
    Σ ;;; Γ ⊢ tEvar e args ≤s[pb] tEvar e args'

| cumul_App : forall t t' u u',
    Σ ;;; Γ ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ u ≤s[Conv] u' ->
    Σ ;;; Γ ⊢ tApp t u ≤s[pb] tApp t' u'

| cumul_Lambda : forall na na' ty ty' t t',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vass na ty ⊢ t ≤s[pb] t' ->
    Σ ;;; Γ ⊢ tLambda na ty t ≤s[pb] tLambda na' ty' t'

| cumul_Prod : forall na na' a a' b b',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ a ≤s[Conv] a' ->
    Σ ;;; Γ ,, vass na a ⊢ b ≤s[pb] b' ->
    Σ ;;; Γ ⊢ tProd na a b ≤s[pb] tProd na' a' b'

| cumul_LetIn : forall na na' t t' ty ty' u u',
    eq_binder_annot na na' ->
    Σ ;;; Γ ⊢ t ≤s[Conv] t' ->
    Σ ;;; Γ ⊢ ty ≤s[Conv] ty' ->
    Σ ;;; Γ ,, vdef na t ty ⊢ u ≤s[pb] u' ->
    Σ ;;; Γ ⊢ tLetIn na t ty u ≤s[pb] tLetIn na' t' ty' u'

| cumul_Case indn : forall p p' c c' brs brs',
    cumul_predicate (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) (compare_universe Σ Conv) Γ p p' ->
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    cumul_branches (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ p brs brs' ->
    Σ ;;; Γ ⊢ tCase indn p c brs ≤s[pb] tCase indn p' c' brs'

| cumul_Proj : forall p c c',
    Σ ;;; Γ ⊢ c ≤s[Conv] c' ->
    Σ ;;; Γ ⊢ tProj p c ≤s[pb] tProj p c'

| cumul_Fix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tFix mfix idx ≤s[pb] tFix mfix' idx

| cumul_CoFix : forall mfix mfix' idx,
    cumul_mfixpoint (fun Γ t u => Σ ;;; Γ ⊢ t ≤s[Conv] u) Γ mfix mfix' ->
    Σ ;;; Γ ⊢ tCoFix mfix idx ≤s[pb] tCoFix mfix' idx

| cumul_Prim p p' :
  onPrims (fun x y => Σ ;;; Γ ⊢ x ≤s[Conv] y) (compare_universe Σ Conv) p p' ->
  Σ ;;; Γ ⊢ tPrim p ≤s[pb] tPrim p'

| cumul_beta : forall na t b a,
    Σ ;;; Γ ⊢ tApp (tLambda na t b) a ≤s[pb] b {0 := a}

| cumul_zeta : forall na b t b',
    Σ ;;; Γ ⊢ tLetIn na b t b' ≤s[pb] b' {0 := b}

| cumul_rel i body :
    option_map decl_body (nth_error Γ i) = Some (Some body) ->
    Σ ;;; Γ ⊢ tRel i ≤s[pb] lift0 (S i) body

| cumul_iota : forall ci c u args p brs br,
    nth_error brs c = Some br ->
    #|args| = (ci.(ci_npar) + context_assumptions br.(bcontext))%nat ->
    Σ ;;; Γ ⊢ tCase ci p (mkApps (tConstruct ci.(ci_ind) c u) args) brs  ≤s[pb] iota_red ci.(ci_npar) p args br

| cumul_fix : forall mfix idx args narg fn,
    unfold_fix mfix idx = Some (narg, fn) ->
    is_constructor narg args = true ->
    Σ ;;; Γ ⊢ mkApps (tFix mfix idx) args ≤s[pb] mkApps fn args

| cumul_cofix_case : forall ip p mfix idx args narg fn brs,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tCase ip p (mkApps (tCoFix mfix idx) args) brs ≤s[pb] tCase ip p (mkApps fn args) brs

| cumul_cofix_proj : forall p mfix idx args narg fn,
    unfold_cofix mfix idx = Some (narg, fn) ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tCoFix mfix idx) args) ≤s[pb] tProj p (mkApps fn args)

| cumul_delta : forall c decl body (isdecl : declared_constant Σ c decl) u,
    decl.(cst_body) = Some body ->
    Σ ;;; Γ ⊢ tConst c u ≤s[pb] body@[u]

| cumul_proj : forall p args u arg,
    nth_error args (p.(proj_npars) + p.(proj_arg)) = Some arg ->
    Σ ;;; Γ ⊢ tProj p (mkApps (tConstruct p.(proj_ind) 0 u) args) ≤s[pb] arg

where " Σ ;;; Γ ⊢ t ≤s[ pb ] u " := (@cumulSpec0 _ Σ Γ pb t u) : type_scope.
Definition cumulSpec `{checker_flags} (Σ : global_env_ext) Γ := cumulSpec0 Σ Γ Cumul.

Notation " Σ ;;; Γ |- t <=s u " := (@cumulSpec _ Σ Γ t u) (at level 50, Γ, t, u at next level).

Module PCUICConversionParSpec <: EnvironmentTyping.ConversionParSig PCUICTerm PCUICEnvironment PCUICTermUtils PCUICEnvTyping.
End PCUICConversionParSpec.

End PCUICCumulativitySpec.
Import MetaCoq.PCUIC.utils.PCUICPrimitive.

Implicit Types (cf : checker_flags) (Σ : global_env_ext).

Definition type_of_constructor mdecl (cdecl : constructor_body) (c : inductive * nat) (u : list Level.t) :=
  let mind := inductive_mind (fst c) in
  subst0 (inds mind u mdecl.(ind_bodies)) (subst_instance u (cstr_type cdecl)).

Include PCUICEnvTyping.

Inductive FixCoFix : Type := Fix | CoFix.

Class GuardChecker :=
{
  guard : FixCoFix -> global_env_ext -> context -> mfixpoint term -> Prop ;
}.

Axiom guard_checking : GuardChecker.
#[global]
Existing Instance guard_checking.

Definition fix_guard := guard Fix.
Definition cofix_guard := guard CoFix.

Definition destInd (t : term) :=
  match t with
  | tInd ind u => Some (ind, u)
  | _ => None
  end.

Definition isCoFinite (r : recursivity_kind) :=
  match r with
  | CoFinite => true
  | _ => false
  end.

Definition check_recursivity_kind
  (lookup: kername -> option global_decl) ind r :=
  match lookup ind with
  | Some (InductiveDecl mib) => ReflectEq.eqb mib.(ind_finite) r
  | _ => false
  end.

Definition check_one_fix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  match nth_error (List.rev (smash_context [] ctx)) arg with
  | Some argd =>
    let (hd, args) := decompose_app argd.(decl_type) in
    match destInd hd with
    | Some (mkInd mind _, u) => Some mind
    | None => None
    end
  | None => None
  end.

Definition wf_fixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  forallb (isLambda ∘ dbody) mfix &&
  let checks := map check_one_fix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind Finite
  | _ => false
  end.

Definition wf_fixpoint (Σ : global_env) := wf_fixpoint_gen (lookup_env Σ).

Definition check_one_cofix d :=
  let '{| dname := na;
         dtype := ty;
         dbody := b;
         rarg := arg |} := d in
  let '(ctx, ty) := decompose_prod_assum [] ty in
  let (hd, args) := decompose_app ty in
  match destInd hd with
  | Some (mkInd ind _, u) => Some ind
  | None => None
  end.

Definition wf_cofixpoint_gen
  (lookup: kername -> option global_decl) mfix :=
  let checks := map check_one_cofix mfix in
  match map_option_out checks with
  | Some (ind :: inds) =>

    forallb (eqb ind) inds &&
    check_recursivity_kind lookup ind CoFinite
  | _ => false
  end.

Definition wf_cofixpoint (Σ : global_env) := wf_cofixpoint_gen (lookup_env Σ).

Reserved Notation "'wf_local' Σ Γ " (at level 9, Σ, Γ at next level).

Reserved Notation " Σ ;;; Γ |- t : T " (at level 50, Γ, t, T at next level).

Variant case_side_conditions `{checker_flags} wf_local_fun typing Σ Γ ci p ps mdecl idecl indices predctx :=
| case_side_info
    (eq_npars : mdecl.(ind_npars) = ci.(ci_npar))
    (wf_pred : wf_predicate mdecl idecl p)
    (cons : consistent_instance_ext Σ (ind_universes mdecl) p.(puinst))
    (wf_pctx : wf_local_fun Σ (Γ ,,, predctx))

    (conv_pctx : eq_context_upto_names p.(pcontext) (ind_predicate_context ci.(ci_ind) mdecl idecl))
    (allowed_elim : is_allowed_elimination Σ idecl.(ind_kelim) ps)
    (ind_inst : ctx_inst (typing Σ) Γ (p.(pparams) ++ indices)
                         (List.rev (subst_instance p.(puinst)
                                                   (ind_params mdecl ,,, ind_indices idecl : context))))
    (not_cofinite : isCoFinite mdecl.(ind_finite) = false).

Variant case_branch_typing `{checker_flags} wf_local_fun typing Σ Γ (ci:case_info) p ps mdecl idecl ptm  brs :=
| case_branch_info
    (wf_brs : wf_branches idecl brs)
    (brs_ty :
       All2i (fun i cdecl br =>

                eq_context_upto_names br.(bcontext) (cstr_branch_context ci mdecl cdecl) ×
                let brctxty := case_branch_type ci.(ci_ind) mdecl idecl p br ptm i cdecl in
                (wf_local_fun Σ (Γ ,,, brctxty.1) ×
                ((typing Σ (Γ ,,, brctxty.1) br.(bbody) (brctxty.2)) ×
                (typing Σ (Γ ,,, brctxty.1) brctxty.2 (tSort ps)))))
             0 idecl.(ind_ctors) brs).

Variant primitive_typing_hyps `{checker_flags}
  (typing : forall (Σ : global_env_ext) (Γ : context), term -> term -> Type)
  Σ Γ : prim_val term -> Type :=
| prim_int_hyps i : primitive_typing_hyps typing Σ Γ (primInt; primIntModel i)
| prim_float_hyps f : primitive_typing_hyps typing Σ Γ (primFloat; primFloatModel f)
| prim_array_hyps a
  (wfl : wf_universe Σ (Universe.make' a.(array_level)))
  (hty : typing Σ Γ a.(array_type) (tSort (sType (Universe.make' a.(array_level)))))
  (hdef : typing Σ Γ a.(array_default) a.(array_type))
  (hvalue : All (fun x => typing Σ Γ x a.(array_type)) a.(array_value)) :
  primitive_typing_hyps typing Σ Γ (primArray; primArrayModel a).

Equations prim_type (p : prim_val term) (cst : kername) : term :=
prim_type (primInt; _) cst := tConst cst [];
prim_type (primFloat; _) cst := tConst cst [];
prim_type (primArray; primArrayModel a) cst := tApp (tConst cst [a.(array_level)]) a.(array_type).

Inductive typing `{checker_flags} (Σ : global_env_ext) (Γ : context) : term -> term -> Type :=
| type_Rel : forall n decl,
    wf_local Σ Γ ->
    nth_error Γ n = Some decl ->
    Σ ;;; Γ |- tRel n : lift0 (S n) decl.(decl_type)

| type_Sort : forall s,
    wf_local Σ Γ ->
    wf_sort Σ s ->
    Σ ;;; Γ |- tSort s : tSort (Sort.super s)

| type_Prod : forall na A B s1 s2,
    lift_typing typing Σ Γ (j_vass_s na A s1) ->
    Σ ;;; Γ ,, vass na A |- B : tSort s2 ->
    Σ ;;; Γ |- tProd na A B : tSort (Sort.sort_of_product s1 s2)

| type_Lambda : forall na A t B,
    lift_typing typing Σ Γ (j_vass na A) ->
    Σ ;;; Γ ,, vass na A |- t : B ->
    Σ ;;; Γ |- tLambda na A t : tProd na A B

| type_LetIn : forall na b B t A,
    lift_typing typing Σ Γ (j_vdef na b B) ->
    Σ ;;; Γ ,, vdef na b B |- t : A ->
    Σ ;;; Γ |- tLetIn na b B t : tLetIn na b B A

| type_App : forall t na A B s u,

    Σ ;;; Γ |- tProd na A B : tSort s ->
    Σ ;;; Γ |- t : tProd na A B ->
    Σ ;;; Γ |- u : A ->
    Σ ;;; Γ |- tApp t u : B{0 := u}

| type_Const : forall cst u decl,
    wf_local Σ Γ ->
    declared_constant Σ cst decl ->
    consistent_instance_ext Σ decl.(cst_universes) u ->
    Σ ;;; Γ |- tConst cst u : decl.(cst_type)@[u]

| type_Ind : forall ind u mdecl idecl,
    wf_local Σ Γ ->
    declared_inductive Σ ind mdecl idecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tInd ind u : idecl.(ind_type)@[u]

| type_Construct : forall ind i u mdecl idecl cdecl,
    wf_local Σ Γ ->
    declared_constructor Σ (ind, i) mdecl idecl cdecl ->
    consistent_instance_ext Σ mdecl.(ind_universes) u ->
    Σ ;;; Γ |- tConstruct ind i u : type_of_constructor mdecl cdecl (ind, i) u

| type_Case : forall ci p c brs indices ps mdecl idecl,
    let predctx := case_predicate_context ci.(ci_ind) mdecl idecl p in
    let ptm := it_mkLambda_or_LetIn predctx p.(preturn) in
    declared_inductive Σ ci.(ci_ind) mdecl idecl ->
    Σ ;;; Γ ,,, predctx |- p.(preturn) : tSort ps ->
    Σ ;;; Γ |- c : mkApps (tInd ci.(ci_ind) p.(puinst)) (p.(pparams) ++ indices) ->
    case_side_conditions (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                         mdecl idecl indices predctx  ->
    case_branch_typing (fun Σ Γ => wf_local Σ Γ) typing Σ Γ ci p ps
                        mdecl idecl ptm brs ->
    Σ ;;; Γ |- tCase ci p c brs : mkApps ptm (indices ++ [c])

| type_Proj : forall p c u mdecl idecl cdecl pdecl args,
    declared_projection Σ p mdecl idecl cdecl pdecl ->
    Σ ;;; Γ |- c : mkApps (tInd p.(proj_ind) u) args ->
    #|args| = ind_npars mdecl ->
    Σ ;;; Γ |- tProj p c : subst0 (c :: List.rev args) pdecl.(proj_type)@[u]

| type_Fix : forall mfix n decl,
    wf_local Σ Γ ->
    fix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_fixpoint Σ mfix ->
    Σ ;;; Γ |- tFix mfix n : decl.(dtype)

| type_CoFix : forall mfix n decl,
    wf_local Σ Γ ->
    cofix_guard Σ Γ mfix ->
    nth_error mfix n = Some decl ->
    All (on_def_type (lift_typing1 (typing Σ)) Γ) mfix ->
    All (on_def_body (lift_typing1 (typing Σ)) (fix_context mfix) Γ) mfix ->
    wf_cofixpoint Σ mfix ->
    Σ ;;; Γ |- tCoFix mfix n : decl.(dtype)

| type_Prim p prim_ty cdecl :
    wf_local Σ Γ ->
    primitive_constant Σ (prim_val_tag p) = Some prim_ty ->
    declared_constant Σ prim_ty cdecl ->
    primitive_invariants (prim_val_tag p) cdecl ->
    primitive_typing_hyps typing Σ Γ p ->
    Σ ;;; Γ |- tPrim p : prim_type p prim_ty

| type_Cumul : forall t A B s,
    Σ ;;; Γ |- t : A ->
    Σ ;;; Γ |- B : tSort s ->
    Σ ;;; Γ |- A <=s B ->
    Σ ;;; Γ |- t : B

where " Σ ;;; Γ |- t : T " := (typing Σ Γ t T)
and "'wf_local' Σ Γ " := (All_local_env (lift_typing1 (typing Σ)) Γ).

Definition wf `{checker_flags} := on_global_env cumulSpec0 (lift_typing typing).

Definition wf_ext `{checker_flags} := on_global_env_ext cumulSpec0 (lift_typing typing).

Record normalizing_flags {cf : checker_flags} : Prop :=
  { nor_check_univs :> check_univs }.
Import MetaCoq.PCUIC.PCUICAst.

Inductive ConversionError :=
| NotFoundConstants (c1 c2 : kername)

| NotFoundConstant (c : kername)

| LambdaNotConvertibleTypes
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)
    (e : ConversionError)

| LambdaNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 t1 : term)
    (Γ2 : context) (na' : aname) (A2 t2 : term)

| ProdNotConvertibleDomains
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)
    (e : ConversionError)

| ProdNotConvertibleAnn
    (Γ1 : context) (na : aname) (A1 B1 : term)
    (Γ2 : context) (na' : aname) (A2 B2 : term)

| ContextNotConvertibleAnn
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleType
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleBody
    (Γ : context) (decl : context_decl)
    (Γ' : context) (decl' : context_decl)
| ContextNotConvertibleLength

| CaseOnDifferentInd
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredParamsUnequalLength
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| CasePredUnequalUniverseInstances
    (Γ1 : context)
    (ci : case_info) (p : predicate term) (c : term) (brs : list (branch term))
    (Γ2 : context)
    (ci' : case_info) (p' : predicate term) (c' : term) (brs' : list (branch term))

| DistinctStuckProj
    (Γ : context) (p : projection) (c : term)
    (Γ' : context) (p' : projection) (c' : term)

| CannotUnfoldFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| FixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| FixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctCoFix
    (Γ : context) (mfix : mfixpoint term) (idx : nat)
    (Γ' : context) (mfix' : mfixpoint term) (idx' : nat)

| CoFixRargMismatch (idx : nat)
    (Γ : context) (u : def term) (mfix1 mfix2 : mfixpoint term)
    (Γ' : context) (v : def term) (mfix1' mfix2' : mfixpoint term)

| CoFixMfixMismatch (idx : nat)
    (Γ : context) (mfix : mfixpoint term)
    (Γ' : context) (mfix' : mfixpoint term)

| DistinctPrimTags
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| DistinctPrimValues
  (Γ : context) (p : prim_val)
  (Γ' : context) (p' : prim_val)

| ArrayNotConvertibleLevels
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayValuesNotSameLength
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)

| ArrayNotConvertibleValues
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleDefault
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| ArrayNotConvertibleTypes
  (Γ : context) (a : array_model term) (Γ' : context) (a' : array_model term)
  (e : ConversionError)

| StackHeadError
    (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackTailError (leq : conv_pb)
    (Γ1 : context)
    (t1 : term) (args1 : list term) (u1 : term) (l1 : list term)
    (Γ2 : context)
    (t2 : term) (u2 : term) (l2 : list term)
    (e : ConversionError)

| StackMismatch
    (Γ1 : context) (t1 : term) (args1 l1 : list term)
    (Γ2 : context) (t2 : term) (l2 : list term)

| HeadMismatch
    (leq : conv_pb)
    (Γ1 : context) (t1 : term)
    (Γ2 : context) (t2 : term).

Inductive type_error :=
| UnboundRel (n : nat)
| UnboundVar (id : string)
| UnboundEvar (ev : nat)
| UndeclaredConstant (c : kername)
| UndeclaredInductive (c : inductive)
| UndeclaredConstructor (c : inductive) (i : nat)
| NotCumulSmaller {abstract_structure} (le : bool)
  (G : abstract_structure) (Γ : context) (t u t' u' : term) (e : ConversionError)
| NotConvertible {abstract_structure}
  (G : abstract_structure)
  (Γ : context) (t u : term)
| NotASort (t : term)
| NotAProduct (t t' : term)
| NotAnInductive (t : term)
| NotAnArity (t : term)
| IllFormedFix (m : mfixpoint term) (i : nat)
| UnsatisfiedConstraints (c : ConstraintSet.t)
| Msg (s : string).

Inductive env_error :=
| IllFormedDecl (e : string) (e : type_error)
| AlreadyDeclared (id : string).

Section EnvCheck.

  Context (abstract_structure : Type).

Inductive EnvCheck (A : Type) :=
| CorrectDecl (a : A)
| EnvError (Σ : abstract_structure) (e : env_error).
Global Instance envcheck_monad : Monad EnvCheck.
Admitted.

End EnvCheck.
Import MetaCoq.Common.uGraph.

Lemma wf_ext_gc_of_uctx {cf:checker_flags} {Σ : global_env_ext} (HΣ : ∥ wf_ext Σ ∥)
: ∑ uctx', gc_of_uctx (global_ext_uctx Σ) = Some uctx'.
Admitted.

Definition on_global_decls {cf:checker_flags} Σ :=
  on_global_decls_data cumulSpec0 (lift_typing typing) (cf:=cf) Σ.(universes) Σ.(retroknowledge) Σ.(declarations).

Class abstract_env_struct {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl : Type) := {

  abstract_env_rel : abstract_env_impl -> global_env -> Prop;
  abstract_env_ext_rel : abstract_env_ext_impl -> global_env_ext -> Prop;

  abstract_env_init (cs:ContextSet.t) (retro : Retroknowledge.t) : on_global_univs cs -> abstract_env_impl;
  abstract_env_add_decl X (kn:kername) (d:global_decl) :
   (forall Σ, abstract_env_rel X Σ -> ∥ on_global_decls Σ kn d ∥)
   -> abstract_env_impl;
  abstract_env_add_udecl X udecl :
    (forall Σ, abstract_env_rel X Σ -> ∥ on_udecl Σ.(universes) udecl ∥) ->
    abstract_env_ext_impl ;
  abstract_pop_decls : abstract_env_impl -> abstract_env_impl ;

  abstract_env_lookup : abstract_env_ext_impl -> kername -> option global_decl;
  abstract_primitive_constant : abstract_env_ext_impl -> Primitive.prim_tag -> option kername;

  abstract_env_level_mem : abstract_env_ext_impl -> Level.t -> bool;
  abstract_env_leqb_level_n : abstract_env_ext_impl -> Z -> Level.t -> Level.t -> bool;
  abstract_env_guard : abstract_env_ext_impl -> FixCoFix -> context -> mfixpoint term -> bool;
  abstract_env_is_consistent : abstract_env_impl -> LevelSet.t * GoodConstraintSet.t -> bool ;

}.

Class abstract_env_prop {cf:checker_flags} (abstract_env_impl abstract_env_ext_impl: Type)
  `{!abstract_env_struct abstract_env_impl abstract_env_ext_impl} : Prop := {

  abstract_env_ext_exists X : ∥ ∑ Σ , abstract_env_ext_rel X Σ ∥;
  abstract_env_ext_wf X {Σ} : abstract_env_ext_rel X Σ -> ∥ wf_ext Σ ∥ ;
  abstract_env_ext_irr X {Σ Σ'} :
      abstract_env_ext_rel X Σ -> abstract_env_ext_rel X Σ' ->  Σ = Σ';

  abstract_env_exists X : ∥ ∑ Σ , abstract_env_rel X Σ ∥;
  abstract_env_wf X {Σ} : abstract_env_rel X Σ -> ∥ wf Σ ∥;
  abstract_env_irr X {Σ Σ'} :
    abstract_env_rel X Σ -> abstract_env_rel X Σ' ->  Σ = Σ';

  abstract_env_init_correct univs retro cuniv :
    abstract_env_rel (abstract_env_init univs retro cuniv)
    {| universes := univs; declarations := []; retroknowledge := retro |} ;
  abstract_env_add_decl_correct X Σ kn d H : abstract_env_rel X Σ ->
    abstract_env_rel (abstract_env_add_decl X kn d H) (add_global_decl Σ (kn,d));
  abstract_env_add_udecl_rel X {Σ} udecl H :
    (abstract_env_rel X Σ.1 /\ Σ.2 = udecl) <->
    abstract_env_ext_rel (abstract_env_add_udecl X udecl H) Σ;
  abstract_pop_decls_correct X decls (prf : forall Σ : global_env, abstract_env_rel X Σ ->
            exists d, Σ.(declarations) = d :: decls) :
    let X' := abstract_pop_decls X in
    forall Σ Σ', abstract_env_rel X Σ -> abstract_env_rel X' Σ' ->
                      Σ'.(declarations) = decls /\ Σ.(universes) = Σ'.(universes) /\
                      Σ.(retroknowledge) = Σ'.(retroknowledge);

  abstract_env_lookup_correct X {Σ} kn decl : abstract_env_ext_rel X Σ ->
      In (kn, decl) (declarations Σ) <-> abstract_env_lookup X kn = Some decl ;

  abstract_env_leqb_level_n_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ):
    let uctx := (wf_ext_gc_of_uctx (abstract_env_ext_wf X wfΣ)).π1 in
    leqb_level_n_spec_gen uctx (abstract_env_leqb_level_n X);
  abstract_env_level_mem_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) l:
    LevelSet.In l (global_ext_levels Σ) <-> abstract_env_level_mem X l;
  abstract_env_is_consistent_correct X Σ uctx udecl :
    abstract_env_rel X Σ ->
    ConstraintSet.For_all (declared_cstr_levels (LevelSet.union udecl.1 (global_levels Σ))) udecl.2 ->
    gc_of_uctx udecl = Some uctx ->
    consistent_extension_on (global_uctx Σ) udecl.2 <-> abstract_env_is_consistent X uctx ;

  abstract_env_guard_correct X {Σ} (wfΣ : abstract_env_ext_rel X Σ) fix_cofix Γ mfix :
      guard fix_cofix Σ Γ mfix <-> abstract_env_guard X fix_cofix Γ mfix;
  abstract_primitive_constant_correct X tag Σ :
    abstract_env_ext_rel X Σ -> abstract_primitive_constant X tag = PCUICEnvironment.primitive_constant Σ tag
  }.

Definition abstract_env_impl {cf:checker_flags} := ∑ X Y Z, @abstract_env_prop _ X Y Z.

Import MCMonadNotation.

Section CheckEnv.
  Context {cf:checker_flags} {nor : normalizing_flags}.

  Context (X_impl : abstract_env_impl).

  Definition X_env_type := X_impl.π1.

  Implicit Type X : X_env_type.
    Context {AA : Type} {BB : AA -> Type} {T : Type -> Type} {M : Monad T} {A} {P : forall (aa:AA), BB aa -> A -> Type} {Q : forall (aa:AA), BB aa -> A -> Type}
    (f : forall x, (forall aa bb, ∥ Q aa bb x ∥) -> T (forall aa bb, ∥ P aa bb x ∥)).
    Program Fixpoint monad_All_All l :
      (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) ->
      T (forall (aa:AA) (bb:BB aa), ∥ All (P aa bb) l ∥) :=
      match l return (forall (aa:AA) (bb: BB aa), ∥ All (Q aa bb) l ∥) -> T (forall (aa:AA) (bb:BB aa) , ∥ All (P aa bb) l ∥) with
        | [] => fun _ => ret (fun aa bb  => sq All_nil)
        | a :: l => fun allq =>
        X <- f a _ ;;
        Y <- monad_All_All l _ ;;
        ret (fun aa bb  => _)
        end.
🛠️ Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted)
🛠️ 📜 Intermediate Coq File log (useful for debugging if minimization did not go as far as you wanted)
📜 Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 4.2MiB file on GitHub Actions Artifacts under build.log)
space/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.zEGGJopEDN
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.yeQsnXL1SE
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.sJBFkFNvkU
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/template-coq'
make -C pcuic
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -f Makefile.coq
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.szNCZ2IAeB
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.7heeIpkewl
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.MwCDwFPZQl
MINIMIZER_DEBUG: files: 
make[4]: Nothing to be done for 'real-all'.
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.eN4q0ZbuuD
MINIMIZER_DEBUG: files: 
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic'
make -C safechecker
make[2]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make -f Makefile.safechecker
make[3]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.dHt6NnZks2
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.CwUvnbwr95
MINIMIZER_DEBUG: files: 
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.HlX1On2uEA
MINIMIZER_DEBUG: files: 
COQC theories/PCUICSafeChecker.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin/////coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w -deprecated-native-compiler-option -native-compiler no -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/utils/theories MetaCoq.Utils -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/common/theories MetaCoq.Common -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/pcuic/theories MetaCoq.PCUIC -R /github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker/theories MetaCoq.SafeChecker theories/PCUICSafeChecker.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.98yBOx4WTk
MINIMIZER_DEBUG: files:  theories/PCUICSafeChecker.v
File "./theories/PCUICSafeChecker.v", line 1739, characters 8-85:
Error:
In environment
cf : checker_flags
nor : normalizing_flags
X_impl : abstract_env_impl
AA : Type
BB : AA -> Type
T : Type -> Type
M : Monad T
A : Type
P : forall aa : AA, BB aa -> A -> Type
Q : forall aa : AA, BB aa -> A -> Type
f :
  forall x : A,
  (forall (aa : AA) (bb : BB aa), ∥ Q aa bb x ∥) ->
  T (forall (aa : AA) (bb : BB aa), ∥ P aa bb x ∥)
monad_All_All :
  Tactics.fix_proto
    (forall l : list A,
     (forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) l ∥) ->
     T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) l ∥))
l : list A
a : A
l0 : list A
allq : forall (aa : AA) (bb : BB aa), ∥ All (Q aa bb) (a :: l0) ∥
Unable to unify
 "EnvCheck ?abstract_structure0@{l0:=l; l:=l0}
    (forall (aa : ?T@{l0:=l; l:=l0}) (bb : ?T0@{l0:=l; l:=l0}),
     ?T1@{l0:=l; l:=l0})" with
 "T (forall (aa : AA) (bb : BB aa), ∥ All (P aa bb) (a :: l0) ∥)".

Command exited with non-zero status 1
theories/PCUICSafeChecker.vo (real: 13.23, user: 13.00, sys: 0.23, mem: 990456 ko)
make[4]: *** [Makefile.safechecker:803: theories/PCUICSafeChecker.vo] Error 1
make[3]: *** [Makefile.safechecker:417: all] Error 2
make[3]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[2]: *** [Makefile:11: theory] Error 2
make[2]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq/safechecker'
make[1]: *** [Makefile:151: safechecker] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/metacoq'
+ code=2
+ echo 'Aggregating timing log...'
Aggregating timing log...
+ echo

+ python ./tools/make-one-time-file.py --real metacoq.log
    Time |  Peak Mem | File Name            
--------------------------------------------
0m13.23s | 990456 ko | Total Time / Peak Mem
--------------------------------------------
0m13.23s | 990456 ko | PCUICSafeChecker.vo  
+ '[' '' ']'
+ exit 2
make: *** [Makefile.ci:193: ci-metacoq] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
📜 🔎 Minimization Log (truncated to last 8.0KiB; full 137KiB file on GitHub Actions Artifacts under bug.log)
.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp65t9uat2/Top/bug_01.v", line 696, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpmj2gcpml/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpmj2gcpml/Top/bug_01.v", line 698, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables

Non-fatal error: Failed to remove variables and preserve the error.  
The new error was:
File "/tmp/tmpk8nz6apl/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpk8nz6apl/Top/bug_01.v", line 697, characters 12-21:
Error: The reference destArity was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to admit [abstract ...]s
�[92m
Admitting [abstract ...] successful.�[0m
�[92m
Admitting [abstract ...] successful.�[0m
Admitting [abstract ...] unsuccessful.
Admitting [abstract ...] unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmp65t9uat2/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmp65t9uat2/Top/bug_01.v", line 696, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions

Non-fatal error: Failed to remove non-instance definitions and preserve the error.  
The new error was:
File "/tmp/tmpmj2gcpml/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpmj2gcpml/Top/bug_01.v", line 698, characters 6-28:
Error: Unknown interpretation for notation "_ ;;; _ |arg+> _".


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused variables

Non-fatal error: Failed to remove variables and preserve the error.  
The new error was:
File "/tmp/tmpk8nz6apl/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpk8nz6apl/Top/bug_01.v", line 697, characters 12-21:
Error: The reference destArity was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to replace Obligation with Admit Obligations
�[92m
Admitting Obligations successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting Obligations unsuccessful.
No successful changes.

I will now attempt to admit lemmas with Admitted
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with Admitted

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpuro2ua0q/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpuro2ua0q/Top/bug_01.v", line 802, characters 27-38:
Error:
In environment
cf : checker_flags
Pcmp : global_env_ext -> context -> conv_pb -> term -> term -> Type
P : global_env_ext -> context -> judgment -> Type
Σ : ?T
mdecl : mutual_inductive_body
v : list Variance.t
indices : ?T0
univs := ind_universes mdecl : universes_decl
p : (universes_decl × list Level.t_) × list Level.t_
p0 : universes_decl × list Level.t_
u' : list Level.t_
univs0 : universes_decl
u : list Level.t_
The term "(Σ, univs0)" has type "?A * universes_decl"
while it is expected to have type "global_env_ext".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpjujjac6l/Top/bug_01.v", line 42, characters 0-25:
Warning: Library File Coq.Bool.Bvector is deprecated since 8.20.
Consider [list bool] instead. See <https://github.com/coq/coq/blob/master/theories/Vectors/Vector.v> for details. Please open an issue if you would like to keep using Bvector.
[deprecated-library-file-since-8.20,deprecated-since-8.20,deprecated-library-file,deprecated,default]
File "/tmp/tmpjujjac6l/Top/bug_01.v", line 803, characters 27-38:
Error:
In environment
cf : checker_flags
Pcmp : global_env_ext -> context -> conv_pb -> term -> term -> Type
P : global_env_ext -> context -> judgment -> Type
Σ : ?T
mdecl : mutual_inductive_body
v : list Variance.t
indices : ?T0
univs := ind_universes mdecl : universes_decl
p : (universes_decl × list Level.t_) × list Level.t_
p0 : universes_decl × list Level.t_
u' : list Level.t_
univs0 : universes_decl
u : list Level.t_
The term "(Σ, univs0)" has type "?A * universes_decl"
while it is expected to have type "global_env_ext".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation successful

I will now attempt to split imports and exports
Import/Export splitting successful

I will now attempt to split := definitions
One-line definition splitting successful

I will now attempt to remove all lines, one at a time

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

EDIT manually interrupted

@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label May 7, 2024
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label May 7, 2024
@SkySkimmer
Copy link
Contributor Author

Some of those failures appear to be real bugs but not sure how minimal they are

iris appears to rely on implicit types not applying to these notations

@herbelin
Copy link
Member

herbelin commented May 8, 2024

Adding locate_with_hole in traverse_binder is apparently too early: it also goes to the match pattern variables which results in the Unsupported pattern cast error. Maybe could it be put instead in Notation_ops.set_anonymous_type which is about only fun and forall.

@SkySkimmer
Copy link
Contributor Author

My motivation for this expired.

Comment on lines +1 to +3
Notation "[ 'fun' x => F ]" := (fun x => F)
(at level 0, x ident, only parsing).
(* or `x pattern` *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example seems a bit obsolete. It seems more appropriate to use name instead of ident now (cf. #11841).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implicit Types declaration doesn't work for notations involving binders
3 participants