@@ -126,12 +126,18 @@ module DataI = struct
126
126
end
127
127
128
128
module Data = struct
129
+ (* XXX move coercion_flags to ComCoercion? *)
130
+ type coercion_flags = {
131
+ coe_local : bool ;
132
+ coe_reversible : bool ;
133
+ }
134
+ type instance_flags = {
135
+ inst_locality : Hints .hint_locality ;
136
+ inst_priority : int option ;
137
+ }
129
138
type projection_flags = {
130
- pf_coercion : bool ;
131
- pf_reversible : bool ;
132
- pf_instance : bool ;
133
- pf_priority : int option ;
134
- pf_locality : Goptions .option_locality ;
139
+ pf_coercion : coercion_flags option ;
140
+ pf_instance : instance_flags option ;
135
141
pf_canonical : bool ;
136
142
}
137
143
type t =
@@ -473,7 +479,9 @@ let warning_or_error ?loc ~info flags indsp err =
473
479
Himsg. explain_type_error env (Evd. from_env env)
474
480
(Pretype_errors. of_type_error te))
475
481
in
476
- if flags.Data. pf_coercion || flags.Data. pf_instance then user_err ?loc ~info st;
482
+ (* XXX flags.pf_canonical? *)
483
+ if Option. has_some flags.Data. pf_coercion || Option. has_some flags.Data. pf_instance then
484
+ user_err ?loc ~info st;
477
485
warn_cannot_define_projection ?loc (hov 0 st)
478
486
479
487
type field_status =
@@ -523,22 +531,21 @@ let instantiate_possibly_recursive_type ind u ntypes paramdecls fields =
523
531
(* * Declare projection [ref] over [from] a coercion
524
532
or a typeclass instance according to [flags]. *)
525
533
let declare_proj_coercion_instance ~flags ref from =
526
- if flags.Data. pf_coercion then begin
527
- let cl = ComCoercion. class_of_global from in
528
- let local = flags.Data. pf_locality = Goptions. OptLocal in
529
- ComCoercion. try_add_new_coercion_with_source ref ~local ~reversible: flags.Data. pf_reversible ~source: cl
530
- end ;
531
- if flags.Data. pf_instance then begin
532
- let env = Global. env () in
533
- let sigma = Evd. from_env env in
534
- let info = Typeclasses. { hint_priority = flags.Data. pf_priority; hint_pattern = None } in
535
- let local =
536
- match flags.Data. pf_locality with
537
- | Goptions. OptLocal -> Hints. Local
538
- | Goptions. (OptDefault | OptExport ) -> Hints. Export
539
- | Goptions. OptGlobal -> Hints. SuperGlobal in
540
- Classes. declare_instance ~warn: true env sigma (Some info) local ref
541
- end
534
+ let () = match flags.Data. pf_coercion with
535
+ | None -> ()
536
+ | Some { coe_local =local ; coe_reversible =reversible } ->
537
+ let cl = ComCoercion. class_of_global from in
538
+ ComCoercion. try_add_new_coercion_with_source ref ~local ~reversible ~source: cl
539
+ in
540
+ let () = match flags.Data. pf_instance with
541
+ | None -> ()
542
+ | Some { inst_locality; inst_priority } ->
543
+ let env = Global. env () in
544
+ let sigma = Evd. from_env env in
545
+ let info = Typeclasses. { hint_priority = inst_priority; hint_pattern = None } in
546
+ Classes. declare_instance ~warn: true env sigma (Some info) inst_locality ref
547
+ in
548
+ ()
542
549
543
550
(* TODO: refactor the declaration part here; this requires some
544
551
surgery as Evarutil.finalize is called too early in the path *)
@@ -718,25 +725,25 @@ module Ast = struct
718
725
{ name : Names .lident
719
726
; is_coercion : coercion_flag
720
727
; binders : local_binder_expr list
721
- ; cfs : (local_decl_expr * record_field_attr ) list
728
+ ; cfs : (local_decl_expr * Data .projection_flags * notation_declaration list ) list
722
729
; idbuild : lident
723
730
; sort : constr_expr option
724
731
; default_inhabitant_id : Id .t option
725
732
}
726
733
727
734
let to_datai { name; idbuild; cfs; sort; default_inhabitant_id; } =
728
- let fs = List. map fst cfs in
735
+ let fs = List. map pi1 cfs in
729
736
{ DataI. name = name
730
737
; constructor_name = idbuild.CAst. v
731
738
; arity = sort
732
- ; nots = List. map (fun (_ , { rf_notation } ) -> List. map Metasyntax. prepare_where_notation rf_notation) cfs
739
+ ; nots = List. map (fun (_ , _ , rf_notation ) -> List. map Metasyntax. prepare_where_notation rf_notation) cfs
733
740
; fs
734
741
; default_inhabitant_id
735
742
}
736
743
end
737
744
738
745
let check_unique_names ~def records =
739
- let extract_name acc (rf_decl , _ ) = match rf_decl with
746
+ let extract_name acc (rf_decl , _ , _ ) = match rf_decl with
740
747
Vernacexpr. AssumExpr ({CAst. v =Name id } ,_ ,_ ) -> id::acc
741
748
| Vernacexpr. DefExpr ({CAst. v =Name id } ,_ ,_ ,_ ) -> id::acc
742
749
| _ -> acc in
@@ -763,47 +770,10 @@ let kind_class =
763
770
function Class true -> DefClass | Class false -> RecordClass
764
771
| Inductive_kw | CoInductive | Variant | Record | Structure -> NotClass
765
772
766
- let check_priorities kind records =
767
- let open Vernacexpr in
768
- let isnot_class = kind_class kind <> RecordClass in
769
- let has_priority { Ast. cfs; _ } =
770
- List. exists (fun (_ , { rf_priority } ) -> not (Option. is_empty rf_priority)) cfs
771
- in
772
- if isnot_class && List. exists has_priority records then
773
- user_err Pp. (str " Priorities only allowed for type class substructures." )
774
-
775
- let check_proj_flags kind rf =
776
- let open Vernacexpr in
777
- let pf_coercion, pf_reversible =
778
- match rf.rf_coercion with
779
- | AddCoercion -> true , Option. default true rf.rf_reversible
780
- | NoCoercion ->
781
- if rf.rf_reversible <> None then
782
- Attributes. (unsupported_attributes
783
- [CAst. make (" reversible (without :>)" ,VernacFlagEmpty )]);
784
- false , false in
785
- let pf_instance =
786
- match rf.rf_instance with NoInstance -> false | BackInstance -> true in
787
- let pf_priority = rf.rf_priority in
788
- let pf_locality =
789
- begin match rf.rf_coercion, rf.rf_instance with
790
- | NoCoercion , NoInstance ->
791
- if rf.rf_locality <> Goptions. OptDefault then
792
- Attributes. (unsupported_attributes
793
- [CAst. make (" locality (without :> or ::)" ,VernacFlagEmpty )])
794
- | AddCoercion , NoInstance ->
795
- if rf.rf_locality = Goptions. OptExport then
796
- Attributes. (unsupported_attributes
797
- [CAst. make (" export (without ::)" ,VernacFlagEmpty )])
798
- | _ -> ()
799
- end ; rf.rf_locality in
800
- let pf_canonical = rf.rf_canonical in
801
- Data. { pf_coercion; pf_reversible; pf_instance; pf_priority; pf_locality; pf_canonical }
802
-
803
- let extract_record_data kind records =
773
+ let extract_record_data records =
804
774
let data = List. map Ast. to_datai records in
805
775
let decl_data = List. map (fun { Ast. is_coercion; cfs } ->
806
- let proj_flags = List. map (fun (_ ,rf ) -> check_proj_flags kind rf) cfs in
776
+ let proj_flags = List. map (fun (_ ,rf , _ ) -> rf) cfs in
807
777
{ Data. is_coercion; proj_flags })
808
778
records
809
779
in
@@ -823,8 +793,7 @@ let extract_record_data kind records =
823
793
let pre_process_structure udecl kind ~flags ~primitive_proj (records : Ast.t list ) =
824
794
let def = (kind = Vernacexpr. Class true ) in
825
795
let indlocs = check_unique_names ~def records in
826
- let () = check_priorities kind records in
827
- let ps, interp_data, decl_data = extract_record_data kind records in
796
+ let ps, interp_data, decl_data = extract_record_data records in
828
797
let entry =
829
798
(* In theory we should be able to use
830
799
[Notation.with_notation_protection], due to the call to
@@ -1107,14 +1076,6 @@ let definition_structure ~flags udecl kind ~primitive_proj (records : Ast.t list
1107
1076
inds
1108
1077
1109
1078
module Internal = struct
1110
- type nonrec projection_flags = Data .projection_flags = {
1111
- pf_coercion : bool ;
1112
- pf_reversible : bool ;
1113
- pf_instance : bool ;
1114
- pf_priority : int option ;
1115
- pf_locality : Goptions .option_locality ;
1116
- pf_canonical : bool ;
1117
- }
1118
1079
let declare_projections = declare_projections
1119
1080
let declare_structure_entry = declare_structure_entry
1120
1081
end
0 commit comments