@@ -70,18 +70,19 @@ let add_definition ~opaque ~hook ~poly ~scope ~kind ~tactic name env evd term ty
70
70
Some lemma
71
71
end
72
72
73
- let declare_abstraction ?(opaque = false ) ?(continuation = default_continuation) ~poly ~scope ~kind arity evdr env a name =
73
+ let declare_abstraction ~ opaque_access ?(opaque = false ) ?(continuation = default_continuation) ~poly ~scope ~kind arity evdr env a name =
74
74
Debug. debug_evar_map Debug. all " declare_abstraction, evd = " env ! evdr;
75
75
debug [`Abstraction ] " declare_abstraction, a =" env ! evdr a;
76
76
let b = Retyping. get_type_of env ! evdr a in
77
77
debug [`Abstraction ] " declare_abstraction, b =" env ! evdr b;
78
78
let b = Retyping. get_type_of env ! evdr a in
79
- let b_R = relation arity evdr env b in
79
+ let module P = WithOpaqueAccess (struct let access = opaque_access end ) in
80
+ let b_R = P. relation arity evdr env b in
80
81
let sub = range (fun k -> prime ! evdr arity k a) arity in
81
82
let b_R = EConstr.Vars. substl sub b_R in
82
83
let a_R = fun evd ->
83
84
let evdr = ref evd in
84
- let a_R = translate arity evdr env a in
85
+ let a_R = P. translate arity evdr env a in
85
86
debug [`Abstraction ] " a_R = " env ! evdr a_R;
86
87
debug_evar_map Debug. all " abstraction, evar_map = " env ! evdr;
87
88
! evdr, a_R
@@ -104,10 +105,11 @@ let declare_abstraction ?(opaque = false) ?(continuation = default_continuation)
104
105
let tactic = Relations. get_parametricity_tactic () in
105
106
add_definition ~tactic ~opaque ~poly ~scope ~kind ~hook name env evd a_R b_R
106
107
107
- let declare_inductive name ?(continuation = default_continuation) arity evd env (((mut_ind , _ ) as ind , inst )) =
108
+ let declare_inductive ~ opaque_access name ?(continuation = default_continuation) arity evd env (((mut_ind , _ ) as ind , inst )) =
108
109
let mut_body, _ = Inductive. lookup_mind_specif env ind in
109
110
debug_string [`Inductive ] " Translating mind body ..." ;
110
- let translation_entry = Parametricity. translate_mind_body name arity evd env mut_ind mut_body inst in
111
+ let module P = Parametricity. WithOpaqueAccess (struct let access = opaque_access end ) in
112
+ let translation_entry = P. translate_mind_body name arity evd env mut_ind mut_body inst in
111
113
debug_string [`Inductive ] (" Translating mind body ... done." );
112
114
debug_evar_map [`Inductive ] " evar_map inductive " env ! evd;
113
115
let size = Declarations. (Array. length mut_body.mind_packets) in
@@ -135,14 +137,15 @@ let translate_inductive_command arity c name =
135
137
let evd = ref sigma in
136
138
declare_inductive name arity evd env pind
137
139
138
- let declare_realizer ?(continuation = default_continuation) ?kind ?real arity evd env name (var : constr ) =
140
+ let declare_realizer ~ opaque_access ?(continuation = default_continuation) ?kind ?real arity evd env name (var : constr ) =
139
141
let gref = (match EConstr. kind ! evd var with
140
142
| Var id -> Names.GlobRef. VarRef id
141
143
| Const (cst , _ ) -> Names.GlobRef. ConstRef cst
142
144
| _ -> error (Pp. str " Realizer works only for variables and constants." )) in
143
145
let evd', typ = Typing. type_of env ! evd var in
144
146
evd := evd';
145
- let typ_R = Parametricity. relation arity evd env typ in
147
+ let module P = Parametricity. WithOpaqueAccess (struct let access = opaque_access end ) in
148
+ let typ_R = P. relation arity evd env typ in
146
149
let sub = range (fun _ -> var) arity in
147
150
let typ_R = Vars. substl sub typ_R in
148
151
let cpt = ref 0 in
@@ -182,24 +185,24 @@ let declare_realizer ?(continuation = default_continuation) ?kind ?real arity ev
182
185
let tactic = Relations. get_parametricity_tactic () in
183
186
add_definition ~tactic ~opaque: false ~poly ~scope ~kind ~hook name env sigma real typ_R
184
187
185
- let realizer_command arity name var real =
188
+ let realizer_command ~ opaque_access arity name var real =
186
189
let env = Global. env () in
187
190
let sigma = Evd. from_env env in
188
191
let (sigma, var) = Constrintern. interp_open_constr env sigma var in
189
192
RetrieveObl. check_evars env sigma;
190
193
let real = fun sigma -> Constrintern. interp_open_constr env sigma real in
191
- ignore(declare_realizer arity (ref sigma) env name var ~real )
194
+ ignore(declare_realizer ~opaque_access arity (ref sigma) env name var ~real )
192
195
193
196
let rec list_continuation final f l _ = match l with [] -> final ()
194
197
| hd ::tl -> f (list_continuation final f tl) hd
195
198
196
- let rec translate_module_command ?name arity r =
199
+ let rec translate_module_command ~ opaque_access ?name arity r =
197
200
check_nothing_ongoing () ;
198
201
let qid = r in
199
202
let mb = try Global. lookup_module (Nametab. locate_module qid)
200
203
with Not_found -> error Pp. (str " Unknown Module " ++ pr_qualid qid)
201
204
in
202
- declare_module ?name arity mb
205
+ declare_module ~opaque_access ?name arity mb
203
206
204
207
and id_of_module_path mp =
205
208
let open Names in
@@ -209,7 +212,7 @@ and id_of_module_path mp =
209
212
| MPfile dp -> List. hd (DirPath. repr dp)
210
213
| MPbound id -> MBId. to_id id
211
214
212
- and declare_module ?(continuation = ignore) ?name arity mb =
215
+ and declare_module ~ opaque_access ?(continuation = ignore) ?name arity mb =
213
216
debug_string [`Module ] " --> declare_module" ;
214
217
let open Declarations in
215
218
let mp = mb.mod_mp in
@@ -242,7 +245,7 @@ and declare_module ?(continuation = ignore) ?name arity mb =
242
245
Evd. (with_sort_context_set univ_rigid evd (UnivGen. fresh_constant_instance env cst))
243
246
in
244
247
let evdr = ref evd in
245
- ignore(declare_realizer ~continuation arity evdr env None (mkConstU (fst ucst, EInstance. make (snd ucst))))
248
+ ignore(declare_realizer ~opaque_access ~ continuation arity evdr env None (mkConstU (fst ucst, EInstance. make (snd ucst))))
246
249
247
250
| (lab , SFBconst cb ) ->
248
251
let opaque =
@@ -270,7 +273,7 @@ and declare_module ?(continuation = ignore) ?name arity mb =
270
273
debug [`Module ] " type :" env ! evdr typ
271
274
with e -> error (Pp. str (Printexc. to_string e)));
272
275
debug_string [`Module ] (Printf. sprintf " constant field: '%s'." (Names.Label. to_string lab));
273
- ignore(declare_abstraction ~opaque ~continuation ~poly ~scope ~kind arity evdr env c lab_R)
276
+ ignore(declare_abstraction ~opaque_access ~ opaque ~continuation ~poly ~scope ~kind arity evdr env c lab_R)
274
277
275
278
| (lab , SFBmind _ ) ->
276
279
let env = Global. env () in
@@ -292,14 +295,14 @@ and declare_module ?(continuation = ignore) ?name arity mb =
292
295
@@ Names.MutInd. label
293
296
@@ mut_ind
294
297
in
295
- declare_inductive ind_name ~continuation arity evdr env pind
298
+ declare_inductive ~opaque_access ind_name ~continuation arity evdr env pind
296
299
end
297
300
| (lab, SFBmodule mb') when
298
301
match mb'.mod_type with NoFunctor _ ->
299
302
(match mb'.mod_expr with FullStruct | Algebraic _ -> true | _ -> false )
300
303
| _ -> false
301
304
->
302
- declare_module ~continuation arity mb'
305
+ declare_module ~opaque_access ~ continuation arity mb'
303
306
304
307
| (lab , _ ) ->
305
308
Pp. (Flags. if_verbose msg_info (str (Printf. sprintf " Ignoring field '%s'." (Names.Label. to_string lab))));
@@ -332,7 +335,7 @@ let translateFullName ~fullname arity (kername : Names.KerName.t) : string =
332
335
(String. concat " _o_" (plstr@ [nstr]))
333
336
else nstr
334
337
335
- let command_constant ?(continuation = default_continuation) ~fullname arity constant names =
338
+ let command_constant ~ opaque_access ?(continuation = default_continuation) ~fullname arity constant names =
336
339
let env = Global. env () in
337
340
let evd = Evd. from_env env in
338
341
let poly, opaque =
@@ -354,9 +357,10 @@ let command_constant ?(continuation = default_continuation) ~fullname arity cons
354
357
Evd. (with_sort_context_set univ_rigid evd (UnivGen. fresh_constant_instance env constant))
355
358
in
356
359
let constr = mkConstU (fst pconst, EInstance. make @@ snd pconst) in
357
- declare_abstraction ~continuation ~opaque ~poly ~scope ~kind arity (ref evd) env constr name
360
+ declare_abstraction ~opaque_access ~continuation ~opaque ~poly ~scope ~kind
361
+ arity (ref evd) env constr name
358
362
359
- let command_inductive ?(continuation = default_continuation) ~fullname arity inductive names =
363
+ let command_inductive ~ opaque_access ?(continuation = default_continuation) ~fullname arity inductive names =
360
364
let env = Global. env () in
361
365
let evd = Evd. from_env env in
362
366
let evd, pind =
@@ -372,36 +376,37 @@ let command_inductive ?(continuation = default_continuation) ~fullname arity ind
372
376
@@ pind
373
377
| Some name -> name
374
378
in
375
- declare_inductive name ~continuation arity (ref evd) env pind
379
+ declare_inductive ~opaque_access name ~continuation arity (ref evd) env pind
376
380
377
381
let command_constructor ?(continuation = default_continuation) arity gref names =
378
382
let open Pp in
379
383
error ((str " '" )
380
384
++ (Printer. pr_global gref)
381
385
++ (str " ' is a constructor. To generate its parametric translation, please translate its inductive first." ))
382
386
383
- let command_reference ?(continuation = default_continuation) ?(fullname = false ) arity gref names =
387
+ let command_reference ~opaque_access ?(continuation = default_continuation) ?(fullname = false )
388
+ arity gref names =
384
389
check_nothing_ongoing () ;
385
390
let open Names.GlobRef in
386
391
(* We ignore proofs for now *)
387
392
let _pstate = match gref with
388
393
| VarRef variable ->
389
394
command_variable ~continuation arity variable names
390
395
| ConstRef constant ->
391
- command_constant ~continuation ~fullname arity constant names
396
+ command_constant ~opaque_access ~ continuation ~fullname arity constant names
392
397
| IndRef inductive ->
393
- command_inductive ~continuation ~fullname arity inductive names;
398
+ command_inductive ~opaque_access ~ continuation ~fullname arity inductive names;
394
399
None
395
400
| ConstructRef constructor ->
396
401
command_constructor ~continuation arity gref names
397
402
in ()
398
403
399
- let command_reference_recursive ?(continuation = default_continuation) ?(fullname = false ) arity gref =
404
+ let command_reference_recursive ~ opaque_access ?(continuation = default_continuation) ?(fullname = false ) arity gref =
400
405
let gref= Globnames. canonical_gr gref in
401
406
let label = Names.Label. of_id (Nametab. basename_of_global gref) in
402
407
(* Assumptions doesn't care about the universes *)
403
408
let c, _ = UnivGen. fresh_global_instance (Global. env() ) gref in
404
- let (direct, graph, _) = Assumptions. traverse label c in
409
+ let (direct, graph, _) = Assumptions. traverse opaque_access label c in
405
410
let inductive_of_constructor ref =
406
411
let open Globnames in
407
412
let ref = Globnames. canonical_gr ref in
@@ -428,9 +433,9 @@ let command_reference_recursive ?(continuation = default_continuation) ?(fullnam
428
433
(* Pp.(msg_info (str "DepRefs:"));
429
434
* List.iter (fun x -> msg_info (Printer.pr_global x)) dep_refs; *)
430
435
list_continuation continuation (fun continuation gref ->
431
- command_reference ~continuation ~fullname arity gref None ) dep_refs ()
436
+ command_reference ~opaque_access ~ continuation ~fullname arity gref None ) dep_refs ()
432
437
433
- let translate_command arity c name =
438
+ let translate_command ~ opaque_access arity c name =
434
439
if ! ongoing_translation then error (Pp. str " On going translation." );
435
440
(* Same comment as above *)
436
441
let env = Global. env () in
@@ -450,5 +455,5 @@ let translate_command arity c name =
450
455
in
451
456
let scope = Locality. (Global ImportDefaultBehavior ) in
452
457
let kind = Decls. (IsDefinition Definition ) in
453
- let _ : Declare.Proof.t option = declare_abstraction ~opaque ~poly ~scope ~kind arity (ref evd) env c name in
458
+ let _ : Declare.Proof.t option = declare_abstraction ~opaque_access ~ opaque ~poly ~scope ~kind arity (ref evd) env c name in
454
459
()
0 commit comments