Skip to content

Commit 28c8d19

Browse files
authored
Merge pull request #2331 from tabareau/sortpoly-equality
Adapt with respect to rocq-prover/rocq#21098
2 parents 42b956c + 4e8c11d commit 28c8d19

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

test/bugs/github1794.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
From HoTT Require Import Basics.Overture.
22

3-
(** When [rewrite] is first used, it defines helper lemmas. If the first use is in a Section that has universe variables, then these lemmas get unnecessary universe variables. Overture uses [rewrite] outside of a section to ensure that they have the expected number of universe variables, and we test that here. *)
43

4+
(** After PR#21098, helper lemmas are not generated as rewrite now relies on typeclass instances *)
5+
6+
(*
57
Check internal_paths_rew@{u1 u2}.
68
Check internal_paths_rew_r@{u1 u2}.
9+
*)

theories/Basics/Overture.v

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
(** This file defines some of the most basic types and type formers, such as sums, products, Sigma types and path types. It defines the action of functions on paths [ap], transport, equivalences, and function extensionality. It also defines truncatedness, and a number of other fundamental definitions used throughout the library. *)
44

55
(** Import the file of reserved notations so we maintain consistent level notations throughout the library. *)
6+
Require Export Equality.
67
Require Export Basics.Settings Basics.Notations.
7-
88
Local Set Polymorphic Inductive Cumulativity.
99

1010
(** This command prevents Coq from automatically defining the eliminator functions for inductive types. We will define them ourselves to match the naming scheme of the HoTT Book. In principle we ought to make this [Global], but unfortunately the tactics [induction] and [elim] assume that the eliminators are named in Coq's way, e.g. [thing_rect], so making it global could cause unpleasant surprises for people defining new inductive types. However, when you do define your own inductive types you are encouraged to also do [Local Unset Elimination Schemes] and then use [Scheme] to define [thing_ind], [thing_rec], and (for compatibility with [induction] and [elim]) [thing_rect], as we have done below for [paths], [Empty], [Unit], etc. We are hoping that this will be fixed eventually; see https://github.com/coq/coq/issues/3745. *)
@@ -395,17 +395,28 @@ Arguments transport {A}%_type_scope P%_function_scope {x y} p%_path_scope u : si
395395
(** Transport is very common so it is worth introducing a parsing notation for it. However, we do not use the notation for output because it hides the fibration, and so makes it very hard to read involved transport expression. *)
396396
Notation "p # u" := (transport _ p u) (only parsing) : path_scope.
397397

398-
(** The first time [rewrite] is used in each direction, it creates transport lemmas called [internal_paths_rew] and [internal_paths_rew_r]. See ../Tactics.v for how these compare to [transport]. We use [rewrite] here to trigger the creation of these lemmas. This ensures that they are defined outside of sections, so they are not unnecessarily polymorphic. The lemmas below are not used in the library. *)
399-
(** TODO: Since Coq 8.20 has PR#18299, once that is our minimum version we can instead register wrappers for [transport] to be used for rewriting. See the comment by Dan Christensen in that PR for how to do this. Then the tactics [internal_paths_rew_to_transport] and [rewrite_to_transport] can be removed from ../Tactics.v. *)
400-
Local Lemma define_internal_paths_rew A x y P (u : P x) (H : x = y :> A) : P y.
401-
Proof. rewrite <- H. exact u. Defined.
398+
Instance path_Has_refl@{l} : Has_refl@{Type Type;l l} (@paths@{l})
399+
:= @idpath.
400+
401+
Definition path_Has_J_elim@{l l'} : Has_J@{Type Type Type; l l l'} (@paths) _
402+
:= paths_rect.
403+
404+
Hint Resolve path_Has_J_elim : rewrite_instances.
405+
406+
Definition path_Has_Leibniz_elim@{l l'} : Has_Leibniz@{Type Type Type;l l l'} (@paths)
407+
:= @paths_rec.
402408

403-
Local Lemma define_internal_paths_rew_r A x y P (u : P y) (H : x = y :> A) : P x.
404-
Proof. rewrite -> H. exact u. Defined.
409+
Hint Resolve path_Has_Leibniz_elim : rewrite_instances.
405410

406-
(* TODO: ": rename" is needed because the default names changed in Rocq 9.2.0. When the minimum supported version is >= 9.2.0, the ": rename" can be removed. *)
407-
Arguments internal_paths_rew {A%_type_scope} {a} P%_function_scope f {a0} p : rename.
408-
Arguments internal_paths_rew_r {A%_type_scope} {a y} P%_function_scope HC X.
411+
Definition path_Has_J_r_elim@{l l'} : Has_J_r@{Type Type Type; l l l'} (@paths) _
412+
:= @paths_ind_r.
413+
414+
Hint Resolve path_Has_J_r_elim : rewrite_instances.
415+
416+
Definition path_Has_Leibniz_r_elim@{l l'} : Has_Leibniz_r@{Type Type s;l l l'} (@paths) :=
417+
fun A x P t y e => @paths_ind_r A x (fun a _ => P a) t y e.
418+
419+
Hint Resolve path_Has_Leibniz_r_elim : rewrite_instances.
409420

410421
(** Having defined transport, we can use it to talk about what a homotopy theorist might see as "paths in a fibration over paths in the base"; and what a type theorist might see as "heterogeneous equality in a dependent type". We will first see this appearing in the type of [apD]. *)
411422

theories/Tactics.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,12 @@ Ltac context_to_lambda G :=
408408

409409
(** The [rewrite <-] tactic uses [internal_paths_rew], which is definitionally equal to [transport], except for the order of the arguments. The following replaces the former with the latter. *)
410410
Ltac internal_paths_rew_to_transport :=
411-
repeat match goal with |- context [ internal_paths_rew ?P ?u ?p ] =>
412-
change (internal_paths_rew P u p) with (transport P p u) end.
411+
repeat match goal with |- context [ path_Has_Leibniz_elim ?A ?x ?P ?u ?y ?p ] =>
412+
change (path_Has_Leibniz_elim A x P u y p) with (transport P p u) end.
413413

414414
(** Unfortunately, the more common [rewrite ->] uses [internal_paths_rew_r], which is not definitionally equal to something involving [transport]. However, we do have a propositional equality. The arguments here match the arguments that [internal_paths_rew_r] takes. *)
415415
Definition internal_paths_rew_r_to_transport {A : Type} {x y : A} (P : A -> Type) (u : P y) (p : x = y)
416-
: internal_paths_rew_r P u p = transport P p^ u.
416+
: path_Has_Leibniz_r_elim _ _ P u _ p = transport P p^ u.
417417
Proof.
418418
destruct p; reflexivity.
419419
Defined.

0 commit comments

Comments
 (0)