Skip to content

Commit 8d2fff9

Browse files
Merge PR #21342: Stop directly checking Printing All while printing constr
Reviewed-by: ppedrot Co-authored-by: ppedrot <[email protected]>
2 parents 1d33385 + 9bdbe7d commit 8d2fff9

File tree

9 files changed

+242
-143
lines changed

9 files changed

+242
-143
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
overlay elpi https://github.com/SkySkimmer/coq-elpi print-raw 21342

interp/constrextern.ml

Lines changed: 19 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
(************************************************************************)
1010

1111
(*i*)
12-
open Pp
1312
open CErrors
1413
open Util
1514
open Names
@@ -40,7 +39,7 @@ module NamedDecl = Context.Named.Declaration
4039
let hole = CAst.make @@ CHole (None)
4140

4241
let is_reserved_type ~flags na t =
43-
not flags.ExternFlags.raw && flags.ExternFlags.use_implicit_types &&
42+
flags.ExternFlags.use_implicit_types &&
4443
match na with
4544
| Anonymous -> false
4645
| Name id ->
@@ -53,49 +52,6 @@ let is_reserved_type ~flags na t =
5352
true
5453
with Not_found | No_match -> false
5554

56-
(**********************************************************************)
57-
(* Control printing of records *)
58-
59-
let is_record indsp =
60-
try
61-
let _ = Structure.find (Global.env ()) indsp in
62-
true
63-
with Not_found -> false
64-
65-
let encode_record r =
66-
let indsp = Nametab.global_inductive r in
67-
if not (is_record indsp) then
68-
user_err ?loc:r.CAst.loc
69-
(str "This type is not a structure type.");
70-
indsp
71-
72-
module PrintingRecordRecord =
73-
PrintingInductiveMake (struct
74-
let encode _env = encode_record
75-
let field = "Record"
76-
let title = "Types leading to pretty-printing using record notation: "
77-
let member_message s b =
78-
str "Terms of " ++ s ++
79-
str
80-
(if b then " are printed using record notation"
81-
else " are not printed using record notation")
82-
end)
83-
84-
module PrintingRecordConstructor =
85-
PrintingInductiveMake (struct
86-
let encode _env = encode_record
87-
let field = "Constructor"
88-
let title = "Types leading to pretty-printing using constructor form: "
89-
let member_message s b =
90-
str "Terms of " ++ s ++
91-
str
92-
(if b then " are printed using constructor form"
93-
else " are not printed using constructor form")
94-
end)
95-
96-
module PrintingRecord = Goptions.MakeRefTable(PrintingRecordRecord)
97-
module PrintingConstructor = Goptions.MakeRefTable(PrintingRecordConstructor)
98-
9955
(**********************************************************************)
10056
(* Various externalisation functions *)
10157

@@ -222,8 +178,8 @@ let drop_implicits_in_patt ~flags cst nb_expl ?(tags=[]) args =
222178
in
223179
let try_impls_fit (imps,args,tags) =
224180
if not !Constrintern.parsing_explicit &&
225-
((flags.ExternFlags.raw || flags.ExternFlags.implicits) &&
226-
List.exists is_status_implicit imps)
181+
flags.ExternFlags.implicits &&
182+
List.exists is_status_implicit imps
227183
(* Note: !print_implicits_explicit_args=true not supported for patterns *)
228184
then None
229185
else impls_fit [] (imps,args,tags)
@@ -296,20 +252,16 @@ let pattern_printable_in_both_syntax ~flags (ind,_ as c) =
296252
List.exists (fun (_,impls) ->
297253
(List.length impls >= nb_params) &&
298254
let params,args = Util.List.chop nb_params impls in
299-
not flags.ExternFlags.raw && not flags.ExternFlags.implicits &&
255+
not flags.ExternFlags.implicits &&
300256
(List.for_all is_status_implicit params)&&(List.for_all (fun x -> not (is_status_implicit x)) args)
301257
) impl_st
302258

303259
let extern_record_pattern ~flags cstrsp args =
260+
if not (ExternFlags.Records.use_record_syntax flags.ExternFlags.records (fst cstrsp))
261+
then None
262+
else
304263
try
305-
if flags.ExternFlags.raw then raise_notrace Exit;
306264
let projs = Structure.find_projections (Global.env ()) (fst cstrsp) in
307-
if PrintingRecord.active (fst cstrsp) then
308-
()
309-
else if PrintingConstructor.active (fst cstrsp) then
310-
raise_notrace Exit
311-
else if not flags.ExternFlags.records then
312-
raise_notrace Exit;
313265
let rec ip projs args acc =
314266
match projs, args with
315267
| [], [] -> acc
@@ -333,7 +285,7 @@ let extern_record_pattern ~flags cstrsp args =
333285
(* Better to use extern_glob_constr composed with injection/retraction ?? *)
334286
let rec extern_cases_pattern_in_scope ~flags ((custom,(lev_after:int option)),scopes as allscopes) vars pat =
335287
try
336-
if !Flags.in_debugger || flags.ExternFlags.raw || flags.ExternFlags.raw_literals then raise No_match;
288+
if !Flags.in_debugger || flags.ExternFlags.raw_literals then raise No_match;
337289
let (na,p,key) = uninterp_prim_token_cases_pattern ~print_float:flags.float pat scopes in
338290
match availability_of_entry_coercion custom constr_lowest_level with
339291
| None -> raise No_match
@@ -343,7 +295,7 @@ let rec extern_cases_pattern_in_scope ~flags ((custom,(lev_after:int option)),sc
343295
(insert_pat_alias ?loc (insert_pat_delimiters ?loc (CAst.make ?loc @@ CPatPrim p) key) na)
344296
with No_match ->
345297
try
346-
if !Flags.in_debugger || flags.ExternFlags.raw || not flags.ExternFlags.notations then raise No_match;
298+
if !Flags.in_debugger || not flags.ExternFlags.notations then raise No_match;
347299
extern_notation_pattern ~flags allscopes vars pat
348300
(uninterp_cases_pattern_notations (Global.env ()) pat)
349301
with No_match ->
@@ -483,7 +435,7 @@ let extern_ind_pattern_in_scope ~flags (custom,scopes as allscopes) vars ind arg
483435
CAst.make @@ CPatCstr (c, Some args, [])
484436
else
485437
try
486-
if flags.ExternFlags.raw || not flags.ExternFlags.notations || Inductiveops.inductive_has_local_defs (Global.env()) ind
438+
if not flags.ExternFlags.notations || Inductiveops.inductive_has_local_defs (Global.env()) ind
487439
then raise No_match;
488440
extern_notation_ind_pattern ~flags allscopes vars ind args
489441
(uninterp_ind_pattern_notations (Global.env ()) ind)
@@ -511,7 +463,7 @@ let is_gvar id c = match DAst.get c with
511463
| _ -> false
512464

513465
let is_projection ~flags nargs r =
514-
if not !Flags.in_debugger && not flags.ExternFlags.raw && flags.ExternFlags.projections then
466+
if not !Flags.in_debugger && flags.ExternFlags.projections then
515467
try
516468
match r with
517469
| GlobRef.ConstRef c ->
@@ -546,7 +498,6 @@ let adjust_implicit_arguments ~flags inctx n args impl =
546498
| a::args, imp::impl when is_status_implicit imp ->
547499
let tail = exprec (args,impl) in
548500
let visible =
549-
flags.ExternFlags.raw ||
550501
(flags.ExternFlags.implicits && flags.ExternFlags.implicits_explicit_args) ||
551502
(is_needed_for_correct_partial_application tail imp) ||
552503
(flags.ExternFlags.implicits_defensive &&
@@ -583,15 +534,11 @@ let is_start_implicit = function
583534

584535
let extern_record ~flags ref args =
585536
try
586-
if flags.ExternFlags.raw then raise_notrace Exit;
587537
let cstrsp = match ref with GlobRef.ConstructRef c -> c | _ -> raise Not_found in
538+
if not (ExternFlags.Records.use_record_syntax flags.ExternFlags.records (fst cstrsp))
539+
then None
540+
else
588541
let struc = Structure.find (Global.env ()) (fst cstrsp) in
589-
if PrintingRecord.active (fst cstrsp) then
590-
()
591-
else if PrintingConstructor.active (fst cstrsp) then
592-
raise_notrace Exit
593-
else if not flags.ExternFlags.records then
594-
raise_notrace Exit;
595542
let projs = struc.Structure.projections in
596543
let rec cut args n =
597544
if Int.equal n 0 then args
@@ -633,9 +580,9 @@ let extern_global impl f us =
633580
let extern_applied_ref ~flags inctx impl (cf,f) us args =
634581
try
635582
if not !Constrintern.parsing_explicit &&
636-
((flags.ExternFlags.raw ||
637-
(flags.ExternFlags.implicits && not flags.ExternFlags.implicits_explicit_args)) &&
638-
List.exists is_status_implicit impl)
583+
flags.ExternFlags.implicits &&
584+
not flags.ExternFlags.implicits_explicit_args &&
585+
List.exists is_status_implicit impl
639586
then raise Expl;
640587
let impl = if !Constrintern.parsing_explicit then [] else impl in
641588
let n = List.length args in
@@ -706,7 +653,7 @@ let match_coercion_app c = match DAst.get c with
706653

707654
let remove_one_coercion ~flags inctx c =
708655
try match match_coercion_app c with
709-
| Some (loc,r,args) when not (flags.ExternFlags.raw || flags.ExternFlags.coercions) ->
656+
| Some (loc,r,args) when not flags.ExternFlags.coercions ->
710657
let nargs = List.length args in
711658
(match Coercionops.hide_coercion r with
712659
| Some nparams when
@@ -1232,22 +1179,16 @@ and extern_local_binder depth scopes eenv = function
12321179
(na::assums,na::ids,
12331180
CLocalAssum([CAst.make na],extern_relevance_info eenv.uvars r,Default bk,ty) :: l))
12341181

1235-
| GLocalPattern ((p,_),_,bk,ty) ->
1236-
let ty =
1237-
if eenv.flags.raw then Some (extern_typ depth scopes eenv ty) else None in
1182+
| GLocalPattern ((p,_),_,bk,_) ->
12381183
let p = mkCPatOr (List.map (extern_cases_pattern ~flags:eenv.flags eenv.vars) p) in
12391184
let (assums,ids,l) = extern_local_binder depth scopes eenv l in
1240-
let p = match ty with
1241-
| None -> p
1242-
| Some ty -> CAst.make @@ (CPatCast (p,ty)) in
12431185
(assums,ids, CLocalPattern p :: l)
12441186

12451187
and extern_eqn depth inctx scopes eenv {CAst.loc;v=(ids,pll,c)} =
12461188
let pll = List.map (List.map (extern_cases_pattern_in_scope ~flags:eenv.flags scopes eenv.vars)) pll in
12471189
make ?loc (pll,extern depth inctx scopes eenv c)
12481190

12491191
and extern_notations depth inctx scopes eenv nargs t =
1250-
if eenv.flags.raw then raise No_match;
12511192
try extern_possible_prim_token ~flags:eenv.flags scopes t
12521193
with No_match ->
12531194
if not eenv.flags.notations then raise No_match;

plugins/funind/indfun_common.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ let without_implicit_declarations f () =
9999

100100
let full_detype_flags () =
101101
let flags = PrintingFlags.Detype.current() in
102-
{ flags with raw = true; universes = true; }
102+
PrintingFlags.Detype.make_raw { flags with universes = true; }
103103

104104
let full_extern_flags () =
105105
let flags = PrintingFlags.Extern.current() in
106-
{ flags with raw = true; factorize_eqns = {
107-
flags.factorize_eqns with
108-
allow_match_default_clause = false } }
106+
PrintingFlags.Extern.make_raw flags
109107

110108
let extern_env_full_printing () =
111109
Constrextern.empty_extern_env ~flags:(full_extern_flags())

pretyping/detyping.ml

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ open Glob_term
2424
open Glob_ops
2525
open Termops
2626
open Namegen
27-
open Libnames
2827
open Globnames
2928
open Mod_subst
3029
open Context.Rel.Declaration
@@ -244,28 +243,8 @@ let encode_tuple env ({CAst.loc} as r) =
244243
(str "This type cannot be seen as a tuple type.");
245244
x
246245

247-
module PrintingInductiveMake =
248-
functor (Test : sig
249-
val encode : Environ.env -> qualid -> inductive
250-
val member_message : Pp.t -> bool -> Pp.t
251-
val field : string
252-
val title : string
253-
end) ->
254-
struct
255-
type t = inductive
256-
module Set = Indset_env
257-
let encode env ind = Environ.QInd.canonize env (Test.encode env ind)
258-
let subst subst obj = subst_ind subst obj
259-
let check_local _ _ = ()
260-
let discharge (i:t) = i
261-
let printer ind = Nametab.pr_global_env Id.Set.empty (GlobRef.IndRef ind)
262-
let key = ["Printing";Test.field]
263-
let title = Test.title
264-
let member_message x = Test.member_message (printer x)
265-
end
266-
267246
module PrintingCasesIf =
268-
PrintingInductiveMake (struct
247+
PrintingFlags.PrintingInductiveMake (struct
269248
let encode = encode_bool
270249
let field = "If"
271250
let title = "Types leading to pretty-printing of Cases using a `if' form:"
@@ -277,7 +256,7 @@ module PrintingCasesIf =
277256
end)
278257

279258
module PrintingCasesLet =
280-
PrintingInductiveMake (struct
259+
PrintingFlags.PrintingInductiveMake (struct
281260
let encode = encode_tuple
282261
let field = "Let"
283262
let title =
@@ -408,7 +387,7 @@ let lookup_index_as_renamed env sigma t n =
408387
let rec join_eqns ~flags (ids,rhs as x) patll = function
409388
| ({CAst.loc; v=(ids',patl',rhs')} as eqn')::rest ->
410389
let open ExternFlags.FactorizeEqns in
411-
if not flags.raw && flags.factorize_match_patterns &&
390+
if flags.factorize_match_patterns &&
412391
List.eq_set Id.equal ids ids' && glob_constr_eq rhs rhs'
413392
then
414393
join_eqns ~flags x (patl'::patll) rest
@@ -455,7 +434,7 @@ let factorize_eqns ~flags eqns =
455434
let mk_anon patl = List.map (fun _ -> DAst.make @@ PatVar Anonymous) patl in
456435
let open CAst in
457436
let open ExternFlags.FactorizeEqns in
458-
if not flags.raw && flags.allow_match_default_clause && eqns <> [] then
437+
if flags.allow_match_default_clause && eqns <> [] then
459438
match select_default_clause eqns with
460439
(* At least two clauses and the last one is disjunctive with no variables *)
461440
| Some {loc=gloc;v=([],patl::_::_,rhs)}, (_::_ as eqns) ->
@@ -615,7 +594,7 @@ let detype_case ~flags computable detype detype_eqns avoid env sigma (ci, univs,
615594
DAst.make @@ GCast (tomatch, None, detype t)
616595
in
617596
let alias, aliastyp, pred =
618-
if (not flags.flg.raw) && synth_type && computable && not (Int.equal (Array.length bl) 0)
597+
if synth_type && computable && not (Int.equal (Array.length bl) 0)
619598
then
620599
Anonymous, None, None
621600
else
@@ -635,7 +614,7 @@ let detype_case ~flags computable detype detype_eqns avoid env sigma (ci, univs,
635614
let constructs = Array.init (Array.length bl) (fun i -> (ci.ci_ind,i+1)) in
636615
let tag = let st = ci.ci_pp_info.style in
637616
try
638-
if flags.flg.raw then
617+
if flags.flg.always_regular_match_style then
639618
RegularStyle
640619
else if st == LetPatternStyle then
641620
st
@@ -948,7 +927,7 @@ and detype_r d flags avoid env sigma t =
948927

949928
and detype_eqns d flags avoid env sigma computable constructs bl =
950929
try
951-
if flags.flg.raw || not flags.flg.matching then raise_notrace Exit;
930+
if not flags.flg.matching then raise_notrace Exit;
952931
let mat = build_tree ~flags Anonymous flags (avoid,env) sigma bl in
953932
List.map (fun (ids,pat,((avoid,env),c)) ->
954933
CAst.make (Id.Set.elements ids,[pat],detype d flags avoid env sigma c))
@@ -1010,9 +989,12 @@ and detype_binder d flags bk avoid env sigma decl c =
1010989
try Retyping.get_sort_quality_of (snd env) sigma ty
1011990
with Retyping.RetypeError _ -> UnivGen.QualityOrSet.qtype
1012991
in
1013-
let t = if not (UnivGen.QualityOrSet.is_prop s) && not flags.flg.raw
1014-
then None
1015-
else Some (detype d (nongoal flags) avoid env sigma ty) in
992+
let t =
993+
(* XXX also sprop? *)
994+
if flags.flg.nonpropositional_letin_types || UnivGen.QualityOrSet.is_prop s
995+
then Some (detype d (nongoal flags) avoid env sigma ty)
996+
else None
997+
in
1016998
GLetIn (na', rinfo, c, t, r)
1017999

10181000
let detype_rel_context d flags avoid env sigma sign =

pretyping/detyping.mli

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,3 @@ val detype_closed_glob : flags:PrintingFlags.Detype.t -> ?isgoal:bool ->
5656
(** look for the index of a named var or a nondep var as it is renamed *)
5757
val lookup_name_as_displayed : env -> evar_map -> constr -> Id.t -> int option
5858
val lookup_index_as_renamed : env -> evar_map -> constr -> int -> int option
59-
60-
module PrintingInductiveMake :
61-
functor (_ : sig
62-
val encode : Environ.env -> Libnames.qualid -> Names.inductive
63-
val member_message : Pp.t -> bool -> Pp.t
64-
val field : string
65-
val title : string
66-
end) -> Goptions.RefConvertArg with type t = inductive

0 commit comments

Comments
 (0)