Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion test/bugs/github1794.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
From HoTT Require Import Basics.Overture.

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

(** After PR#21098, helper lemmas are not generated as rewrite now relies on typeclass instances *)

(*
Check internal_paths_rew@{u1 u2}.
Check internal_paths_rew_r@{u1 u2}.
*)
31 changes: 21 additions & 10 deletions theories/Basics/Overture.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
(** 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. *)

(** Import the file of reserved notations so we maintain consistent level notations throughout the library. *)
Require Export Equality.
Require Export Basics.Settings Basics.Notations.

Local Set Polymorphic Inductive Cumulativity.

(** 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. *)
Expand Down Expand Up @@ -70,10 +70,10 @@
Notation "x * y" := (prod x y) : type_scope.
Notation "( x , y , .. , z )" := (pair .. (pair x y) .. z) : core_scope.
Notation "A /\ B" := (prod A B) (only parsing) : type_scope.
Notation and := prod (only parsing).

Check warning on line 73 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use
Notation conj := pair (only parsing).

Check warning on line 74 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use

#[export] Hint Resolve pair inl inr : core.

Check warning on line 76 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Implicitly declaring hint databases is deprecated. Please explicitly

(** ** Type classes *)

Expand Down Expand Up @@ -139,7 +139,7 @@
(** ** Basic definitions *)

(** Define an alias for [Set], which is really [Type₀], the smallest universe. *)
Notation Type0 := Set.

Check warning on line 142 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use

(** ** Sigma types *)

Expand Down Expand Up @@ -186,8 +186,8 @@
(** We bind [fibration_scope] with [sig] so that we are automatically in [fibration_scope] when we are passing an argument of type [sig]. *)
Bind Scope fibration_scope with sig.

Notation pr1 := proj1.

Check warning on line 189 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use
Notation pr2 := proj2.

Check warning on line 190 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use

(** The following notation is very convenient, although it unfortunately clashes with Proof General's "electric period". We have added [format] specifiers in Notations.v so that it will display without an extra space, as [x.1] rather than as [x .1]. *)
Notation "x .1" := (pr1 x) : fibration_scope.
Expand All @@ -196,7 +196,7 @@
(** ** Functions *)

(** We make the identity map a notation so we do not have to unfold it, or complicate matters with its type. *)
Notation idmap := (fun x => x).

Check warning on line 199 in theories/Basics/Overture.v

View workflow job for this annotation

GitHub Actions / opam-build (dev, ubuntu-latest)

Use of "Notation" keyword for abbreviations is deprecated, use

Instance reflexive_fun : Reflexive (fun A B => A -> B)
:= fun _ => idmap.
Expand Down Expand Up @@ -395,17 +395,28 @@
(** 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. *)
Notation "p # u" := (transport _ p u) (only parsing) : path_scope.

(** 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. *)
(** 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. *)
Local Lemma define_internal_paths_rew A x y P (u : P x) (H : x = y :> A) : P y.
Proof. rewrite <- H. exact u. Defined.
Instance path_Has_refl@{l} : Has_refl@{Type Type;l l} (@paths@{l})
:= @idpath.

Definition path_Has_J_elim@{l l'} : Has_J@{Type Type Type; l l l'} (@paths) _
:= paths_rect.

Hint Resolve path_Has_J_elim : rewrite_instances.

Definition path_Has_Leibniz_elim@{l l'} : Has_Leibniz@{Type Type Type;l l l'} (@paths)
:= @paths_rec.

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

(* 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. *)
Arguments internal_paths_rew {A%_type_scope} {a} P%_function_scope f {a0} p : rename.
Arguments internal_paths_rew_r {A%_type_scope} {a y} P%_function_scope HC X.
Definition path_Has_J_r_elim@{l l'} : Has_J_r@{Type Type Type; l l l'} (@paths) _
:= @paths_ind_r.

Hint Resolve path_Has_J_r_elim : rewrite_instances.

Definition path_Has_Leibniz_r_elim@{l l'} : Has_Leibniz_r@{Type Type s;l l l'} (@paths) :=
fun A x P t y e => @paths_ind_r A x (fun a _ => P a) t y e.

Hint Resolve path_Has_Leibniz_r_elim : rewrite_instances.

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

Expand Down
6 changes: 3 additions & 3 deletions theories/Tactics.v
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ Ltac context_to_lambda G :=

(** 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. *)
Ltac internal_paths_rew_to_transport :=
repeat match goal with |- context [ internal_paths_rew ?P ?u ?p ] =>
change (internal_paths_rew P u p) with (transport P p u) end.
repeat match goal with |- context [ path_Has_Leibniz_elim ?A ?x ?P ?u ?y ?p ] =>
change (path_Has_Leibniz_elim A x P u y p) with (transport P p u) end.

(** 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. *)
Definition internal_paths_rew_r_to_transport {A : Type} {x y : A} (P : A -> Type) (u : P y) (p : x = y)
: internal_paths_rew_r P u p = transport P p^ u.
: path_Has_Leibniz_r_elim _ _ P u _ p = transport P p^ u.
Proof.
destruct p; reflexivity.
Defined.
Expand Down
Loading