Skip to content

Commit 511492f

Browse files
committed
Uniformize semantics of :> in class after deprecation phase of rocq-prover#16230
This ends the deprecation phases of rocq-prover#16230 and rocq-prover#15802 that introduced :: instead of :> for subclasses in Class declarations. Now :> means coercion in all record declarations (including typeclasses).
1 parent dc26512 commit 511492f

File tree

8 files changed

+18
-74
lines changed

8 files changed

+18
-74
lines changed

doc/sphinx/addendum/type-classes.rst

Lines changed: 4 additions & 14 deletions
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.:
@@ -309,9 +309,8 @@ Command summary
309309
declared rigid during resolution so that the typeclass abstraction is
310310
maintained.
311311

312-
The `>` in
313-
:token:`record_definition` currently does nothing. In a future version, it will
314-
create coercions as it does when used in :cmd:`Record` commands.
312+
The `>` in :token:`record_definition`
313+
creates coercions as it does when used in :cmd:`Record` commands.
315314

316315
Like any command declaring a record, this command supports the
317316
:attr:`universes(polymorphic)`, :attr:`universes(template)`,
@@ -333,18 +332,9 @@ Command summary
333332

334333
This command has no effect when used on a typeclass.
335334

336-
.. _warn-future-coercion-class-field:
337-
338-
.. warn:: A coercion will be introduced instead of an instance in future versions when using ':>' in 'Class' declarations. Replace ':>' with '::' (or use '#[global] Existing Instance field.' for compatibility with Coq < 8.17).
339-
340-
In future versions, :g:`:>` in the :n:`@record_definition` or
341-
:n:`@constructor` will declare a :ref:`coercion<coercions>`, as
342-
it does for other :cmd:`Record` commands. To eliminate the warning, use
343-
:g:`::` instead.
344-
345335
.. warn:: Ignored instance declaration for “@ident”: “@term” is not a class
346336

347-
Using the ``::`` (or deprecated ``:>``) syntax in the :n:`@record_definition`
337+
Using the ``::`` syntax in the :n:`@record_definition`
348338
or :n:`@constructor` with a right-hand-side that
349339
is not itself a Class has no effect (apart from emitting this warning).
350340

doc/sphinx/language/core/records.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Defining record types
9292
:n:`:>`
9393
If specified, the field is declared as a coercion from the record name
9494
to the class of the field type. See :ref:`coercions`.
95-
Note that this currently does something else in :cmd:`Class` commands.
9695

9796
:n:`::`
9897
If specified, the field is declared a typeclass instance of the class

vernac/comInductive.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ let eq_params (up1,p1) (up2,p2) =
671671
let extract_coercions indl =
672672
let mkqid (_,({CAst.v=id},_)) = qualid_of_ident id in
673673
let iscoe (_, coe, inst) = match inst with
674-
(* remove BackInstanceWarning after deprecation phase *)
675-
| Vernacexpr.(NoInstance | BackInstanceWarning) -> coe = Vernacexpr.AddCoercion
674+
| Vernacexpr.NoInstance -> coe = Vernacexpr.AddCoercion
676675
| _ -> user_err (Pp.str "'::' not allowed in inductives.") in
677676
let extract lc = List.filter (fun (coe,_) -> iscoe coe) lc in
678677
List.map mkqid (List.flatten(List.map (fun (_,_,_,lc) -> extract lc) indl))

vernac/g_vernac.mlg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ GRAMMAR EXTEND Gram
576576
| ":" -> { NoCoercion } ] ]
577577
;
578578
of_type_inst:
579-
[ [ ":>" -> { (AddCoercion, BackInstanceWarning) (* replace with NoInstance at end of deprecation phase *) }
580-
| ":"; ">" -> { (AddCoercion, BackInstanceWarning) (* replace with NoInstance at end of deprecation phase *) }
579+
[ [ ":>" -> { (AddCoercion, NoInstance) }
580+
| ":"; ">" -> { (AddCoercion, NoInstance) }
581581
| "::" -> { (NoCoercion, BackInstance) }
582582
| "::>" -> { (AddCoercion, BackInstance) }
583583
| ":" -> { (NoCoercion, NoInstance) } ] ]

vernac/ppvernac.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ let pr_oc coe ins = match coe, ins with
544544
| AddCoercion, NoInstance -> str" :>"
545545
| NoCoercion, BackInstance -> str" ::"
546546
| AddCoercion, BackInstance -> str" ::>"
547-
| _, BackInstanceWarning -> str" :>" (* remove this line at end of deprecation phase *)
548547

549548
let pr_record_field (x, { rfu_attrs = attr ; rfu_coercion = coe ; rfu_instance = ins ; rfu_priority = pri ; rfu_notation = ntn }) =
550549
let prx = match x with

vernac/record.ml

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,8 @@ let instantiate_possibly_recursive_type ind u ntypes paramdecls fields =
376376

377377
(** Declare projection [ref] over [from] a coercion
378378
or a typeclass instance according to [flags]. *)
379-
(* remove the last argument (it will become alway true) after deprecation phase
380-
(started in 8.17, c.f. https://github.com/coq/coq/pull/16230) *)
381-
let declare_proj_coercion_instance ~flags ref from ~with_coercion =
382-
if with_coercion && flags.Data.pf_coercion then begin
379+
let declare_proj_coercion_instance ~flags ref from =
380+
if flags.Data.pf_coercion then begin
383381
let cl = ComCoercion.class_of_global from in
384382
let local = flags.Data.pf_locality = Goptions.OptLocal in
385383
ComCoercion.try_add_new_coercion_with_source ref ~local ~reversible:flags.Data.pf_reversible ~source:cl
@@ -451,7 +449,7 @@ let build_named_proj ~primitive ~flags ~poly ~univs ~uinstance ~kind env paramde
451449
in
452450
let refi = GlobRef.ConstRef kn in
453451
Impargs.maybe_declare_manual_implicits false refi impls;
454-
declare_proj_coercion_instance ~flags refi (GlobRef.IndRef indsp) ~with_coercion:true;
452+
declare_proj_coercion_instance ~flags refi (GlobRef.IndRef indsp);
455453
let i = if is_local_assum decl then i+1 else i in
456454
(Some kn, i, Projection term::subst)
457455

@@ -668,37 +666,18 @@ let implicits_of_context ctx =
668666
| LocalAssum _ as d -> Some (RelDecl.get_name d))
669667
ctx)))
670668

671-
(* deprecated in 8.16, to be removed at the end of the deprecation phase
672-
(c.f., https://github.com/coq/coq/pull/15802 ) *)
673-
let warn_future_coercion_class_constructor =
674-
CWarnings.create ~name:"future-coercion-class-constructor" ~category:Deprecation.Version.v8_16
675-
~default:CWarnings.AsError
676-
Pp.(fun () -> str "'Class >' currently does nothing. Use 'Class' instead.")
677-
678-
(* deprecated in 8.17, to be removed at the end of the deprecation phase
679-
(c.f., https://github.com/coq/coq/pull/16230 ) *)
680-
let warn_future_coercion_class_field =
681-
CWarnings.create ~name:"future-coercion-class-field" ~category:Deprecation.Version.v8_17
682-
Pp.(fun definitional ->
683-
strbrk "A coercion will be introduced instead of an instance in future versions when using ':>' in 'Class' declarations. "
684-
++ 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."
685-
++ strbrk (if definitional then " Add an explicit #[global] attribute if you need to keep the current behavior. For example: \"Class foo := #[global] baz :: bar.\""
686-
else " Add an explicit #[global] attribute to the field if you need to keep the current behavior. For example: \"Class foo := { #[global] field :: bar }.\""))
687-
688669
let check_proj_flags kind rf =
689670
let open Vernacexpr in
690671
let pf_coercion, pf_reversible =
691672
match rf.rf_coercion with
692-
(* replace "kind_class kind = NotClass" with true after deprecation phase *)
693-
| AddCoercion -> kind_class kind = NotClass, Option.default true rf.rf_reversible
673+
| AddCoercion -> true, Option.default true rf.rf_reversible
694674
| NoCoercion ->
695675
if rf.rf_reversible <> None then
696676
Attributes.(unsupported_attributes
697677
[CAst.make ("reversible (without :>)",VernacFlagEmpty)]);
698678
false, false in
699679
let pf_instance =
700-
match rf.rf_instance with NoInstance -> false | BackInstance -> true
701-
| BackInstanceWarning -> kind_class kind <> NotClass in
680+
match rf.rf_instance with NoInstance -> false | BackInstance -> true in
702681
let pf_priority = rf.rf_priority in
703682
let pf_locality =
704683
begin match rf.rf_coercion, rf.rf_instance with
@@ -712,19 +691,10 @@ let check_proj_flags kind rf =
712691
[CAst.make ("export (without ::)",VernacFlagEmpty)])
713692
| _ -> ()
714693
end; rf.rf_locality in
715-
(* remove following let after deprecation phase (started in 8.17,
716-
c.f., https://github.com/coq/coq/pull/16230 ) *)
717-
let pf_locality =
718-
match rf.rf_instance, rf.rf_locality with
719-
| BackInstanceWarning, Goptions.OptDefault -> Goptions.OptGlobal
720-
| _ -> pf_locality in
721694
let pf_canonical = rf.rf_canonical in
722695
Data.{ pf_coercion; pf_reversible; pf_instance; pf_priority; pf_locality; pf_canonical }
723696

724-
(* remove the definitional argument at the end of the deprecation phase
725-
(started in 8.17)
726-
(c.f., https://github.com/coq/coq/pull/16230 ) *)
727-
let pre_process_structure ?(definitional=false) udecl kind ~poly (records : Ast.t list) =
697+
let pre_process_structure udecl kind ~poly (records : Ast.t list) =
728698
let indlocs = check_unique_names records in
729699
let () = check_priorities kind records in
730700
let ps, data = extract_record_data records in
@@ -750,11 +720,6 @@ let pre_process_structure ?(definitional=false) udecl kind ~poly (records : Ast.
750720
| Some n, _ -> n
751721
in
752722
let is_coercion = match is_coercion with AddCoercion -> true | NoCoercion -> false in
753-
if kind_class kind <> NotClass then begin
754-
if is_coercion then warn_future_coercion_class_constructor ();
755-
if List.exists (function (_, Vernacexpr.{ rf_instance = BackInstanceWarning; _ }) -> true | _ -> false) cfs then
756-
warn_future_coercion_class_field definitional
757-
end;
758723
{ Data.id = name.CAst.v; idbuild; rdata; is_coercion; proj_flags; inhabitant_id }
759724
in
760725
let data = List.map2 map data records in
@@ -896,7 +861,7 @@ let declare_class_constant ~univs paramimpls params data =
896861
Classes.set_typeclass_transparency ~locality:Hints.SuperGlobal
897862
[Evaluable.EvalConstRef cst] false;
898863
let () =
899-
declare_proj_coercion_instance ~flags:proj_flags (GlobRef.ConstRef proj_cst) cref ~with_coercion:false in
864+
declare_proj_coercion_instance ~flags:proj_flags (GlobRef.ConstRef proj_cst) cref in
900865
let m = {
901866
meth_name = Name proj_name;
902867
meth_info = None;
@@ -1030,16 +995,11 @@ let declare_existing_class g =
1030995
let definition_structure udecl kind ~template ~cumulative ~poly ~primitive_proj
1031996
finite (records : Ast.t list) : GlobRef.t list =
1032997
let impargs, params, univs, variances, projections_kind, data, indlocs =
1033-
let definitional = kind_class kind = DefClass in
1034-
pre_process_structure ~definitional udecl kind ~poly records
998+
pre_process_structure udecl kind ~poly records
1035999
in
10361000
let inds, def = match kind_class kind with
10371001
| DefClass -> declare_class_constant ~univs impargs params data
10381002
| RecordClass | NotClass ->
1039-
(* remove the following block after deprecation phase
1040-
(started in 8.16, c.f., https://github.com/coq/coq/pull/15802 ) *)
1041-
let data = if kind_class kind = NotClass then data else
1042-
List.map (fun d -> { d with Data.is_coercion = false }) data in
10431003
let structure =
10441004
interp_structure_core
10451005
~cumulative finite ~univs ~variances ~primitive_proj

vernac/vernacentries.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ let preprocess_inductive_decl ~atts kind indl =
931931
user_err Pp.(str "Definitional classes do not support the \">\" syntax.");
932932
let ((attr, rf_coercion, rf_instance), (lid, ce)) = l in
933933
let rf_locality = match rf_coercion, rf_instance with
934-
| AddCoercion, _ | _, (BackInstance | BackInstanceWarning) -> parse option_locality attr
934+
| AddCoercion, _ | _, BackInstance -> parse option_locality attr
935935
| _ -> let () = unsupported_attributes attr in Goptions.OptDefault in
936936
let f = AssumExpr ((make ?loc:lid.loc @@ Name lid.v), [], ce),
937937
{ rf_coercion ; rf_reversible = None ; rf_instance ; rf_priority = None ;
@@ -959,7 +959,7 @@ let preprocess_inductive_decl ~atts kind indl =
959959
| AddCoercion -> reversible
960960
| NoCoercion -> Notations.return None in
961961
let loc = match f.rfu_coercion, f.rfu_instance with
962-
| AddCoercion, _ | _, (BackInstance | BackInstanceWarning) -> option_locality
962+
| AddCoercion, _ | _, BackInstance -> option_locality
963963
| _ -> Notations.return Goptions.OptDefault in
964964
Notations.(rev ++ loc ++ canonical_field) in
965965
let (rf_reversible, rf_locality), rf_canonical = parse attr f.rfu_attrs in

vernac/vernacexpr.mli

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ type 'a search_restriction =
109109

110110
type verbose_flag = bool (* true = Verbose; false = Silent *)
111111
type coercion_flag = AddCoercion | NoCoercion
112-
(* Remove BackInstanceWarning at end of deprecation phase
113-
(this is just to print a warning when :> is used instead of ::
114-
to declare instances in classes) *)
115-
type instance_flag = BackInstance | BackInstanceWarning | NoInstance
112+
type instance_flag = BackInstance | NoInstance
116113

117114
type export_flag = Lib.export_flag = Export | Import
118115

0 commit comments

Comments
 (0)