Skip to content

Commit 55b5f53

Browse files
committed
Turn warnings about :> in Class as error
This way, in next version, we can finally have :> declare a coercion in any record declaration, including typeclasses. Whereas :: consistently declares typeclass instances since Coq 8.18.
1 parent c858865 commit 55b5f53

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
- **Changed:**
2+
warnings `future-coercion-class-constructor`
3+
and `future-coercion-class-field` about ``:>`` in :cmd:`Class` as
4+
error by default. This offers a last opportunity to replace ``:>``
5+
with ``::`` (available since Coq 8.18) to declare typeclass instances
6+
before making ``:>`` consistently declare coercions in all records in
7+
next version.
8+
To adapt huge codebases, you can try
9+
`this script <https://gist.github.com/JasonGross/59fc3c03664f2280849abf50b531be42>`_
10+
or the one below. But beware that both are incomplete.
11+
12+
.. code-block:: sh
13+
14+
#!/bin/awk -f
15+
BEGIN {
16+
startclass = 0;
17+
inclass = 0;
18+
indefclass = 0; # definitionalclasses (single field, without { ... })
19+
}
20+
{
21+
if ($0 ~ "[ ]*Class") {
22+
startclass = 1;
23+
}
24+
if (startclass == 1 && $0 ~ ":=") {
25+
inclass = 1;
26+
indefclass = 1;
27+
}
28+
if (startclass == 1 && $0 ~ ":=.*{") {
29+
indefclass = 0;
30+
}
31+
if (inclass == 1) startclass = 0;
32+
33+
if (inclass == 1 && $0 ~ ":>") {
34+
if ($0 ~ "{ .*:>") { # first field on a single line
35+
sub("{ ", "{ #[global] ");
36+
} else if ($0 ~ ":=.*:>") { # definitional classes on a single line
37+
sub(":= ", ":= #[global] ");
38+
} else if ($0 ~ "^ ") {
39+
sub(" ", " #[global] ");
40+
} else {
41+
$0 = "#[global] " $0;
42+
}
43+
sub(":>", "::")
44+
}
45+
print $0;
46+
47+
if ($0 ~ ".*}[.]" || indefclass == 1 && $0 ~ "[.]$") inclass = 0;
48+
}
49+
50+
(`#18590 <https://github.com/coq/coq/pull/18590>`_,
51+
by Pierre Roux).

doc/sphinx/addendum/type-classes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ the implicit arguments mechanism if available, as shown in the example.
248248
Substructures
249249
~~~~~~~~~~~~~
250250

251-
.. index:: :> (substructure)
251+
.. index:: :: (substructure)
252252

253253
Substructures are components of a typeclass which are themselves instances of a
254254
typeclass. They often arise when using typeclasses for logical properties, e.g.:

vernac/record.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ let warn_future_coercion_class_constructor =
679679
(c.f., https://github.com/coq/coq/pull/16230 ) *)
680680
let warn_future_coercion_class_field =
681681
CWarnings.create ~name:"future-coercion-class-field" ~category:Deprecation.Version.v8_17
682+
~default:CWarnings.AsError
682683
Pp.(fun definitional ->
683684
strbrk "A coercion will be introduced instead of an instance in future versions when using ':>' in 'Class' declarations. "
684685
++ strbrk "Replace ':>' with '::' (or use '#[global] Existing Instance field.' for compatibility with Coq < 8.18). Beware that the default locality for '::' is #[export], as opposed to #[global] for ':>' currently."

0 commit comments

Comments
 (0)