Skip to content

Commit 1dee026

Browse files
Merge pull request #2332 from tabareau/sortpoly-equality
Adapt with respect to rocq-prover/rocq#21371
2 parents 28c8d19 + 704649d commit 1dee026

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

test/bugs/github1794.v

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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. *)
34

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

theories/Basics/Overture.v

Lines changed: 11 additions & 21 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.
76
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. *)
@@ -282,6 +282,7 @@ Definition paths_rect := paths_ind.
282282
Register paths as core.identity.type.
283283
Register idpath as core.identity.refl.
284284
Register paths_rect as core.identity.ind.
285+
Register paths_rec as core.identity.rec.
285286

286287
Notation "x = y :> A" := (@paths A x y) : type_scope.
287288
Notation "x = y" := (x = y :>_) : type_scope.
@@ -395,28 +396,17 @@ Arguments transport {A}%_type_scope P%_function_scope {x y} p%_path_scope u : si
395396
(** 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. *)
396397
Notation "p # u" := (transport _ p u) (only parsing) : path_scope.
397398

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.
399+
(** 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. *)
400+
(** 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. Rocq 9.2 will contain PR#21098 which adds further registration options. It should be possible to do things in a way that works across these versions. See #2332 for a discussion of this. *)
401+
Local Lemma define_internal_paths_rew A x y P (u : P x) (H : x = y :> A) : P y.
402+
Proof. rewrite <- H. exact u. Defined.
408403

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

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.
407+
(* 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. *)
408+
Arguments internal_paths_rew {A%_type_scope} {a} P%_function_scope f {a0} p : rename.
409+
Arguments internal_paths_rew_r {A%_type_scope} {a y} P%_function_scope HC X.
420410

421411
(** 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]. *)
422412

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 [ 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.
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.
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-
: path_Has_Leibniz_r_elim _ _ P u _ p = transport P p^ u.
416+
: internal_paths_rew_r P u p = transport P p^ u.
417417
Proof.
418418
destruct p; reflexivity.
419419
Defined.

0 commit comments

Comments
 (0)