1 (* Copyright (C) 2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 open DisambiguateTypes
31 exception No_choices of domain_item
32 exception NoWellTypedInterpretation
33 exception PathNotWellFormed
35 (** raised when an environment is not enough informative to decide *)
39 let debug_print = if debug then prerr_endline else ignore
42 (** print benchmark information *)
44 let max_refinements = ref 0 (* benchmarking is not thread safe *)
45 let actual_refinements = ref 0
46 let domain_size = ref 0
47 let choices_avg = ref 0.
50 let descr_of_domain_item = function
53 | Num i -> string_of_int i
56 | Ok of 'a * Cic.metasenv
60 let refine_term metasenv context uri term ugraph =
61 (* if benchmark then incr actual_refinements; *)
64 CicMkImplicit.expand_implicits metasenv [] context term in
65 debug_print (sprintf "TEST_INTERPRETATION: %s" (CicPp.ppterm term));
67 let term', _, metasenv',ugraph1 =
68 CicRefine.type_of_aux' metasenv context term ugraph in
69 (Ok (term', metasenv')),ugraph1
71 | CicRefine.Uncertain s ->
72 debug_print ("UNCERTAIN!!! [" ^ s ^ "] " ^ CicPp.ppterm term) ;
74 | CicRefine.RefineFailure msg ->
75 debug_print (sprintf "PRUNED!!!\nterm%s\nmessage:%s"
76 (CicPp.ppterm term) msg);
79 let refine_obj metasenv context uri obj ugraph =
80 assert (context = []);
81 let metasenv, obj = CicMkImplicit.expand_implicits_in_obj metasenv [] obj in
82 debug_print (sprintf "TEST_INTERPRETATION: %s" (CicPp.ppobj obj));
84 let obj', metasenv,ugraph = CicRefine.typecheck metasenv uri obj in
85 (Ok (obj', metasenv)),ugraph
87 | CicRefine.Uncertain s ->
88 debug_print ("UNCERTAIN!!! [" ^ s ^ "] " ^ CicPp.ppobj obj) ;
90 | CicRefine.RefineFailure msg ->
91 debug_print (sprintf "PRUNED!!!\nterm%s\nmessage:%s"
92 (CicPp.ppobj obj) msg);
95 let resolve (env: environment) (item: domain_item) ?(num = "") ?(args = []) () =
97 snd (Environment.find item env) env num args
99 failwith ("Domain item not found: " ^
100 (DisambiguateTypes.string_of_domain_item item))
102 (* TODO move it to Cic *)
103 let find_in_environment name context =
104 let rec aux acc = function
105 | [] -> raise Not_found
106 | Cic.Name hd :: tl when hd = name -> acc
107 | _ :: tl -> aux (acc + 1) tl
111 let interpretate_term ~context ~env ~uri ~is_path ast =
113 let rec aux loc context = function
114 | CicAst.AttributedTerm (`Loc loc, term) ->
116 | CicAst.AttributedTerm (_, term) -> aux loc context term
117 | CicAst.Appl (CicAst.Symbol (symb, i) :: args) ->
118 let cic_args = List.map (aux loc context) args in
119 resolve env (Symbol (symb, i)) ~args:cic_args ()
120 | CicAst.Appl terms -> Cic.Appl (List.map (aux loc context) terms)
121 | CicAst.Binder (binder_kind, (var, typ), body) ->
122 let cic_type = aux_option loc context typ in
123 let cic_body = aux loc (var :: context) body in
124 (match binder_kind with
125 | `Lambda -> Cic.Lambda (var, cic_type, cic_body)
126 | `Pi | `Forall -> Cic.Prod (var, cic_type, cic_body)
128 resolve env (Symbol ("exists", 0))
129 ~args:[ cic_type; Cic.Lambda (var, cic_type, cic_body) ] ())
130 | CicAst.Case (term, indty_ident, outtype, branches) ->
131 let cic_term = aux loc context term in
132 let cic_outtype = aux_option loc context outtype in
133 let do_branch ((head, args), term) =
134 let rec do_branch' context = function
135 | [] -> aux loc context term
136 | (name, typ) :: tl ->
137 let cic_body = do_branch' (name :: context) tl in
140 | None -> Cic.Implicit (Some `Type)
141 | Some typ -> aux loc context typ
143 Cic.Lambda (name, typ, cic_body)
145 do_branch' context args
147 let (indtype_uri, indtype_no) =
148 match indty_ident with
149 | Some indty_ident ->
150 (match resolve env (Id indty_ident) () with
151 | Cic.MutInd (uri, tyno, _) -> (uri, tyno)
152 | Cic.Implicit _ -> raise Try_again
153 | _ -> raise DisambiguateChoices.Invalid_choice)
155 let fst_constructor =
157 | ((head, _), _) :: _ -> head
158 | [] -> raise DisambiguateChoices.Invalid_choice
160 (match resolve env (Id fst_constructor) () with
161 | Cic.MutConstruct (indtype_uri, indtype_no, _, _) ->
162 (indtype_uri, indtype_no)
163 | Cic.Implicit _ -> raise Try_again
164 | _ -> raise DisambiguateChoices.Invalid_choice)
166 Cic.MutCase (indtype_uri, indtype_no, cic_outtype, cic_term,
167 (List.map do_branch branches))
168 | CicAst.LetIn ((name, typ), def, body) ->
169 let cic_def = aux loc context def in
173 | Some t -> Cic.Cast (cic_def, aux loc context t)
175 let cic_body = aux loc (name :: context) body in
176 Cic.LetIn (name, cic_def, cic_body)
177 | CicAst.LetRec (kind, defs, body) ->
179 List.fold_left (fun acc ((name, _), _, _) -> name :: acc)
182 let cic_body = aux loc context' body in
185 (fun ((name, typ), body, decr_idx) ->
186 let cic_body = aux loc context' body in
187 let cic_type = aux_option loc context typ in
191 CicTextualParser2.fail loc
192 "Recursive functions cannot be anonymous"
193 | Cic.Name name -> name
195 (name, decr_idx, cic_type, cic_body))
198 let counter = ref ~-1 in
199 let build_term funs =
200 (* this is the body of the fold_right function below. Rationale: Fix
201 * and CoFix cases differs only in an additional index in the
202 * inductiveFun list, see Cic.term *)
205 (fun (var, _, _, _) cic ->
207 Cic.LetIn (Cic.Name var, Cic.Fix (!counter, funs), cic))
210 List.map (fun (name, _, typ, body) -> (name, typ, body)) funs
212 (fun (var, _, _, _) cic ->
214 Cic.LetIn (Cic.Name var, Cic.CoFix (!counter, funs), cic))
216 List.fold_right (build_term inductiveFuns) inductiveFuns cic_body
218 | CicAst.Uri _ when is_path -> raise PathNotWellFormed
219 | CicAst.Ident (name, subst)
220 | CicAst.Uri (name, subst) as ast ->
221 let is_uri = function CicAst.Uri _ -> true | _ -> false in
223 if is_uri ast then raise Not_found;(* don't search the env for URIs *)
224 let index = find_in_environment name context in
225 if subst <> None then
226 CicTextualParser2.fail loc
227 "Explicit substitutions not allowed here";
231 if is_uri ast then (* we have the URI, build the term out of it *)
233 CicUtil.term_of_uri name
234 with UriManager.IllFormedUri _ ->
235 CicTextualParser2.fail loc "Ill formed URI"
237 resolve env (Id name) ()
241 List.map (fun uri -> UriManager.name_of_uri uri, uri) uris
248 List.assoc s ids_to_uris, aux loc context term
250 raise DisambiguateChoices.Invalid_choice))
252 | None -> List.map (fun uri -> uri, Cic.Implicit None) uris)
256 | Cic.Const (uri, []) ->
257 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
258 let uris = CicUtil.params_of_obj o in
259 Cic.Const (uri, mk_subst uris)
260 | Cic.Var (uri, []) ->
261 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
262 let uris = CicUtil.params_of_obj o in
263 Cic.Var (uri, mk_subst uris)
264 | Cic.MutInd (uri, i, []) ->
266 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
267 let uris = CicUtil.params_of_obj o in
268 Cic.MutInd (uri, i, mk_subst uris)
270 CicEnvironment.Object_not_found _ ->
271 (* if we are here it is probably the case that during the
272 definition of a mutual inductive type we have met an
273 occurrence of the type in one of its constructors.
274 However, the inductive type is not yet in the environment
276 (*here the explicit_named_substituion is assumed to be of length 0 *)
277 Cic.MutInd (uri,i,[]))
278 | Cic.MutConstruct (uri, i, j, []) ->
279 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
280 let uris = CicUtil.params_of_obj o in
281 Cic.MutConstruct (uri, i, j, mk_subst uris)
282 | Cic.Meta _ | Cic.Implicit _ as t ->
285 "Warning: %s must be instantiated with _[%s] but we do not enforce it"
289 (fun (s, term) -> s ^ " := " ^ CicAstPp.pp_term term)
294 raise DisambiguateChoices.Invalid_choice
296 CicEnvironment.CircularDependency _ ->
297 raise DisambiguateChoices.Invalid_choice))
298 | CicAst.Implicit -> Cic.Implicit None
299 | CicAst.UserInput -> Cic.Implicit (Some `Hole)
300 | CicAst.Num (num, i) -> resolve env (Num i) ~num ()
301 | CicAst.Meta (index, subst) ->
304 (function None -> None | Some term -> Some (aux loc context term))
307 Cic.Meta (index, cic_subst)
308 | CicAst.Sort `Prop -> Cic.Sort Cic.Prop
309 | CicAst.Sort `Set -> Cic.Sort Cic.Set
310 | CicAst.Sort `Type -> Cic.Sort (Cic.Type (CicUniv.fresh())) (* TASSI *)
311 | CicAst.Sort `CProp -> Cic.Sort Cic.CProp
312 | CicAst.Symbol (symbol, instance) ->
313 resolve env (Symbol (symbol, instance)) ()
314 and aux_option loc context = function
315 | None -> Cic.Implicit (Some `Type)
316 | Some term -> aux loc context term
319 | CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
320 | term -> aux CicAst.dummy_floc context term
322 let interpretate_path ~context ~env path =
323 interpretate_term ~context ~env ~uri:None ~is_path:true path
325 let interpretate_obj ~context ~env ~uri ~is_path obj =
326 assert (context = []);
327 assert (is_path = false);
329 | TacticAst.Inductive (params,tyl) ->
330 let uri = match uri with Some uri -> uri | None -> assert false in
334 (fun (context,res) (name,t) ->
335 (Cic.Name name)::context,
336 (name, interpretate_term context env None false t)::res
339 context,List.rev res in
342 (fun (name,ty) t -> Cic.Prod (Cic.Name name,ty,t)) params in
346 (*here the explicit_named_substituion is assumed to be of length 0 *)
347 (fun (i,res) (name,_,_,_) ->
348 i + 1,(name,name,Cic.MutInd (uri,i,[]))::res
350 let con_env = DisambiguateTypes.env_of_list name_to_uris env in
354 (fun (name,_,_,_) (i,t) ->
355 (*here the explicit_named_substituion is assumed to be of length 0 *)
356 let t' = Cic.MutInd (uri,i,[]) in
357 let t = CicSubstitution.subst t' t in
359 ) tyl (List.length tyl - 1,t)) in
362 (fun (name,b,ty,cl) ->
363 let ty' = add_params (interpretate_term context env None false ty) in
368 add_params (interpretate_term context con_env None false ty)
376 Cic.InductiveDefinition (tyl,[],List.length params,[])
377 | TacticAst.Record (params,name,ty,fields) ->
378 let uri = match uri with Some uri -> uri | None -> assert false in
382 (fun (context,res) (name,t) ->
383 (Cic.Name name)::context,
384 (name, interpretate_term context env None false t)::res
387 context,List.rev res in
390 (fun (name,ty) t -> Cic.Prod (Cic.Name name,ty,t)) params in
391 let ty' = add_params (interpretate_term context env None false ty) in
395 (fun (context,res) (name,ty) ->
396 let context' = (Cic.Name name)::context in
397 context',(name,interpretate_term context env None false ty)::res
398 ) (context,[]) fields) in
400 (*here the explicit_named_substituion is assumed to be of length 0 *)
401 let mutind = Cic.MutInd (uri,0,[]) in
402 if params = [] then mutind
403 else Cic.Appl (mutind::CicUtil.mk_rels (List.length params) (List.length fields)) in
406 (fun t (name,ty) -> Cic.Prod (Cic.Name name,ty,t))
408 let con' = add_params con in
409 let tyl = [name,true,ty',["mk_" ^ name,con']] in
410 Cic.InductiveDefinition (tyl,[],List.length params,[`Class `Record])
411 | TacticAst.Theorem (_,name,ty,bo) ->
412 let ty' = interpretate_term [] env None false ty in
415 Cic.CurrentProof (name,[],Cic.Implicit None,ty',[],[])
417 let bo' = Some (interpretate_term [] env None false bo) in
418 Cic.Constant (name,bo',ty',[],[])
420 (* e.g. [5;1;1;1;2;3;4;1;2] -> [2;1;4;3;5] *)
422 let module SortedItem =
424 type t = DisambiguateTypes.domain_item
425 let compare = Pervasives.compare
428 let module Set = Set.Make (SortedItem) in
430 let rev_l = List.rev l in
431 let (_, uniq_rev_l) =
433 (fun (members, rev_l) elt ->
434 if Set.mem elt members then
437 Set.add elt members, elt :: rev_l)
438 (Set.empty, []) rev_l
442 (* "aux" keeps domain in reverse order and doesn't care about duplicates.
443 * Domain item more in deep in the list will be processed first.
445 let rec domain_rev_of_term ?(loc = CicAst.dummy_floc) context = function
446 | CicAst.AttributedTerm (`Loc loc, term) ->
447 domain_rev_of_term ~loc context term
448 | CicAst.AttributedTerm (_, term) -> domain_rev_of_term ~loc context term
449 | CicAst.Appl terms ->
451 (fun dom term -> domain_rev_of_term ~loc context term @ dom) [] terms
452 | CicAst.Binder (kind, (var, typ), body) ->
455 | `Exists -> [ Symbol ("exists", 0) ]
458 let type_dom = domain_rev_of_term_option loc context typ in
459 let body_dom = domain_rev_of_term ~loc (var :: context) body in
460 body_dom @ type_dom @ kind_dom
461 | CicAst.Case (term, indty_ident, outtype, branches) ->
462 let term_dom = domain_rev_of_term ~loc context term in
463 let outtype_dom = domain_rev_of_term_option loc context outtype in
464 let get_first_constructor = function
466 | ((head, _), _) :: _ -> [ Id head ]
468 let do_branch ((head, args), term) =
469 let (term_context, args_domain) =
471 (fun (cont, dom) (name, typ) ->
475 | Some typ -> domain_rev_of_term ~loc cont typ @ dom)))
478 args_domain @ domain_rev_of_term ~loc term_context term
481 List.fold_left (fun dom branch -> do_branch branch @ dom) [] branches
483 branches_dom @ outtype_dom @ term_dom @
484 (match indty_ident with
485 | None -> get_first_constructor branches
486 | Some ident -> [ Id ident ])
487 | CicAst.LetIn ((var, typ), body, where) ->
488 let body_dom = domain_rev_of_term ~loc context body in
489 let type_dom = domain_rev_of_term_option loc context typ in
490 let where_dom = domain_rev_of_term ~loc (var :: context) where in
491 where_dom @ type_dom @ body_dom
492 | CicAst.LetRec (kind, defs, where) ->
494 List.fold_left (fun acc ((var, typ), _, _) -> var :: acc)
497 let where_dom = domain_rev_of_term ~loc context' where in
500 (fun dom ((_, typ), body, _) ->
501 domain_rev_of_term ~loc context' body @
502 domain_rev_of_term_option loc context typ)
506 | CicAst.Ident (name, subst) ->
508 let index = find_in_environment name context in
509 if subst <> None then
510 CicTextualParser2.fail loc
511 "Explicit substitutions not allowed here"
519 (fun dom (_, term) ->
520 let dom' = domain_rev_of_term ~loc context term in
524 | CicAst.Implicit -> []
525 | CicAst.Num (num, i) -> [ Num i ]
526 | CicAst.Meta (index, local_context) ->
528 (fun dom term -> domain_rev_of_term_option loc context term @ dom) []
530 | CicAst.Sort _ -> []
531 | CicAst.Symbol (symbol, instance) -> [ Symbol (symbol, instance) ]
532 | CicAst.UserInput -> assert false
534 and domain_rev_of_term_option loc context = function
536 | Some t -> domain_rev_of_term ~loc context t
538 let domain_of_term ~context ast =
539 rev_uniq (domain_rev_of_term context ast)
541 let domain_of_obj ~context ast =
542 assert (context = []);
545 | TacticAst.Theorem (_,_,ty,bo) ->
548 | Some bo -> domain_rev_of_term [] bo) @
550 | TacticAst.Inductive (params,tyl) ->
557 (fun (_,ty) -> domain_rev_of_term [] ty) cl) @
558 domain_rev_of_term [] ty) tyl)
562 not ( List.exists (fun (name',_) -> name = Id name') params
563 || List.exists (fun (name',_,_,_) -> name = Id name') tyl)
565 | TacticAst.Record (params,_,ty,fields) ->
568 (List.rev_map (fun (_,ty) -> domain_rev_of_term [] ty) fields) in
572 not ( List.exists (fun (name',_) -> name = Id name') params
573 || List.exists (fun (name',_) -> name = Id name') fields)
576 dom' @ domain_rev_of_term [] ty
581 let domain_diff dom1 dom2 =
582 (* let domain_diff = Domain.diff *)
584 List.fold_left (fun pred elt -> (fun elt' -> elt' = elt || pred elt'))
585 (fun _ -> false) dom2
587 List.filter (fun elt -> not (is_in_dom2 elt)) dom1
589 module type Disambiguator =
591 val disambiguate_term :
593 context:Cic.context ->
594 metasenv:Cic.metasenv ->
595 ?initial_ugraph:CicUniv.universe_graph ->
596 aliases:environment -> (* previous interpretation status *)
598 (environment * (* new interpretation status *)
599 Cic.metasenv * (* new metasenv *)
601 CicUniv.universe_graph) list (* disambiguated term *)
603 val disambiguate_obj :
605 aliases:environment -> (* previous interpretation status *)
606 uri:UriManager.uri option -> (* required only for inductive types *)
608 (environment * (* new interpretation status *)
609 Cic.metasenv * (* new metasenv *)
611 CicUniv.universe_graph) list (* disambiguated obj *)
614 module Make (C: Callbacks) =
616 let choices_of_id dbd id =
617 let uris = MetadataQuery.locate ~dbd id in
621 [UriManager.string_of_uri (C.input_or_locate_uri
622 ~title:("URI matching \"" ^ id ^ "\" unknown.") ~id ())]
625 C.interactive_user_uri_choice ~selection_mode:`MULTIPLE
626 ~ok:"Try selected." ~enable_button_for_non_vars:true
627 ~title:"Ambiguous input." ~id
628 ~msg: ("Ambiguous input \"" ^ id ^
629 "\". Please, choose one or more interpretations:")
637 CicUtil.term_of_uri uri
640 debug_print (Printexc.to_string exn);
646 let disambiguate_thing ~dbd ~context ~metasenv
647 ?(initial_ugraph = CicUniv.empty_ugraph) ~aliases:current_env
648 ~uri ~pp_thing ~domain_of_thing ~interpretate_thing ~refine_thing thing
650 debug_print "NEW DISAMBIGUATE INPUT";
651 let disambiguate_context = (* cic context -> disambiguate context *)
653 (function None -> Cic.Anonymous | Some (name, _) -> name)
656 debug_print ("TERM IS: " ^ (pp_thing thing));
657 let thing_dom = domain_of_thing ~context:disambiguate_context thing in
658 debug_print (sprintf "DISAMBIGUATION DOMAIN: %s"
659 (string_of_domain thing_dom));
661 Environment.fold (fun item _ dom -> item :: dom) current_env []
663 let todo_dom = domain_diff thing_dom current_dom in
664 (* (2) lookup function for any item (Id/Symbol/Num) *)
666 let id_choices = Hashtbl.create 1023 in
672 Hashtbl.find id_choices id
674 let choices = choices_of_id dbd id in
675 Hashtbl.add id_choices id choices;
677 | Symbol (symb, _) -> DisambiguateChoices.lookup_symbol_choices symb
678 | Num instance -> DisambiguateChoices.lookup_num_choices ()
680 if choices = [] then raise (No_choices item);
687 if benchmark then begin
688 let per_item_choices =
692 let len = List.length (lookup_choices dom_item) in
693 debug_print (sprintf "BENCHMARK %s: %d"
694 (string_of_domain_item dom_item) len);
696 with No_choices _ -> 0)
699 max_refinements := List.fold_left ( * ) 1 per_item_choices;
700 actual_refinements := 0;
701 domain_size := List.length thing_dom;
703 (float_of_int !max_refinements) ** (1. /. float_of_int !domain_size)
709 (* (3) test an interpretation filling with meta uninterpreted identifiers
711 let test_env current_env todo_dom ugraph =
718 | Id _ | Num _ -> (fun _ _ _ -> Cic.Implicit (Some `Closed))
719 | Symbol _ -> (fun _ _ _ -> Cic.Implicit None))) env)
724 interpretate_thing ~context:disambiguate_context ~env:filled_env
725 ~uri ~is_path:false thing
727 let k,ugraph1 = refine_thing metasenv context uri cic_thing ugraph in
730 | Try_again -> Uncertain,ugraph
731 | DisambiguateChoices.Invalid_choice -> Ko,ugraph
733 (* (4) build all possible interpretations *)
734 let rec aux current_env todo_dom base_univ =
737 (match test_env current_env [] base_univ with
738 | Ok (thing, metasenv),new_univ ->
739 [ current_env, metasenv, thing, new_univ ]
740 | Ko,_ | Uncertain,_ -> [])
741 | item :: remaining_dom ->
742 debug_print (sprintf "CHOOSED ITEM: %s"
743 (string_of_domain_item item));
744 let choices = lookup_choices item in
745 let rec filter univ = function
747 | codomain_item :: tl ->
748 debug_print (sprintf "%s CHOSEN" (fst codomain_item)) ;
750 Environment.add item codomain_item current_env
752 (match test_env new_env remaining_dom univ with
753 | Ok (thing, metasenv),new_univ ->
754 (match remaining_dom with
755 | [] -> [ new_env, metasenv, thing, new_univ ]
756 | _ -> aux new_env remaining_dom new_univ )@
758 | Uncertain,new_univ ->
759 (match remaining_dom with
761 | _ -> aux new_env remaining_dom new_univ )@
763 | Ko,_ -> filter univ tl)
765 filter base_univ choices
767 let base_univ = initial_ugraph in
770 match aux current_env todo_dom base_univ with
771 | [] -> raise NoWellTypedInterpretation
772 | [ e,me,t,u ] as l ->
773 debug_print "UNA SOLA SCELTA";
776 debug_print (sprintf "PIU' SCELTE (%d)" (List.length l));
779 (fun (env, _, _, _) ->
783 fst (Environment.find domain_item env)
785 (descr_of_domain_item domain_item, description))
789 let choosed = C.interactive_interpretation_choice choices in
790 List.map (List.nth l) choosed
794 let res_size = List.length res in
796 ("BENCHMARK: %d/%d refinements performed, domain size %d, interps %d, k %.2f\n" ^^
797 "BENCHMARK: estimated %.2f")
798 !actual_refinements !max_refinements !domain_size res_size
800 (float_of_int (!domain_size - 1) *. !choices_avg *. (float_of_int res_size) +. !choices_avg)));
804 CicEnvironment.CircularDependency s ->
805 failwith "Disambiguate: circular dependency"
807 let disambiguate_term ~dbd ~context ~metasenv
808 ?(initial_ugraph = CicUniv.empty_ugraph) ~aliases term
810 disambiguate_thing ~dbd ~context ~metasenv ~initial_ugraph ~aliases
811 ~uri:None ~pp_thing:CicAstPp.pp_term ~domain_of_thing:domain_of_term
812 ~interpretate_thing:interpretate_term ~refine_thing:refine_term term
814 let disambiguate_obj ~dbd ~aliases ~uri obj =
815 disambiguate_thing ~dbd ~context:[] ~metasenv:[] ~aliases ~uri
816 ~pp_thing:TacticAstPp.pp_obj ~domain_of_thing:domain_of_obj
817 ~interpretate_thing:interpretate_obj ~refine_thing:refine_obj
823 exception Ambiguous_term of string
827 let interactive_user_uri_choice ~selection_mode ?ok
828 ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
830 let interactive_interpretation_choice interp = raise Exit
831 let input_or_locate_uri ~(title:string) ?id = raise Exit
833 module Disambiguator = Make (Callbacks)
834 let disambiguate_string ~dbd ?(context=[]) ?(metasenv=[]) ?initial_ugraph
835 ?(aliases=DisambiguateTypes.Environment.empty) term =
836 let ast = CicTextualParser2.parse_term (Stream.of_string term) in
838 Disambiguator.disambiguate_term ~dbd ~context ~metasenv ast
839 ?initial_ugraph ~aliases
840 with Exit -> raise (Ambiguous_term term)