X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Ftactics%2FprimitiveTactics.ml;h=55b9d2e420ec8def3d11fd93902dfe1bb320486c;hb=09cfe0657d77c16be2cc1974cb5242939f1d98fb;hp=5c187b05367c92eecd6241b4db3378531b245fc1;hpb=f4b9cc6f689b52e0408ac3231ba2a480d71216fb;p=helm.git diff --git a/helm/ocaml/tactics/primitiveTactics.ml b/helm/ocaml/tactics/primitiveTactics.ml index 5c187b053..55b9d2e42 100644 --- a/helm/ocaml/tactics/primitiveTactics.ml +++ b/helm/ocaml/tactics/primitiveTactics.ml @@ -37,13 +37,13 @@ exception WrongUriToVariable of string (* and [bo] = Lambda/LetIn [context].(Meta [newmeta]) *) (* So, lambda_abstract is the core of the implementation of *) (* the Intros tactic. *) -let lambda_abstract context newmeta ty mk_fresh_name = +let lambda_abstract metasenv context newmeta ty mk_fresh_name = let module C = Cic in let rec collect_context context = function C.Cast (te,_) -> collect_context context te | C.Prod (n,s,t) -> - let n' = mk_fresh_name context n ~typ:s in + let n' = mk_fresh_name metasenv context n ~typ:s in let (context',ty,bo) = collect_context ((Some (n',(C.Decl s)))::context) t in @@ -74,7 +74,7 @@ let eta_expand metasenv context t arg = C.Var (uri,exp_named_subst') | C.Meta _ | C.Sort _ - | C.Implicit as t -> t + | C.Implicit _ as t -> t | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty) | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t) | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t) @@ -115,7 +115,8 @@ let eta_expand metasenv context t arg = T.type_of_aux' metasenv context arg in let fresh_name = - ProofEngineHelpers.mk_fresh_name context (Cic.Name "Heta") ~typ:argty + FreshNamesGenerator.mk_fresh_name + metasenv context (Cic.Name "Heta") ~typ:argty in (C.Appl [C.Lambda (fresh_name,argty,aux 0 t) ; arg]) @@ -159,6 +160,21 @@ let new_metasenv_for_apply newmeta proof context ty = let rec aux newmeta = function C.Cast (he,_) -> aux newmeta he + (* If the expected type is a Type, then also Set is OK ==> + * we accept any term of type Type *) + (*CSC: BUG HERE: in this way it is possible for the term of + * type Type to be different from a Sort!!! *) + | C.Prod (name,(C.Sort C.Type as s),t) -> + let irl = + CicMkImplicit.identity_relocation_list_for_metavariable context + in + let newargument = C.Meta (newmeta+1,irl) in + let (res,newmetasenv,arguments,lastmeta) = + aux (newmeta + 2) (S.subst newargument t) + in + res, + (newmeta,[],s)::(newmeta+1,context,C.Meta (newmeta,[]))::newmetasenv, + newargument::arguments,lastmeta | C.Prod (name,s,t) -> let irl = CicMkImplicit.identity_relocation_list_for_metavariable context @@ -201,15 +217,30 @@ let CicSubstitution.subst_vars !exp_named_subst_diff ty | _ -> raise (WrongUriToVariable (UriManager.string_of_uri uri)) in - let irl = - CicMkImplicit.identity_relocation_list_for_metavariable context - in - let subst_item = uri,C.Meta (!next_fresh_meta,irl) in - newmetasenvfragment := - (!next_fresh_meta,context,ty)::!newmetasenvfragment ; - exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ; - incr next_fresh_meta ; - subst_item::(aux (tl,[])) + (match ty with + C.Sort C.Type as s -> + let irl = + CicMkImplicit.identity_relocation_list_for_metavariable context + in + let fresh_meta = !next_fresh_meta in + let fresh_meta' = fresh_meta + 1 in + next_fresh_meta := !next_fresh_meta + 2 ; + let subst_item = uri,C.Meta (fresh_meta',irl) in + newmetasenvfragment := + (fresh_meta,[],C.Sort C.Type) :: + (fresh_meta',[],C.Meta (fresh_meta,[])) :: !newmetasenvfragment ; + exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ; + subst_item::(aux (tl,[])) + | _ -> + let irl = + CicMkImplicit.identity_relocation_list_for_metavariable context + in + let subst_item = uri,C.Meta (!next_fresh_meta,irl) in + newmetasenvfragment := + (!next_fresh_meta,context,ty)::!newmetasenvfragment ; + exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ; + incr next_fresh_meta ; + subst_item::(aux (tl,[]))) | uri::tl1,((uri',_) as s)::tl2 -> assert (UriManager.eq uri uri') ; s::(aux (tl1,tl2)) @@ -219,7 +250,6 @@ let !exp_named_subst_diff,!next_fresh_meta, List.rev !newmetasenvfragment, exp_named_subst' in -prerr_endline ("@@@ " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst)) ^ " |--> " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst'))) ; new_fresh_meta,newmetasenvfragment,exp_named_subst',exp_named_subst_diff ;; @@ -264,19 +294,17 @@ let apply_tac ~term ~status:(proof, goal) = | _ -> [],newmeta,[],term in let metasenv' = metasenv@newmetasenvfragment in -prerr_endline ("^^^^^TERM': " ^ CicPp.ppterm term') ; let termty = CicSubstitution.subst_vars exp_named_subst_diff (CicTypeChecker.type_of_aux' metasenv' context term) in -prerr_endline ("^^^^^TERMTY: " ^ CicPp.ppterm termty) ; (* newmeta is the lowest index of the new metas introduced *) let (consthead,newmetas,arguments,_) = new_metasenv_for_apply newmeta' proof context termty in let newmetasenv = metasenv'@newmetas in let subst,newmetasenv' = - CicUnification.fo_unif newmetasenv context consthead ty + CicUnification.fo_unif newmetasenv context consthead ty in let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in let apply_subst = CicMetaSubst.apply_subst subst in @@ -293,7 +321,6 @@ prerr_endline ("^^^^^TERMTY: " ^ CicPp.ppterm termty) ; Cic.Appl (term'::arguments) ) in -prerr_endline ("XXXX " ^ CicPp.ppterm (if List.length newmetas = 0 then term' else Cic.Appl (term'::arguments)) ^ " |>>> " ^ CicPp.ppterm bo') ; let newmetasenv'' = new_uninstantiatedmetas@old_uninstantiatedmetas in let (newproof, newmetasenv''') = let subst_in = CicMetaSubst.apply_subst ((metano,bo')::subst) in @@ -312,7 +339,7 @@ let apply_tac ~term ~status = raise (Fail (Printexc.to_string e)) let intros_tac - ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name) () + ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name) () ~status:(proof, goal) = let module C = Cic in @@ -321,7 +348,7 @@ let intros_tac let metano,context,ty = CicUtil.lookup_meta goal metasenv in let newmeta = new_meta_of_proof ~proof in let (context',ty',bo') = - lambda_abstract context newmeta ty mk_fresh_name_callback + lambda_abstract metasenv context newmeta ty mk_fresh_name_callback in let (newproof, _) = subst_meta_in_proof proof metano bo' [newmeta,context',ty'] @@ -329,7 +356,7 @@ let intros_tac (newproof, [newmeta]) let cut_tac - ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name) + ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name) term ~status:(proof, goal) = let module C = Cic in @@ -338,7 +365,7 @@ let cut_tac let newmeta1 = new_meta_of_proof ~proof in let newmeta2 = newmeta1 + 1 in let fresh_name = - mk_fresh_name_callback context (Cic.Name "Hcut") ~typ:term in + mk_fresh_name_callback metasenv context (Cic.Name "Hcut") ~typ:term in let context_for_newmeta1 = (Some (fresh_name,C.Decl term))::context in let irl1 = @@ -361,7 +388,7 @@ let cut_tac (newproof, [newmeta1 ; newmeta2]) let letin_tac - ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name) + ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name) term ~status:(proof, goal) = let module C = Cic in @@ -370,7 +397,7 @@ let letin_tac let _ = CicTypeChecker.type_of_aux' metasenv context term in let newmeta = new_meta_of_proof ~proof in let fresh_name = - mk_fresh_name_callback context (Cic.Name "Hletin") ~typ:term in + mk_fresh_name_callback metasenv context (Cic.Name "Hletin") ~typ:term in let context_for_newmeta = (Some (fresh_name,C.Def (term,None)))::context in let irl =