diff options
| author | Pierre-Marie Pédrot | 2018-05-23 19:45:22 +0200 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2018-11-20 16:10:54 +0100 |
| commit | 2d81a99e14d32f9f79ae617986148db3a36707e7 (patch) | |
| tree | 79ee8b75e8e910d92674d6bb56bd9c057be45345 /kernel/typeops.ml | |
| parent | 82f7c721ea066a4776be09bd40444cf491f3659e (diff) | |
More efficient implementation of type_of_apply.
Diffstat (limited to 'kernel/typeops.ml')
| -rw-r--r-- | kernel/typeops.ml | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/kernel/typeops.ml b/kernel/typeops.ml index c8fd83c8a9..956e5f7947 100644 --- a/kernel/typeops.ml +++ b/kernel/typeops.ml @@ -152,27 +152,33 @@ let make_judgev c t = Array.map2 make_judge c t let type_of_apply env func funt argsv argstv = + let open CClosure in let len = Array.length argsv in - let rec apply_rec i typ = - if Int.equal i len then typ - else - (match kind (whd_all env typ) with - | Prod (_,c1,c2) -> - let arg = argsv.(i) and argt = argstv.(i) in - (try - let () = conv_leq false env argt c1 in - apply_rec (i+1) (subst1 arg c2) - with NotConvertible -> - error_cant_apply_bad_type env - (i+1,c1,argt) - (make_judge func funt) - (make_judgev argsv argstv)) - + let infos = create_clos_infos all env in + let tab = create_tab () in + let rec apply_rec i typ = + if Int.equal i len then term_of_fconstr typ + else + let typ, _ = whd_stack infos tab typ [] in + match fterm_of typ with + | FProd (_, c1, c2, e) -> + let arg = argsv.(i) in + let argt = argstv.(i) in + let c1 = term_of_fconstr (mk_clos e c1) in + begin match conv_leq false env argt c1 with + | () -> apply_rec (i+1) (mk_clos (Esubst.subs_cons ([| inject arg |], e)) c2) + | exception NotConvertible -> + error_cant_apply_bad_type env + (i+1,c1,argt) + (make_judge func funt) + (make_judgev argsv argstv) + end | _ -> - error_cant_apply_not_functional env - (make_judge func funt) - (make_judgev argsv argstv)) - in apply_rec 0 funt + error_cant_apply_not_functional env + (make_judge func funt) + (make_judgev argsv argstv) + in + apply_rec 0 (inject funt) (* Type of product *) |
