@@ -35,6 +35,10 @@ include (Evd.MiniEConstr : module type of Evd.MiniEConstr
35
35
type types = t
36
36
type constr = t
37
37
type existential = t pexistential
38
+ type case_return = t pcase_return
39
+ type case_branch = t pcase_branch
40
+ type case_invert = (t , EInstance .t ) pcase_invert
41
+ type case = (t , t , EInstance .t ) pcase
38
42
type fixpoint = (t , t ) pfixpoint
39
43
type cofixpoint = (t , t ) pcofixpoint
40
44
type unsafe_judgment = (constr , types ) Environ .punsafe_judgment
@@ -69,7 +73,7 @@ let mkInd i = of_kind (Ind (in_punivs i))
69
73
let mkConstructU pc = of_kind (Construct pc)
70
74
let mkConstruct c = of_kind (Construct (in_punivs c))
71
75
let mkConstructUi ((ind ,u ),i ) = of_kind (Construct ((ind,i),u))
72
- let mkCase (ci , c , iv , r , p ) = of_kind (Case (ci, c, iv, r, p))
76
+ let mkCase (ci , u , pms , c , iv , r , p ) = of_kind (Case (ci, u, pms , c, iv, r, p))
73
77
let mkFix f = of_kind (Fix f)
74
78
let mkCoFix f = of_kind (CoFix f)
75
79
let mkProj (p , c ) = of_kind (Proj (p, c))
@@ -195,7 +199,7 @@ let destCoFix sigma c = match kind sigma c with
195
199
| _ -> raise DestKO
196
200
197
201
let destCase sigma c = match kind sigma c with
198
- | Case (ci , t , iv , c , p ) -> (ci, t, iv, c, p)
202
+ | Case (ci , u , pms , t , iv , c , p ) -> (ci, u, pms , t, iv, c, p)
199
203
| _ -> raise DestKO
200
204
201
205
let destProj sigma c = match kind sigma c with
@@ -320,19 +324,28 @@ let existential_type = Evd.existential_type
320
324
321
325
let lift n c = of_constr (Vars. lift n (unsafe_to_constr c))
322
326
323
- let map_under_context f n c =
324
- let f c = unsafe_to_constr (f (of_constr c)) in
325
- of_constr (Constr. map_under_context f n (unsafe_to_constr c))
326
- let map_branches f ci br =
327
- let f c = unsafe_to_constr (f (of_constr c)) in
328
- of_constr_array (Constr. map_branches f ci (unsafe_to_constr_array br))
329
- let map_return_predicate f ci p =
330
- let f c = unsafe_to_constr (f (of_constr c)) in
331
- of_constr (Constr. map_return_predicate f ci (unsafe_to_constr p))
327
+ let of_branches : Constr.case_branch array -> case_branch array =
328
+ match Evd.MiniEConstr. unsafe_eq with
329
+ | Refl -> fun x -> x
330
+
331
+ let unsafe_to_branches : case_branch array -> Constr.case_branch array =
332
+ match Evd.MiniEConstr. unsafe_eq with
333
+ | Refl -> fun x -> x
334
+
335
+ let of_return : Constr.case_return -> case_return =
336
+ match Evd.MiniEConstr. unsafe_eq with
337
+ | Refl -> fun x -> x
332
338
333
- let map_user_view sigma f c =
339
+ let unsafe_to_return : case_return -> Constr.case_return =
340
+ match Evd.MiniEConstr. unsafe_eq with
341
+ | Refl -> fun x -> x
342
+
343
+ let map_branches f br =
344
+ let f c = unsafe_to_constr (f (of_constr c)) in
345
+ of_branches (Constr. map_branches f (unsafe_to_branches br))
346
+ let map_return_predicate f p =
334
347
let f c = unsafe_to_constr (f (of_constr c)) in
335
- of_constr (Constr. map_user_view f (unsafe_to_constr (whd_evar sigma c) ))
348
+ of_return (Constr. map_return_predicate f (unsafe_to_return p ))
336
349
337
350
let map sigma f c =
338
351
let f c = unsafe_to_constr (f (of_constr c)) in
@@ -346,7 +359,49 @@ let iter sigma f c =
346
359
let f c = f (of_constr c) in
347
360
Constr. iter f (unsafe_to_constr (whd_evar sigma c))
348
361
349
- let iter_with_full_binders sigma g f n c =
362
+ let expand_case env _sigma (ci , u , pms , p , iv , c , bl ) =
363
+ let u = EInstance. unsafe_to_instance u in
364
+ let pms = unsafe_to_constr_array pms in
365
+ let p = unsafe_to_return p in
366
+ let iv = unsafe_to_case_invert iv in
367
+ let c = unsafe_to_constr c in
368
+ let bl = unsafe_to_branches bl in
369
+ let (ci, p, iv, c, bl) = Inductive. expand_case env (ci, u, pms, p, iv, c, bl) in
370
+ let p = of_constr p in
371
+ let c = of_constr c in
372
+ let iv = of_case_invert iv in
373
+ let bl = of_constr_array bl in
374
+ (ci, p, iv, c, bl)
375
+
376
+ let expand_branch env _sigma u pms (ind , i ) (nas , _br ) =
377
+ let open Declarations in
378
+ let u = EInstance. unsafe_to_instance u in
379
+ let pms = unsafe_to_constr_array pms in
380
+ let (mib, mip) = Inductive. lookup_mind_specif env ind in
381
+ let paramdecl = Vars. subst_instance_context u mib.mind_params_ctxt in
382
+ let paramsubst = Vars. subst_of_rel_context_instance paramdecl (Array. to_list pms) in
383
+ let subst = paramsubst @ Inductive. ind_subst (fst ind) mib u in
384
+ let (ctx, _) = mip.mind_nf_lc.(i - 1 ) in
385
+ let (ctx, _) = List. chop mip.mind_consnrealdecls.(i - 1 ) ctx in
386
+ let ans = Inductive. instantiate_context u subst nas ctx in
387
+ let ans : rel_context = match Evd.MiniEConstr. unsafe_eq with Refl -> ans in
388
+ ans
389
+
390
+ let contract_case env _sigma (ci , p , iv , c , bl ) =
391
+ let p = unsafe_to_constr p in
392
+ let iv = unsafe_to_case_invert iv in
393
+ let c = unsafe_to_constr c in
394
+ let bl = unsafe_to_constr_array bl in
395
+ let (ci, u, pms, p, iv, c, bl) = Inductive. contract_case env (ci, p, iv, c, bl) in
396
+ let u = EInstance. make u in
397
+ let pms = of_constr_array pms in
398
+ let p = of_return p in
399
+ let iv = of_case_invert iv in
400
+ let c = of_constr c in
401
+ let bl = of_branches bl in
402
+ (ci, u, pms, p, iv, c, bl)
403
+
404
+ let iter_with_full_binders env sigma g f n c =
350
405
let open Context.Rel.Declaration in
351
406
match kind sigma c with
352
407
| (Rel _ | Meta _ | Var _ | Sort _ | Const _ | Ind _
@@ -357,7 +412,10 @@ let iter_with_full_binders sigma g f n c =
357
412
| LetIn (na ,b ,t ,c ) -> f n b; f n t; f (g (LocalDef (na, b, t)) n) c
358
413
| App (c ,l ) -> f n c; Array.Fun1. iter f n l
359
414
| Evar (_ ,l ) -> List. iter (fun c -> f n c) l
360
- | Case (_ ,p ,iv ,c ,bl ) -> f n p; iter_invert (f n) iv; f n c; Array.Fun1. iter f n bl
415
+ | Case (ci ,u ,pms ,p ,iv ,c ,bl ) ->
416
+ (* FIXME: skip the type annotations *)
417
+ let (ci, p, iv, c, bl) = expand_case env sigma (ci, u, pms, p, iv, c, bl) in
418
+ f n p; iter_invert (f n) iv; f n c; Array.Fun1. iter f n bl
361
419
| Proj (p ,c ) -> f n c
362
420
| Fix (_ ,(lna ,tl ,bl )) ->
363
421
Array. iter (f n) tl;
@@ -566,9 +624,13 @@ let universes_of_constr sigma c =
566
624
| Array (u ,_ ,_ ,_ ) ->
567
625
let s = LSet. fold LSet. add (Instance. levels (EInstance. kind sigma u)) s in
568
626
fold sigma aux s c
569
- | Case (_ ,_ ,CaseInvert {univs;args =_ } ,_ ,_ ) ->
627
+ | Case (_ ,u ,_ ,_ ,CaseInvert {univs;args =_ } ,_ ,_ ) ->
628
+ let s = LSet. fold LSet. add (Instance. levels (EInstance. kind sigma u)) s in
570
629
let s = LSet. fold LSet. add (Instance. levels (EInstance. kind sigma univs)) s in
571
630
fold sigma aux s c
631
+ | Case (_ , u , _ , _ , NoInvert, _ , _ ) ->
632
+ let s = LSet. fold LSet. add (Instance. levels (EInstance. kind sigma u)) s in
633
+ fold sigma aux s c
572
634
| _ -> fold sigma aux s c
573
635
in aux LSet. empty c
574
636
0 commit comments